There is new:
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#define WiFiSSID "strych"
#define WiFiHaslo "marianna73"
#define adresSerwera "192.168.1.14"
#define portSerwera 80
void setup() {
Serial.begin(115200);
wifiConnect();
}
void loop() {
float t,h;
t=2;
h=3;
wyslijDane(t,h);
delay((uint16_t) 10 * 1000);
}
void wifiConnect()
{
Serial.print("Trwa laczenie z siecia");
WiFi.begin(WiFiSSID, WiFiHaslo);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("Nawiazano polaczenie WiFi");
}
void wyslijDane(float t,float h)
{
WiFiClient client;
while(!client.connect(adresSerwera, portSerwera)) {
Serial.println("blad polaczenia");
wifiConnect();
}
String url = "/food/conec.php?temperatura="+String(t)+"&wilgotnosc="+String(h);
Serial.print("Wysylam dane na serwer: ");
Serial.println(url);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + String(adresSerwera) + "\r\n" +
"Connection: close\r\n" +
"Content-Length: 0\r\n" +
"\r\n");
delay(3000);
while(client.available()){
client.readStringUntil('\n');
client.readStringUntil('\n');
client.readStringUntil('\n');
client.readStringUntil('\n');
client.readStringUntil('\n');
client.readStringUntil('\n');
client.readStringUntil('\n');
client.readStringUntil('\n');
client.readStringUntil('\n');
String acc = client.readStringUntil('\n');
Serial.print(acc);
//acc is : {"temp_min":"20","temp_max":"30","humidity_min":"30","humidity_max":"65","food_min":"20"}
char response[1024];
strncpy(response, acc.c_str(), sizeof(response));
response[sizeof(response) - 1] = 0; // get response here
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(response);
// Note the '&' above
if (!root.success()) {
Serial.println("parseObject() failed");
return;
}
const char* temp_min = root["temp_min"];
const char* temp_max = root["temp_max"];
const char* humidity_min = root["humidity_min"];
const char* humidity_max = root["humidity_max"];
const char* food_min = root["food_min"];
}
And i think it should work but i have these errors :
sketch\Blink.ino.cpp.o:(.text._ZN11ArduinoJson9JsonArray7invalidEv[_ZN11ArduinoJson9JsonArray7invalidEv]+0x8): undefined reference to `__cxa_guard_acquire'
sketch\Blink.ino.cpp.o:(.text._ZN11ArduinoJson9JsonArray7invalidEv[_ZN11ArduinoJson9JsonArray7invalidEv]+0xc): undefined reference to `__cxa_guard_release'
sketch\Blink.ino.cpp.o: In function `ArduinoJson::JsonArray::invalid()':
C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master/include/ArduinoJson/JsonArray.hpp:148: undefined reference to `__cxa_guard_acquire'
C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master/include/ArduinoJson/JsonArray.hpp:148: undefined reference to `__cxa_guard_release'
sketch\Blink.ino.cpp.o: In function `ArduinoJson::JsonObject::invalid()':
C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master/include/ArduinoJson/JsonObject.hpp:131: undefined reference to `__cxa_guard_acquire'
C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master/include/ArduinoJson/JsonObject.hpp:131: undefined reference to `__cxa_guard_release'
collect2.exe: error: ld returned 1 exit status