Connecting an ESP8266 or ESP32

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

Creating a Project

The Cloud4RPi library is published in the PlatformIO Registry. Follow the instructions below to start a new Cloud4RPi-enabled project:

  1. Create a new PlatformIO project for your board as described in the PlatformIO documentation (Visual Studio Code, Atom)
  2. Open your platformio.ini and add the following lines to the end:

    lib_deps =
        cloud4rpi-esp-arduino
    
    build_flags=
    ; Required for PubSub library
        -D MQTT_MAX_PACKET_SIZE=1024
        -D MQTT_MAX_TRANSFER_SIZE=128
    ; Enables the verbose output to Serial
        -D CLOUD4RPI_DEBUG=1
    
  3. Save the platformio.ini file and open the src\main.cpp file.

  4. Copy-paste the sample code.
  5. If the LED_BUILTIN constant is not defined in your board's library, change this constant to the LED's pin number (for example, 2).
  6. Replace the __SSID__ and __PASSWORD__ strings with your Wi-Fi network data.

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.

Running

  1. Hit the Build button and wait until the compilation is completed.
  2. Hit the Upload button.
  3. If the upload fails, try to start the board in the flashing mode (connect the power supply with the GPIO0 pin connected to GND) and try uploading again.
  4. Once flashing is complete, open Serial Monitor to monitor the device's status.
  5. Notice that the device on the Devices page went online and started sending data.
  6. Go to the Control Panels page and add a new control panel.
  7. Add a new Number widget and bind it to the Uptime variable.
  8. Add a new Switch widget and bind it to the LED On variable.
  9. Add a new Text widget and bind it to the State variable. Configure different colors for the "IDLE", "RING" and "BOOM!" strings.
  10. Add a new Slider widget and bind it to the DesiredTemp variable, set its minimum value to 10 and maximum value to 30.
  11. Add a new Gauge widget and bind it to the DesiredTemp variable, set its minimum value to 10 and maximum value to 30.

Video