Get value from reply of a http request to thingspeak

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Get value from reply of a http request to thingspeak

#1 Post by chromo23 » 23 Oct 2023, 16:00

I can receive the latest value of a thingspeak channel via an http request:

Code: Select all

api.thingspeak.com/channels/<channel_id>/fields/<field_id>/last.<format>
when <format> is txt you´ll get just the number as reply.
In ESPeasy the log output is:

Code: Select all

HTTP: sendToHTTP,api.thingspeak.com,80,/channels/1637928/fields/3/last.txt
HTTP : SendToHTTP api.thingspeak.com:80 GET... HTTP code: 200
HTTP : SendToHTTP api.thingspeak.com GET... HTTP code: 200 Received reply: 99.0
EVENT: http#api.thingspeak.com=200
Is there a secret/undocumented way to parse the reply in rules? (I am almost sure there isn´t but maybe it is possible to attach it to the http response event?)

User avatar
Ath
Normal user
Posts: 3522
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Get value from reply of a http request to thingspeak

#2 Post by Ath » 23 Oct 2023, 16:16

This has been requested several times already, but hasn't been implemented, because the returned string object size can be between empty and huge, and the latter would most likely overwhelm the ESP, causing it to crash & reset (even very possible on ESP32 :?).
/Ton (PayPal.me)

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Get value from reply of a http request to thingspeak

#3 Post by chromo23 » 23 Oct 2023, 17:00

Ath wrote: 23 Oct 2023, 16:16 causing it to crash & reset (even very possible on ESP32 ).
This i understand very well.
That´s why the reply in the log is cut off after a certain amount of characters i guess?
Why not keeping that limitation for an event? (I personally only need this for max 32bit numbers)
It would be a compromise for anyone that requested it.

What do you think?

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Get value from reply of a http request to thingspeak

#4 Post by chromo23 » 23 Oct 2023, 17:51

OK, i added the functionality for myself. Not sure if this is something for integrating into ESPeasy (in the form i did it).
But in general i would vote for it... :D

sanc0
New user
Posts: 8
Joined: 18 Oct 2022, 12:16

Re: Get value from reply of a http request to thingspeak

#5 Post by sanc0 » 20 Jan 2024, 15:23

I also advocate for the introduction of a reading function. I need it to control the switch over Internet.
Many simple arduino applications use it commonly.

"api.thingspeak.com/channels/xxxxxx/fields/x/last"
return 0=switch off
return 1=switch on

Thanks, Sanc0

sanc0
New user
Posts: 8
Joined: 18 Oct 2022, 12:16

Re: Get value from reply of a http request to thingspeak

#6 Post by sanc0 » 20 Jan 2024, 20:57

I tried the HTTP Advanced plugin. HTTP GET reads the value of the field, but I don't know how to use the value as DummyDevice.

Log report:

Code: Select all

HTTP : C011 GET... HTTP code: 200 0
HTTP : C011 GET... HTTP code: 200 1
(field value is 0 and 1)

Can anyone help?
Sanc0

User avatar
Ath
Normal user
Posts: 3522
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Get value from reply of a http request to thingspeak

#7 Post by Ath » 20 Jan 2024, 22:09

That value is not available to be used anywhere... unfortunately.
/Ton (PayPal.me)

sanc0
New user
Posts: 8
Joined: 18 Oct 2022, 12:16

Re: Get value from reply of a http request to thingspeak

#8 Post by sanc0 » 20 Jan 2024, 22:15

Thank you for your response.
Would it be possible to implement Mathworks' Thingspeak Library in the future?

https://github.com/mathworks/thingspeak-arduino

Using this library, a few lines of code can read field values ​​from Thingspeak.
I've been using ESP Easy for many years and it's a great product (thank you very much), but I was surprised that it couldn't read from Thingspeak, which I thought was a trivial task.

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Get value from reply of a http request to thingspeak

#9 Post by chromo23 » 21 Jan 2024, 00:21

sanc0 wrote: 20 Jan 2024, 20:57Can anyone help?
The "Thinkspeakreply" event is still a pending pull request: https://github.com/letscontrolit/ESPEasy/pull/4856
But i can provide you with a binary if you want. (I also made a "Openweatherreply" event if this also interesting for you)
Which binary you need?

sanc0
New user
Posts: 8
Joined: 18 Oct 2022, 12:16

Re: Get value from reply of a http request to thingspeak

#10 Post by sanc0 » 21 Jan 2024, 08:06

Thank you very much. I need Thingspeakreply mod, ESP8266_4M1M for tests and ESP8266_1M for ESP01 relay. (I don't know Openweather, I'll check it out, thanks for the tip.)

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Get value from reply of a http request to thingspeak

#11 Post by chromo23 » 21 Jan 2024, 10:53

