added the project image
This commit is contained in:
parent
07b2850c84
commit
b0d3c58fb4
Binary file not shown.
After Width: | Height: | Size: 106 KiB |
|
@ -1 +1,4 @@
|
||||||
### this is for esp32, where it receive the sensor data from arduino uno and send it to server, this esp32 is connected to arduino uno and oled 128x64 for displaying the data
|
### this is for esp32, where it receive the sensor data from arduino uno and send it to server, this esp32 is connected to arduino uno and oled 128x64 for displaying the data
|
||||||
|
|
||||||
|
|
||||||
|
![alt text](<project.jpg>)
|
30
src/main.cpp
30
src/main.cpp
|
@ -3,6 +3,7 @@
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <Adafruit_GFX.h>
|
#include <Adafruit_GFX.h>
|
||||||
#include <Adafruit_SSD1306.h>
|
#include <Adafruit_SSD1306.h>
|
||||||
|
#include <HTTPClient.h>
|
||||||
|
|
||||||
#define SCREEN_WIDTH 128 // OLED display width, in pixels
|
#define SCREEN_WIDTH 128 // OLED display width, in pixels
|
||||||
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
|
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
|
||||||
|
@ -18,6 +19,9 @@ String dataIn;
|
||||||
const char *ssid = "KARAN";
|
const char *ssid = "KARAN";
|
||||||
const char *password = "12345679";
|
const char *password = "12345679";
|
||||||
|
|
||||||
|
HTTPClient http;
|
||||||
|
String url = "http://192.168.20.45:3001/";
|
||||||
|
|
||||||
void displayData(String data)
|
void displayData(String data)
|
||||||
{
|
{
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
|
@ -52,28 +56,35 @@ void seperator(String data)
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
String dataForDisplay = "";
|
String dataForDisplay = "";
|
||||||
|
String jsonSend ="{\"fase\":";
|
||||||
while (token != NULL)
|
while (token != NULL)
|
||||||
{
|
{
|
||||||
switch (count)
|
switch (count)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
dataForDisplay += String(token) +"\n";
|
dataForDisplay += String(token) +"\n";
|
||||||
|
Serial.println(String(token));
|
||||||
|
jsonSend +="\""+ String(token) + "\",";
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
dataForDisplay += ifElse(String(token), "Voltage", "V");
|
dataForDisplay += ifElse(String(token), "Voltage", "V");
|
||||||
|
jsonSend += "\"voltage\":\""+ String(token) + "\",";
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
dataForDisplay += ifElse(String(token), "Current", "A");
|
dataForDisplay += ifElse(String(token), "Current", "A");
|
||||||
|
jsonSend += "\"current\":\""+ String(token) + "\",";
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
dataForDisplay += ifElse(String(token), "Power", "W");
|
dataForDisplay += ifElse(String(token), "Power", "W");
|
||||||
|
jsonSend += "\"power\":\"" + String(token) + "\",";
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
dataForDisplay += ifElse(String(token), "Energy", "kWh");
|
dataForDisplay += ifElse(String(token), "Energy", "kWh");
|
||||||
|
jsonSend += "\"energy\":\"" + String(token) + "\",";
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
dataForDisplay += ifElse(String(token), "Power Factor", "pf");
|
dataForDisplay += ifElse(String(token), "Power Factor", "pf");
|
||||||
|
jsonSend += "\"pf\":\"" + String(token) + "\"";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dataForDisplay += ifElse(String(token), "Wifi", "");
|
dataForDisplay += ifElse(String(token), "Wifi", "");
|
||||||
|
@ -82,8 +93,25 @@ void seperator(String data)
|
||||||
token = strtok(NULL, ","); // Get the next token
|
token = strtok(NULL, ","); // Get the next token
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
jsonSend += "}";
|
||||||
|
|
||||||
displayData(dataForDisplay);
|
displayData(dataForDisplay);
|
||||||
|
Serial.println(jsonSend);
|
||||||
|
http.begin(url);
|
||||||
|
http.addHeader("Content-Type", "application/json");
|
||||||
|
int httpResponseCode = http.POST(jsonSend);
|
||||||
|
|
||||||
|
if (httpResponseCode > 0) {
|
||||||
|
Serial.print("HTTP Response code: ");
|
||||||
|
Serial.println(httpResponseCode);
|
||||||
|
String payload = http.getString();
|
||||||
|
Serial.println(payload);
|
||||||
|
}else{
|
||||||
|
Serial.print("Error code: ");
|
||||||
|
Serial.println(httpResponseCode);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
|
|
Loading…
Reference in New Issue