Borrar filtros
Borrar filtros

Write to Thingspeak Error in Matlab - URL is incorrectly formed

6 visualizaciones (últimos 30 días)
Tazlina Dentinger
Tazlina Dentinger el 8 de Mzo. de 2021
Comentada: Christopher Stapels el 2 de Abr. de 2024
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?

Respuestas (3)

Austin
Austin el 1 de Abr. de 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 comentarios
Austin Jacobs
Austin Jacobs el 2 de Abr. de 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
Christopher Stapels el 2 de Abr. de 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.

Iniciar sesión para comentar.


Christopher Stapels
Christopher Stapels el 8 de Mzo. de 2021
Editada: Christopher Stapels el 8 de Mzo. de 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 el 16 de Ag. de 2021
Editada: Christopher Stapels el 1 de Abr. de 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

Comunidades de usuarios

Más respuestas en  ThingSpeak Community

Categorías

Más información sobre Read Data from Channel en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by