Automagically setting the system time to a reasonable value in DexterOS/Cinch


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.

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:  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} );


JavaScript’s Date Object:

jQuery’s post() function:

Jim “JR”

1 Like