Jump to content

Narrowband

Weather Station Ideas


Gina

Recommended Posts

That's progress! Yes you need to format the injected timestamp, which according to the node help is:
 a timestamp of the current time in millisecs since January 1st, 1970.

This thread on the topic is useful - looks like they recommend the Moment contributed node, which you will need to install. I haven't used it myself but if Nick O'Leary recommends it it must be good.
https://discourse.nodered.org/t/date-time-formatting/1138

I don't like formatting date strings in javascript generally so I must take a look at this myself.

Link to comment
Share on other sites

Looks to be milliseconds since Jan 1, 1970.

If this helps (from google) 

In python

import datetime
readable = datetime.datetime.fromtimestamp(1603194392).isoformat()
print(readable)
# 2020-10-20T13:46:32+02:00
 

 

Link to comment
Share on other sites

I'm thinking of getting the time from ntpServer

const char* ntpServer = "pool.ntp.org";
const long  gmtOffset_sec = 0;
const int   daylightOffset_sec = 3600;
void showLocalTime()
  {
  struct tm timeinfo;
  if(!getLocalTime(&timeinfo)){
    myDT = "Failed to obtain time";
    return;}
    else {
      year = timeinfo.tm_year + 1900;
      month = timeinfo.tm_mon + 1;
      day = timeinfo.tm_mday;
      hour = timeinfo.tm_hour;
      minute = timeinfo.tm_min;
      myDT = "";
      myDT += year;
      myDT += "-";
      if (month < 10) {myDT += "0";}
      myDT += month;
      myDT += "-";
      if (day < 10) {myDT += "0";}
      myDT += day;
      myDT += "  ";
      if (hour < 10) {myDT += "0";}
      myDT += hour;
      myDT += ":";
      if (minute < 10) {myDT += "0";}
      myDT += minute;
      }
  }

 

Link to comment
Share on other sites

I think I'll add the date/time code and message to the living room client rather that the ROR Automation then I can simply add a switch to change GMT/BST.  Doesn't look like NTP does it.

Link to comment
Share on other sites

Internally I'd suggest it's best to work in some format like "seconds since the epoch" (where the epoch is 1st Jan 1970 for UNIX and UNIX-like systems).  Then you only worry about daylight savings when dates are entered or displayed.  Which is kind of how daylight savings works, in a way.  It's not like the Earth's position relative to the Sun has changed this weekend, for example.  It's just what we call the time when we want to communicate it with someone else that we've altered.  Using a value such as "seconds since the epoch" also makes it easier to compare times or find the difference between them.

James

  • Thanks 1
Link to comment
Share on other sites

char chDT[16];
void showLocalTime()
  {
  struct tm timeinfo;
  if(!getLocalTime(&timeinfo)){
    myDT = "Failed to obtain time";
    return;}
    else {
      year = timeinfo.tm_year + 1900;
      month = timeinfo.tm_mon + 1;
      day = timeinfo.tm_mday;
      hour = timeinfo.tm_hour;
      minute = timeinfo.tm_min;
      myDT = "";
      myDT += year;
      myDT += "-";
      if (month < 10) {myDT += "0";}
      myDT += month;
      myDT += "-";
      if (day < 10) {myDT += "0";}
      myDT += day;
      myDT += "  ";
      if (hour < 10) {myDT += "0";}
      myDT += hour;
      myDT += ":";
      if (minute < 10) {myDT += "0";}
      myDT += minute;
      }
    myDT.toCharArray(chDT, 16);
  }

Then something like

  client.publish("local/datetime", chDT);

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.