Arduino MKR1000 & Favoriot

A simple IoT experiment, using an Arduino MKR1000 board to monitor a potentiometer and DHT11 sensor via Favoriot IoT platform.

favoriotok_29nHr0Rvhs

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×8

Software apps and online services

Arduino IDE
Arduino IDE

Story

MKR1000_Favoriot_Schematics

3. Favoriot Setup ?

  • Device Developer IDSignup & 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 KeyNow, 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:
'986673un6377ef1fde2357ebdcb0da582lintang150b00cabcd5a0d83045425407ab4'

4. Arduino Sketch ?

First you need to install Arduino MKR1000 platform on Arduino IDE, follow these instructions: click here. Install Adafruit DHT11 and WiFi101 library, then copy sketch below to your Arduino IDE. Make sure you have chosen the right option for Board et Port under Outils menu, then upload to your Arduino MKR1000 board.

5. Have Fun! ?

Now you can monitor your potentiometer and DHT11 sensor every five seconds on Favoriot data stream menu, and create data visualization on graph section. For more information about Favoriot, read its full documentation here.MKR1000_Favoriot_Graph

Code

#define _DISABLE_TLS_
#include <SPI.h>
#include <WiFi101.h>
#include "DHT.h" 

#define DHTPIN 6
#define DHTTYPE DHT11
DHT dht(DHTPIN,DHTTYPE);

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);
  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() {
  String pot = String(map(analogRead(A0), 0, 1023, 0, 100));
  String temp = String(dht.readTemperature());
  String humid = String(dht.readHumidity());
  String json = "{\"device_developer_id\":\""+yourDevice+"\",\"data\":{\"Potentio\":\""+pot+"\",\"Temperature\":\""+temp+"\",\"Humidity\":\""+humid+"\"}}";
  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);
  }
  delay(5000);
}

Source : Arduino MKR1000 & Favoriot


A Propos De L'Auteur

Ibrar Ayyub

Je suis expérimenté, rédacteur technique, titulaire d'une Maîtrise en informatique de BZU Multan, Pakistan à l'Université. Avec un arrière-plan couvrant diverses industries, notamment en matière de domotique et de l'ingénierie, j'ai perfectionné mes compétences dans la rédaction claire et concise du contenu. Compétent en tirant parti de l'infographie et des diagrammes, je m'efforce de simplifier des concepts complexes pour les lecteurs. Ma force réside dans une recherche approfondie et de présenter l'information de façon structurée et logique format.

Suivez-Nous:
LinkedinTwitter

Laisser un Commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

fr_FRFrench
Faire défiler vers le Haut