Connecting Arduino Devices to WolkAbout IoT Platform

Connecting Arduino Devices to WolkAbout IoT Platform © GPL3+

Monitor and control your Arduino devices easily from the cloud with WolkAbout IoT Platform.

  • 14 views
  • 0 comments
  • 1 respect

Components and supplies

Apps and online services

About this project

Introduction

How to connect a device to WolkAbout IoT Platform?

By using WolkConnect - an open-source library that manages all the communication with WolkAbout IoT Platform and exposes it in an easy to use API.

WolkConnect library is intended to be used as a dependency in firmware with existing business logic on devices with IP connectivity. Providing WolkConnect library with IP connectivity from the Hardware Abstraction Layer is the user's responsibility.

WolkConnect library's functionality is split through the API into three distinct parts:

  • Connection management - Connecting to and disconnecting from WolkAbout IoT Platform, and a keep-alive mechanism to maintain the connection.
  • Data handling - Send sensor readings, alarm events and the status of the device's actuators
  • Device management - Change the device's configuration options and perform device software/firmware update.

This post intends to showcase the process of connecting an Arduino device to WolkAbout IoT Platform and publishing a single sensor reading through the use of WolkConnect-Arduino.

We used the Arduino-MRK1000 as example hardware for this showcase as it already has built-in WiFi connectivity, an essential part for any Internet of Things project. Other Arduino boards and different WiFi chips can easily be used instead, as the library is device-agnostic.

Example Usage

  • Install library

Let's begin with including the WolkConnect-Arduino library into Arduino IDE. Adding a library to Arduino IDE is achieved from the menu bar with Sketch->Includelibrary->ManageLibraries... and searching for WolkConnect and clicking on the "Install" button.

  • Create sketch

Connect your board and create a new sketch in Arduino IDE. Copy the code from the Simple example attachment into the sketch and start by editing in your WiFi credentials:

const char* ssid = "wifi_ssid";
const char* wifi_pass = "wifi_password";
  • Getting device credentials

The other thing that is necessary to edit in this example is device credentials used to identify a device on WolkAbout IoT Platform. To obtain this information, go to the Demo instance and register an account. After you've logged in, go to Devices section in the navigational menu on the left side, then switch over to the Device manifests tab. A device manifest is simply a description of what kind of data the device sends, where it sends it, and in what form. To speed up the process of creating the device and getting the credentials needed, download the simple-example-manifest.json attachment and click the "+" button to create a manifest.

A popup presents the choice of creating a manifest from scratch or uploading a manifest. Select upload and navigate to where you saved simple-example-manifest.json. Now we can click "Create Device" to create a device from this device manifest.

A new form will be presented with the Simple example manifest pre-selected so click "Next Step". Now fill in a device name, eg. Arduino-MKR1000 and tick the "Create semantic group from this device" checkbox.

When the "Save" button is pressed, a popup containing device credentials will be displayed.

It is important to save this information somehow, perhaps by using the "Send to my email" option, or simply copy-pasting this information into our sketch:

const char *device_key = "device_key";
const char *device_password = "device_password";

That is all the customisation necessary for this example, but if you are using a different WiFI chip, please refer to the setup required for it.

  • Connecting the device and visualising data

If you compile and upload this sketch to our board, the device will connect to the Platform and publish a single temperature reading, but you need to create a way to display this information.

On the platform, select "Dashboards" from the navigational menu and click the "+" button to create a new dashboard.

Enter a name and click save. Now press the "+" sign to create a widget and select "Card". Here, select Temperature from the Arduino-MKR1000 and click "Save".

Now we're displaying the information received from our Arduino-MKR1000 board.

  • Conclusion

You connected your IP enabled Arduino board to WolkAbout IoT Platform and visualised device data published from your board. The features of WolkAbout IoT Platform that were used in this showcase are thoroughly explained in our user guides.

This was an example to show how simple it is to connect your Arduino device to the cloud, for more advanced features of WolkConnect-Arduino library visit the full feature set example.

Code

Simple exampleArduino
Connects to WiFI network and then to WolkAbout IoT Platform to publish a single temperature reading
#include <WiFi101.h>

#include "WolkConn.h"
#include "MQTTClient.h"

const char* ssid = "wifi_ssid";
const char* wifi_pass = "wifi_password";

const char *device_key = "device_key";
const char *device_password = "device_password";
const char* hostname = "api-demo.wolkabout.com";
int portno = 1883;

/* WolkConnect-Arduino Connector context */
static wolk_ctx_t wolk;

WiFiClient espClient;
PubSubClient client(espClient);

void setup_wifi() {

  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, wifi_pass);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void setup() {
  Serial.begin(9600);

  setup_wifi();

  wolk_init(&wolk, NULL, NULL, NULL, NULL,
            device_key, device_password, &client, hostname, portno, PROTOCOL_JSON_SINGLE, NULL, NULL);

  wolk_connect(&wolk);

  delay(1000);
  
  wolk_add_numeric_sensor_reading(&wolk, "T", 23.4, 0);

  wolk_publish(&wolk);

  delay(500);

}

void loop() {

  if (Serial.available() > 0)
  {
    wolk_disconnect(&wolk);
    Serial.println("Disconnected!");
    while (true)
    {
      delay(10000);
    };
  }
  wolk_process(&wolk, 5);

  delay(1000);
}
simple-example-manifest.jsonJSON
A device manifest with a single temperature sensor that is necessary in order to register a device on WolkAbout IoT Platform
{
  "id": 663,
  "name": "Simple example manifest",
  "protocol": "JsonSingleReferenceProtocol",
  "description": "A minimal manifest with one sensor",
  "deviceType": "STANDARD",
  "connectivityType": "MQTT_BROKER",
  "published": false,
  "feeds": [
    {
      "id": 1107,
      "name": "Temperature",
      "reference": "T",
      "description": "",
      "unit": {
        "id": 31,
        "name": "CELSIUS",
        "symbol": "℃",
        "readingTypeId": 2,
        "system": "SI",
        "context": null,
        "inUse": true
      },
      "minimum": -20,
      "maximum": 80,
      "readingType": {
        "id": 2,
        "name": "TEMPERATURE",
        "dataType": "NUMERIC",
        "size": 1,
        "precision": 1,
        "labels": null,
        "iconName": "ico_temperature"
      }
    }
  ],
  "actuators": [],
  "alarms": [],
  "configs": [],
  "generallyAvailable": false
}
WolkConnect-Arduino
Arduino library which provides easy connectivity to WolkAbout IoT Platform.

Comments

Similar projects you might like

Arduino IoT with SAP HANA Cloud Platform

by derapados

  • 5,849 views
  • 11 comments
  • 8 respects

IoT Blink - Getting started with IoT

Project showcase by AppShed Support

  • 2,300 views
  • 1 comment
  • 14 respects

Create Mobile Apps for Android and iOS Connecting to the MKR

Project tutorial by Chandana Pathirage

  • 5,983 views
  • 4 comments
  • 16 respects

MKR1000 Connecting to the WiFi (3 steps)

by Anton Nazarenko

  • 12,556 views
  • 3 comments
  • 18 respects
Add projectSign up / Login