Cloud4RPi Client Library for Arduino Framework
The package provides a client library that simplifies connecting Internet-enabled Arduino devices to the Cloud4RPi service.
Supported hardware:
- ESP8266 boards (like NodeMCU Dev Kit and others).
- ESP32 boards (like ESP32-DevKitC and others).
Supported ecosystems:
The further instructions depend on your preferred ecosystem.
The Cloud4RPi library is published in the PlatformIO Registry. Follow the instructions below to start a new Cloud4RPi-enabled project:
-
Create a new PlatformIO project for your board as described in the PlatformIO documentation (Visual Studio Code, Atom)
-
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
-
Save the
platformio.ini
file and open thesrc\main.cpp
file. -
Copy-paste the sample code.
-
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.
-
Replace the
__YOUR_DEVICE_TOKEN__
string with your device token. -
Replace the
__SSID__
and__PASSWORD__
strings with your Wi-Fi network data. -
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
). -
Hit the
Build
button and wait until the compilation is completed. -
Hit the
Upload
button. -
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.
-
Once flashing is complete, open
Serial Monitor
to monitor the device's status. -
Notice that the device on the Devices page went online and started sending data.
-
Go to the Control Panels page and add a new control panel.
-
Add a new Switch widget and bind it to the
LED On
variable. -
Add a new Text widget and bind it to the
State
variable. Configure different colors for the "IDLE", "RING" and "BOOM!" strings. -
Add a new Slider widget and bind it to the
DesiredTemp
variable, set its minimum value to 10 and maximum value to 30. -
Add a new Gauge widget and bind it to the
DesiredTemp
variable, set its minimum value to 10 and maximum value to 30.
- Open Arduino and select your board in the Tools | Board menu. Add ESP8266 or ESP32 support if it is not added yet.
- 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. - Install the dependencies: ArduinoJson and PubSubClient libraries.
- Configure the installed libraries:
- 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). - Add the following define directives at the beginning:
#define MQTT_MAX_PACKET_SIZE 1024 #define MQTT_MAX_TRANSFER_SIZE 128
- [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.
- Open the
- Use the File | Examples | cloud4rpi-esp-arduino menu item to open the sample code. Restart Arduino IDE if this item does not appear.
- Select the ESP32 Dev Module board in Tools menu.
- Log in to your Cloud4RPi account or create a new one.
- 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.
- Replace the
__YOUR_DEVICE_TOKEN__
string with your device token. - Replace the
__SSID__
and__PASSWORD__
strings with your Wi-Fi network data. - 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
). - Hit the
Build
button and wait until the compilation is completed. - Hit the
Upload
button. - 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.
- Once flashing is complete, open
Serial Monitor
to monitor the device's status. - Notice that the device on the Devices page went online and started sending data.
- Go to the Control Panels page and add a new control panel.
- Add a new Switch widget and bind it to the
LED On
variable. - Add a new Text widget and bind it to the
State
variable. Configure different colors for the "IDLE", "RING" and "BOOM!" strings. - Add a new Slider widget and bind it to the
DesiredTemp
variable, set its minimum value to 10 and maximum value to 30. - Add a new Gauge widget and bind it to the
DesiredTemp
variable, set its minimum value to 10 and maximum value to 30.