Ok, so far we are working with a Mesh that is not connected to the Internet. However, I have recently installed a Pharos 360 GPS unit (inspired by K5KTF's article under the Applications link). I then wrote a simple perl program and a cron job script to grab the date and time data from the gps and set the node's date/time with the date command. So far it is only accurate to within about a minute, but that's a lot better that "Jan 1 2000" Now, I'm thinking about setting up a local time server on the same node to pass the date/time to other nodes. There's no pride in authorship here. I've been out of the programming world for nearly 20 years, so this was a 're-learning' experience for me. I'm sure there are probably more elegant ways to accomplish this. I'm open to improvements. I'm sure there are some regular expression ways to reformat, I'm just VERY rusty on my regular expressions! My first version was writing the time data to a file and then reading the file. Now, I've combined it and avoided the step involving the file completely. Here's how I did it: GPS unit is directly soldered to the second serial port with three wires. Once initiated at boot-up, it sends a continual stream of data at 4800 baud to /dev/tts/1. I set up a cron job to run every two hours to capture the GPRMC line of data from the GPS and pipe it to a perl program (fmtgpsdate) which pulls out the date and time date and re-formats it to something the date command can understand. Although the documentation at OpenWRT shows thre or four different acceptable formats, I could only get one (the one shown below) to actually work. All others returned an "Invalid Date" error from the date command. crontab -e Added the following line: 15 */2 * * * date -s `head /dev/tts/1|grep GPRMC | perl /www/cgi-bin/fmtgpsdate` to tell the system to run the command at 15 minutes past the hour every two hours. Note: the argument for the date command is surrounded in backticks (under the ~ on my keyboard), not apostrophes. It tells the shell to execute the command. I saved the following perl program in /www/cgi-bin/ directory, although it should probably be in /etc/sbin/ or similar. It's called fmtgpsdate.
#!/usr/bin/perl $debug = 0; use perlfunc; # Read in GPRMC Data from previous command ($gps_type, $gps_time, $gps_state, $gps_lat, $gps_ns, $gps_lon, $gps_ew, $gps_speed, $gps_track, $gps_date, $gps_rest) = split(',',<STDIN>); # Format the data to acceptable form print "20" . substr($gps_date,4,2) . "." . substr($gps_date,2,2) . "." . substr($gps_date,0,2) . "-" . substr($gps_time,0,2) . ":" . substr($gps_time,2,2) . ":45";
I then issued: chmod +x fmtgpsdate to make it executable. I wish I could do the cron job at boot-up but it takes some time for the gps to acquire the data. Again, its not accurate to the second. The GPRMC data is only accurate to the minute (no seconds are provided). So, I added 45 seconds to the minute which seems to get me fairly close to the actual time. Have fun- 73s W5CWT, David |