close
In this tutorial, you will learn how to use MQTT to transmit and receive data to QIoT Suite Lite using an ESP8266. As the ESP8266 has different firmware, specifications and instructions, there are two common methods:
- ESP826 useing Arduino Core
- ESP826 useing AT Command combined with Arduino
Ready task (Using Arduino IDE to install the Library and establish IoT Application)
1. In this example, we use MQTT (for more information, visit https://pubsubclient.knolleary.net/ ).
2. Add a new IoT Application (Refer to "How to show DHT11 data on QIoT Dashboard?"
We use the "button" and "led" as examples (both Resource Name and Resource ID are "button" and "led").
3. Go to the "Rule" page, connect your data from "button" to the dashboard and also send the status to your device.
4. Set up QBroker node: Set up "button" resource as "MQTT Message In"
5. Set up QDashboard: Use the name "Button"
6. Set up change node: Move "msg.payload.value" to "msg.payload"
7. Set up QBroker node: Set up "led" resource as "MQTT Message Out"
8. Go to the "Dashboard" page to see your Button status
For more examples of the json file, refer to the below link: https://github.com/qnap-dev/qnap-qiot-sdks/blob/master/projects/esp8266-example/qiot-suite-lite-export/ESP8266.json
ESP8266 using Arduino Core
Using third-party open source libraries - Arduino core for ESP8266 WiFi chip: https://github.com/esp8266/Arduino
Example program: https://github.com/qnap-dev/qnap-qiot-sdks/blob/master/projects/esp8266-example/arduino-core/mqtt-esp8266-example/mqtt-esp8266-example.ino
Using nodemcu as an example (and it is same as other ESP8266 packaged wafers) modify the relation circuit by yourself. The below is a reference image:
Modify the following based on your resourceinfo.json file:
This code manages the data representing receiving the message and then controlling the LED (For example: if receiving data value is "1" and then turn on the LED).
This code manages the first connection and reconnection. Subscriptions can also be set up here.
This code manages the main task that packages input messages to "{"value":"0"}" and "{"value":"1"}" and then publishes to QIoT Suite Lite.
After setting up, click the Button and then the LED will be turned on. At the same time the Button in the QIoT Suite Lite Dashboard will also be turned on as below:
ESP8266 using AT Command combine with Arduino
Using third-party open source libraries - WiFiEsp: https://github.com/bportaluri/WiFiEsp
Example program: https://github.com/qnap-dev/qnap-qiot-sdks/blob/master/projects/esp8266-example/at-command-with-arduino/mqtt-esp8266-Wifiesp-example/mqtt-esp8266-Wifiesp-example.ino
Using Seeeduino as an example, and it is same as other Arduino Uno development boards
Note: The ESP-01 only supports 3.3V so when using Seeeduino please change your voltage to 3.3V. (When using Arduino Uno or other development boarda, modify the relation circuit by yourself. The below is a reference image).
Modify the following based on your resourceinfo.json file:
This code manages the data representing receiving the message and then controlling the LED (For example: if receiving data value is "1" then turn on the LED).
This code manages the first connection and reconnection. Subscriptions can also be set up here.
This code manages the main task that packages input messages to "{"value":"0"}" and "{"value":"1"}" and then publishes to QIoT Suite Lite.
After setting up, click the Button and then the LED will be turned on. At the same time the Button in the QIoT Suite Lite Dashboard will also be turned on as below:
全站熱搜
留言列表