Skip to content

Commit 918ab2b

Browse files
committed
fix device conditionally offline bug.
1 parent a7d21d9 commit 918ab2b

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

pkg/mqtt/connection.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,6 @@ func (c *Connection) RcvMsgFromClient() {
190190
AccessRPCHost: server.GetRPCHost(),
191191
HeartbeatInterval: uint32(c.KeepAlive),
192192
}
193-
err = c.Mgr.Provider.OnDeviceOnline(args)
194-
if err != nil {
195-
server.Log.Warn("device online error : %v", err)
196-
c.Close()
197-
return
198-
}
199193

200194
c.Mgr.AddConn(c.DeviceId, c)
201195
connack := &ConnAck{
@@ -204,7 +198,15 @@ func (c *Connection) RcvMsgFromClient() {
204198

205199
c.Submit(connack)
206200
c.KeepAlive = msg.KeepAliveTimer
207-
server.Log.Infof("%s, connected to server now", host)
201+
202+
err = c.Mgr.Provider.OnDeviceOnline(args)
203+
if err != nil {
204+
server.Log.Warn("device online error : %v", err)
205+
c.Close()
206+
return
207+
}
208+
209+
server.Log.Infof("device %d, connected to server now, host: %s", c.DeviceId, host)
208210

209211
case *Publish:
210212
server.Log.Infof("%s, publish topic: %s", host, msg.TopicName)

pkg/mqtt/manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func (m *Manager) CleanWorker() {
9393
if uint16(curTime-con.LastHbTime) > uint16(3*con.KeepAlive/2) {
9494
server.Log.Infof("connection %v inactive , removing", con)
9595
con.Close()
96+
delete(m.IdToConn, con.DeviceId)
9697
}
9798
}
9899

pkg/online/online.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ func (mgr *Manager) SetHeartbeat(id uint64) error {
8080
return err
8181
}
8282

83-
if err != nil {
84-
return nil
85-
}
8683
if status == nil {
8784
return errors.New("device offline.")
8885
}

0 commit comments

Comments
 (0)