HttpClient failing suddenly - solved

i have these two devices (ESP8266), collecting water usage info at two locations. they are running the same code.

one is nearby and one is 60 miles away.

I recently added some code to do dynamic firmware updates, and the process starts by sending an HttpClient GET request to my aws server to get the current software version available on the server. (by mac address)
the side effect also sends the current version string, which is saved at the server…

the HttpClient code is called from an interval timer… once every 15 minutes (the distant device) and 2 minutes (the local device)…

I can see the device requests by looking at the server http/access_log. and up til yesterday it was solid as a rock… every 15 minutes…

now, nothing…

the local device is still working just fine.

the water level info is still being recorded (using Blynk) … so the device connection to wifi is good,
the timers are working (info reported every minute to Blynk server)

the get request is using a dns name, not ip address. I don’t know what Blynk is doing under the covers.

the code used on timer
as the device is 60 miles away I cannot connect to the serial port to see any messages
am I doing something wrong…


void checkForUpdates() {
String mac = getMAC();
String fwURL = String("/version.php?mac=" );
fwURL.concat( mac );
String fwVersionURL = fwURL;
fwVersionURL.concat( "&type=version_check" );
fwVersionURL.concat( "&version=");
fwVersionURL.concat(urlencode(compile_date));

Serial.println( "Checking for firmware updates." );
Serial.print( "MAC address: " );
Serial.println( mac );
Serial.print( "Firmware version URL: " );
Serial.println( fwVersionURL );

// This will free the socket on the WiFi shield
// httpClient.stop();

// if there's a successful connection:
httpClient.begin(server, updatePort,fwVersionURL); // < --- did this fail?
Serial.println("connecting...");
// send the HTTP GET request:
int httpCode = httpClient.GET(); // < --- this should cause an entry in the access log

if( httpCode == 200 ) {
String newFWVersion = httpClient.getString();

newFWVersion.trim();

// Serial.println( "compile date=: "+ String(compile_date) );

Serial.print( "Current firmware version: " );
Serial.println( String(compile_date) );
Serial.print( "Available firmware version: " );
Serial.println( String(newFWVersion));

if( !newFWVersion.equals(String(compile_date))){
Serial.println( "Preparing to update" );

String fwImageURL = fwURL;
fwImageURL.concat( "&type=bin" );
Serial.println("will get binary update from="+fwImageURL);
t_httpUpdate_return ret = ESPhttpUpdate.update( server, updatePort,fwImageURL );

switch(ret) {
case HTTP_UPDATE_FAILED:
Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s \n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
break;

case HTTP_UPDATE_NO_UPDATES:
Serial.println("HTTP_UPDATE_NO_UPDATES");
break;
default:
Serial.println("update return code="+ ret);
break;
} 
}
else {
Serial.println( "Already on latest version" );
}
}
else {
Serial.print( "Firmware version check failed, got HTTP response code " );
Serial.println( httpCode );
}
httpClient.end();
}
String getMAC()
{
uint8_t mac[6];
char result[14];
WiFi.macAddress(mac);
snprintf( result, sizeof( result ), "%02x%02x%02x%02x%02x%02x", mac[ 0 ], mac[ 1 ], mac[ 2 ], mac[ 3 ], mac[ 4 ], mac[ 5 ] );

return String( result );
}

an example of the serial port debug messages (from the local device)

08:50:33.609 -> Checking for firmware updates.
08:50:33.609 -> MAC address: 84f3eb0c8538
08:50:33.644 -> Firmware version URL: /version.php?mac=84f3eb0c8538&type=version_check&version=compiled%3AApr%2015%202019%2007%3A20%3A25%3B
08:50:33.644 -> connecting...
08:50:36.321 -> Current firmware version: compiled:Apr 15 2019 07:20:25;
08:50:36.321 -> Available firmware version: compiled:Apr 15 2019 07:20:25;
08:50:36.321 -> Already on latest version

and the access_log entry for this at the server

47.220.WWW.ZZZ - - [18/Apr/2019:13:50:36 +0000] "GET /version.php?mac=84f3eb0c8538&type=version_check&version=compiled%3AApr%2015%202019%2007%3A20%3A25%3B HTTP/1.1" 200 30 "-" "ESP8266HTTPClient"

the last accesses from the remote location 67.44.www.zzz - - [17/Apr/2019:19:02:33 +0000] "GET /version.php?mac=84f3eb0c8316&type=version_check&version=compiled%3A Apr%2014%202019%2013%3A31%3A22%3B HTTP/1.1" 200 30 "-" "ESP8266HTTPClient" 67.44.www.zzz - - [17/Apr/2019:19:17:32 +0000] "GET /version.php?mac=84f3eb0c8316&type=version_check&version=compiled%3A Apr%2014%202019%2013%3A31%3A22%3B HTTP/1.1" 200 30 "-" "ESP8266HTTPClient" 67.44.www.zzz - - [17/Apr/2019:19:32:33 +0000] "GET /version.php?mac=84f3eb0c8316&type=version_check&version=compiled%3A Apr%2014%202019%2013%3A31%3A22%3B HTTP/1.1" 200 30 "-" "ESP8266HTTPClient"

As the device is 60 miles away, why do you assume a software issue when it fails to check in on time?

it is supposed to check in every 15 minutes.. and I should see that in the server access log..

the timer fires every 15 minutes..

its been over a day now since last get request

so, something is not working... I cannot provide a software update if this heartbeat doesn't work..

so, something is not working

Someone could have stolen it. It could have been struck by lightening. There are many possibilities that I would consider more likely than the possibility that functioning code quit functioning because it was feeling put upon.

it is in a locked garage, so no-one is stealing it…

but… you missed the other comment…

it is still reporting its WATER monitoring functions to another server…
so, that part IS RUNNING as expected

SO, it is powered on, connected to the wifi network, has access to the internet (can send Blynk data)
that function is also on a timer, so timers are working…

I expect that this functions timer is also working… (worked for almost 3 days)
so… something in the posted routine failed…

and its down to these stmts

const char* server = "ec2-18-188-xx-yy.compute.amazonaws.com";
int updatePort=8082;

void checkForUpdates() {
String mac = getMAC(); // < --- get the mac address... I supposed I could do this once at init

httpClient.begin(server, updatePort,fwVersionURL); // < --- did this fail?

int httpCode = httpClient.GET(); // < --- this should cause an entry in the access log

well, thank you for challenging me...

in the effort to be more clear, i found that the network address of the remote system has changed.. from x.y.z.205 to z.y.x.125 (which should really never happen, dhcp keep alive and all)... but anyhow..

I had restricted access to a single ip address... x.y.z.205...oops..

so, the code didn't fail, just wasn't allowed to connect.. changed the ip filter rule and all is good again..