I've developed a platform using NodeMCU which sends a number entered through a 3x4 keypad to a specified URL. This job is done without any problem using multiple WiFi networks and WiFi modem/routers but when I connect through my customer office modem/router WiFi network, after sending 3 or 4 times, I get "-1" return value from GET method! That's weird, no unusual configurations is on my customer modem/router. Here's the related piece of my code:
void loop()
{
if (WiFi.status() != WL_CONNECTED)
{
WiFi.begin(String(ssid), String(pass));
while (WiFi.status() != WL_CONNECTED)
{
lcd.print("WiFi .");
delay(500);
lcd.clear();
lcd.print("WiFi ..");
delay(500);
lcd.clear();
lcd.print("WiFi ...");
delay(500);
lcd.clear();
}
lcd.clear();
lcd.print("Phone number:");
}
char myKey = myKeypad.getKey();
if (myKey != NULL) {
if (myKey == '*') {
if (pn.length() != 0) {
pn.remove(pn.length() - 1, 1);
clearSecondLceLine();
lcd.setCursor(0, 1);
lcd.print(pn);
}
else {
reboot = 1;
}
}
else if (myKey == '#') {
if (pn.length() == 11)
{
String tmpUrl = String(url);
tmpUrl = tmpUrl + "?id=" + String(devid) + "-" + pn;
clearSecondLceLine();
lcd.setCursor(0, 1);
lcd.print("Sending .");
delay(500);
http.begin(tmpUrl);
http.addHeader("Content-Type", "text/plain");
httpCode = http.GET();
http.end();
clearSecondLceLine();
lcd.setCursor(0, 1);
while (true)
{
clearSecondLceLine();
lcd.setCursor(0, 1);
lcd.print("Sending ..");
delay(500);
clearSecondLceLine();
lcd.setCursor(0, 1);
lcd.print("Sending ...");
delay(500);
clearSecondLceLine();
lcd.setCursor(0, 1);
lcd.print("Sending ....");
delay(500);
if (httpCode == 200)
{
clearSecondLceLine();
lcd.setCursor(0, 1);
lcd.print("Sent");
break;
}
else
{
if (cnt > 0)
{
clearSecondLceLine();
lcd.setCursor(0, 1);
lcd.print("Failed");
cnt = 0;
break;
}
else
{
clearSecondLceLine();
lcd.setCursor(0, 1);
lcd.print("Failed, retrying");
cnt++;
String tmpUrl = String(url);
tmpUrl = tmpUrl + "?id=" + String(devid) + "-" + pn;
clearSecondLceLine();
lcd.setCursor(0, 1);
lcd.print("Sending .");
delay(500);
http.begin(tmpUrl);
http.addHeader("Content-Type", "text/plain");
httpCode = http.GET();
http.end();
continue;
}
}
}
pn = "";
delay(1000);
clearSecondLceLine();
lcd.setCursor(0, 1);
}
else if (pn.length() == 0) {
if (reboot == 1) {
lcd.clear();
while (true)
{
lcd.print("Flashing .");
delay(500);
lcd.clear();
lcd.print("Flashing ..");
delay(500);
lcd.clear();
lcd.print("Flashing ...");
delay(500);
lcd.clear();
lcd.print("Flashing ....");
delay(700);
lcd.clear();
lcd.print("Flashing .....");
delay(900);
lcd.clear();
break;
}
reboot = 0;
flashEeprom();
WiFi.disconnect();
ESP.restart();
}
}
}
else if (pn.length() < 11) {
reboot = 0;
pn += String(myKey);
clearSecondLceLine();
lcd.setCursor(0, 1);
lcd.print(pn);
}
}
}