From d1a1fc3dc28dea7b1357c21a3fc2167bdf18e58f Mon Sep 17 00:00:00 2001 From: thunic Date: Sun, 26 Mar 2023 22:21:04 +0200 Subject: [PATCH] doesnt work because responsecode = -1 --- .gitignore | 3 +++ WorkerNode/NodeMCWifi/NodeMCWifi.ino | 32 ++++++++++++++-------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 0bdc70d..bae90c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ SQLHandler/config.json +.vscode/arduino.json +.gitignore +.vscode/c_cpp_properties.json diff --git a/WorkerNode/NodeMCWifi/NodeMCWifi.ino b/WorkerNode/NodeMCWifi/NodeMCWifi.ino index a3a5232..6e77211 100644 --- a/WorkerNode/NodeMCWifi/NodeMCWifi.ino +++ b/WorkerNode/NodeMCWifi/NodeMCWifi.ino @@ -20,7 +20,7 @@ DHT dht(DHT_PIN, DHT_TYPE); const char* ssid = "Andy"; const char* password = "AndyNicoChiara"; -const char* serverName = "http://192.168.178.170/sensordata"; +const char* serverName = "http://192.168.178.170:3564/sensordata"; // Moisture sensor variables int sense_Pin = 0; // sensor input at Analog pin A0 @@ -82,22 +82,9 @@ void loop() { */ if(WiFi.status()== WL_CONNECTED){ - WiFiClient client; - HTTPClient http; - - // Your Domain name with URL path or IP address with path - http.begin(client, serverName); - // Specify content-type header - //http.addHeader("Content-Type", "application/x-www-form-urlencoded"); - // Data to send with HTTP POST - //String httpRequestData = "moisture=" + String(moisture) + "&humidity="+ String(humidity) + "&temperature=" + String(temperature); - // Send HTTP POST request - //int httpResponseCode = http.POST(httpRequestData); + - // If you need an HTTP request with a content type: application/json, use the following: - http.addHeader("Content-Type", "application/json"); - - StaticJsonDocument<200> doc; + DynamicJsonDocument doc(2048); // Add values in the document doc["temperature"] = temperature; @@ -107,6 +94,16 @@ void loop() { String requestBody; serializeJson(doc, requestBody); + WiFiClient client; + HTTPClient http; + + + // Your Domain name with URL path or IP address with path + http.begin(client, serverName); + // If you need an HTTP request with a content type: application/json, use the following: + //http.addHeader("Content-Type", "application/json"); + + int httpResponseCode = http.POST(requestBody); // If you need an HTTP request with a content type: text/plain @@ -115,6 +112,9 @@ void loop() { Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); + + // Read response + Serial.print(http.getString()); // Free resources http.end();