MATLAB Answers

Write to Thingspeak Error in Matlab - URL is incorrectly formed

15 views (last 30 days)
Tazlina Dentinger
Tazlina Dentinger on 8 Mar 2021
Answered: Nazmi Rosly on 16 Aug 2021
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?

Answers (2)

Christopher Stapels
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.
The write data page will help with the format.

Nazmi Rosly
Nazmi Rosly on 16 Aug 2021
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');
i = 1;
data(i)= str2double(fscanf(s));
title('Temperature Monitoring')
% Generate timestamps for the data
%tStamps = datetime('now')-minutes(9):minutes(1):datetime('now');
channelID = 1463959; % Change to your Channel ID
writeKey = '9OUSQA9OXZU0EO4X'; % Change to your Write API Key
% Write 10 values to each field of your channel along with timestamps
tStamp = datetime('now')


More Answers in the  ThingSpeak Community




Community Treasure Hunt

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

Start Hunting!

Translated by