-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[sendtohttp] thingspeak only reply event #4856
Conversation
Rules Example:
Output:
|
I made this optional but i am not sure if i did it right.. |
Should i add this to the documentation as an annotation in the SendToHTTP section? |
Yes, as it is on by default for regular builds (without |
I will do it tomorrow.. my battery is empty |
@TD-er & @tonhuisman i tried another approach where all the fields gets parsed from csv the command: the code: if (httpCode == 200 && equals(host, F("api.thingspeak.com")) && uri.endsWith(F("/last.csv"))) {
String result = http.getString();
//created_at,entry_id,field1,field2,field3,field4,field5,field6,field7,field8^2023-10-26T16:14:17+02:00,921,5929,353,42.0,177,19.1,995.6,,
result = result.substring(result.lastIndexOf(':'), result.length());
//00,921,5929,353,42.0,177,19.1,995.6,,
result = result.substring(result.indexOf(',', result.indexOf(',') + 1 )+1, result.length()-1);
//5929,353,42.0,177,19.1,995.6,,
eventQueue.add(strformat(F("ThingspeakReply=%s,%s"),
parseStringKeepCase(uri, 2, '/').c_str(),
result.c_str()));
} the output: Would this also be an option or are there good reasons not to do it? |
Hmm, it looks like |
Is there something i can do? |
Nope, those build issues are often a network issue on the build environment. |
Nope, server response may not be complete, or something else may be wrong. |
Dear @TD-er, Command: Event: ( Response: Code: if (httpCode == 200 && equals(host, F("api.openweathermap.org"))) {
String result = http.getString();
result.replace('[', '_'); //get rid of these otherwise parsing won´t work
result.replace(']', '_');
String wVals;
String res;
int Num[10]{25, 8, 9, 10, 11, 12, 13, 15, 16, 5};
for (int i : Num) {
res = parseStringKeepCase(result, i);
res = res.substring(res.lastIndexOf(':')+1);
if (res.endsWith("}")) {res = res.substring(0,res.lastIndexOf('}'));} //get rid of
if (i == 5) {res = res.substring(1);} //unwanted characters
wVals += res;
if (i != 5) {
wVals += ",";
}
}
eventQueue.addMove(strformat(F("OpenweatherReply=%s"),
wVals.c_str()));
} I would make this a custom build feauture only... |
The funny thing is, i was just searching in the forum a bit if anybody had a requests regarding this topic. Who would have guessed, that 2,5 years later i am the one helping me from the past... |
That response should better be parsed as the Json it is, not try to pick out just some values. Most likely the content of that Json will change somewhere in the future, breaking your fixed indexes 🤔 |
That i learned with my easy2ntfy project. So this is out of the question
That is a risk i am willing to take. Either i would adjust the code or remove it completely. Edit:
I mean it is not added yet anyhow... :) |
Yes, but the same goes for a lot of similar services, think of Weather Underground, Yahoo weather, your local weather service, etc. Mostly limited by a lack of time/resources, but good ideas are always welcome & helpful. (I have some brewing in my head, I'll try to write them down 😸) |
Absolutely.. but in general i couldn´t find a better API than that of openweathermap. I mean that in terms of free calls per day and length of the response. Because even if we had a nice json parser, i would imagine the esp8266 to suffer or even left out. |
Hmm, code for specific interacting with some external service and providing code to parse specific syntax... Looks a lot like a "controller" for ESPEasy, doesn't it? |
If you update to |
61a8a28
to
5cdeeae
Compare
…nto reply-event-for-thingspeak
I added an event for a specific thingspeak request:
Get the value of a single field:
Example command:
SendToHTTP,api.thingspeak.com,80,/channels/1637928/fields/5/last.csv
Example of the resulting event:
"EVENT: ThingspeakReply=1637928,5,24.2"
| channel number =
%eventvalue1%
| field number =
%eventvalue2%
| value =
%eventvalue3%
Get the values of all fields:
Example command:
SendToHTTP,api.thingspeak.com,80,/channels/1637928/feeds/last.csv
Example of the resulting event:
"EVENT:ThingspeakReply=1637928,5929,353,42.0,177,19.1,995.6,,"
| channel number =
%eventvalue1%
| values =
%eventvalue2%
to%eventvalue9%