0

Checking connection to IO
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Checking connection to IO

by biggles4808 on Thu Feb 22, 2018 10:25 am

Hoping somebody can help me sort a problem with occasional disconnects from IO.
I am using the adafruit_IO_client library in a project that sends data from a remote sonar sensor via RF to a base station (esp8266). Then the data is uploaded to IO. The samples are sent every 2 hours. Everything works well for approx 1 week then I see that the feed is not being updated. The base station display IS being updated so the code is still running. I have trapped any disconnection from my WiFI and display an error on the LCD if disconnected. I am not seeing any wifi error. So I assume that it the connection to IO that is not good. Once failed, it never sends another feed until I restart the base station. It is pretty random and I don't have a PC connected to the base station to debug.
I would like to check the connection to IO before sending the feed, but not sure of the best way. Any suggestions?

The relevant parts of the code pasted below

//****************************Send data to web and email servers********************
if (datapacket.battery_level >= 3.7)
{
// turn on wifi if we aren't connected
if (WiFi.status() != WL_CONNECTED)
wifi_init();

if ( WiFi.status() == WL_CONNECTED)
{
send_oil_level(displayvolume, to_fill, battery_level); // Send data to Adafruit.IO
Serial.println("Sent to Adafruit.IO");

void send_oil_level(float oil_level_IO, float to_fill_IO, float battery_level_IO) {
// AIO init
Serial.println("Connecting to Adafruit.io");
aio.begin();

// grab the oil_level feed
Adafruit_IO_Feed oillevel = aio.getFeed("oillevel");
Adafruit_IO_Feed oil_to_fill = aio.getFeed("oil_to_fill");
Adafruit_IO_Feed battery_level = aio.getFeed("battery_level");

// send oil level to AIO
oillevel.send(oil_level_IO);
oil_to_fill.send(to_fill_IO);
battery_level.send(battery_level_IO);
}

biggles4808
 
Posts: 14
Joined: Tue Aug 15, 2017 12:20 pm

Re: Checking connection to IO

by biggles4808 on Tue Mar 06, 2018 10:59 am

Any ideas out there? I've read through the library.h and cpp files, but can't work out what I need to do to check the status.
Not sure if just something like if(!aoi.connect()) then aoi.stop(), followed by aoi.connect() (pseudo code)

Any thoughts greatly appreciated

biggles4808
 
Posts: 14
Joined: Tue Aug 15, 2017 12:20 pm

Re: Checking connection to IO

by abachman on Tue Mar 06, 2018 3:40 pm

you might've been hitting the same issue as this thread: viewtopic.php?f=56&t=131860

We fixed a memory leak in the Adafruit IO Arduino library that was affecting firmware using versions 2.7.0 and 2.7.1 and was causing errors like this. If you update your project to 2.7.2+ and rebuild / reflash, you shouldn't see it anymore.



- adam

abachman
 
Posts: 239
Joined: Mon Feb 01, 2010 12:48 pm

Re: Checking connection to IO

by biggles4808 on Wed Mar 07, 2018 5:17 am

Hi Adam, you had my hopes up there.... I am using library version 1.0.1 and if I go above that, even only to 2.0.0 I get an "unable to compile for huzzah esp8266 error". Have the commands changed in later versions? My code was based on sample code from the site.

biggles4808
 
Posts: 14
Joined: Tue Aug 15, 2017 12:20 pm

Re: Checking connection to IO

by biggles4808 on Fri Apr 13, 2018 11:07 am

Ok, I found out the reason for the compile error is that the original library I was using "Adafruit_IO_Client.h" is not included in the 2.7.2 version of the package. So I have re written the code to include the AdafruitIO_WiFi.h library to make the connection. See sample for Humidity/temperature included with the library.

io.run(); This is now in the top of the main loop

These lines:
AdafruitIO_Feed *oillevel = io.feed("oillevel");
AdafruitIO_Feed *oil_to_fill = io.feed("oil_to_fill");
AdafruitIO_Feed *battery_level = io.feed("battery_level");

Were originally placed in the header of the code, as per the temperature / humidity example, but the IO failed to update after about 12 hours.
I then moved them to the sub routine that was saving the data to IO so that they are run again each time data is sent. So far it's been running ok since the 7th April so almost a week. Another few days and it will be the longest continuous period without the update failing. This is where I had them before with the Adafruit_IO_Client.h library, but we'll see what happens with this version 2.7.2
I'll let you know

biggles4808
 
Posts: 14
Joined: Tue Aug 15, 2017 12:20 pm

Re: Checking connection to IO

by hanskristianyddal on Fri Apr 27, 2018 10:12 am

Hello,

So, did you have success?

I have some experience in setting up reliability tests that needs to run for a long time, so I thought I would add (you maybe figured this out already):
It is extremely important to run your code in fast forward mode to check for bugs like this (typically memory leaks). I have learned the hard way many times :)

hanskristianyddal
 
Posts: 2
Joined: Fri Apr 27, 2018 9:28 am

Re: Checking connection to IO

by biggles4808 on Fri Apr 27, 2018 10:26 am

Hi, No it still failed initially after moving those lines to the "send data" sub routine. I ended up putting the AO setup line -
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
In to the top of the main void loop above io.run as opposed to in the general header of the code.
So far it's been ok but it has only just been a week or so since I did that.
I did run some tests with my tach time set much lower that 2 hrs to test the code, but I am wary of exceeding the max data points limit on the Adafruit IO website so didn't go too quickly.
I'll let you know how it goes.

biggles4808
 
Posts: 14
Joined: Tue Aug 15, 2017 12:20 pm

Re: Checking connection to IO

by abachman on Fri Apr 27, 2018 1:11 pm

I don't know if it would be helpful, but I have a snippet of code I use for tracking memory usage in running Arduino sketches, it actually helped with debugging/testing the memory leak fix in 2.7.2. Here's the code: https://gist.github.com/abachman/9da5eafb2642604db73f843310177ad8

The significant pieces are at the top of the sketch, and then a single function call to get the current available memory:
Code: Select all | TOGGLE FULL SIZE
extern "C" {
#include "user_interface.h"
}
// other setup stuff...

void loop() {
    io.run();

    // do other stuff...

    // print available memory to Serial
    uint32_t free_heap = system_get_free_heap_size(); // <-- provided by user_interface.h lib
    Serial.print("free heap size ");
    Serial.println(free_heap);
}

abachman
 
Posts: 239
Joined: Mon Feb 01, 2010 12:48 pm

Re: Checking connection to IO

by biggles4808 on Mon Apr 30, 2018 4:02 am

Thanks very much, might give it a try if my uploads fail again.

biggles4808
 
Posts: 14
Joined: Tue Aug 15, 2017 12:20 pm

Please be positive and constructive with your questions and comments.