Matlab Thingspeakwrite data appears 1 day off | MATLAB | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Matlab Thingspeakwrite data appears 1 day off
No permission to create posts
January 25, 2018
3:09 pm
Avatar
turgo

Gold
Members
Forum Posts: 70
Member Since:
June 16, 2013
sp_UserOfflineSmall Offline

I'm using thingspeakwrite to upload Nov 2013 data to a new channel.  I downloaded data from a channel dated: 22-Nov-2013 00:00:00 UTC

The last data point I processed and wrote is dated 22-Nov-2013 00:00:00. 

When I view the data on the graph in the private view on my channel, the last date is: 22-Nov-2013 00:00:00 GMT - 800

When I download the newly written channel, the last date is: 2013-11-22 08:00:00 UTC

My data appears to have been shifted ahead 8 hours on the thingspeakwrite step.

Is there an error in the way thingspeak is handling these dates, or is there some nuance that I don't understand?

January 25, 2018
6:40 pm
Avatar
turgo

Gold
Members
Forum Posts: 70
Member Since:
June 16, 2013
sp_UserOfflineSmall Offline

I see in the documentation that:  "the Timestamp provided is interpreted in local timezone."

How do I get thingspeak to take my timestamp data in UTC, or how do I convert it to local time, accounting for daylight savings time?

January 25, 2018
7:07 pm
Avatar
turgo

Gold
Members
Forum Posts: 70
Member Since:
June 16, 2013
sp_UserOfflineSmall Offline

This timestamp business is a confusing topic.  

1. For example, when I use thingspeakread in matlab, are the start and end dates in UTC or local time?  The documentation doesn't say.

2. Is thingspeakread returning UTC or local time in a timetable?

3. Are the datetime values shown in Matlab UTC or local time.  

4. If I set a local timezone(d.TimeZone = 'America/New_York'), does it affect the timetable I send to thingspeakwrite, or just the display values in the matlab output pane?

January 26, 2018
2:16 pm
Avatar
Adarsh_Murthy

MathWorks
Members
Forum Posts: 62
Member Since:
August 25, 2015
sp_UserOfflineSmall Offline

Hi turgo,

datetime('now') function in MATLAB by default displays the local timezone defined in MATLAB. If you set the time, i.e., evaluate code like

dt = datetime('1-Jan-2018'),

then the datetime value is assigned to dt (without a timezone). you can assign a timezone to this variable by setting the property:

dt.TimeZone = 'America/New_York'

or

dt.TimeZone = 'local'

Refer to this link for further information:

https://www.mathworks.com/help/matlab/matlab_prog/specify-time-zones.html

-----------------------------------------------------

 

When you use ThingSpeakRead in MATLAB, the returned timestamps are always in local time by default. This is the case whether you return the data in an array, table, and timetable, i.e., for each of the cases below, timestamps will be in your local timezone:

[data, time] = thingSpeakRead(12397, 'NumPoints', 10);

dataT = thingSpeakRead(12397, 'NumPoints', 10, 'OutputFormat', 'table');

dataTT = thingSpeakRead(12397, 'NumPoints', 10, 'OutputFormat', 'timetable');

---------------------------

If the timestamps provided to thingSpeakWrite do not have their TimeZone property set, then thingSpeakWrite assumes local timezone (as defined by MATLAB). Else if the timestamps provided to thingSpeakWrite have their TimeZone property set, then thingSpeakWrite will use the specified TimeZone.

 

-Adarsh 

January 26, 2018
5:13 pm
Avatar
turgo

Gold
Members
Forum Posts: 70
Member Since:
June 16, 2013
sp_UserOfflineSmall Offline

Thanks Adarsh.

 

Upon examination of the flow of dates in and out of matlab and thingspeak, I think that there is no problem with the new recorded data:

1.  thingspeakread Start and end dates are in local time.

2.  Results are returned from thingspeakread to matlab in local time.

3.  Datetime values displayed in Matlab are in local time

4.  Didn't mess with d.Timezone

5. thingspeakwrite converts local times to UTC and writes UTC to the channel feed.

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
21 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

terranceqh2, DianeEmids, Alanawaype, uqovitay, ufijifode, manish01

Administrators: Hans: 387, lee: 457