-
Notifications
You must be signed in to change notification settings - Fork 8
IonoUDP
This library provides functionalities to monitor and control a Iono Ethernet via a simple protocol employing UDP communication.
Import the library in your sketch:
#include <IonoUDP.h>
The library provides the following methods:
IonoUDP.begin(const char *id, EthernetUDP Udp, unsigned int port, unsigned long stableTime, float minVariation)
This method initializes the library.
Parameters:
-
id
: a string identifying this iono; -
Udp
: a reference to an EthernetUDP object to be used for the communication; -
port
: the IP port number to use; -
stableTime
: the number of milliseconds after which a variation on an input is considered stable; -
minVariation
: the minimum variation to be taken into account for analog inputs.
IonoUDP.process()
This method must be called periodically (inside the loop()
function) in order to monitor the inputs and send notifications.
Every time there is a stable variation on one of iono's pins, a notification is sent.
A notification consists of 3 repetitions of an UDP packet broadcasted on the local network (i.e. sent to 255.255.255.255).
The payload of the packet contains the following JSON object:
{
"id": <id>,
"pin": <pin_name>,
"pr": <n>,
"val": <value>
}
where:
-
<id>
is the id string passed to theIonoUDP.begin()
method; -
<pin_name>
is the name of the pin that triggered the notification. It can be "DO1", "DO2", "DO3", "DO4", "DO5", "DO6", "DI1", "DI2", "DI3", "DI4", "DI5", "DI6", "AV1", "AV2", "AV3", "AV4", "AI1", "AI2", "AI3" or "AI4"; -
<n>
is a sequence number that increases for each notification. It goes from 0 to 9 and starts over; -
<value>
is the current value of the pin. It can be 0 or 1 for digital pins or a floating value for analog pins.
Other than these notifications, a heartbeat notification is sent every 30 seconds with the following payload:
{
"id": <id>,
"pr": <n>
}
To request the state of all iono's pins, send an UDP packet to iono's IP with the string "state" as payload.
The library will reply with the following JSON object:
{
"id": <id>,
"DO1": <do1_value>,
"DO2": <do2_value>,
"DO3": <do3_value>,
"DO4": <do4_value>,
"DO5": <do5_value>,
"DO6": <do6_value>,
"DI1": <di1_value>,
"AV1": <av1_value>,
"AI1": <ai1_value>,
"DI2": <di2_value>,
"AV2": <av2_value>,
"AI2": <ai2_value>,
"DI3": <di3_value>,
"AV3": <av3_value>,
"AI3": <ai3_value>,
"DI4": <di4_value>,
"AV4": <av4_value>,
"AI4": <ai4_value>,
"DI5": <di5_value>,
"DI6": <di6_value>
}
which includes the assigned id and the current value of each pin.
To change the value of one of iono's output, send an UDP packet to iono's IP with the following payload:
<output_name>=<value>
where:
-
<output_name>
can be "DO1", "DO2", "DO3", "DO4", "DO5", "DO6", "AO1"; -
<value>
can be a floating value for output AO1; for a digital output the allowed values are '0', '1' or 'f' (flip the current state).
For instance:
DO1=f
The library will reply "ok" upon success or "error" upon failure.
Sfera Labs - www.sferalabs.cc
Apps
Other resources
Libraries API