Arvand Tabatabaie
Published

IoT Solution with ESP32 Json and a Perfect Simple Platform

Platforms are the 3rd part of an IoT solution system. I recently found a new platform, which is very simple and easy to use. Ubeac can help.

IntermediateProtip24 minutes4,434
IoT Solution with ESP32 Json and a Perfect Simple Platform

Things used in this project

Hardware components

NodeMcu ESP32
×1

Software apps and online services

uBeac IoT Platform ubeac

Story

Read more

Code

IoT Solution ESP32 Code

C/C++
Its a simple code for just send something random to the Ubeac IoT Platform. I just use it to show how Ubeac is Easy and fast.
#include <WiFi.h>
#include <HTTPClient.h>
 
const char* ssid = "Irancell*******";
const char* password =  "*******";
const char* url =  "http://hub.ubeac.io/AWrzMkv98dpx";
String payload_pattern = "{'id':'MyESP','sensors':[{'id': 'Temperature','data': $temperature$},
{'id':'Humidity','value': $humidity$},{'id': 'Counter','value': $counter$}]}";

int counter = 0;

void setup() {
 
  Serial.begin(115200);
  delay(4000);   //Delay needed before calling the WiFi.begin
 
  WiFi.begin(ssid, password); 
 
  while (WiFi.status() != WL_CONNECTED) { //Check for the connection
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }
 
  Serial.println("Connected to the WiFi network");
 
}
 
void loop() {
  
 counter += 1;
 float temperature = 23.456;
 float humidity = 80.21;
 String payload = payload_pattern;
 payload.replace("$temperature$",String(temperature));
 payload.replace("$humidity$",String(humidity));
 payload.replace("$counter$",String(counter));
 
 if(WiFi.status()== WL_CONNECTED){ 
 
   HTTPClient http;   
 
   http.begin(url);  
   int httpResponseCode = http.POST(payload); 
 
   if(httpResponseCode>0){
    String response = http.getString(); 
    Serial.println(httpResponseCode);
    Serial.println(response);
   }else{
    Serial.print("Error on sending POST: ");
    Serial.println(httpResponseCode);
   }
   http.end();
 
 }else{
 
    Serial.println("Error in WiFi connection");   
 
 }
 
  delay(1000);  //Send a request every second
 
}

Credits

Arvand Tabatabaie

Arvand Tabatabaie

10 projects • 8 followers
My real life is stitch to IoT hardware and Platforms. everyday i find something new to work with and enjoy. some of my projects will be here

Comments