I am pretty new to the Arduino neighborhood - and a bit rusty concerning my own programming in c++. But I hope to get into gear quickly again.
Anyway, I recently got myself an Arduino Uno and a Wifi Shield 2.0 from SeeedStudio (tech details at the end of this post). Planned project is to have a webserver (its basic purpose will be to read out some pin states, lit some LEDs and primarily calculate, and show the last time stamp when certain pin states had changed).
A bit of background story:
On my way there (during the last couple of evenings), I already solved a few problems.
Just in case anyone else runs into the same problems: here they are.
I had quite some difficulties connecting to my existing Wifi network, i.e. to my Access Point (AP) via WPA2 authentication.
As a beginner, I just tried the example from http://wiki.seeedstudio.com/Wifi_Shield_V2.0/ , specifically the Example 4, since that is basically what I need as a starter.
It wouldn't connect to my AP, and in the end turned out to be a mean combination of two factors:
a) The SSID may contain spaces (emtpy characters) like in my SSID, but in the string, you have to substitute them by escape character $.
The command to assign a different character here didn't work, by the way. Not sure if it was my fault. Was in an early phase of learning.
b) The WPA pass phrase may not exceed 22 characters. Mine does because the encryption gets stronger with longer passwords.
Hey guys, a tiny comment in the code snippet would have saved a lot of time.
#define SSID "myssid" //spaces in the SSID have to be substituted by $ in this string
#define KEY "mypassword" //keys with more than 22 characters are not processed correctly
Anyway, this is what I finally achieved: I could get the example 4 from http://wiki.seeedstudio.com/Wifi_Shield_V2.0/ running.
Wow. What an achievement.
Now, what is my actual current problem?
What if the AP has a temporary power failure, or the connection to the AP is lost temporarily for any other reason?
I learned from forum studies that the RN-171 which is on the shield is not good in reconnecting from within loop(). The handbook does not elaborate on this at all - or I am blind...
I also learned that rebooting is not so easy, neither for the shield (does not lead to reconnection) nor for the Arduino itself (a true reboot by software that has the same effect like the hardware button is not part of the design).
Well, so I did what is (according to most forums) the cleanest way and what is as close to the HW button as one can get: I use the watchdog to initiate a "reconnect" to the AP during setup(). Or better: I plan to use it once I can figure out how the damn RN-171 let me know whether it is still connected to the AP.
To be honest: the guys having written the WiFly library... A bit more of code commenting would help a lot.
To put it short:
How can I retrieve the information "still connected to AP" while being up and ready as a webserver?
If I use
Code: Select all
How can I make the Wifi Shield 2.0 automatically reconnect again once the AP is available again (after the circuit breaker for the room with the AP is in place again, for instance)?
My code (pretty much the same as in the example; just added or altered a few lines for trying to improve things) is this:
Code: Select all
- Arduino Uno rev. 3
- wifly-EZX Ver: 4.41 Build: r1057, Jan 17 2014 10:23:56 on RN-171
- LinkSys router WRT54GL 1.1 (using that old one since I do not want to change my home setup for testing)