HTTP CLIENT RETURN -1 always

Hi,
from no reason my code stop working i dont add anything or delete anything but http client return -1 always if i connect to serial monitor on early maked device with same code it work without any problem
I am relay stuck here can anyone help my why this happen ?

EDIT: i find somewhere it can be cause when device have low memory, is that possible ? how can i free up some memory ?

i am unable to post whole code here so i upload it to GitHub:
https://github.com/GamerClassN7/MeteoStation/blob/master/sketch_ino

JonatanRek:
how can i free up some memory ?

Start by puting all your literal strings in the F macro.

Serial.println("HW: " + String(hwId));
Serial.println(F("HW: ") + String(hwId));

Only those in serial print ?

EDIT: done

https://github.com/GamerClassN7/MeteoStation/edit/master/sketch_ino

EDIT compilation end up with error

conversion from 'const __FlashStringHelper*' to 'const StringSumHelper' is ambiguous

EDIT: Compilation error solved by separating it to two lines

Serial.println("HW: "); 
Serial.print(String(hwId));

EDIT: still successful to send request

JonatanRek:
Only those in serial print ?

ALL literal strings. Not just the ones in Serial.print.

If you are doing string manipulation with strcpy and strcat etc then Arduino provides versions of these functions, strcpy_P and strcat_P, where the second parameter is a literal string in an F() macro.

Do that to all strings :confused: without any success HTTP request still dont work.

Edit: it is really weird that both think work separately but not together

I try to separate code to two sketch

first: Setting HTTP server save to EEPROM
second: Connect to WI-FI send Request

But not together :confused:

Have anyone similar experience like i have ?

HA!

Finally get that working now it return 400 and message

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.

</p>
<hr>
<address>Apache/2.4.25 (Debian) Server at ***.****.** Port 80</address>
</body></html>

But when i test it via curl it return with same payload … it return 200.

Updated code: https://github.com/GamerClassN7/MeteoStation/edit/master/sketch_ino

So my next question is could be payload corrupted by low free memory size ?

I could not see your later version of code, but the original one was quite full of ISSUES.
I did not bother to read it fully.
Remember that the setup(){} runs once and the loop(){} is called after the setup() has been done.
Normally you would put all the Wifi connection stuff in Setup()

I would make a suggestion that you step back a bit and construct each bit seperatly, test, improve and then once done merge back into your original project.

Get the Wifi and serial parts going first.
And then add in the DHT and other extras.

All the basic examples will give a starting framework for each section.

Hiddenvision:
I could not see your later version of code, but the original one was quite full of ISSUES.
I did not bother to read it fully.
Remember that the setup(){} runs once and the loop(){} is called after the setup() has been done.
Normally you would put all the Wifi connection stuff in Setup()

I would make a suggestion that you step back a bit and construct each bit seperatly, test, improve and then once done merge back into your original project.

Get the Wifi and serial parts going first.
And then add in the DHT and other extras.

All the basic examples will give a starting framework for each section.

  1. it is easy to say that everything is wrong, can you be more specific ?
  2. i do that several time, it work like charm every time without any issues
  3. i dont have problem with connecting to WiFi or reading dht11 values
  4. i cant connect to WiFi in setup(){} because i need to have power consumption low as possible i am ruining it on battery & i am running deepSleep() and on each run setup is not called only once on turn on or restart.
  5. i have only problem with sending POST request witch is tested via restAPI so i know that is 100% correct, but server always return
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.

</p>
<hr>
<address>Apache/2.4.25 (Debian) Server at ***.****.** Port 80</address>
</body></html>

so i thing that something happen just in time when http.POST((String) requestJson); is called.

But thanks! for your suggestions :slight_smile:

I am really unable to fix the problem :slight_smile: could anyone, absolutely anyone help me ?

The link to your code example does not work for me.
If you post your code then I can take a look.

Hiddenvision:
The link to your code example does not work for me.
If you post your code then I can take a look.

i rewrite it seweral times nothing worked :frowning:

and if you are crazy enough i would love some people to join my project :slight_smile: