This is the OpenSensors client for Arduino boards with Ethernet or WiFi connectivity. It uses MQTT v3.1 and the Arduino MQTT client by Nick O'Leary (MIT licensed) as a dependency.
You need an Arduino board with a network interface (Ethernet wire or WiFi), for example, an Arduino UNO and Arduino ethernet shield without PoE, or a single Arduino shield.
Arduino IDE or another IDE, Codebender.cc etc.
-
Download the Arduino MQTT client dependency, created by Nick O'Leary, from here.
-
Import the Arduino MQTT client file you just downloaded into the Arduino IDE. To do this we go to the Arduino IDE toolbar, go to Sketch -> Import Library -> Add library and add PubSubClient.zip
-
Restart the Arduino IDE
-
Download the OpenSensors Arduino Client from here.
-
Import the OpenSensors Arduino Client into the Arduino IDE, mirroring step 2, add osio_client.zip
-
To implement in your sketch, you will need to now add the two libraries to your sketch. Navigate to Sketch -> Import library, select pubsubclient and then osio_client from the drop down list. Alternatively, type:
#include <pubsubclient.h>
#include <osio_client.h>
This client library realized as C++ class named OSIOClient. There are such public methods to work with it:
Constructors which initialize necessary connection parameters. There are some overrides of it ("server name" and "callback" parameters are not mandatory):
OSIOClient::OSIOClient(Client & client, char * userName, char * deviceId, char * devicePassword);
OSIOClient::OSIOClient(Client & client, char * userName, char * deviceId, char * devicePassword, char * serverName);
OSIOClient::OSIOClient(Client & client, char * userName, char * deviceId, char * devicePassword, void (*callback)(char*,uint8_t*,unsigned int));
OSIOClient::OSIOClient(Client & client, char * userName, char * deviceId, char * devicePassword, char * serverName, void (*callback)(char*,uint8_t*,unsigned int));
Method to process iteration of receiving data (callback supplied in constructor (if necessary)):
boolean OSIOClient::loop();
Method to publish message to topic:
boolean OSIOClient::publish(char* topic, char* payload);
Method to subscribe for topic:
boolean OSIOClient::subscribe(char* topic);
Some examples can be found in the sample directory.