ESP8266 http POST kérés nem megy...
Sziasztok!
Csináltam egy ESP8266 alapon egy 5 csatornás hőmérsékletmérő eszközt, ami WiFi-n HTTP POST-al tolná
föl az adatokat egy szerverre. (Arduino framework, Platform.IO)
Nem értem, a válasz a POST kérésnek:
"HTTP Response code: 400" - tehát valami szintaktikai hiba lehet?! Már a szemem kifolyik, nem találom
a hibám.
Ez a programrész:
bool puthttp() { bool result = false; long rssi = WiFi.RSSI(); String localip = WiFi.localIP().toString(); WiFiClient client; HTTPClient http; char jsonstr[400]; char jsonstr2[100]; char jsonstr3[30]; Serial.println(serverstr); snprintf(jsonstr, sizeof(jsonstr), "{\"device_id\":%d, \"ip_address\":\"%s\", \"ssid\":\"%s\", \"rssi\":%d, ",didx,localip.c_str(),ssidstr,rssi); snprintf(jsonstr2, sizeof(jsonstr2), "\"value_1\":%.1f, \"value_2\":%.1f, \"value_3\":%.1f, \"value_4\":%.1f, \"value_5\":%.1f, ",hom1,hom2,hom3,hom4,hom5); snprintf(jsonstr3, sizeof(jsonstr3), "\"timestamp\":%ld}", helyiUTC); strncat(jsonstr, jsonstr2, sizeof(jsonstr2)); strncat(jsonstr, jsonstr3, sizeof(jsonstr3)); Serial.println(jsonstr); // Your Domain name with URL path or IP address with path Serial.print("http.begin:"); bool mi = http.begin(client, serverstr); Serial.println(mi); http.addHeader("Content-Type", "application/json"); int httpResponseCode = http.POST(jsonstr); //int httpResponseCode = http.POST("{\"value\": 20 }"); Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); http.end(); if (httpResponseCode == 200) result = true; return result; }
És ez a készített "jsonstr":
{"device_id":10170, "ip_address":"192.168.3.162", "ssid":"gentoom", "rssi":-62, "value_1":22.8, "value_2":-100.0,
"value_3":-100.0, "value_4":-100.0, "value_5":-100.0, "timestamp":1709045163}
Köszönöm!
Roland
- Tovább (ESP8266 http POST kérés nem megy...)
- 905 megtekintés