Write to Thingspeak Error in Matlab - URL is incorrectly formed

조회 수: 4 (최근 30일)
Tazlina Dentinger
Tazlina Dentinger 2021년 3월 8일
댓글: Christopher Stapels 2024년 4월 2일
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?

답변 (3개)

Austin
Austin 2024년 4월 1일
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
Austin Jacobs
Austin Jacobs 2024년 4월 2일
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 2024년 4월 2일
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
Christopher Stapels 2021년 3월 8일
편집: Christopher Stapels 2021년 3월 8일
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 2021년 8월 16일
편집: Christopher Stapels 2024년 4월 1일
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

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

Help CenterFile Exchange에서 Read Data from Channel에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by