WolkWriter
Published © GPL3+

Connecting Arduino Devices to WolkAbout IoT Platform

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

BeginnerProtip30 minutes533
Connecting Arduino Devices to WolkAbout IoT Platform

Things used in this project

Story

Read more

Code

Simple example

Arduino
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-deviceTemplate.json

JSON
A device template with a single temperature sensor that is used in order to register a device on WolkAbout IoT Platform
{
  "id": 883,
  "name": "Simple-example",
  "protocol": "JsonSingleReferenceProtocol",
  "description": "A minimal template with one sensor",
  "deviceType": "STANDARD",
  "connectivityType": "MQTT_BROKER",
  "published": false,
  "feeds": [
    {
      "id": 1472,
      "name": "Temperature",
      "reference": "T",
      "description": "",
      "unit": {
        "id": 31,
        "name": "CELSIUS",
        "symbol": "℃",
        "readingTypeId": 2,
        "system": "SI",
        "precision": 1,
        "context": null,
        "inUse": true,
        "readingTypeName": "TEMPERATURE"
      },
      "minimum": -20,
      "maximum": 80,
      "readingType": {
        "id": 2,
        "name": "TEMPERATURE",
        "dataType": "NUMERIC",
        "size": 1,
        "labels": null,
        "iconName": "ico_temperature"
      }
    }
  ],
  "actuators": [],
  "alarms": [],
  "configs": [],
  "generallyAvailable": false
}

WolkConnect-Arduino

Arduino library which provides easy connectivity to WolkAbout IoT Platform.

Credits

WolkWriter

WolkWriter

15 projects • 23 followers
With WolkAbout IoT Platform, we give you proven technology to develop powerful IoT applications and control your business ecosystem.

Comments