MQTT will use

Most people should have this need:

 

I want my APP or a PC or a login page when acquiring online or offline status of the device

Terminal equipment need only set

Note: MQTT itself will set

So we can set up a will, pay attention to Kazakhstan, Kazakhstan issued their own free theme, assuming that is a testament aaaaa hypothesis set is    {data: state, state: offline } Note wills retain must be set to 1, that allows the server to keep this news

If this is set, as long as the equipment is down, the server will send to the theme or APP subscription aaaaa PC or web page {data: state, state: offline} 

 

But only this setting is not enough, because you will find every APP or PC, or as long as a start page will receive {data: state, state: offline} 

 

So it is necessary next step

Active devices at the time a message is successfully connected MQTT theme must likewise transmitted Ha aaaaa message is assumed {data: state, state: online} Note that retain the message must be set to 1, i.e. so that the retained message server

 

In this case, you can, as long as APP or PC or a start page, then the current status of all equipment will take the initiative in coming up

I can look at ESP8266 set, regardless of the language used in the development of wisdom, self-realization can find API

 

 Then point out

MQTT have heartbeat packets every time is how much time is actually sent to the server C0 00

Server determines the client to take away line is:

Heartbeat packets are provided is assumed 5S

So if more than 5 * 1.5 = 7.5S server does not receive a heartbeat packet, then the server will assume that the device is down

At this point the server will be dropped wills that piece of equipment sent to the appropriate PC

 

Guess you like

Origin www.cnblogs.com/yangfengwu/p/11241776.html