IoTool Arduino library documentation
IoTool Arduino library
This library allows an Arduino to communicate with the IoTool application. Data is sent and received using a Bluetooth connection. IoTool supports classic Bluetooth modules and the integrated Bluetooth Low Energy on Arduino/Genuino 101. Follow the first part of the IoTool Arduino extension user guide to get it working.
IoTool constructor
setSerial()
setBleSerial()
Desctiption
Sets an emulated serial connection on Arduino/Genuino 101 as a communication channel between 101 and IoTool Arduino service. Use this only with built in Bluetooth LE on Arduino/Genuino 101.
Example
/* WARNING: This is only implemented on Arduino/Genuino 101 */
#include <IoTool.h>
IoTool ioTool;
CurrieBLESerial cSerial;
void setup() {
/* Initialize 101 BLE Serial emulation */
cSerial.begin();
/* Attach CurrieBLESerial object to the IoTool object */
ioTool.setBleSerial(cSerial);
}
void loop() {
}
addSensor()
addAction()
loop()
Description
The main processing loop of the IoTool object. This should not be blocked with delay() calls, as it may result in potentially unexecuted actions.
Example
#include <IoTool.h>
IoTool ioTool;
void setup() {
/* At minimum, Stream object such as Serial should be provided to use loop() method */
Serial.begin(9600);
ioTool.setSerial(Serial);
}
void loop() {
/* Do not block this loop with delay() calls, as this will result in unexecuted actions */
ioTool.loop();
}
IoToolSensor constructor
Syntax
-
sensor(id, name, shortName)
-
sensor(id, name, shortName, units)
-
sensor(id, name, shortName, decimalPlaces)
Parameters
-
sensor: IoToolSensor object variable name
-
id: sensor id (must be unique)
-
name: sensor name
-
shortName: short sensor name displayed in IoTool dashboard (up to ~8 characters)
-
units: sensor data units
-
decimalPlaces: number of decimal places to use in IoTool dashboard
Example
#include <IoTool.h>
IoTool ioTool;
/* First constructor id, name, short name */
IoToolSensor sensor("id", "My sensor", "M.sens");
/* Second constructor id, name, short name, units */
IoToolSensor tempSensor("t", "Temperature", "Temp", "C");
/* Third constructor id, name, short name, units, decimal places */
IoToolSensor acc("acc", "Acceleration", "Acc", "G", 2);
void setup() {
}
void loop() {
}
write()
Description
The write method sends a provided numeric value to the IoTool app. The value is sent immediately.
Example
#include <IoTool.h>
/* Create IoTool object */
IoTool ioTool;
/* Create sensor object*/
IoToolSensor sensor("id", "Sensor", "Sens");
/* Time keeping variable */
unsigned long pMillis;
void setup() {
/* Initialize Serial connection */
Serial.begin(9600);
/* Set Serial connection, IoTool will use this connection to communicate with IoTool App */
ioTool.setSerial(Serial);
/* Add sensor to the IoTool object */
ioTool.addSensor(sensor);
}
void loop() {
/* Call main loop of the ioTool object, this is neccesary to enable Sync functionality */
ioTool.loop();
/**
* Delay should not be used, as it will block executon of IoTool loop.
* Use millis() instead, check if difference in time is equal or greater
* than 500 ms, if it is wirte value to the sensor and update time keeping
* variable
*/
if (millis() - millis >= 500) {
/* Update time keeping variable */
pMillis = millis();
/* Write value of the Analog Pin 0 to the sensor */
sensor.write(analogRead(0));
}
}
IoToolAction constructor
setHandler()
Description
Set callback function for an IoToolAction object. This function will be executed in the IoTool loop() method when given the signal to execute. The method accepts a function with the following signature: void /functionname/(void).
Example
#include <IoTool.h>
IoTool ioTool;
IoToolAction action("id", "Toggle LED");
/* Action handler function */
void actionHandler() {
/* Toggle LED on pin 13 */
digitalWrite(13, !digitalRead(13));
}
void setup() {
/* Set pin 13 as output */
pinMode(13, OUTPUT);
/* Initialize Serial object and set it to the IoTool object */
Serial.begin(9600);
ioTool.setSerial(Serial);
/* Add action handler function to the IoToolAction object */
action.setHandler(actionHandler);
}
void loop() {
/* Action will be executed here when given signal from IoTool app */
ioTool.loop();
}
CurieBLESerial constructor
begin()
Example
/* WARNING: This is only implemented on Arduino/Genuino 101 */
#include <IoTool.h>
IoTool ioTool;
CurieBLESerial cSerial;
void setup() {
/* Fully initialize CurieBLESerial object */
cSerial.begin();
/* cSerial can now be used with IoTool object */
ioTool.setBleSerial(cSerial);
}
void loop() {
ioTool.loop();
}