This example will guide you through setting up a simple ESP32 application running the Astarte SDK and interacting with a local instance of Astarte.
The example device will perform the following actions:
We will assume you already performed the common configuration and satisfy the common prerequisites. You flashed your device with the example firmware and connection between the device and the Astarte instance has been established.
Now that our device is connected to Astarte it's time to start publishing data.
We will use two sub-commands of astartectl
in this example, send-data
, and get-samples
.
With send-data
we can publish new values on a server-owned interface.
The syntax is the following:
Plaintext
astartectl appengine \
--appengine-url http://localhost:4002/ --realm-management-url http://localhost:4000/ \
--realm-key <REALM_NAME>_private.pem --realm-name <REALM_NAME> \
devices send-data <DEVICE_NAME> \
org.astarteplatform.esp32.examples.ServerAggregate /11 \
'{"longinteger_endpoint":45993543534, "booleanarray_endpoint":[false,false,true,true]}'
Where <REALM_NAME>
is your realm name,<DEVICE_NAME>
is the device ID to send the data to.
The last argument is the data to publish.
The device will react to this event by publishing some values on its interface.
We can check if the publish from the device has been correctly received on the server using
get-samples
as follows:
Plaintext
astartectl appengine \
--appengine-url http://localhost:4002/ --realm-management-url http://localhost:4000/ \
--realm-key <REALM_NAME>_private.pem --realm-name <REALM_NAME> \
devices get-samples <DEVICE_NAME> \
org.astarteplatform.esp32.examples.DeviceAggregate /24 -c 1
This will print the latest published data from the device that has been stored in the Astarte Cloud
instance.
To print a longer history of the published data change the number in -c 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:aggregates"