Write to Thingspeak Error in Matlab - URL is incorrectly formed
16 views (last 30 days)
Show older comments
I am trying to write data that was loaded to an app in MATLAB to a Thingspeak channel. The line of code I am using is:
thingSpeakWrite(app.channelID, 'Fields', [1, 2, 3], 'Values', [posVal, velVal, accelVal], 'WriteKey', app.writeAPIKey, 'TimeStamp', tStamp);
channelID and writeAPIKey have been defined as public properties within the app; posVal, velVal, and accelVal are numeric arrays; and tStamp is a datetime array. The error message I am getting is "URL is incorrectly formed, or the requested feature is not supported in this version of ThingSpeak." Any ideas what the problem could be?
0 Comments
Answers (3)
Austin
on 1 Apr 2024
I found this situation suddenly come out of nowhere in working code due to the clocks changing forward in UK spring.
MATLAB thingspeakwrite() uses local time when doing a matrix or datatable write.
Because I had insert timestamps during a non-existent hour in local time in my datatable, it gave this error. At least I think that was the issue.
My workaround was to omit the write step after midnight and before 3am ( I wasn't sure which hour it uses). Very crude but it resolved the error.
3 Comments
Austin Jacobs
on 2 Apr 2024
Oh sure, its excused, thanks for looking at it. In the end I did manually insert the rows up to 2am and then timeshifted the hour it didn't like by an hour plus one minute (don't ask) but it kept my other programs happy enough to run as normal. I prefer to keep all my data on UT / GMT (same), although it introduces its own hassle when making conversion, so no perfect answer. Timezone would be a great option to have on this function in future.
Christopher Stapels
on 2 Apr 2024
Agreed, it would be nice.
The API has timezone but not the function sadly. Its in the request hopper, but the line is long.
Christopher Stapels
on 8 Mar 2021
Edited: Christopher Stapels
on 8 Mar 2021
The most likely reason is that the timestamps already exist in your channel. You cannot write data with a timestamp that already exists in the channel.
The best way to find out why it isnt working is to try the same request as an API call, either in POSTMAN, your browser, or with webread/webwrite in MATLAB.
0 Comments
Nazmi Rosly
on 16 Aug 2021
Edited: Christopher Stapels
on 1 Apr 2024
Hi. Im trying to send data from matlab which is the data from serial monitor from arduino. It is fine until 9th of data and then it stopped and says :
Error using Untitled (line 27)
'Values' must have a maximum of 9 elements, including the timestamp.
My coding is:
clear all
s = serial('com4');
fopen(s);
i = 1;
while(1)
data(i)= str2double(fscanf(s));
plot(data);
title('Temperature Monitoring')
xlabel('Time')
ylabel('Temperature')
pause(30);
i=i+1;
%thingSpeakWrite(1463959,data,'WriteKey','xxxxxxxxxxxxxxxx')
% Generate timestamps for the data
%tStamps = datetime('now')-minutes(9):minutes(1):datetime('now');
channelID = 1463959; % Change to your Channel ID
writeKey = 'xxxxxxxxxxxxxxxx'; % Change to your Write API Key
% Write 10 values to each field of your channel along with timestamps
tStamp = datetime('now')
thingSpeakWrite(1463959,data,'WriteKey','xxxxxxxxxxxxxxxx','TimeStamp',tStamp)
end
0 Comments
Communities
More Answers in the ThingSpeak Community
See Also
Categories
Find more on Read Data from Channel in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!