This post was last edited by Ansersion on 2019-6-22 11:42
IoT Smart Lights
1. Introduction:
Physical network smart lights can synchronize data to users' mobile terminals in real time through the Internet, and users can also remotely control smart lights through mobile terminals.
2. System Description:
Smart lights are mainly composed of 3 parts:
- GD32E231 acts as the master controller, thus controlling peripherals;
- ESP8266, as a Wifi communication module, is responsible for transparently transmitting data between the main control and the BcServer server, and interacting with GD32E231 through the serial port;
- The LED light, which is a peripheral, is controlled by GD32E231 using GPIO .
Smart lights and Android apps use the Beecom protocol ( BC protocol for short) to transmit data to each other through the BcServer server.
3. GD32E231 control logic description:
GD32E231 uses a state machine to implement five states, as described below:
- CONNECT
Use the CONNECT command of the BC protocol to initiate a connection to the BcServer server. If successful, it means that the BcServer server has been connected, and then enters the "REPORT verification code" state; otherwise, wait for a while and continue to initiate the CONNECT command.
- REPORT check code
Use the REPORT command of the BC protocol to send the signal table check code to the BcServer server. If successful, it means that the BcServer server has saved the signal table of the device and then enters the "REPORT all signal values" state; otherwise, it enters the "REPORT signal table" state.
- REPORT signal table
Use the REPORT command of the BC protocol to send the device signal table to the BcServer server. If successful, it means that the BcServer server has received and saved the device signal table, and then enters the "REPORT all signal values" state; otherwise, it returns to the "CONNECT state".
- REPORT all signal values
Use the REPORT command of the BC protocol to send all signal values (i.e. LED status, etc.) to the BcServer server. If successful, it means that the BcServer server has received and synchronized the device signal value, and then enters the "working cycle" state; otherwise, it returns to the "CONNECT state".
- Working cycle
In the "working cycle" state, GD32E231 remains idle unless it receives the following events:
- Key triggers external interrupt event:
After the event is triggered, GD32E231 uploads the latest LED signal value to the BcServer server.
- Receive network data event (i.e. serial port interrupt)
After this event is triggered, GD32E231 will parse the network data and update local parameters or perform related operations accordingly, and clear the command sending timeout.
- Command sending timeout event
After this event is triggered, it means that there is no response to the network data packet sent by GD32E231, and it returns to the "CONNECT state".
- Keep-alive timeout event
After this event is triggered, GD32E231 must send a BC protocol PING command to the BcServer server to maintain the link between the smart light and the BcServer server.
4. Demonstration video (recommended to switch to "HD" to watch):
5. Source code and documentation:
基于GD32E231的物联网智能灯.docx
(1.47 MB, downloads: 13)
bc_light_keil_eeworld_gd32e231.zip
(1.19 MB, downloads: 13)
|