setup()
method. As well as you initialize your devices, set the input/output direction of a digital pin, or initialize the Serial port speed, you also need to initialize here your resources. This basically consists on configuring what values or resources you want to expose over the Internet.loop()
is the place to always call to the thing.handle()
method, so the thinger libraries can handle the connection with the platform. This is the place also for calling your endpoints, or streaming real-time data to a dashboard. Please, take into account to do not add any delay inside the loop()
except if you know what you are doing, like working with deep sleep modes or so in your device. Any other delay will condition the proper functioning of Thinger in your device. Also it can be bad to read a sensor value in every loop if the sensor takes too much time to complete a read. This will result in a device with a noticeable lag while attending to our commands.thing
instance. Replace the your username
, deviceId
, and deviceCredential
with the values you have registered in the cloud. Note that credentials uses to be defined inside arduino_secrets.h
setup()
method of the Arduino sketch. This way the resources are configured at the beginning, but can be accessed later as necessary.<<
pointing to the resource name, and it uses a C++11 Lambda function to define the function.pson
that is a variable type that can contain booleans, numbers, floats, strings, or even structured information like in a JSON document.pson
type can hold multiple data types, we can think that the pson
parameter of the input function is like a boolean.setup
function you can place a resource called led
(but you can use any other name), of input type (using the operator <<
), that takes a reference to a pson
parameter. This example will turn on/off the digital pin 10 using a ternary operator over the in
parameter.pson
type can hold multiple data types, we can still use the pson
type as an integer value.pson
data type can hold not only different data types, but also is fully compatible with JSON documents. So you can use the Pson data type to receive multiple values at the same time. This example will receive two different floats that are stored with the lat
and lon
keys.>>
pointing out of the resource name, and it uses a C++11 Lambda function to define the output function.pson
type that is a variable type that can contain booleans, numbers, floats, strings, or even structured information like in a JSON document.>>
. In the callback function we can fill the out value with any value we want, like in this case the output from a sensor reading.=
. In this case the function takes two different pson
parameters. One for input data and another one for output data. This example provides an altitude reading using the BMP180 Sensor. It takes the reference altitude as input, and provides the current altitude as output.value1
and value2
to provide the sum
and mult
values.sdLogging
variable defined as a global variable.hysteresisVar
changes.deviceA
and deviceB
, and we want to communicate both calling from deviceB
to a specific deviceA
input resource. We can use "thing.call_device(,);" as shown in the example below:deviceA
defines a resource like in the following example.deviceB
can easily call this resource and send data to it by running the following command.pson
payload in order to share data between devices. In this case, the deviceA
will need to define a resource with some expected inputdeviceB
can call this method providing the appropriated input by defining a pson
type that is filled with the same keys used on resourceOnA
, as shown in the code below:deviceB
can also call this method by providing the information from an defined resource that generates the information, in this case, the call is similar as the previous example, but using the resource as the data source.Thinger.io Device Call
. Just register an endpoint of this type in the console, like in the following example.call_endpoint
method.call_endpoint
method over the thing
variable.high_temp_email
that contains some warning text about the temperature. For this case we do not want to check the temperature every millisecond, so we are introducing some variables to control the sensing and warning frequency. In this example, the temperature is checked every hour, and if it is above 30ºC, it will call the endpoint called high_temp_email
which will send us an email with the predefined text. It is important here to do not add delays inside the loop method, as it will prevent the required execution of the thing.handle()
method, so we are using here a non-blocking delay based on the millis()
function.call_endpoint
method, but in this case adding some information based on the pson
data format, which will be automatically converted to JSON. For example, if we want to report data to a third party service like Keen.io, we can create such kind of endpoints in the console. Once configured, we can call the endpoint with our readings, for example with humidity and temperature values from a DHT sensor."The actual level is %"
The actual level is 80.34%
Serial
communication, as all the debugging information is displayed over Serial. So enable it in your sketch in the setup method.set_state_listener
function in the setup()
method. For example, itis possible to define a listener that will receive the different connection states for the network, server, or authentication: