This example will guide you through setting up a simple ESP32 application running the Astarte SDK and interacting with a local instance of Astarte.
We will configure the device to perform the following actions:
Turning on and off the LED can be accomplished by sending some data from Astarte to the device. This can be done using the following command:
Plaintext
astartectl appengine --appengine-url http://localhost:4002/ \
--realm-key <REALM>_private.pem --realm-name <REALM> \
devices send-data <DEVICE_ID> \
org.astarteplatform.esp32.examples.ServerDatastream \
--interface-type individual-datastream --payload-type boolean \
/led <VALUE>
The <VALUE>
should be in the boolean format. Sending true
will turn the LED on, and sending
false
will turn it off.
Each time the button is pressed, the device will send its uptime in seconds to the local Astarte instance. You can verify the transmitted data has been successfully stored in Astarte by running:
Plaintext
astartectl appengine --appengine-url http://localhost:4002/ \
--realm-key <REALM>_private.pem --realm-name <REALM> \
devices get-samples <DEVICE_ID> \
org.astarteplatform.esp32.examples.DeviceDatastream /uptimeSeconds --count 1
This will print the latest message from the device that has been stored in the Astarte Cloud
instance. To print a longer history of messages change the number in --count 1
to the history
length of your liking.
To create a project from this example, run:
idf.py create-project-from-example "astarte-platform/astarte-device-sdk-esp32=1.3.3:toggle_led"