Insert Time and Date into a Tag
-
Hello,
Sorry if this has been asked before. I tried searching.
Is it possible to put the time and date into an internal/virtual tag so I can publish it to other devices that don't support NTP?
Thanks,
-FF -
Hi FF,
I'm not sure what you mean, but it sounds like you're just trying to store a current timestamp into a point? If so I would use a meta point on a cron to
return CONTEXT.getRuntime();
into a numeric meta point, or from a meta point set the value to the point that will actually set it out to the device. Does it need to be in a particular format, or are you trying to get milliseconds since 1970?If it's another format, you probably want to use an alphanumeric meta point and do something like ```return new Date().toString();````
-
I figured meta tags was the way to go.
Ideally I would like separate tags for hour of day (0-23), minute (0-59), day (0-31) month (1-12) year (yyyy) .
So, five tags.
I would set up a modbus publisher so the PLC's can query in and sync up times once per day.
It would be nice to get them as close as possible (within the minute), but to-the-second precision isn't needed.
-
Ah, I would actually use a script then. Something like,
var dt = new Date(); year.set(dt.getYear()); month.set(dt.getMonth()); date.set(dt.getDate()); hour.set(dt.getHours()); minute.set(dt.getMinutes());
{ "dataSources":[ { "xid":"DS_d8821015-0a1e-4944-ba5b-73e7beaeb344", "name":"TimePoints", "enabled":false, "type":"SCRIPTING", "alarmLevels":{ "SCRIPT_ERROR":"URGENT", "DATA_TYPE_ERROR":"URGENT", "POLL_ABORTED":"URGENT", "LOG_ERROR":"URGENT" }, "purgeType":"YEARS", "updateEvent":"CONTEXT_UPDATE", "context":[ ], "logLevel":"NONE", "cronPattern":"0 * * * * ?", "executionDelaySeconds":0, "historicalSetting":false, "script":"var dt = new Date();\nyear.set(dt.getYear());\nmonth.set(dt.getMonth());\ndate.set(dt.getDate());\nhour.set(dt.getHours());\nminute.set(dt.getMinutes());", "scriptPermissions":{ "customPermissions":"", "dataPointReadPermissions":"superadmin", "dataPointSetPermissions":"superadmin", "dataSourcePermissions":"superadmin" }, "editPermission":"", "purgeOverride":false, "purgePeriod":1 } ], "dataPoints":[ { "xid":"DP_861812d3-3375-472b-90d3-1f631aa7526a", "name":"Year", "enabled":true, "loggingType":"NONE", "intervalLoggingPeriodType":"MINUTES", "intervalLoggingType":"AVERAGE", "purgeType":"YEARS", "pointLocator":{ "dataType":"NUMERIC", "contextUpdate":false, "settable":true, "varName":"year" }, "eventDetectors":[ ], "plotType":"SPLINE", "rollup":"NONE", "unit":"", "simplifyType":"NONE", "chartColour":"", "chartRenderer":{ "type":"IMAGE", "timePeriodType":"DAYS", "numberOfPeriods":1 }, "dataSourceXid":"DS_d8821015-0a1e-4944-ba5b-73e7beaeb344", "defaultCacheSize":1, "deviceName":"TimePoints", "discardExtremeValues":false, "discardHighLimit":1.7976931348623157E308, "discardLowLimit":-1.7976931348623157E308, "intervalLoggingPeriod":1, "intervalLoggingSampleWindowSize":0, "overrideIntervalLoggingSamples":false, "preventSetExtremeValues":false, "purgeOverride":false, "purgePeriod":1, "readPermission":"", "setExtremeHighLimit":1.7976931348623157E308, "setExtremeLowLimit":-1.7976931348623157E308, "setPermission":"", "tags":{ }, "textRenderer":{ "type":"ANALOG", "useUnitAsSuffix":true, "unit":"", "renderedUnit":"", "format":"0" }, "tolerance":0.0 }, { "xid":"DP_f6d89968-0b5d-4f6a-b266-060015953d04", "name":"Month", "enabled":true, "loggingType":"NONE", "intervalLoggingPeriodType":"MINUTES", "intervalLoggingType":"AVERAGE", "purgeType":"YEARS", "pointLocator":{ "dataType":"NUMERIC", "contextUpdate":false, "settable":true, "varName":"month" }, "eventDetectors":[ ], "plotType":"SPLINE", "rollup":"NONE", "unit":"", "simplifyType":"NONE", "chartColour":"", "chartRenderer":{ "type":"IMAGE", "timePeriodType":"DAYS", "numberOfPeriods":1 }, "dataSourceXid":"DS_d8821015-0a1e-4944-ba5b-73e7beaeb344", "defaultCacheSize":1, "deviceName":"TimePoints", "discardExtremeValues":false, "discardHighLimit":1.7976931348623157E308, "discardLowLimit":-1.7976931348623157E308, "intervalLoggingPeriod":1, "intervalLoggingSampleWindowSize":0, "overrideIntervalLoggingSamples":false, "preventSetExtremeValues":false, "purgeOverride":false, "purgePeriod":1, "readPermission":"", "setExtremeHighLimit":1.7976931348623157E308, "setExtremeLowLimit":-1.7976931348623157E308, "setPermission":"", "tags":{ }, "textRenderer":{ "type":"ANALOG", "useUnitAsSuffix":true, "unit":"", "renderedUnit":"", "format":"0" }, "tolerance":0.0 }, { "xid":"DP_52ae55ae-058f-41aa-9739-14f1bce971e3", "name":"Date", "enabled":true, "loggingType":"NONE", "intervalLoggingPeriodType":"MINUTES", "intervalLoggingType":"AVERAGE", "purgeType":"YEARS", "pointLocator":{ "dataType":"NUMERIC", "contextUpdate":false, "settable":true, "varName":"date" }, "eventDetectors":[ ], "plotType":"SPLINE", "rollup":"NONE", "unit":"", "simplifyType":"NONE", "chartColour":"", "chartRenderer":{ "type":"IMAGE", "timePeriodType":"DAYS", "numberOfPeriods":1 }, "dataSourceXid":"DS_d8821015-0a1e-4944-ba5b-73e7beaeb344", "defaultCacheSize":1, "deviceName":"TimePoints", "discardExtremeValues":false, "discardHighLimit":1.7976931348623157E308, "discardLowLimit":-1.7976931348623157E308, "intervalLoggingPeriod":1, "intervalLoggingSampleWindowSize":0, "overrideIntervalLoggingSamples":false, "preventSetExtremeValues":false, "purgeOverride":false, "purgePeriod":1, "readPermission":"", "setExtremeHighLimit":1.7976931348623157E308, "setExtremeLowLimit":-1.7976931348623157E308, "setPermission":"", "tags":{ }, "textRenderer":{ "type":"ANALOG", "useUnitAsSuffix":true, "unit":"", "renderedUnit":"", "format":"0" }, "tolerance":0.0 }, { "xid":"DP_caed7349-9f12-4786-a5ae-4c88d55d5f7d", "name":"Hour", "enabled":true, "loggingType":"NONE", "intervalLoggingPeriodType":"MINUTES", "intervalLoggingType":"AVERAGE", "purgeType":"YEARS", "pointLocator":{ "dataType":"NUMERIC", "contextUpdate":false, "settable":true, "varName":"hour" }, "eventDetectors":[ ], "plotType":"SPLINE", "rollup":"NONE", "unit":"", "simplifyType":"NONE", "chartColour":"", "chartRenderer":{ "type":"IMAGE", "timePeriodType":"DAYS", "numberOfPeriods":1 }, "dataSourceXid":"DS_d8821015-0a1e-4944-ba5b-73e7beaeb344", "defaultCacheSize":1, "deviceName":"TimePoints", "discardExtremeValues":false, "discardHighLimit":1.7976931348623157E308, "discardLowLimit":-1.7976931348623157E308, "intervalLoggingPeriod":1, "intervalLoggingSampleWindowSize":0, "overrideIntervalLoggingSamples":false, "preventSetExtremeValues":false, "purgeOverride":false, "purgePeriod":1, "readPermission":"", "setExtremeHighLimit":1.7976931348623157E308, "setExtremeLowLimit":-1.7976931348623157E308, "setPermission":"", "tags":{ }, "textRenderer":{ "type":"ANALOG", "useUnitAsSuffix":true, "unit":"", "renderedUnit":"", "format":"0" }, "tolerance":0.0 }, { "xid":"DP_16f26342-362b-4840-ad91-0918de13b1af", "name":"Minute", "enabled":true, "loggingType":"NONE", "intervalLoggingPeriodType":"MINUTES", "intervalLoggingType":"AVERAGE", "purgeType":"YEARS", "pointLocator":{ "dataType":"NUMERIC", "contextUpdate":false, "settable":true, "varName":"minute" }, "eventDetectors":[ ], "plotType":"SPLINE", "rollup":"NONE", "unit":"", "simplifyType":"NONE", "chartColour":"", "chartRenderer":{ "type":"IMAGE", "timePeriodType":"DAYS", "numberOfPeriods":1 }, "dataSourceXid":"DS_d8821015-0a1e-4944-ba5b-73e7beaeb344", "defaultCacheSize":1, "deviceName":"TimePoints", "discardExtremeValues":false, "discardHighLimit":1.7976931348623157E308, "discardLowLimit":-1.7976931348623157E308, "intervalLoggingPeriod":1, "intervalLoggingSampleWindowSize":0, "overrideIntervalLoggingSamples":false, "preventSetExtremeValues":false, "purgeOverride":false, "purgePeriod":1, "readPermission":"", "setExtremeHighLimit":1.7976931348623157E308, "setExtremeLowLimit":-1.7976931348623157E308, "setPermission":"", "tags":{ }, "textRenderer":{ "type":"ANALOG", "useUnitAsSuffix":true, "unit":"", "renderedUnit":"", "format":"0" }, "tolerance":0.0 } ], "publishers": [ { "xid":"PUB_51603f56-35d6-43e4-af34-6b0e0c7b65f2", "name":"Publish Time", "enabled":false, "type":"MODBUS_IP", "points":[ { "dataPointId":"DP_861812d3-3375-472b-90d3-1f631aa7526a", "registerType":"HOLDING_REGISTER", "modbusDataType":"TWO_BYTE_INT_UNSIGNED", "decimalPlaces":0, "offset":0, "readOnly":true, "registerCount":1 }, { "dataPointId":"DP_f6d89968-0b5d-4f6a-b266-060015953d04", "registerType":"HOLDING_REGISTER", "modbusDataType":"TWO_BYTE_INT_UNSIGNED", "decimalPlaces":0, "offset":1, "readOnly":true, "registerCount":1 }, { "dataPointId":"DP_52ae55ae-058f-41aa-9739-14f1bce971e3", "registerType":"HOLDING_REGISTER", "modbusDataType":"TWO_BYTE_INT_UNSIGNED", "decimalPlaces":0, "offset":2, "readOnly":true, "registerCount":1 }, { "dataPointId":"DP_caed7349-9f12-4786-a5ae-4c88d55d5f7d", "registerType":"HOLDING_REGISTER", "modbusDataType":"TWO_BYTE_INT_UNSIGNED", "decimalPlaces":0, "offset":3, "readOnly":true, "registerCount":1 }, { "dataPointId":"DP_16f26342-362b-4840-ad91-0918de13b1af", "registerType":"HOLDING_REGISTER", "modbusDataType":"TWO_BYTE_INT_UNSIGNED", "decimalPlaces":0, "offset":4, "readOnly":true, "registerCount":1 } ], "snapshotSendPeriodType":"MINUTES", "publishType":"ALL", "alarmLevels":{ "RECURSION_FAILURE":"URGENT", "PORT_IN_USE_EVENT":"URGENT", "POINT_DISABLED_EVENT":"URGENT", "DATA_TYPE_MISMATCH":"URGENT", "MODBUS_INIT_ERROR_EVENT":"URGENT", "ENCAPSULATION_MISMATCH":"URGENT", "DATA_POINT_NOT_SETTABLE":"URGENT", "QUEUE_SIZE_WARNING_EVENT":"URGENT" }, "encapsulated":false, "port":502, "logCount":1, "logIO":false, "logSize":1.0, "slaveId":123, "strictAddressing":true, "cacheDiscardSize":1000, "cacheWarningSize":100, "sendSnapshot":false, "snapshotSendPeriods":5 } ] }
(JSON for scripting data source, five points for those values, and a modbus publisher. I didn't confirm the default JavaScript ranges were your requested ranges (0-31?! :D))