When I convert the time stamp I retrieve from a sensor from Unix time to current time (in Colorado) there appears to be a 6-hour shift. I need to remove 6 hours. Is this correct?
Hi @Mtnbiker88
I had to deal with something similar regarding timezones, UTC and local time with Notecard, so thought I’d chip in.
Colorado is presently on Mountain Daylight Time, which is GMT-6, so you would need to subtract 6 hours from the current UTC time to arrive at local time.
If you anticipate that your Notecard may be used in other timezones, or want to better handle the changes between standard and daylight time, you can use the card.timerequest to determine the current timezone along with the number of minutes offset, and use that to add the appropriate number of minutes to the UTC time to get local time. In your case, Notecard would respond to the card.time request with “minutes": -720 which you would then multiply by 60 to convert minutes to seconds, and add this to the UTC time.
As a rule of thumb, times for computers are best stored as UTC time. This is unambiguous and avoids grappling with changing timezones due to geographical movement and/or daylight savings. In contrast, when displaying times for people, then local time is usually preferred, along with displaying the timezone abbreviation (such as MST or MDT) to help clear up any ambiguity.
Nice Elert Dev! Thank you for the clear response and instructions. I will code up your suggestion.
John
I am not sure how to get access to the Notecard. I have looked at CoPilot AI for assistance, and here is code snippet (C#), but I can’t include NoteCard, so note is undefined. (NoteCard is not available on NuGet. Any suggestions?
// Create a new request for “card.time”
var req = new JObject();
req[“req”] = “card.time”;
// Send the request to the Notecard
var rsp = note.Request(req);
// Parse the response
if (rsp != null)
{
long epochTime = rsp.Value(“time”);
string zone = rsp.Value(“zone”);
string area = rsp.Value(“area”);
string country = rsp.Value(“country”);
Console.WriteLine($"Time (Epoch): {epochTime}");
Console.WriteLine($"Zone: {zone}");
Console.WriteLine($"Area: {area}");
Console.WriteLine($"Country: {country}");
}
else
{
Console.WriteLine(“No response from Notecard.”);
}
Hey @Mtnbiker88,
Could you tell us a bit more about how you’re trying to access your Notecard? I’m mostly interested in what MCU or SBC you’re using (Swan, Cygnet, Uno, Pi, etc).
There is an older, community-built Notecard library that uses C# (see GitHub - bytewizer/blueswireless: Blues Wireless libraries built for GHI Electronics TinyCLR OS and .NET nanoFramework.) and works with a few different boards—but in general we recommend using one of our official firmware libraries, especially when getting started.
TJ
Hi TJ,
I have developed an interactive GIS-based mapping system in Windows .Net using C#. I have access to numerous sensors across the US using USGS, State of Colorado and several private APIs such as SoraCom and Cloudloop. I am tasked with adding new sensors using Blues comms. So, I am using a web-based URL approach to retrieving the sensor data (I can share my code if you think it would be helpful). So, I am trying to solve this card.time problem in that manner. So, I guess accessing the firmware via a url?
Does that make sense?
John
Hey @Mtnbiker88,
The card.time request is a Notecard API request that can only be done at the firmware level—it’s not something you can access remotely via a cloud app.
TJ
Yeah, that’s what I thought. Thanks for your support!