Skip to content

Connecting an ESP8266

Follow the instructions below to connect your ESP8266 board (like NodeMCU Dev Kit) to the Cloud4RPi control panel.

Prerequisites

  • USB-UART Adapter (if it is not integrated into your board).
  • Access to ESP8266's GPIO0 pin to enter flashing mode.

Getting Libraries and Examples

  1. Open Arduino and select your board in the Tools | Board menu. Add ESP8266 support if required.
  2. Install the Cloud4RPi library from the Library Manager by opening the Sketch | Include Library | Manage Libraries menu, entering cloud4rpi into the search field and installing the cloud4rpi-esp-arduino package.
  3. Install ArduinoJson and PubSubClient libraries. You should do it manually because the Library Manager does not manage package dependencies.
  4. Configure the installed libraries:

    1. Open the %HOMEPATH%\Documents\Arduino\libraries\PubSubClient\src\PubSubClient.h (~/Documents/Arduino/libraries/PubSubClient/src/PubSubClient.h on Mac) file with any text editor (for instance, VS Code).
    2. Add the following define directives at the beginning:

      #define MQTT_MAX_PACKET_SIZE 1024
      #define MQTT_MAX_TRANSFER_SIZE 128
      
    3. Open the %HOMEPATH%\Documents\Arduino\libraries\cloud4rpi-esp-arduino\src\Cloud4RPi.h (~/Documents/Arduino/libraries/cloud4rpi-esp-arduino/src/Cloud4RPi.h on Mac) file and enable verbose output by adding the #define CLOUD4RPI_DEBUG 1 line at the beginning.

Opening Sample Code

  1. Open the sample code using the File | Examples | cloud4rpi-esp-arduino | ESP8266 menu item. Restart Arduino IDE if this item did not appear.
  2. If you know the pin number connected to an LED on your board, replace the BUILTIN_LED constant with it.

Connecting to Your Cloud4RPi Account

  1. Log in to your Cloud4RPi account or create a new one.
  2. Copy your device's Device Token. You can create a device on the Devices page and copy its Device Token if you do not have one.
  3. Replace the __YOUR_DEVICE_TOKEN__ string with your device token.
  4. Replace the __SSID__ and __PASSWORD__ strings with your Wi-Fi network data.

Running

  1. Hit the Build button and wait until the compilation is completed.
  2. Connect the board in the flashing mode (power it with the GPIO0 pin connected to GND) and hit the Upload button.
  3. Once flashing is complete, open Serial Monitor and watch the sample code's output.
  4. Notice that the device went online and started sending data.
  5. Go to the Control Panels page and add a new control panel.
  6. Add a new Chart widget and bind it to the Uptime variable.
  7. Add a new Switch widget and bind it to the LED On variable.
  8. Add a new Text widget and bind it to the STATUS variable. Configure different colors for the "IDLE", "RING" and "BOOM!" strings.

Video