Know when imp has no internet connection

Hi.
I have working around the imp functions and I would like to know if there is anyway to know if the imp has internet connection available at a certain moment. The best think I could do is to use the imp.rssi() function and compare the result to zero that’s when I have no WiFi connection, but even with WiFi connection the imp could not have internet connection… Is there a way / method to have that kind of information from the imp?

I would like to have the imp reading analog data and check if there is internet connection, if there is then commit the data to a online database, but IF THERE ISN’T i need to store that data locally until the imp have internet connection and then send the stored data… I think this can be accomplished if I could know if the imp has internet… I’m I right??

At the moment the imp doesn’t do anything when there is no internet connection, but you can use a watchdog timer witch can inform you that it still has connection to the impserver

I experimented with having the imp set a pin, and my PHP script (remote server) resets it. If it doesn’t reset within 2 seconds, the imp knows it is offline:

http://forums.electricimp.com/discussion/874/is-my-imp-within-my-wifi-area-lets-test-it-out-#Item_3

But when the new Agents come out, you can do all of it without the planner nodes. That will make it even easier.

It will be much easier to do this when Agents become available soon.

Thanks for all the replys :slight_smile:
The watchdog timer given by @mlseim seems to work… but in the planner using a VARIABLE TICK TOCK can we accomplish the same result? The output of the tick tock is sent by Web right? (sorry if this is a noob question… )

I saw that agents will go online in the end of March… does anyone have a clue when it will be available?

Another subject:
I make some tests reading values and switch the state of a LED and when I turn off my router the program still works offline nice unless I do some server operations like server.log so I assume that for some operations, the Imp works offline…

The imp can run fine unless it needs to send or receive data. But i remember reading something about it stopping because of a buffer full or something needing to be periodically pinged? Like some sort of housekeeping function? Maybe Hugo can answer this.

That detail is important to me @mlseim… Maybe Hugo can answer this. :slight_smile:

If imp is offline, what’s the best way to store data locally to send it to webserver when it has internet? I saw in the wiki the NV Tables but not really test them… will it work for this kind of purpose?

Yes the NV table will work for. My imps are battery powered so offline most of the time I keep state, time stamps etc in the NV table.

I didn’t find too much information about the sintax to be used for data storage in nv tables… Can you show me how I store for example one timestamp and a integer value in the same object?
Thanks…

@carlosmaia83 sorry for the delay hear you go
What are you trying to achieve?

`if (“nv” in getroottable()){ // Warm boot from serversleep ot pin1 wake

local sleptFor = time()-nv.sleepTS;
server.log("woken from deep sleep- slept: "sleptFor);
nv.sleepTS=time(); // log the time of waking as it’s used evalute time of last wake

} else { // cold boot state
nv <- {activitySleep=0,sleepTS=time()};
server.log("cold boot: "+nv.sleepTS);
}`

@carlosmaia83 at the moment your code won’t run if it doesn’t have a Internet connection. In the next ImpOS release you will be able to control if your on/offline I’m not sure if any part of this release is a status var like .connected.

As a strategy you could keep a ring buffer in nv to ensure you don’t loose readings when you send to the cloud and don’t get a acknowledge you just keep using the ring buffer. What i cant find in the wiki is the size of nv memory. I will try and put an example together I’m not much of a programmer so will take a few days of fumbling in the dark.

You’re right of course: we should explain the size limit of the nv table in the wiki. In fact it’s a bit under 4Kbytes, so not a huge amount of logging at all. This is a hardware limitation.

Peter

Peter thanks.

Thanks @controlCloud. I think I understand now…

One more thing just to clear…

nv <- {activitySleep=0,sleepTS=time()};

This means that nv table will have two variables? activitySleep and sleepTS right?
Using this kind of sintax I can have multiple variables in the nv table I guess…

When you check for nv in getroottable(), it’s recommended to use validation of variables in vn also? Something like this:

if (“nv” in getroottable()) && (“sleepTS” in nv)

What I’m trying to achieve is read some analog data and send it to one webserver… but if I do not have internet connection save it in nv table so I can send it when it gets internet back… :smiley:

That’s why the title of this thread. For my application is really important to know when imp has connection or not…

I think this can be accomplished using the watchdog method and nv table like you described… Or i’m missing something?

It really depends on how critical the data is, how long the outage is, and how much data you need to store, bearing in mind you only have around 4k to play with, and a table wont survive a power cycle. If the data is critical/large, I’d be using an external EEPROM.

Thanks guys for the help.

@controlCloud you say that my code don’t run offline right now why? Some operations work fine offline in Imp unless I try to communicate with imp servers… I only make a few tests but I guess it’s true…

The circular buffer seems a good ideia to work out… But if imp becames offline during several hours I think I will lose data… But I can workout a solution to when the imp is offline increases delays between data storage… Or… Maybe using a EEPROM is the best solution…

You say that next firmware release will bring some methods to know if imp is online/offline… any release date for this? I really think this is a very important feature.

Imp is a great product… May I only sugest to keep documentation well structured? I think the information is a little dispersed … but I understand that you guys are really busy to bring some news to us… :slight_smile:

code don’t run offline right now why?
The imp is connected to the cloud in the background.

But if imp becames offline during several hours
Given Peters details on buffer size you could store aprox 200 16bit sensor readings. You need to set the worst case e.g. something like this: no of sensors * bytes per sensor reading * samples per second and work out how quickly you would fill buffer. If it’s quick then use an external flash storage. There are serial to flash solutions I think some of the others on the forum have used these.

Yes the wiki takes a while to find your way around and there’s lot good stuff tucked away in the forums.

If you’re ok with the power (ie it not being in sleep) then with release23 you can have a much bigger buffer - basically, however much free memory you have on the imp.

With that release the imp can be configured not to go into low power mode on a failed connection and hence it will continue running (vs sleeping, where all RAM apart from nv is lost).

Hugo thanks for that now for the perennial question will release23 be this quarter?