Greetings!
One well known issue, (feature!), with DexterOS/Cinch is that there is no connection to the external Internet. Though this is by design to make the system as bullet-proof as possible, it prevents the system from obtaining an accurate and current system time and date.
The result of this lack is that the time stamps on important things like system logs, (for troubleshooting purposes), or user files can be incredibly wrong, causing confusion at the very least.
Fortunately, this need not be so. Not only is it possible, it is relatively easy to implement a method to update the GoPiGo’s system time by pulling the current time/date from the system the GoPiGo is connected to.
This is based on several assumptions that are very likely to be true. If they’re not true, it should be almost trivially easy to make them so.
- The existing DexterOS/Cinch web portal uses, or can be configured to use, Ajax/JavaScript.
- The web server on the GoPiGo can be configured to request, and accept, POST requests back to the server, if it does not do this already.
- It is possible to create a process or script that can be given access rights to set the system time, while blocking any other advanced permissions. Or, the GoPiGo’s web server may already have sufficient access to set the system time.
- It is assumed that the system connected to the GoPiGo has a reasonably accurate system clock, and the system time available to the user’s browser is reasonably close.
Given these assumptions - which should be easy to implement if not already true - it borders on trivial to design a simple process that fetches the correct time from the system the GoPiGo is connected to.
Viz.:
An abstract of an e-mail I received from a friend who is a web server guru. I asked him this question and here is his reply: (My comments are in [square brackets].)
Because the data is coming through in a non-standard way, you probably can only get within +/- a second or two. [Which is more than adequate for the GoPiGo.]
Here is one way, documented here: https://stackoverflow.com/questions/9641138/timestamp-from-the-web-browser/9641342#9641342. The basic idea is to force the browser to make a second connection back to the server with the time embedded in the query data.
Getting the time with JavaScript returns the current user’s machine time. [i.e. The “system time” on the machine that connected to the GoPiGo and is displaying the GoPiGo’s web page.]
The following JavaScript code will return the number of milliseconds since midnight Jan 1, 1970:
var timestamp = new Date().getTime();
Now just grab the timestamp variable and send it back to your webserver, [i.e. the GoPiGo], if that’s where you want to save this information. The easiest unobtrusive way I can think of to do this is by using ajax to POST the time information back to your server, for example (using jQuery):
$.post("saveusertime.php", { time: timestamp} );
Sources
JavaScript’s Date Object: http://www.w3schools.com/jsref/jsref_obj_date.asp
jQuery’s post() function: http://api.jquery.com/jQuery.post/
Jim “JR”