What's tingg.io

tingg.io is a IoT platform designed for developers for fast and easy prototyping with a robust and straightforward connectivity. tingg manages the connection with your devices to the data visualization in a few lines of code. Using tingg.io, you can get from idea to prototype to awesome product in no time.

Main

Developer console

Console

The Console is the main part on tingg.io. It allows developers to configure and control Things.

When logging in for the first time, the Developer Console will allow you to connect a Thing. Once you already have a connected thing, you will see the list of your Things.

You can see the details of your Thing by clicking on See details. You will then be able to configure and manage Resources, retrieve live and historical data, configure Things settings and debug the communication between Thing and tingg.io.

Resources

Resources

List of available resources for your Thing. Once configured, they are displayed as cards and they will show the last data sent or received for each one of the topics.

Resource details

Resource Details

Display the details regarding a resource. I.e. Topic, Method, Type and State. For better understanting of the terms, please check the Platform Glossary section.

Live data

Live

Display live data coming from the Thing. By now we will be only displaying live charts for Resource of types: Integer and Numbers.

Chart

Charts

Display a chart with aggregated data (by average) coming from the Thing. By now we will be only displaying historical charts for Resource of types: Integer and Numbers.

The displayed data consider five sets of ranges and aggregation periods.

  • 1 Month of data (1 day average).
  • 1 Week of data (1 hour average).
  • 1 Day of data (10 minutes average).
  • 1 Hour of data (1 minute average)
  • 10 Minutes of data (15 seconds average).

At the bottom of the page the user can select:

  • Range and aggregation periods
  • Start and End datetime
  • Chart type (Lines or Bar charts)

Settings

Settings

You can edit the details of the Thing. The available options are:

  • Thing Details: Allow users to edit Thing Name and Description.
  • Thing Authentication: Allow users to access the identification of the Thing. Contains fields Thing ID and Thing Key.
  • Data Storage: Allow users to export and delete all the data generate by the Thing.

This section also allows you to Delete Thing and all related data from tingg.io platform.

Debug

Debug

You can check all the communication logs regarding the resources. The log will be displayed on the right side screen once it is selected. For resources using method Subcribe (Sub), it will display a text box where you can send data to your Thing.

tingg.io from the inside

Platform Overview

The tingg.io platform is a connectivity platform for IoT devices and developers. The platform allows developers to connect and prototype their hardware easily.

The connection between developers and tingg.io is established using HTTP and WebSockets, which after authenticated and authorized (on Authentication and Authorization layers) will be able to create Things and Resources to assign to their Hardware, or Thing.

The connection between Things and tingg.io is established via Message Broker using MQTT or HTTP protocols. Things will be authenticated and authorized (on Authentication and Authorization layers) and will get managed on the Things Manager service.

Things Manager is the service that controls all the information regarding things and resources. It is the main point of communication between Things and developers.

The Storing service will read all the data coming to and from a Thing and store the data for later use.

Platform glossary

Thing

A Thing is a data source or sink that is connected to tingg.io platform. This can be a smart device, a smartphone, a Gateway that communicates with non-IP-enabled devices, a computer, or even a virtual device running on a computer.

Resource

A Resource is part of a Thing. It can be any type of sensor or actuators (i.e. any part/device that can read or write data) on your thing. This can be a temperature sensor, humidity sensor, LED, etc.

A Resource has 4 properties:

  1. Topic
  2. Method (Pub/Sub)
  3. Type
  4. State

In order to setup a Resource it will be needed to define Topic, Method and Type.

Topic

Topic identifies uniquely the resource of the Thing and defines where data will be sent or received. This can be any text to identify your resource. For example temperature, humidity, light or LED. Allows lowercase, alphanumerical values, dashes, underscores

Method

Method defines the method that the resource will be using. It can be Publish or Subscribe. Basically it tells (from the perspective of the Thing) if the information is being sent or received from a Thing. Publish data from your thing to the platform or Subscribe to data coming from the platform.

Type

Type defines the data type that this resource is writing or reading. It can be: Boolean, String, Integer, Number, Object, Array or Location.

  • Boolean: true or false;
  • String: Any text;
  • Integer: A whole number that can be positive, negative, or zero;
  • Number: Number value that could contain a decimal point;
  • Object: Any kind of JSON valid object consider key/value pairs. E.g. {'key1':'value1', 'key2':'value2'}
  • Array: A sequence of values represented between brackets. E.g. [1,2,3];
  • Location: Coordinates pair containing latitude and longitude values. E.g. -22.9633557,-43.1730737

