Skip to content
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Controllers
  3. Node-RED
  4. "Sketch Time" (I_TIME) Handler
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

"Sketch Time" (I_TIME) Handler

Scheduled Pinned Locked Moved Node-RED
5 Posts 2 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • crankyC Offline
    crankyC Offline
    cranky
    wrote on last edited by
    #1

    This flow takes care of the I_TIME call made to the gateway.

    The confusing part about this Internal call is: do we return UTC, or local time? It would be trivial to have a sensor pass as

    [id];255;3;0;1;(timezone)

    rather than

    [id];255;3;0;1;\n

    so that Time local to where the sensor was placed could be recorded. The only caveat is that DST would mess it up... However, since the Arduino sketch "Time Aware Sensor" polls the gateway every hour for time, at most your logs/data will be off by at most 1 hour. This can easily be changed to the tolerance your need desires.

    [{"id":"8e3e8f02.7fd0c","type":"mqtt-broker","z":"63842e72.893f78","broker":"localhost","port":"8883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"15","cleansession":true,"willTopic":"","willQos":"0","willRetain":null,"willPayload":"","birthTopic":"","birthQos":"0","birthRetain":null,"birthPayload":""},{"id":"71e13b71.966fa4","type":"mqtt in","z":"63842e72.893f78","name":"Sensor Requests Time ","topic":"MySensors/+/255/3/0/1","broker":"8e3e8f02.7fd0c","x":102,"y":852,"wires":[["24b5e719.a8a1d8"]]},{"id":"92a5ad9d.a8b328","type":"function","z":"63842e72.893f78","name":"seconds since epoch","func":"var timezone_offset = -5  // As hours against UTC\n\nmsg.payload = Math.floor( Date.now() / 1000 ); // seconds since jan 1 1970\nmsg.payload = msg.payload + ( timezone_offset * 3600);\nreturn msg;","outputs":1,"noerr":0,"x":465,"y":851,"wires":[["b7cc49b4.1520c8","4686a23a.28493c"]]},{"id":"b7cc49b4.1520c8","type":"mqtt out","z":"63842e72.893f78","name":"Time to Topic","topic":"","qos":"","retain":"","broker":"8e3e8f02.7fd0c","x":657,"y":850,"wires":[]},{"id":"e059f1d.9421f1","type":"comment","z":"63842e72.893f78","name":"I_TIME handler ([0-255];255;3;0;1;[sec since epoch])","info":"Whenever a sensor announces itself to the network as [any];255;3;0;1;(null),\nit returns to the same topic the amount of seconds since Jan 1 1970 (also called Epoch)\n\nA rate limiter was required as to keep NR and the sensor from a spam-loop","x":301,"y":899,"wires":[]},{"id":"4686a23a.28493c","type":"debug","z":"63842e72.893f78","name":"","active":false,"console":"false","complete":"false","x":642,"y":817,"wires":[]},{"id":"24b5e719.a8a1d8","type":"delay","z":"63842e72.893f78","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":284,"y":852,"wires":[["92a5ad9d.a8b328"]]},{"id":"46b988b9.969a88","type":"comment","z":"63842e72.893f78","name":"Change timezone here","info":"","x":450,"y":818,"wires":[]}]
    
    1 Reply Last reply
    0
    • hekH Offline
      hekH Offline
      hek
      Admin
      wrote on last edited by
      #2

      It returns local time adjusted for DST.

      1 Reply Last reply
      0
      • crankyC Offline
        crankyC Offline
        cranky
        wrote on last edited by
        #3

        Really? I'd rather handle absolute time of "Seconds since the Epoch". If you use that, there's no reason or need to mess with DST, time zones, or anything else. It's only when you convert "Seconds Since Epoch"->"String of Current time/date" do you get into having to deal with TZdata and all that garbage.

        Then, on the local device, the user can bake in the Arduino sketch the timezone they are using. Of course, then they have to deal with the horrors of DST and timezones... that is if they want to.

        I log most of my data in seconds(or ms) since epoch. All my logs are then completely synchronized, as much as an NTP client can manage.

        Sincerely,
        Cranky

        1 Reply Last reply
        0
        • hekH Offline
          hekH Offline
          hek
          Admin
          wrote on last edited by
          #4

          What I mean is that the TimeAware-example sketch expects to get seconds since 1970.
          It does not adjust. for summer time by itself or know anything about timezones. So the controller must make these adjustments.

          1 Reply Last reply
          0
          • crankyC Offline
            crankyC Offline
            cranky
            wrote on last edited by
            #5

            Ah cool :) So yes, make the user do it. I like the sound of that.

            Time stinks. Only thing I can say about that is, "Never again."

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            16

            Online

            11.7k

            Users

            11.2k

            Topics

            113.0k

            Posts


            Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • OpenHardware.io
            • Categories
            • Recent
            • Tags
            • Popular