Connect-153 Webhooks

From I-CubeX Wiki
Jump to: navigation, search

Connect can output sensor data to the web as HTTP requests, for use in IoT (Internet of Things) applications. This enables use of I-CubeX devices to trigger an event on the web using an IoT platform such as IFTTT and Zapier. The Web field in the digitizer view window requires a Webhook URL address that may be provided by the IoT platform.


Connect-153 digitizer view web.png


In the address field, enter one or more URLs, one for each sensor input. If multiple URLs are entered, each URL should be separated by a newline character, which can be entered by holding down the Control button while pressing the Return button. If less than 8 URLs are entered, the remaining sensor inputs will have empty lines. If the line is empty no HTTP requests will be sent.


GET requests

To send HTTP requests using the GET method, set the POST/GET button accordingly. The GET method does not include sensor data like the POST method below so its use is limited to triggering scripts to run on a server.


Testing

To test sending HTTP GET requests use the digitizer in standalone mode. Configure the digitizer with EditorX to use eg. the Threshold or Peak signal processing methods to output a sensor value incidentally as a way to trigger an event. Sending messages to the web continuously at a high rate, eg. at 100 ms interval or less could have unexpected or even undesirable results.


POST requests

To send HTTP requests using the POST method, set the POST/GET button accordingly.


Output format

Connect will send the sensor data using a POST message with a JSON attachment, with the following general format:

{\"value1\":\"<timestamp>", \"value2\":\"<sensor_input_address>/<sensor_parameter_name(s)>", \"value3\":\"<sensor_parameter_value(s)>\"}

where <sensor_input_address> takes the form "/<digitizer_name>/Input_<sensor_input_number>", spaces are represented by the underscore character (ie. "_"), and <sensor_input_number> is any number between 01 and 08 (ie. with leading zero) representing the sensor inputs 1 .. 8 and

where <sensor_parameter_name> is a comma-separated string of names enclosed by square brackets (ie. "[" and "]") if multiple sensor parameters are output by the sensor.

The timestamp format is as follows:

yyyy-MM-dd hh:mm:ss.SSS

where yyyy is the year, MM is the month, dd is the day, hh is the hour, mm is the minute, ss is the second and SSS is the millisecond, all with leading zero(s).

This format specification translates into the following formats when applied to analog and digital sensors, in host and standalone mode:


Analog sensors

{\"value1\":\"<timestamp>", \"value2\":\"<sensor_input_address>/V", \"value3\":\"<sensor_parameter_value>\"}

where "V" is the <sensor_parameter_name> since analog sensor inputs measure the sensor's output voltage, output as a number without unit of measurement.

For example, if the digitizer "Wi-microDig 0458" outputs sensor value 42 from input 1, one message will be POSTed to the Web and the JSON attachment will contain:

{\"value1\":"2018-01-14 15:10:11.334", \"value2\":"/Wi-microDig_0458/Input_01/V", \"value3\":\"42\"}


Digital (I2C) sensors, standalone mode

{\"value1\":\"<timestamp", \"value2\":\"<sensor_input_address>/<sensor_parameter_name>", \"value3\":\"<sensor_parameter_value>\"}.

where <sensor_parameter_name> contains one name since each sensor parameter value is received asynchronously from the digitizer and output as a separate message, even if the method selected for the sensor specifies multiple sensor parameters. Note that <sensor_parameter_value> may be a number without unit of measurement - check the sensor's product page.

For example, if the digitizer "USB-microDig 0208" outputs sensor value 30, 71 and 34 for parameters M (moisture), I (illumination) and T (temperature) from input 1, three messages will be POSTed to the Web and the three JSON attachments will contain:

{"value1":"2018-01-14 15:11:12.344", "value2":"/USB-microDig_0208/Input_01/M", "value3":"30"}

{"value1":"2018-01-14 15:11:12.345", "value2":"/USB-microDig_0208/Input_01/I", "value3":"71"}

{"value1":"2018-01-14 15:11:12.346", "value2":"/USB-microDig_0208/Input_01/T", "value3":"34"}


Digital (I2C) sensors, host mode

{\"value1\":\"<sensor_input_address>", \"value2\":\"<sensor_parameter_name(s)>\", \"value3\":\"<sensor_parameter_value(s)>\"}

where <sensor_parameter_name(s)> can contain between 1 and 16 names depending on the method selected for the digital sensor. The method determines how many parameter values the sensor outputs. All the parameter values are received at the same time from the digitizer and hence can be output together in one message. Note that <sensor_parameter_value(s)> may be numbers without unit of measurement - check the sensor's product page.

For example, if the digitizer "USB-microDig 0208" outputs sensor values 23.460411, 53.85824 and 27.3 for parameters M (moisture), I (illumination) and T (temperature) from input 1, one message will be POSTed to the Web and the JSON attachment will contain:

{"value1":"2018-01-14 15:13:16.366", "value2":"/USB-microDig_0208/Input_01/[M,I,T]", "value3":"(23.460411, 53.85824, 27.3)"}


Testing

To test sending HTTP POST requests use the digitizer in standalone mode. Configure the digitizer with EditorX to use eg. the Threshold or Peak signal processing methods to output a sensor value incidentally as a way to trigger an event. Sending messages to the web continuously at a high rate, eg. at 100 ms interval or less could have unexpected or even undesirable results.

For example, to use this feature with IFTTT.com do the following (assuming you have already created an account at IFTTT.com):

  1. Create a new applet, eg. by selecting "New Applet" from the user menu in the top right.
  2. Click on the blue "This" word in the "If This Then That" phrase
  3. Enter "Webhooks" in the search field for "Select a service".
  4. Click the "Receive a web request" button.
  5. Enter a name for the event, eg. "I-CubeX_Sensor_Triggered".
  6. Click on the blue "That" word in the "If This Then That" phrase.
  7. Select an action service, eg. Email
  8. Click the "Send me an email" button
  9. Click "Create action". The applet is now created.
  10. Click on your username, then services.
  11. Choose Maker, and click on the settings on the top right near/below your username.
  12. Copy the URL to the Web field in Connect.
  13. In the URL replace the word "use" with "trigger/<name_of_event>/with/key", where "<name_of_event>" is the name given to the event, eg. "I-CubeX_Sensor_Triggered".
  14. Set the "Output" toggle in Connect.

Now, every time a sensor outputs a value, an email will be sent to the email address specified in the applet.