-
Notifications
You must be signed in to change notification settings - Fork 8
IonoWeb
This library provides functions to control and monitor iono ethernet via a HTTP-based API.
The library provides the following methods:
Start the Web server on the specified port number.
This method must be called periodically (inside the loop()
function) in order serve the incoming HTTP requests.
This method can be used to have iono make a HTTP request to a remote host whenever a digital input changes state.
After calling this method, every time the specified pin changes state and maintains such state at least for a time equal to stableTime
(in milliseconds), iono will perform a HTTP request to the specified port
of the specified host
with the string command
as a path:
An occurrence of "$pin" or "$val" in the string command
will be respectively substituted by the name of the pin and its current value.
For instance, after calling:
IonoWeb.subscribeDigital(DI1, 500, "192.168.0.100", 8080, "/foo?$pin=$val");
if the input DI1
goes high and stays high for 500 ms, iono will perform a HTTP request equivalent to this:
http://192.168.0.100:8080/foo?DI1=1
IonoWeb.subscribeAnalog(int pin, unsigned long stableTime, float minVariation, char *host, int port, char *command)
This method can be used to have iono make a HTTP request to a remote host whenever an analog input changes state.
After calling this method, every time the specified pin changes value of an amount equal or bigger than the minVariation
parameter and maintains such state at least for a time equal to stableTime
(in milliseconds), iono will perform a HTTP request to the specified port
of the specified host
with the string command
as a path:
An occurrence of "$pin" or "$val" in the string command
will be respectively substituted by the name of the pin and its current value.
For instance, after calling:
IonoWeb.subscribeAnalog(AV2, 0, 1, "192.168.0.100", 8080, "/bar?$pin=$val");
if the voltage on AV2
changes of a value greater or equal to 1V (e.g. from 4V to 5.4V), iono will perform a HTTP request equivalent to this:
http://192.168.0.100:8080/bar?AV2=5.40
This method can be used to obtain a reference to the underlying WebServer object.
## HTTP API The HTTP API provides for the following three actions:
Making a HTTP request to this path, like the following:
http://192.168.0.100/api/state
will return a JSON object with the following format:
{
"DO1": <do1_val>,
"DO2": <do2_val>,
"DO3": <do3_val>,
"DO4": <do4_val>,
"DO5": <do5_val>,
"DO6": <do6_val>,
"I1": {
"D": <di1_val>,
"V": <av1_val>,
"I": <ai1_val>
},
"I2": {
"D": <di2_val>,
"V": <av2_val>,
"I": <ai2_val>
},
"I3": {
"D": <di3_val>,
"V": <av3_val>,
"I": <ai3_val>
},
"I4": {
"D": <di4_val>,
"V": <av4_val>,
"I": <ai4_val>
},
"I5": {
"D": <di5_val>
},
"I6": {
"D": <di6_val>
}
}
which reports the current value of iono's pins.
An HTTP request to this path with a set of pairs = as parameters can be used to control iono's outputs.
Here is a few examples:
http://192.168.0.100/api/set?DO1=1
http://192.168.0.100/api/set?DO1=0&DO4=f
http://192.168.0.100/api/set?DO1=0&DO2=1&DO3=0&DO4=1&DO5=0&DO6=0&AO1=7.3
For digital outputs the allowed values are '0' (low), '1' (high) or 'f' (flip the current state); for analog ones, the allowed values are floating numbers from 0.0 to 10.0.
This HTTP request must be used following this format:
http://192.168.1.243/api/subscribe?pin=<pin_name>&st=<time>&mv=<var>&host=<host>&port=<port>&cmd=<command>
The above request corresponds to a call to one of the following methods, depending on the pin:
IonoWeb.subscribeDigital(<pin_name>, <time>, <host>, <port>, <command>);
IonoWeb.subscribeAnalog(<pin_name>, <time>, <var>, <host>, <port>, <command>);
For instance, after making this request:
http://192.168.0.100/api/subscribe?pin=DI1&st=500&host=192.168.0.242&port=8080&cmd=/foo?$pin=$val
every time the input DI1 will go high and stay high for 500ms the following request will be triggered:
http://192.168.0.242:8080/foo?DI1=1
The library folder includes some examples that can be opened directly from the Arduino IDE menu File > Examples > IonoWeb.
Sfera Labs - www.sferalabs.cc
Apps
Other resources
Libraries API