State

State shows the last data sent or received in that Resource. It will only show up when checking the Resource Details on the Console.

Tutorials

Getting Started guide

Getting started with tingg.io and NodeMCU(ESP8266)

What will you do?

From the installation of Arduino to the development and integration of an IoT Device (using NodeMCU-ESP8266), you will connect and debug your first Thing on tingg.io!

We will guide you through a simple example where you will prototype a LED and a Photoresistor, sending the data via the tingg.io platform!

For the getting started guide, we will need the following material on the picture,

Material

Enjoy and have fun!

Overview

  • Setup Arduino, drivers, libraries and board.
  • Configure Wifi
  • Configure MQTT and tingg.io
  • Play with data

Download & Install Arduino IDE

If you already installed Arduino IDE on your machine, you can skip this step.

  • Go to the Arduino IDE Software webpage and select your operating system

Download Arduino

  • Then click on "JUST DOWNLOAD"
  • Once downloaded, install ARDUINO IDE

Installation of drivers and port configuration

  • Install Silicon Labs drivers. Mac users should make sure they don't have any pending permission on the Mac OSX on: System Preferences > Security and Privacy > General on Allow apps downloaded from:"

tingg tip: For some users, a reboot was needed.

  • After installing, connect the NodeMCU to your USB port.
  • Open Arduino and select the port on Tools > Port > /dev/cu.SLAB_USBtoUART for Mac users, and Tools > Port > COMX for Windows users.

Port Selection

Configuration of board and libraries

  • Open Arduino Software and adjust the following configurations: In: Arduino > Preferences > Settings > Additional Board Manager URLs replace the URL with: http://arduino.esp8266.com/stable/package_esp8266com_index.json

Preferences

Settings Json

  • Go to Tools > Board > Boards Manager.

Board Manager

  • Search for esp8266.
  • Click Install

ESP8266

  • In Arduino, go to: Sketch > Include Library > Manage Libraries

Manage Libraries

  • Search for pubsub.

  • Install the library called PubSubClient from Nick O'Leary

PubSubClient

  • Go to Tools > Board and select NodeMCU 1.0 (ESP 12E Module)

Download Arduino

  • Go to Tools > Upload Speed and set your upload speed to 921600.

First upload

  • Create a new Arduino File, by going on File > New.
  • Copy the following code and paste it in your Arduino File. Make sure you copy all the code:
#include <ESP8266WiFi.h>
#include <PubSubClient.h>

// Pins Config
const int LightPin = D0;
const int PhotoPin = A0;
const int DefaultPin = D4;

// Wifi Config
const char* ssid = "SSID";
const char* password = "PASSWORD";

// MQTT Config
const char* mqtt_server = "<mqtt_server>";
const int port = 1883; // 8883 for mqtts connections.

// Thing Config
const char* thing_id = "<thing_id>";
const char* thing_key = "<thing_key>";

// Topics Config
const char* pubTopic = "<pub_resource>";
const char* subTopic = "<sub_resource>";


// Default Config
const char* username = "thing";

WiFiClient espClient;
PubSubClient client(espClient);

// Vars
int val;
int prevVal = 0;
char buf[12];
long lastUpdateMillis = 0;


// Function to validate connection with the board
void blinking_loop(){
  while (ssid == "SSID") {
    digitalWrite(DefaultPin,HIGH);
    delay(500);
    digitalWrite(DefaultPin,LOW);
    delay(500);
    Serial.println("Default light should be blinking. Please set up your Wifi configuration.");
  }
}

