UNIX epoch time stamp in Opto22

I’ve been working on sending metric data from control systems (namely, Opto22 PAC controllers) into time series databases such as Graphite and InfluxDB.  These both want UNIX epoch time in their API.

The conversion is pretty simple:

Opto22 time to UNIX epoch
Opto22 time to UNIX epoch

I use the built-in conversion to NTP time and then bit shift this over to remove the NTP fractional seconds.  Then I needed to subtract 2,208,988,800 seconds since the NTP epoch is Jan 1, 1900 and the UNIX epoch is Jan 1, 1970.

The last entry converts the epoch to a string so it’s ready to go out the HTTP API with the metric data.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s