Skip to content

Latest commit

 

History

History
65 lines (40 loc) · 2.88 KB

README.md

File metadata and controls

65 lines (40 loc) · 2.88 KB

Arduino Client for OpenSensors

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.

Hardware prerequisites

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.

Software prerequisites

Arduino IDE or another IDE, Codebender.cc etc.

Using the Library

  1. Download the Arduino MQTT client dependency, created by Nick O'Leary, from here.

  2. 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

  3. Restart the Arduino IDE

  4. Download the OpenSensors Arduino Client from here.

  5. Import the OpenSensors Arduino Client into the Arduino IDE, mirroring step 2, add osio_client.zip

  6. 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>

Library reference

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);

Code Examples

Some examples can be found in the sample directory.