void setup_wifi() {
  delay(10);
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.mode(WIFI_STA);

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

  randomSeed(micros());

  Serial.println("");
  Serial.print("Congratulations!! WiFi connected on IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println("");
  Serial.println("Now, follow up on the steps for the MQTT configuration. ");
}

void reconnect() {
  while (!client.connected()) {
    Serial.print("Attempting to connect MQTT...");
    if (client.connect(thing_id, username, thing_key)) {
      Serial.println("connected");
      client.subscribe(subTopic);
    } else {
      Serial.print(" Still not connected...");      // Serial.print(client.state());
      Serial.println(" trying again in 5 seconds"); // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

String message(byte* payload, unsigned int length) {
  payload[length] = '\0';
  String s = String((char*)payload);
  return s;
}

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.println(topic);
  String msg = message(payload, length);

  if ((msg == "ON") || (msg == "on") || (msg == "1")) {
    Serial.println("Light turned On");
    digitalWrite(LightPin,HIGH);
  }
  else if ((msg == "OFF") || (msg == "off") || (msg == "0")) {
    Serial.println("Light turned Off");
    digitalWrite(LightPin,LOW);
  }
  else {
    Serial.println("Unknown command. Please try: ON, on, 1, OFF, off or 0.");
  }
}

void setup() {
  pinMode(LightPin,OUTPUT);
  pinMode(PhotoPin,INPUT);
  pinMode(DefaultPin,OUTPUT);

  Serial.begin(115200);
  blinking_loop();
  setup_wifi();
  client.setServer(mqtt_server, port);
  client.setCallback(callback);
}

void loop() {
  if (!client.connected()) {
    reconnect();
  }
  client.loop();

  val = analogRead(PhotoPin);

  if (prevVal != val || millis() - lastUpdateMillis > 3000) {
    lastUpdateMillis = millis();
    prevVal = val;
    client.publish(pubTopic,itoa(val, buf, 10));
    Serial.print("Updating value to ");
    Serial.println(val);
    delay(250);
  }
  delay(50);
}
  • Having the board connected, press the Upload Icon (or go to Sketch > Upload). When clicking to Upload you will be asked about saving the file. Choose where you want to save it.

Upload

  • Open the Serial Monitor going on Tools > Serial Monitor.
  • Set the baud rate to 115200 baud.

Baud

  • You should be able to see the following screen and your blue LED should be blinking.

Led Blinking

Wifi Configuration

  • In your Arduino File, replace the variables <wifi_ssid> and <wifi_password> with your wifi configuration:
// Wifi Config
const char* ssid = "My Wifi SSID";
const char* password = "My Wifi Password";
  • After uploading again , you should be able to get the IP address for the Wifi connection.

tingg tip: We will configure the MQTT connection later.

Wifi Configuration

Connection to tingg.io

Now comes the fun part.

We will configure your thing on tingg.io

  • If not registered yet, open the tingg.io and register a tingg.io account.
  • After that you should see the following screen:

Console Empty State

  • Click on Connect a Thing. Give it a name and a description.

  • Then click on Connect.

Connect a Thing

Thing List

  • Click on See Details to access the Things Details:

Console Empty State

Configuration of resources

Your Starter Kit includes a LED that will be turning on and off and a photoresistor that will show the value of the luminosity.

  • We will first configure the LED to the tingg.io platform. Click on Configure a Resource, add the following informations:
Resource topicResource MethodResource Type
lightSubscribe to data (Sub)String

Configure Resource Light

  • Then click on Configure
  • You should now see a card for the resource light that you just configured:

Console Light Card

  • We will now do the same for the photoresistor, Click on Configure a Resource , add the following informations:
Resource topicResource MethodResource Type
photoPublish to data (Pub)Integer

Configure Resource Photo

  • Then click on Configure
  • Great, you successfully configured 2 Resources to the tingg.io platform! πŸŽ‰ You should be able to see both resources cards you just configured:

Console Light and Photo Cards

Configuration of a Thing

  • Click on Settings tab to get all the configurations related to the thing:

Settings

  • Go back to your Arduino File.
  • We can now replace <thing_id> and <thing_key> default configurations with the Thing Configurations you can find in the Settings tab.
  • Replace <mqtt_server> with mqtt.tingg.io
  • Replace <pub_resource> with photo and <sub_resource> with light
// MQTT Config
const char* mqtt_server = "<mqtt_server>";
const int port = 1883; // 8883 for mqtts connections.

// Thing Config
const char* thing_id = "<thing_id>";
const char* key = "<thing_key>";

// Topics Config
const char* pubTopic = "<pub_resource>";
const char* subTopic = "<sub_resource>";
  • Your Arduino File should look like that:

Arduino Configuration Values

  • Now connect the board with the Photoresistor and the LED, configure the board as follow:

tingg tip: Now, we will start doing some manual work. Make sure to zoom in the image and connect the cable and devices on the correct place.

Material Getting Started

Consider the following:

  • The breadboard is aligned as the schema below.
  • NodeMCU board is plugged with the usb plug closer to the top.
  • We still have free spaces on the sides of the board (i.e. vertical lines A and J).

Sketch of Project

Now, check the connections we should have with cables:

  • A1 β†’ left red vertical line
  • A2 β†’ left blue vertical line
  • J1 β†’ right red vertical line
  • J2 β†’ right blue vertical line
  • A15 β†’ E 24
  • A19 β†’ left blue vertical line
  • J15 β†’ J25
  • J21 β†’ right blue vertical line
  • J28 β†’ right red vertical line

Checking the parts:

  • LED's shorter leg on B19 and LED's longer leg on B20
  • 220 ohms resistor on C20 β†’ C24
  • 10k ohms resistor on H21 β†’ H25
  • Photoresistor on F25 β†’ F28

Upload the Arduino File again. Tingg! πŸ¦– Congrats! You are now all set! πŸŽ‰

Checking the data

Now we can check that are able to receive and send data using tingg.io

  • Go back to the tingg.io website, refresh it and you should be able to see the following screen:

Resources

As you can see, we are receiving the photo sensor value*(from 0 to 1024). You can click on Live Data. After that we will see the values arriving on the chart, as the following screen.

tingg tip: If you can't see any data, try to put your finger over the sensor so it changes the values of the sensor.

Live Data

Also we can check historical data clicking on Charts.

Charts

  • Click on Debug and we see the log being generated real time.

Debug

  • Now We just need to select the light resource and send data to the thing. In this case, we can send texts with ON, OFF, on, off, 1 or 0.

Debug Light

This is it! Enjoy and have fun! πŸ¦–. Now you can control your thing send data and receiving data.

Connect Raspberry Pi using node.js

Preparation

Install node and npm

The Raspberry Pi does not come with the latest version of node.js, so we need to install it and the build-essentials. Be sure that your Raspberry Pi is connected to the Internet!

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs  # npm nodejs-legacy
sudo apt-get install -y build-essential
Install mqtt

It is useful to have the mqtt command line tools at hand. Install them globally with: npm install mqtt -g

The code
  • Create a new directory
mkdir myproject
  • Enter the new directory
cd  myproject
  • Create a new node.js project
npm init
  • Install the mqtt library for this project
npm install mqtt --save
  • Write your code Use your favourite text editor (e.g. nano) and edit the file provided at the end of this tutorial. We will go through the source code step by step. First, we need to import the mqtt package and make it accessible in our code through the variable mqtt:
const mqtt = require('mqtt');

We need to set the connection parameters in another variable called mqtt_options:

const mqtt_options={
  clientId: '<YOUR-THING-ID>',
  username: 'thing',
  password: '<YOUR-THING-KEY>',
  clean: true,
};
  • Now, we can open a connection to the tingg mqtt broker:
const client = mqtt.connect('mqtt://mqtt.tingg.io', mqtt_options);
  • We want to know that the Raspberry Pi is connected to tingg, so we add a listener for the β€œconnect” event and publish a message to the resource:
client.on('connect', function(){
  console.log('connected');
  client.publish('<YOUR-RESOURCE-NAME>', '<MESSAGE-PAYLOAD>');
});
  • If there are no more messages to send, we can close the connection. In this example, this will close the application.
client.end();

Example Let’s say, you created a thing with the following credentials:

Thing ID: Bf6e1aa1-b964-4eda-9e82-ec827e11c6ef
Thing Key: srxt8v8iag4uwb5u60aj2jmfs4ev4ws0

And you created a resource called button for this thing.

For this example, you can modify the source code like this:

const mqtt = require('mqtt');
const mqtt_options = {
  clientId: 'Bf6e1aa1-b964-4eda-9e82-ec827e11c6ef',
  username: 'thing',
  password: 'srxt8v8iag4uwb5u60aj2jmfs4ev4ws0',
  clean: true
};

const client = mqtt.connect('mqtt://mqtt.tingg.io', mqtt_options);


client.on('connect', function(){
  console.log('connected');
  client.publish('button', '1');
  client.end();
});

Run the Code

In the terminal, you can run the program now (change index.js to the filename that you created for your code):

node index.js