ESP Dev Board
For a better understanding, we recommend that you read the documentation on Dashboard, Sandbox, and Uniot Core.
In this guide, we will take a detailed look at the entire process of connecting a development board, from writing firmware and authorizing the board to writing a script and interacting with the dashboard. We will be using the ESP8266 Witty Cloud board, but you can easily use another board with minor adjustments. We chose Witty Cloud because this board has built-in external devices such as a button, 3 LEDs, and a light sensor (LDR).
Let's start with setting up PlatformIO, below is the configuration file:
PlatformIO Configuration
Main Code
First, let's take a look at the ESP8266 Witty Cloud Pinout:
LDR: ADC (A0)
Button: GPIO0 (D2)
RGB LED:
Red: GPIO15 (D8)
Green: GPIO12 (D6)
Blue: GPIO13 (D7)
All we need to do is define the external devices, configure the NetworkController and set up the primitives so that we can later control the external devices in the script.
That's it! You are ready to build the code and flash the board. The next step is to connect the board to the Platform. The instructions can be found here. Once the board is added, you can create a script!
Script
Let's describe an imaginary scenario. We will read the value of the light sensor and, depending on the value received, we will turn on one or another LED. The button will enable/disable reading data from the sensor. The values from the sensor can be in the range 0-1023. For example:
0 - 50: Turn on the red LED
51 - 100: Turn on the green LED
101 - 1023: Turn on the blue LED
The script for this scenario may look like this:
Compile the script, send it to the board and play with the light sensor to change the LEDs state.
Now let's assume that we want to control the board from the dashboard and display data from the light sensor. We will now enable/disable data reading using both a physical button and a widget from the dashboard (besides, the buttons will be synchronized). We will display the read value from the light sensor on the dashboard using the corresponding widget:
The new script may look like this:
Pay attention to the data type of the run
variable. In the first script, this variable was a Boolean flag. When the physical button was pressed, we changed the value of the variable locally. In the second script, this variable has a numeric type, since the state change now occurs on an event from the MQTT broker.
The event value is always of type Number. A Boolean value will be converted to a Number. A String value is not allowed.
Last updated