-
Notifications
You must be signed in to change notification settings - Fork 13.3k
I cannot send data to a server when using lwIP v2 #4495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Today I modified my sketch, and now it works with both lwIP v1.4 Higher Bandwidth and lwIP v2 Higher Bandwidth. #include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#define USE_SERIAL Serial
ESP8266WiFiMulti WiFiMulti;
long int previousMilisStormWarning=0;
float Pressure_mmHg = 760.00;
float PressureHourDifference = 1.00;
void setup() {
USE_SERIAL.begin(19200);
// USE_SERIAL.setDebugOutput(true);
USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
for (uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
USE_SERIAL.flush();
delay(1000);
}
WiFi.mode(WIFI_STA);
WiFiMulti.addAP("myNetwork", "myPassword");
IPAddress ip(192, 168, 2, 213);
IPAddress gateway(192, 168, 2, 1);
IPAddress subnet(255, 255, 255, 0);
WiFi.config(ip, gateway, subnet);
}
void loop() {
if (millis() - previousMilisStormWarning >= 60000 ) {
previousMilisStormWarning = millis();
HTTPClient http;
http.begin("http://maker.ifttt.com/trigger/storm_warning/with/key/dxnXXXXXXXXXXXXXXzSI");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
http.POST("value1="+String(Pressure_mmHg) + "&value2="+String(PressureHourDifference));
Serial.println("Response from server:");
http.writeToStream(&Serial);
Serial.println();
http.end();
}
}
|
I found a fix for my issue. update: Ok, now my big sketch works with lwIP v2 also. Problem solved. #include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>
// Replace with your network credentials
const char* ssid = "myNetwork";
const char* password = "myPassword";
WiFiClient client;
long int previousMilisStormWarning=0;
float Pressure_mmHg = 760.00;
float PressureHourDifference = 1.00;
void setup() {
Serial.begin(19200);
WiFi.mode(WIFI_STA);
// important delay, it doesn't send data to the server without it (only needed if using lwIP v2)
delay(4000);
WiFi.begin(ssid, password);
IPAddress ip(192, 168, 2, 213);
IPAddress gateway(192, 168, 2, 1);
IPAddress subnet(255, 255, 255, 0);
WiFi.config(ip, gateway, subnet);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
}
void loop() {
if (millis() - previousMilisStormWarning >= 60000 ) {
previousMilisStormWarning = millis();
HTTPClient http;
http.begin("http://maker.ifttt.com/trigger/storm_warning/with/key/dxnXXXXXXXXXXXXXXzSI");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
http.POST("value1="+String(Pressure_mmHg) + "&value2="+String(PressureHourDifference));
Serial.println("Response from server:");
http.writeToStream(&Serial);
Serial.println();
http.end();
}
} |
probably the problem is
|
@5chufti I am not an expert, but the sketch is waiting 60 seconds before executing http.begin() is it not enough? Also, my delay(4000) is before WiFi.begin(ssid, password) so it shouldn't have any effect at all, but it has. Anyways my programming knowledge is limited, but I am still curious what is going on. |
I will get to this lwip2 issue as soon as I have some spare time. |
ok, didn't realize the "wait" at begin of loop(). It will not be 60s for the first loop but fair enough. As I do almost the same and don't have a problem see my code for connecting and transfer
I use the result of client.print() and the server response in debug version
instead of client.flush(), but as I run the sensor with deep sleep I use an optimistic shortcut for real. |
@5chufti I also use almost the same code to send my data to ThingSpeak in my big sketch, and it didn't work with lwip v2 (without that delay), but I only check like this: if(client.connect(SERVER, 80)) and then I send the data. The interesting thing that web server and WebSocketsServer work fine, only sending data to IFTTT and ThingSpeak stops working after choosing lwip v2. But that delay(4000) somehow fixed my problem. It would be interesting to see if someone can reproduce the issue using those examples above. |
The problem appears that the sketch does not set any dns server address. Then the maker.iffft.com server cannot be resolved, and the "connection refused" (which is wrong, should be something like "unknown host"). With the extra delay it works because by default a dhcp server is requested, and the answer comes up with a dns server in the reply. Then after assigning static addresses, with a luckily valid dns server, the address can be resolved. Without the delay, this works: Now we need to check
|
🤦♂️ doh ... should have seen that ... |
It is good that we know what causes the issue, but I still don't understand how... I mean ESP8266 will try to connect to AP (the router) after |
@Deimos1994 Without the delay, the dns information does not come through dhcp, nor through your static IP request. Without dns, esp cannot resolve ifttt.com to its IP. You can see that in action with debug mode enabled in the Tool menu of the arduino IDE. |
@d-a-v, is this bug all done? Looks like it, but you're the expert here. |
Closing as sorted out |
Basic Infos
Platform
Settings in IDE
Problem Description
I cannot send data to IFTTT when using lwIP v2. With lwIP v1.4 it works fine.
I use core version: 2.4.1, but it doesn't send data with 2.4.0 and lwIP v2 also.
I also have a sketch that uses client.connect(serverThingSpeak, 80) and sends data to ThingSpeak, and it also stops working after choosing lwIP v2.
Is it a bug?
Sketch:
Debug Messages
The text was updated successfully, but these errors were encountered: