Skip to content

cloud4rpi/cloud4rpi-esp-arduino

Repository files navigation

Cloud4RPi Client Library for Arduino Framework

Build Status

The package provides a client library that simplifies connecting Internet-enabled Arduino devices to the Cloud4RPi service.

Supported hardware:

Supported ecosystems:

The further instructions depend on your preferred ecosystem.

PlatformIO

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. Log in to your Cloud4RPi account or create a new one.

  6. 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.

  7. Replace the __YOUR_DEVICE_TOKEN__ string with your device token.

  8. Replace the __SSID__ and __PASSWORD__ strings with your Wi-Fi network data.

  9. 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).

  10. Hit the Build button and wait until the compilation is completed.

  11. Hit the Upload button.

  12. 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.

  13. Once flashing is complete, open Serial Monitor to monitor the device's status.

  14. Notice that the device on the Devices page went online and started sending data.

  15. Go to the Control Panels page and add a new control panel.

  16. Add a new Switch widget and bind it to the LED On variable.

  17. Add a new Text widget and bind it to the State variable. Configure different colors for the "IDLE", "RING" and "BOOM!" strings.

  18. Add a new Slider widget and bind it to the DesiredTemp variable, set its minimum value to 10 and maximum value to 30.

  19. Add a new Gauge widget and bind it to the DesiredTemp variable, set its minimum value to 10 and maximum value to 30.

Arduino

  1. Open Arduino and select your board in the Tools | Board menu. Add ESP8266 or ESP32 support if it is not added yet.
  2. Install the Cloud4RPi library from the Library Manager. To do this, open the Sketch | Include Library | Manage Libraries menu, enter cloud4rpi into the search field and install the cloud4rpi-esp-arduino package.
  3. Install the dependencies: ArduinoJson and PubSubClient libraries.
  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. [Optional] 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 add the #define CLOUD4RPI_DEBUG 1 line at the beginning to enable verbose output.
  5. Use the File | Examples | cloud4rpi-esp-arduino menu item to open the sample code. Restart Arduino IDE if this item does not appear.
  6. Select the ESP32 Dev Module board in Tools menu.
  7. Log in to your Cloud4RPi account or create a new one.
  8. 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.
  9. Replace the __YOUR_DEVICE_TOKEN__ string with your device token.
  10. Replace the __SSID__ and __PASSWORD__ strings with your Wi-Fi network data.
  11. 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).
  12. Hit the Build button and wait until the compilation is completed.
  13. Hit the Upload button.
  14. 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.
  15. Once flashing is complete, open Serial Monitor to monitor the device's status.
  16. Notice that the device on the Devices page went online and started sending data.
  17. Go to the Control Panels page and add a new control panel.
  18. Add a new Switch widget and bind it to the LED On variable.
  19. Add a new Text widget and bind it to the State variable. Configure different colors for the "IDLE", "RING" and "BOOM!" strings.
  20. Add a new Slider widget and bind it to the DesiredTemp variable, set its minimum value to 10 and maximum value to 30.
  21. Add a new Gauge widget and bind it to the DesiredTemp variable, set its minimum value to 10 and maximum value to 30.

See Also