ESP8266 SDK Development: Things papers - integrated -APP use SmartConfig distribution network binding ESP8266, and remote communication via control MQTT

 

 

 

Foreword

Section 1. This is the first implementation of remote communication function tests

https://www.cnblogs.com/yangfengwu/p/11961168.html

 

2. Section APP has put the source code to the user

 

 

The following four sections of the production process for the APP

https://www.cnblogs.com/yangfengwu/p/11839484.html   the Android simple connection MQTT Demo

https://www.cnblogs.com/yangfengwu/p/11883204.html   the Android source package instructions implemented MQTT

https://www.cnblogs.com/yangfengwu/p/11911992.html   Android realize SmartConfig simple Demo

https://www.cnblogs.com/yangfengwu/p/11925612.html   transplant program source code to your own project SmartConfig

 

3. Reminds

APP in the source code, when the device to use SmartConfig distribution network,

APP acquired MAC address of XX: XX: XX: XX: XX: XX

Then subscribe to APP theme: device / XX: XX: XX: XX: XX: XX

APP released the theme: user / XX: XX: XX: XX: XX: XX

 

So subscribe to the equipment end of the program theme: user / XX: XX: XX: XX: XX: XX

Publish the theme: device / XX: XX: XX: XX: XX: XX

 

protocol:

APP query state relay

"{\"data\":\"switch\",\"bit\":\"1\",\"status\":\"-1\"}"

 

设备根据继电器的状态返回

"{\"data\":\"switch\",\"bit\":\"1\",\"status\":\"1\"}" //继电器吸合
"{\"data\":\"switch\",\"bit\":\"1\",\"status\":\"0\"}"  //继电器断开

 

 

APP控制继电器吸合:

"{\"data\":\"switch\",\"bit\":\"1\",\"status\":\"1\"}"

APP控制继电器断开:

"{\"data\":\"switch\",\"bit\":\"1\",\"status\":\"0\"}"

Wi-Fi根据相应的指令控制继电器吸合/断开

 

继电器的状态发生改变以后,把继电器的状态返回给APP

 

 

 

 

程序主要部分说明

1.为了和APP直接配合,这节连接的MQTT服务器修改为云端的服务器

然后定义其它一些数组和变量.

 

 

 

 

 

 

2.获取设备MAC地址,设置订阅和发布的主题

 

 

 

3.处理MQTT数据

 

 

4.检测继电器状态

 

 

 

 

测试

1.长按开发板的固件引脚大约3S,等待指示灯快闪,之后松开按钮

 

    

 

 

 

2,点击APP上面的搜索设备按钮

    

 

3,搜索成功,主页面会添加一个设备,然后点击这个设备,进入控制页面

 

 

    

4.控制继电器

    

 

 

 

 

 

   

 

Guess you like

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