I am working on my YUN and Xbee project, but running into a question on whether it is a necessary or viable option to use a RTC for anything on this platform since the YUN is wifi proficient.
<p id="mon"></p> <script> var d = new Date(); document.getElementById("mon").innerHTML = d.getMonth(); //day, year, hour ,minutes, etc </script>
1 script block for each value needed----
and load the “document.getElementById(“mon”).innerHTML = d.getMonth();” in the proper section that RTC library uses to set the month, etc.
Here is some code borrowed from:
// The following codes transmits the data to the RTC Wire.beginTransmission(DS1307); Wire.write(byte(0)); Wire.write(decToBcd(second)); Wire.write(decToBcd(minute)); Wire.write(decToBcd(hour)); Wire.write(decToBcd(weekday)); Wire.write(decToBcd(monthday)); Wire.write(decToBcd(month)); Wire.write(decToBcd(year)); Wire.write(byte(0)); Wire.endTransmission(); // Ends transmission of data }
Once the 8 am hour is reached I would set a flag and my 12 hour timer would start without actually using a real timer function, and at the same time activate my function to power on the lights relay via my Xbee, then setup a new poll now to check and see if it is 8 pm when my lights should turn off–when it is 8 pm, then reset the flag, Xbee turns the relay off, and go on, ad infinitum.
A significant problem I see with a pure internet based timer only is if I lose internet access and have no RTC backup-- the polling would still continue, but no actual changes in status could occur until the internet access is resumed. In a scenario such as that, it could be profitable to include a $20 RTC module to my YUN as a failsafe and not have to worry about that problem. Polling could take place using one or the other type of Time indicator, either RTC or web based. I could also then poll the RTC periodically as above to check for the 8 o’clock times. It would accomplish the same goals I believe, but now with built in redundancies as noted.
Any thoughtful feedback appreciated.