Bug in API response, Reading multiple Fields with ESP8266 Arduino Library.

7 views (last 30 days)
Hey,
I am currently programming something in ArduinoIDE for an ESP8266 to read my sensor data that is already uploaded to TS.
For this, I use the function:
ThingSpeak.readMultipleFields(CHANNELID,READKEY).
Unfortunately, I found that the server no longer returns the correct data.
Here some debug Log from the Arduino library right after caling ThingSpeak.readMultipleFields(CHANNELID,READKEY):
ts::readRaw (channelNumber: 13xxxxx readAPIKey: H89OOxxYFXxxxxxx suffixURL: "/feeds/last.txt?status=true&location=true")
Connect to default ThingSpeak: api.thingspeak.com:80...Success.
GET "/channels/13xxxxx/feeds/last.txt?status=true&location=true"
Got Status of 200
Content Length: 210
Found end of header
Response: "{"created_at":"2021-04-06T20:25:06Z","entry_id":5,"field1":null,"field2":null,"field3":null,"field4":null,"field5":"27.82000","field6":"28.96680","latitude":null,"longitude":null,"elevation":null,"status":null}"
Read: "{"created_at":"2021-04-06T20:25:06Z","entry_id":5,"field1":null,"field2":null,"field3":null,"field4":null,"field5":"27.82000","field6":"28.96680","latitude":null,"longitude":null,"elevation":null,"status":null}"
disconnected.
As you can see, field 4 returns "null".
When reading the same Channel and field with the function:
ThingSpeak.readFloatField(CHANNELID,FIELD ID,READKEY)
I get:
ts::readStringField(channelNumber: 13xxxxx readAPIKey: H89OOxxYFXxxxxxx field: 4)
ts::readRaw (channelNumber: 13xxxxx readAPIKey: H89OOxxYFXxxxxxx suffixURL: "/fields/4/last")
Connect to default ThingSpeak: api.thingspeak.com:80...Success.
GET "/channels/13xxxxx/fields/4/last"
Got Status of 200
Content Length: 8
Found end of header
Response: "29.94141"
Read: "29.94141"
disconnected.
And this is the right value.
Im using the latest Version from TS arduino Library. I already opend an issue on Github but there is no reaction on it.
Does anyone have any ideas?
Greetings!

Accepted Answer

Christopher Stapels
Christopher Stapels on 12 Apr 2021
I think you are comparing two different operations as well. The first is a read of the latest feed entry, or all of the field values. The second is a call to the last entry for the field, which may not return the last feed, it might return a field entry from an older feed. The field call is looking for the last non-null entry. As Vinod says, comparing to the full export will likely show the issue.
  2 Comments
Christopher Stapels
Christopher Stapels on 14 Apr 2021
You will need to use multiple calls to read a filed get that behavior. Read multiple fields uses a single feed entry (common timestamp) read and extracts the data from multiple fields.
You might be able to use the readraw command to read multiple feed entries and then parse the results yourself.

Sign in to comment.

More Answers (1)

Vinod
Vinod on 12 Apr 2021
I think looking at the response at one point in time is probably leading you to incorrect conclusions because the channel was updated during the period you switched from retrieving the feed vs/ retrieving just the field. I recommend you download the data from the "Import/Export Data" tab of the channel and confirm the library is giving you the correct reading.

Communities

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!