How to read the fieldname from a field in ThinkSpeak when using ThinkSpeak library for Arduino

1 Ansicht (letzte 30 Tage)
How to read the fieldname from a field in ThinkSpeak when using ThinkSpeak library for Arduino?
  3 Kommentare
Aarnout Wieers
Aarnout Wieers am 27 Jan. 2022
Bearbeitet: Aarnout Wieers am 27 Jan. 2022
I tried using readRaw as shown below, with XXXXXX being a real channel number and readAPIKey also being the real read key + activated debugging comments; See ERROR below
ts::readRaw (channelNumber: XXXXXXXX readAPIKey: XXXXXXXXXX suffixURL: "/fields/1?results=2?")
Connect to default ThingSpeak: api.thingspeak.com:80...Success.
GET "/channels/XXXXXXX/fields/1?results=2?"
Got Status of 200 (which is good)
ERROR: Didn't find Content-Length header
Why do I get this error? And how do I solve this?
I also tried another command:
ts::readRaw (channelNumber: XXXXXX readAPIKey: XXXXX suffixURL: "/fields/1/Last")
Connect to default ThingSpeak: api.thingspeak.com:80...Success.
GET "/channels/XXXXX/fields/1/Last"
Got Status of 200
Content Length: 2
Found end of header
Response: "-1"
Read: "-1"
disconnected.
The actual last value is NOT -1, but 23.0
And tried another one:
ts::readRaw (channelNumber: XXXXXX readAPIKey: XXXXXXX suffixURL: "/channels")
Connect to default ThingSpeak: api.thingspeak.com:80...Success.
GET "/channels/XXXXXX/channels"
Got Status of 302
disconnected.
The thinkspeak library used is version 2.0.0
It seems like never any data is returned?
Using the same commands in a browser it works fine
Can anybody help me to resolve these problems or point me to what I'm doing wrong
Actual code used is below, with suffixURL changed in respectively
case 1) String("/fields/1?results=2?")
case 2) String("/fields/1/Last")
case 3) String("/channels.json")
Main code lines:
String JsonStr = ThingSpeak.readRaw(channelID, String("/channels.json"), readAPIKey);
Serial.print("Response: "); Serial.println(JsonStr);
Also increasing the server response time to 10sec did not make any changes (not expecting this to be a connectivity or response issue)
Christopher Stapels
Christopher Stapels am 3 Feb. 2022
Case 3 is the one I meant for you to try. I'm not sure why you got the -302 error, was it consistant? For the channels endpoint, you need to supply User API key.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Communitys

Weitere Antworten in  ThingSpeak Community

Kategorien

Mehr zu Write Data to Channel finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by