I'm using the WiFi shield on an Arduino Uno but I do not think the shield is fully disconnecting. I have a loop that checks a sensor for input. If the sensor hits the threshold, it connects with te WiFi shield to download some data, sleeps for a few seconds, then enters the loop again.
The function that I have to connect to the network, in it's simplest form, performs a WiFi.begin(), client.connect(), send message, client.stop() and WiFi.disconnect().
However, as I enter the main loop (after what I believe to be disconnecting form the network) the LINK light on the shield remains on. Furthermore if I loop through the loop after quite some time the Uno eventually halts. This is suggestive of a memory leak.
With the green light on am I REALLY disconnected from the network despite me running client.stop() and WiFi.disconnect()?
Has anyone else seen memory leak issues with the WiFi Shield?
I am also using the SD card and I've heard that there used to be memory leaks with that, but if I am not using strings to interface with the SD card I should be good, right? I am referring to this link about the SD card memory leak: c++ - Arduino memory leaks (SD card + strings) - Stack Overflow I am executing a close() each time I reference the SD card...
// if the file is available, write to it:
if (dataFile) {
dataFile.println(logEntry);
dataFile.close();
Serial.println("Closed");
// print to the serial port too:
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
}
I didn't think the SD function was an issue, hence why I didn't post it. I can post my entire sketch, but it is a few hundred lines....
Really I wanted to know if there is a correct way to shut off the WiFi Shield. Currently once you connect it does not appear to be a way to shut it down/disconnect....
Ahhh, good question but with (I believe) an even better answer:
My arduino is going to be mobile and will spend an unknown amount of time out of WiFi reach. When it is within Wifi reach I want to connect, download data, make one quick server call and disconnect. As I have very limited amount of memory, disconnecting should (I believe) free up once I disconnect. As I want my arduino doing other things when it is not in range of the WiFi, the less resources I am using the better.
So to answer your question about disconnecting - YES. For example, if I have a cell phone and it uses Wifi but I am out of range of any WiFi I would ultimately like it to not to try to connect to save power. Similar motivation but rather saving on power I'd like to save on memory.
Is the shield not designed to fully disconnect/disengage? Why would the link light stay on even though I have sent a disconnect() call?
Really I wanted to know if there is a correct way to shut off the WiFi Shield. Currently once you connect it does not appear to be a way to shut it down/disconnect....
If you turn off the wifi shield, how will you know when to turn it back on? What are the actual power use differences when the wifi is connected to another wifi point and it is not connected. What makes you think you will be saving memory between being connected and not being connected to an external point?
The fact that the 'link light' is on after I've disconnected is disconcerting to me. I'd expect the light to be off if I am not connected, hence my confusion and initial query of how to really disconnect....
gramsky:
The fact that the 'link light' is on after I've disconnected is disconcerting to me. I'd expect the light to be off if I am not connected, hence my confusion and initial query of how to really disconnect....
Hi Gramsky. Did you find a solution to your problem? I to am experiencing the same problem i.e.
client.stop();
WiFi.disconnect();
does not appear to work. Putting the following code after the previous:
delay(10000);
if (client.connected())
{
Serial.println("Client is still connected");
}
else
{
Serial.println("Client is not connected");
}
Reports that the client is correctly not connected, however the link LED on the wifi shield remains on, suggesting that the shield is still connected.
In my arduino project, I only want to turn on the wifi and transmit data (in my case a Twitter post) when a sensor fires. Once its sent the data I want to turn the wifi shield off, as I don't want to waste power. I'm tempted to raise a bug in the Arduino source project on GitHub, what do the rest of you think?
Darduino, have you made any progress on this? i'm experiencing the same problem and I'm extremely frustrated with the fact there is no answer from the Arduino crew considering the Wifi shield is not a cheap piece of HW to have such a poor behaviour.
Nope, I've made no progress on this issue. I've recently found an Arduino plug-in for Visual Studio (MIcrosoft's development IDE) (http://www.visualmicro.com/), and I might debug the issue. I'll post an update if I pinpoint the problem.
I too have been very disappointed with the Arduino community on the feedback received. It's blatantly a problem with the Wifi library.
I'm getting my hands on an Arduino based device called pinoccio (http://pinocc.io/) which has a big emphasis on low energy consumption. The community they have there is already very promising, more so than I've found on the Arduino forums
gramsky:
Is the shield not designed to fully disconnect/disengage?
That's a very good question. I don't know the answer, but it's something that I suspect typical WiFi users wouldn't bother to do perhaps not a requirement that the designers considered when designing the hardware and associated library. The library source is available to you, so you could investigate to find out for yourself what happens when you connect and disconnect, and whether a disconnection actually undoes everything that is done during a connection.