Write to Thingspeak Error in Matlab - URL is incorrectly formed

18 Ansichten (letzte 30 Tage)
Tazlina Dentinger
Tazlina Dentinger am 8 Mär. 2021
Kommentiert: Christopher Stapels am 2 Apr. 2024 um 20:05
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?

Antworten (3)

Austin
Austin am 1 Apr. 2024 um 22:58
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 Kommentare
Austin Jacobs
Austin Jacobs am 2 Apr. 2024 um 19:23
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
Christopher Stapels am 2 Apr. 2024 um 20:05
Agreed, it would be nice.
The API has timezone but not the function sadly. Its in the request hopper, but the line is long.

Melden Sie sich an, um zu kommentieren.


Christopher Stapels
Christopher Stapels am 8 Mär. 2021
Bearbeitet: Christopher Stapels am 8 Mär. 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.
The write data page will help with the format.

Nazmi Rosly
Nazmi Rosly am 16 Aug. 2021
Bearbeitet: Christopher Stapels am 1 Apr. 2024 um 23:29
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

Communitys

Weitere Antworten in  ThingSpeak Community

Kategorien

Mehr zu Read Data from Channel finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by