Getting Real Time from wifi to use in sketches
-
Since the omega2+ is wifi, how do I call for the date and time to use in sketches?
In a more simple way of asking, I would like something to turn on at a specific time of day and run for a specific amount of time,
an example, turn relay on Monday at 0600 and then turn relay off at 0605, 5 minutes later.
So, how do I use omega that is connected to the wifi get date and time to apply it to my needs?Thanks
-
@Tyler-Brown
If that sketch might be a shell script, usedate
on Command Line.
date --help
Time arithmetic is easy using seconds since the epoch (1970-01-01 UTC) to a date.
Usage examples:# date 'now' (Sunday) root@Omega-5BE1:~# date Sun May 7 17:08:29 GMT 2017 # seconds 'now' root@Omega-5BE1:~# date +%s 1494176909 # converting seconds to date root@Omega-5BE1:~# date -d @1494176909 Sun May 7 17:08:29 GMT 2017 # converting date to seconds # 'on' tomorrow morning (Monday) 06:00 root@Omega-5BE1:~# date +%s 'May 8 6:00:00 2017' 1494223200 # 'off' tomorrow morning (Monday) 06:05 root@Omega-5BE1:~# date +%s 'May 8 6:05:00 2017' 1494223500
now, on, off - you should only write a little shell script to set/reset a GPIO output.
Footnotes:
I think your favorite programming language has similar capabilities too.
There is no battery backed RTC on the Omega2(+) board/docks, it gets the date/time from the net.
-
@Tyler-Brown said in Getting Real Time from wifi to use in sketches:
Since the omega2+ is wifi, how do I call for the date and time to use in sketches?
In a more simple way of asking, I would like something to turn on at a specific time of day and run for a specific amount of time,
an example, turn relay on Monday at 0600 and then turn relay off at 0605, 5 minutes later.
So, how do I use omega that is connected to the wifi get date and time to apply it to my needs?If I get the above right, a very basic shell script combined with the standard cron functionality is all what you may need.
# below whatever you use to turn the relays on - this is I guess what you call a sketch my_favorite_relay_script on # wait for some time (below for 5 min) sleep 300 # below whatever you use to turn the relays off my_favorite_relay_script off
Now you define your schedule with the crontab, and this is what you may want to read about it:
https://docs.onion.io/omega2-docs/running-a-command-on-a-schedule.htmlBelow, a crontab file that will execute the command every Monday at 6:00:
0 6 * * 1 /bin/sh /fulpath_to_the script_above
Note that if you need to switch it on and later off at specific times, you don't need any extra script and you can do it like this:
0 6 * * 1 /fulpath/my_favorite_relay_script on 5 6 * * 1 /fulpath/my_favorite_relay_script off
-
Thank you both for the replays.
What I meant on sketch is that the Omega is attached to the arduino dock, I want to be able to use the Omega as a RTC (Real-Time-Clock) in sketches, since it is wifi/net connected and will keep perfect time. I hoping no additional hardware is needed.
For further more understanding of what I am trying to accomplish; I want to put together a sprinkler/irrigation system and garden lights sensor/timer for my home.
I know what you maybe thinking, there is a ton of resources out there that I can use to accomplish this. I have been searching and reading alot of forums and getting their information; yet, none of it is actually complete information, just bits and pieces and alot of unanswered responses.
I like the fact that I can send information to the arduino via wifi through the omega, makes it easier to get my sketches out to the location that I would like to put my setup. I know there are other ways to do so with just an adruino and wifi/BLE hardware, but I feel this method is easier for me.
I hoping if I'm able to gather all the information and get it working, I can post the hardware and code I used for others to use so that it is almost a plug and play ready system. Maybe someone has already done this with the Omega, I just couldn't find it.Here is some of my questions:
-
(As stated above) Is there away to use the Omega and the wifi as a Real-Time-Clock when attached to the arduino dock. I am trying to control an 8 relay board and a 4 channel Mosfet PWM board
-
Through the terminal on the homepage of the Omega (when plugged into the arduino dock) can a command like blink LED on pin 13 be done live or does there need to be a sketch uploaded to the arduino dock for blink LED on pin 13? I am just trying to get further clarification on how the
Omega and the arduino dock are able to communicate with each other. -
I am not really sure how to word this without any confusion. From my understanding, that when a sketch is running on the arduino, that nothing else can happen until the current process is over. Example, my garden lights turn on at a specific time or through a light sensor at dusk, but because the lights are on from the use of a sketch that is controlling the lights, that I can't have my sprinklers run at 2100 hours. Am I correct for understanding it this way? Hope no one got lost in that question.
-
-
@Tyler-Brown Hey Tyler,
I think using the time in seconds would be very useful for you.On the arduino that controls both your lights and your sprinklers seperately. You can shoot the time from your omega to the arduino constantly.
You then have an arduino sketch that is waiting for those specific numbers to come in:#for sprinklers
If seconds is >= (6am in seconds) and <= (6:05 in seconds)
Turn Sprinkler on
#for Lights
else if seconds >= (dusk in seconds) or <= (dawn in seconds)
Turn Lights On