So here's what I changed:
First, in the reconnect function, I changed how many times the system would reconnect to the wifi from five to seven. This way every week the clock would perform a full reboot. Its up to you how you want to handle that. The section of code looks like this:
// reboot if not working right yet.
iTrack++;
if ( iTrack > 7 ) {
WiFly.reboot();
iTrack = 0;
}
Next, here's the loop function with the easy fix and something I really should have done the first time. Just set the netTime variable again after the reconnect function finishes. Also, because I want to keep it from reconnecting again, I extended the delay to 30 seconds. 30 seconds is a very long time and really I'm being overly cautious. Adjust it to whatever you like. Personally, the reconnect function takes 30-40 seconds to connect to my wifi router so another 30 seconds before polling the wifi module keeps it from running the reconnect function again, for me. Anyway, the loop function should should look like this now:
void loop()
{
if (netTime==0) // if the netTime var is equal to 0, which should be midnight, then resync the time
{
Serial << "Reconnect netTime = " << netTime << endl; // debug output
backlightColor(); // The Colors!!!
Reconnect(); // Reconnect to the wifi AP and query the NTP server for the time.
delay(30000); // I run a long delay to keep it from running from querying the NTP server too offten. No reason to abuse a free service.
netTime=((hour()-5)*100)+minute(); //set the netTime after running the Reconnect.
}
else
{
Serial << "netTime = " << netTime << endl; // debug output
getNetTime(); // run GMT to local Time Zone conversion
backlightColor(); // The Colors!!!
nixNum(netTime); // send data to the nixie clock. int array nixNum with int data from gmt converstion.
delay(100); // Short delay for the backlight
}
}
Here's a link to the updated code. Remember to set your wifi settings and a NTP server.
Cool Project! I'm building the same and wondered if you had any idea on how to modify the code to include the "seconds" with 2 extra tubes?
ReplyDeleteOhh yea, that's real simple. The seconds are already in the code we so all we need to do is modify the equation and update the Nixie tube setup to allow for six characters in the array instead of four.
ReplyDeleteFor the equation, we just need to move the Hour and Minute digits up and add the seconds. So we take the original equation:
x = (hour() * 100) + minute()
And move the hour and minutes up to the make room for the seconds:
x = (hour() * 10000) + (minute() * 100) + second()
So now if its 3:40:30pm, x should be 154030.
Make sure you update all the other equations in the code to reflect this change.
I hope this helps
I've also recently updated my code again to reflect changes in the WiflySerial library as well as getting the code working on version 1.0 of the Arduino software. And I've added a little flair for when the clock starts up or needs to reconnect to the wifi. I'll be posting that later this weekend.