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

4 visualizaciones (últimos 30 días)
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!

Respuesta aceptada

Christopher Stapels
Christopher Stapels el 12 de Abr. de 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 comentarios
Chris Nas
Chris Nas el 12 de Abr. de 2021
Editada: Chris Nas el 12 de Abr. de 2021
Thanks for your reply!
Do I understand it correctly. That the function: readMultipleFields() only displays the data that was added during the last write?
For example: I write two values at 12:01:01 a value in field 1 a value in field 2.
There are also values in fields 3-6, but these are older and are not rewritten during the write process.
If I now try to read out all fields via ReadMultipleFields(), I only get the first two fields, because these are the only ones with the timestamp 12:01:01 during the last write process.
Is there a way to apply the behaviour that ReadFieldAsFloat() has to readMultipleFields()? So simply the last values that were not "null" are returned?
Christopher Stapels
Christopher Stapels el 14 de Abr. de 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.

Iniciar sesión para comentar.

Más respuestas (1)

Vinod
Vinod el 12 de Abr. de 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.

Comunidades de usuarios

Más respuestas en  ThingSpeak Community

Categorías

Más información sobre Run on Target Hardware en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by