Page 1 of 1

Get value from reply of a http request to thingspeak

Posted: 23 Oct 2023, 16:00
by chromo23
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?)

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

Posted: 23 Oct 2023, 16:16
by Ath
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 :?).

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

Posted: 23 Oct 2023, 17:00
by chromo23
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?

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

Posted: 23 Oct 2023, 17:51
by chromo23
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

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

Posted: 20 Jan 2024, 15:23
by sanc0
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

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

Posted: 20 Jan 2024, 20:57
by sanc0
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

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

Posted: 20 Jan 2024, 22:09
by Ath
That value is not available to be used anywhere... unfortunately.

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

Posted: 20 Jan 2024, 22:15
by sanc0
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.

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

Posted: 21 Jan 2024, 00:21
by chromo23
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?

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

Posted: 21 Jan 2024, 08:06
by sanc0
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.)

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

Posted: 21 Jan 2024, 10:53
by chromo23
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 ..."

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

Posted: 21 Jan 2024, 14:25
by sanc0
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

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

Posted: 21 Jan 2024, 16:49
by chromo23
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 2523 times

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

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

Posted: 21 Jan 2024, 21:33
by sanc0
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

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

Posted: 21 Jan 2024, 23:21
by sanc0
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.)

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

Posted: 21 Jan 2024, 23:46
by chromo23
sanc0 wrote: 21 Jan 2024, 23:21 Can you please compile a new working ESP8266_1M.bin for me?
Here you go :)

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

Posted: 22 Jan 2024, 00:37
by TD-er
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

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

Posted: 22 Jan 2024, 08:12
by sanc0
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.

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

Posted: 12 Feb 2024, 13:12
by chromo23
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