Data Logging Using Favoriot IoT Platform and ESP32

Now, Favoriot IoT platform with Arduino ESP32 board!

INTRODUCTION

Instead of using Favoriot IoT platform with Raspberry Pi, we also can do it with ESP32 board. Before that, please refer the following tutorial first.

VIDEO

This video will show you how to store data into Favoriot IoT platform using ESP32 board.

Untuk versi bahasa Melayu sila rujuk video dibawah.

HARDWARE PREPARATION

Below is the list of items used in the video.

Wiring connection table.

Node32 LiteDHT22
3.3VVCC
GNDGND
25DAT

Sample Code

This is sample code used in the video. Please replace Your Favoriot APIKEY” and “Your Device Developer ID” with yours. This code is using following library:

/*
* Board: Node32 Lite (ESP32 Dev Module)
* https://www.cytron.io/p-node32-lite-wifi-and-amp;-bluetooth-development-kit
*/
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <SimpleDHT.h>
#define APIKEY "Your Favoriot APIKEY"
#define DEVICE_DEV_ID "Your Device Developer ID"
const int SEN_PIN = 25;
SimpleDHT22 dht22(SEN_PIN);
const char ssid[] = "Your WiFi SSID";
const char password[] = "Your WiFi Password";
float temperature = 0;
float humidity = 0;
long previousMillis = 0;
int interval = 5000; // 5 seconds
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
Serial.print("Connecting to ");
Serial.print(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected!");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
}
void loop()
{
if (millis() - previousMillis > interval) {
int err = SimpleDHTErrSuccess;
if ((err = dht22.read2(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("Read DHT22 failed, err="); Serial.println(err);
delay(1000);
return;
}
Serial.print("Sample OK: ");
Serial.print((float)temperature);
Serial.print(" *C, ");
Serial.print((float)humidity);
Serial.println(" RH%");
StaticJsonDocument<200> doc;
JsonObject root = doc.to<JsonObject>(); // Json Object refer to { }
root["device_developer_id"] = DEVICE_DEV_ID;
JsonObject data = root.createNestedObject("data");
data["temperature"] = (int)temperature;
data["humidity"] = (int)humidity;
String body;
serializeJson(root, body);
Serial.println(body);
HTTPClient http;
http.begin("http://api.favoriot.com/v1/streams");
http.addHeader("Content-Type", "application/json");
http.addHeader("Apikey", APIKEY);
int httpCode = http.POST(body);
if (httpCode > 0) {
Serial.printf("[HTTP] POST... code: %d\n", httpCode);
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
}
}
else {
Serial.printf("[HTTP] POST... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
previousMillis = millis();
}
}
view raw ESP32Favoriot.ino hosted with ❤ by GitHub

Thank You

References:

  1. Getting Started With Favoriot IoT Platform Using Raspberry Pi

Thanks for reading this tutorial. If you have any technical inquiry, please post at Cytron Technical Forum.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

Why Raspberry Pi is the future of computing devices?
Face Recognition Door Lock System Using OpenCV on Raspberry Pi
Send Data to Firebase Using Arduino Uno WiFi Rev2
Simple Alarm System Using Maker Nano
Program Cucumber ESP32-S2 Using CircuitPython
Scroll to Top