doesnt work because responsecode = -1

main
thunic 3 years ago
parent bb69d68e74
commit d1a1fc3dc2

3
.gitignore vendored

@ -1 +1,4 @@
SQLHandler/config.json SQLHandler/config.json
.vscode/arduino.json
.gitignore
.vscode/c_cpp_properties.json

@ -20,7 +20,7 @@ DHT dht(DHT_PIN, DHT_TYPE);
const char* ssid = "Andy"; const char* ssid = "Andy";
const char* password = "AndyNicoChiara"; 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 // Moisture sensor variables
int sense_Pin = 0; // sensor input at Analog pin A0 int sense_Pin = 0; // sensor input at Analog pin A0
@ -82,22 +82,9 @@ void loop() {
*/ */
if(WiFi.status()== WL_CONNECTED){ 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: DynamicJsonDocument doc(2048);
http.addHeader("Content-Type", "application/json");
StaticJsonDocument<200> doc;
// Add values in the document // Add values in the document
doc["temperature"] = temperature; doc["temperature"] = temperature;
@ -107,6 +94,16 @@ void loop() {
String requestBody; String requestBody;
serializeJson(doc, 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); int httpResponseCode = http.POST(requestBody);
// If you need an HTTP request with a content type: text/plain // If you need an HTTP request with a content type: text/plain
@ -115,6 +112,9 @@ void loop() {
Serial.print("HTTP Response code: "); Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode); Serial.println(httpResponseCode);
// Read response
Serial.print(http.getString());
// Free resources // Free resources
http.end(); http.end();

Loading…
Cancel
Save