/RobotDyn_UnoWiFi_Favoriot

A simple IoT experiment, using a RobotDyn Uno+WiFi board to monitor MQ-2 & DHT22 sensor, via Favoriot IoT platform.

Primary LanguageC++

favoriot

RobotDyn Uno+WiFi & Favoriot

Favoriot offers an IoT platform specifically designed for any Internet of Things (IoT) projects. The platform is developed to support the integration of data from sensors and actuators on the internet. Collecting and storing data from IoT devices become much easier. Moreover, the platform also helps developers in building vertical applications without worry about the hosting.

This article will present a step by step example how to upload gas, temperature & humidity sensor's value from RobotDyn Uno+WiFi to Favoriot IoT platform. Watch video below (or click here) for its demonstration, then follow these instructions to start building your project with RobotDyn Uno+WiFi & Favoriot.

Video UnoWiFi & Favoriot

1. What You Need 🎁

To build this project, you need the following items:

  • 1 RobotDyn Uno+WiFi board
  • 1 breadboard
  • 1 MQ-2 gas sensor
  • 1 DHT22 temperature & humidity sensor
  • some jumper wires
  • Arduino IDE (download here)

2. Schematics 🔧🔨

Gather your parts then follow the schematics below.

UnoWiFi schema

3. Favoriot Setup 💜

  • Device Developer ID

    Signup & login to Favoriot. If you are registered in Favoriot, you have a default device already created for you. Go to right platform on https://platform.favoriot.com and see the device panel to see the devices that are present. Basically you need the device_developer_id that might be something like defaultDevice@myusername. But if you want, you can create a new device and use it in this example.

  • API Key

    Now, go to your Favoriot Account Setting which is available on the top right corner in the dropdown and check your API key. You need this API key to complete this example. It's a big alphanumeric token like:

    '986673a6377ef1fde2357ebdcb0da582lintang150b00cabcd5a0d83045425407ab4'

4. Arduino Sketch 📋

First you need to install ESP8266 platform on Arduino IDE, follow these instructions: click here. Copy sketch below to your Arduino IDE. Make sure you have chosen the right option for Board and Port under Tools menu, then upload to your Arduino board.

#include <SPI.h>
#include <ESP8266WiFi.h>
#include <dht.h>
dht DHT;
#define DHT22_PIN 2

char ssid[] = "your_network_SSID";      // change it!
char pass[] = "your_network_password";  // change it!
const String yourDevice = "deviceDefault@your_Username"; // change it!
int status = WL_IDLE_STATUS;
char server[] = "api.favoriot.com";
WiFiClient client;

void setup() {
  Serial.begin(115200);
  pinMode(2,INPUT);
  WiFi.disconnect();
  Serial.println("Mulai menghubungkan");
  WiFi.begin(ssid,pass);
  while((!(WiFi.status() == WL_CONNECTED))){
    delay(300);
    Serial.print("...");
  }
  Serial.println(WiFi.status());
  Serial.println("Terhubung");
  Serial.println("");
}

void loop() {
  int chk = DHT.read22(DHT22_PIN);
  String suhu = String(DHT.temperature, 1);
  String lembab = String(DHT.humidity, 1);
  String gas = String(map(analogRead(A0),0,1024,100,0));
  
  String json = "{\"device_developer_id\":\""+yourDevice+"\",\"data\":{\"Suhu\":\""+suhu+"\",\"Kelembaban\":\""+lembab+"\",\"Gas\":\""+gas+"\"}}";
  Serial.println(json);
  if (client.connect(server, 80)) {
    client.println("POST /v1/streams HTTP/1.1");
    client.println("Host: api.favoriot.com");
    client.println(F("apikey: your_API_key"));  // change it!
    client.println("Content-Type: application/json");
    client.println("cache-control: no-cache");
    client.print("Content-Length: ");
    int thisLength = json.length();
    client.println(thisLength);
    client.println("Connection: close");
    client.println();
    client.println(json);
  }

  while (client.available()) {
    char c = client.read();
    Serial.write(c);
  }

  if (!client.connected()) {
    client.stop();
  }

  delay(5000);
}

5. Have Fun! 😎

Now you can monitor your MQ-2 & DHT22 every 5 seconds on Favoriot dashboard. For more information about Favoriot, read its full documentation: click here.

My other tutorials on Favoriot:

Lintang Wisesa 💌 lintangwisesa@ymail.com

Facebook | Twitter | Google+ | Youtube | :octocat: GitHub | Hackster