Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By hunterwc
#60649 Dont look at this old code :)

There is new:
Code: Select all#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 :

Code: Select allsketch\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
User avatar
By martinayotte
#60659 I've copied/pasted your code, there was a missing bracket around there :

Code: Select all    while(client.available()){
          client.readStringUntil('\n');


Also, I don't understand why you are doing so many of those readStringUntil(), you should probably looks if those are empty line and skip them until real data comes in.

I've compiled it without errors. So, I don't know where the errors you shown is coming from.
Googling it seems that such thing occurs in old version of ArduinoESP :
https://github.com/esp8266/Arduino/issues/500
Which version are you running ?