sanc0 wrote: 21 Jan 2024, 08:06 (I don't know Openweather, I'll check it out, thanks for the tip.)
Since i was already in a branch where thinkspeak and openweather events are integrated you have them both.
If you ever want to test openweather:
Generate event with the response of a openweathermap request (https://openweathermap.org/api/one-call-api)
Example command: sendtohttp,api.openweathermap.org,80,/data/2.5/weather?id=2950159&units=metric&appid=<your appid>
For the app id you have to register (https://home.openweathermap.org/users/sign_up)
The location id you´ll get by finding a city/village on the website and get the id at the end of the url (e.g. https://openweathermap.org/city/2950159)
Example of the event: "EVENT: OpenweatherReply=<id>,<temp>,<feels_like>,<temp_min>,<temp_ma>,<pressure>,<humidity>,<windspeed_m/s>,<wind_direction>,<condition>,<condition_string>"
A cheatsheet for the weather-conditions (<condition>) can be found here: https://openweathermap.org/weather-conditions
In rules you can grep the reply by "On OpenweatherReply Do ..."
Attachments
normal esp8266 1M and 4M1M binaries.zip
(1.21 MiB) Downloaded 45 times

sanc0
New user
Posts: 8
Joined: 18 Oct 2022, 12:16

Re: Get value from reply of a http request to thingspeak

#12 Post by sanc0 » 21 Jan 2024, 14:25

Thanks a lot, I'm testing it now.

Edit: I messed around a bit, but it works now. :)
In the Github example you have: EVENT: reply#api.thingspeak.com
The real is: EVENT: ThingspeakReply
chromo23 wrote: 21 Jan 2024, 10:53 Since i was already in a branch where thinkspeak and openweather events are integrated you have them both.
Thank you very much for your willingness. You helped me a lot, I appreciate it.
Sanc0

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Get value from reply of a http request to thingspeak

#13 Post by chromo23 » 21 Jan 2024, 16:49

sanc0 wrote: 21 Jan 2024, 14:25 In the Github example you have: EVENT: reply#api.thingspeak.com
Actually the first post on GitHub looks like this:
Bildschirmfoto 2024-01-21 um 16.47.50.png
Bildschirmfoto 2024-01-21 um 16.47.50.png (165.39 KiB) Viewed 1960 times

Edit:
I get it. It was the second post you looked at.
(i changed it now...)

sanc0
New user
Posts: 8
Joined: 18 Oct 2022, 12:16

Re: Get value from reply of a http request to thingspeak

#14 Post by sanc0 » 21 Jan 2024, 21:33

chromo23 wrote: 21 Jan 2024, 16:49 I get it. It was the second post you looked at.
(i changed it now...)
Now everything is clear and understandable. Thanks again, great job. ;)
Sanc0

sanc0
New user
Posts: 8
Joined: 18 Oct 2022, 12:16

Re: Get value from reply of a http request to thingspeak

#15 Post by sanc0 » 21 Jan 2024, 23:21

Hi chromo23.
I have a problem with the ESP8266_1M version because it does not return EVENT: ThingspeakReply, return only EVENT: http#api.thingspeak.com=200. I tested it on the ESP01 and on the Wemos D1 mini with the same result. Can you please compile a new working ESP8266_1M.bin for me?
(ESP8266_4M1M.bin works properly on my WEMOS D1 Mini.)

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Get value from reply of a http request to thingspeak

#16 Post by chromo23 » 21 Jan 2024, 23:46

sanc0 wrote: 21 Jan 2024, 23:21 Can you please compile a new working ESP8266_1M.bin for me?
Here you go :)
Attachments
ESP_Easy_mega_20240121_normal_ESP8266_1M.bin.zip
(586.45 KiB) Downloaded 45 times

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Get value from reply of a http request to thingspeak

#17 Post by TD-er » 22 Jan 2024, 00:37

I strongly suggest you'd also look into replacing that 1M flash chip if possible for a 4M flash chip.
That will save you a lot of problems updating the build later

sanc0
New user
Posts: 8
Joined: 18 Oct 2022, 12:16

Re: Get value from reply of a http request to thingspeak

#18 Post by sanc0 » 22 Jan 2024, 08:12

chromo23 wrote: 21 Jan 2024, 23:46 Here you go :)
Work fine, thanks. ;)
TD-er wrote: 22 Jan 2024, 00:37 I strongly suggest you'd also look into replacing that 1M flash chip if possible for a 4M flash chip.
That will save you a lot of problems updating the build later
It's a simple ESP01 Relay Switch, hopefully it won't need to be updated.

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Get value from reply of a http request to thingspeak

#19 Post by chromo23 » 12 Feb 2024, 13:12

The "Thingspeak Event" was merged int to ESPEasy and can now be used by defining it in custom.h

Code: Select all

#define FEATURE_THINGSPEAK_EVENT        1 

Yesterday a new feature was merged where you can get a value of a channel or all channels at a specific point in time.
Infos can be found in the docs:
https://espeasy.readthedocs.io/en/lates ... sendtohttp

Post Reply

Who is online

Users browsing this forum: No registered users and 41 guests