diff --git a/project.jpg b/project.jpg new file mode 100644 index 0000000..4779cbb Binary files /dev/null and b/project.jpg differ diff --git a/readme.md b/readme.md index b898743..122de67 100644 --- a/readme.md +++ b/readme.md @@ -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 \ No newline at end of file +### 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]() \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index d661ce5..8e7afc1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels @@ -18,6 +19,9 @@ String dataIn; const char *ssid = "KARAN"; const char *password = "12345679"; +HTTPClient http; +String url = "http://192.168.20.45:3001/"; + void displayData(String data) { display.clearDisplay(); @@ -52,28 +56,35 @@ void seperator(String data) int count = 0; String dataForDisplay = ""; - + String jsonSend ="{\"fase\":"; while (token != NULL) { switch (count) { case 1: dataForDisplay += String(token) +"\n"; + Serial.println(String(token)); + jsonSend +="\""+ String(token) + "\","; break; case 2: dataForDisplay += ifElse(String(token), "Voltage", "V"); + jsonSend += "\"voltage\":\""+ String(token) + "\","; break; case 3: dataForDisplay += ifElse(String(token), "Current", "A"); + jsonSend += "\"current\":\""+ String(token) + "\","; break; case 4: dataForDisplay += ifElse(String(token), "Power", "W"); + jsonSend += "\"power\":\"" + String(token) + "\","; break; case 5: dataForDisplay += ifElse(String(token), "Energy", "kWh"); + jsonSend += "\"energy\":\"" + String(token) + "\","; break; case 6: dataForDisplay += ifElse(String(token), "Power Factor", "pf"); + jsonSend += "\"pf\":\"" + String(token) + "\""; break; default: dataForDisplay += ifElse(String(token), "Wifi", ""); @@ -82,8 +93,25 @@ void seperator(String data) token = strtok(NULL, ","); // Get the next token count++; } + jsonSend += "}"; 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()