Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4060dad
Update Networking.cpp
chromoxdor Oct 23, 2023
bb5ac3e
Update Networking.cpp
chromoxdor Oct 25, 2023
425aec4
Update Networking.cpp
chromoxdor Oct 25, 2023
db1d7d9
make thinkspeak event optional
chromoxdor Oct 25, 2023
6b5e249
compare also the last part of the uri to generate an event
chromoxdor Oct 25, 2023
fb0f8ed
add check if we got an answer otherwise we get -1 as a value
chromoxdor Oct 25, 2023
197dc10
Update Networking.cpp
chromoxdor Oct 25, 2023
4c934d4
Update Networking.cpp
chromoxdor Oct 25, 2023
4ad08ac
Update define_plugin_sets.h
chromoxdor Oct 25, 2023
ad5e2ea
Update define_plugin_sets.h
chromoxdor Oct 25, 2023
1ef66a4
Update Networking.cpp
chromoxdor Oct 25, 2023
5a689b2
Add ThingspeakReply to wordlist
chromoxdor Oct 25, 2023
89bf66c
Update Networking.cpp
chromoxdor Oct 25, 2023
600367b
Update Networking.cpp
chromoxdor Oct 25, 2023
99b8156
added documentation
chromoxdor Oct 26, 2023
7d37637
Update Rules.rst
chromoxdor Oct 26, 2023
c9ef151
single + multifield reply combined
chromoxdor Oct 26, 2023
c6b96c5
Update Rules.rst
chromoxdor Oct 26, 2023
065efcd
Update Rules.rst
chromoxdor Oct 26, 2023
8c2f5a2
Merge branch 'mega' into reply_event
chromoxdor Oct 29, 2023
ae3cbb9
a little formatting
chromoxdor Oct 29, 2023
61a8a28
Merge branch 'mega' into reply_event
chromoxdor Nov 15, 2023
9756b8a
Merge branch 'reply_event' of https://github.com/chromoxdor/ESPEasy i…
chromoxdor Nov 30, 2023
967f940
Update espeasy.min.js
chromoxdor Nov 30, 2023
7f2a4ed
Update Rules.rst
chromoxdor Nov 30, 2023
33006a7
Merge branch 'letscontrolit:mega' into reply_event
chromoxdor Dec 27, 2023
7c85873
Merge branch 'mega' into reply_event
chromoxdor Jan 14, 2024
bcae422
Merge branch 'mega' into reply_event
chromoxdor Jan 18, 2024
8967740
Merge branch 'mega' into reply_event
chromoxdor Jan 21, 2024
1667923
Merge branch 'letscontrolit:mega' into reply_event
chromoxdor Jan 24, 2024
c215acf
Merge branch 'mega' into reply_event
chromoxdor Jan 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions docs/source/Rules/Rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,48 @@ Added: 2022/07/23
* Host name can contain user credentials. For example: ``http://username:pass@hostname:portnr/foo.html``
* HTTP user credentials now can handle Basic Auth and Digest Auth.

Added: 2023/10/26

* ``SendToHTTP`` now generates an event with the response of a thingspeak request (https://de.mathworks.com/help/thingspeak/readlastfieldentry.html & // https://de.mathworks.com/help/thingspeak/readdata.html)
* There are two options:

1. 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%``

2. 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%``

.. warning:: When using the command for all fields, the reply can become extremely big and can lead to memory issues which results in instabilities of your device (especially when all eight fields are filled with very big numbers)

* Example for two single field events in rules:

.. code:: none

on ThinkspeakReply do
LogEntry,'The channel number is: %eventvalue1%'
if %eventvalue2% = 5 //when the field number is 5
LogEntry,'%eventvalue3%°C in Berlin'
elseif %eventvalue2% = 6 //when the field number is 6
LogEntry,'%eventvalue3%°C in Paris'
endif
endon



Convert curl POST command to PostToHTTP
---------------------------------------
Expand Down
11 changes: 6 additions & 5 deletions src/Custom-sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
// --- Feature Flagging ---------------------------------------------------------
// Can be set to 1 to enable, 0 to disable, or not set to use the default (usually via define_plugin_sets.h)

#define FEATURE_RULES_EASY_COLOR_CODE 1 // Use code highlighting, autocompletion and command suggestions in Rules
#define FEATURE_ESPEASY_P2P 1 // (1/0) enables the ESP Easy P2P protocol
#define FEATURE_ARDUINO_OTA 1 //enables the Arduino OTA capabilities
// #define FEATURE_SD 1 // Enable SD card support
// #define FEATURE_DOWNLOAD 1 // Enable downloading a file from an url
#define FEATURE_RULES_EASY_COLOR_CODE 1 // Use code highlighting, autocompletion and command suggestions in Rules
#define FEATURE_ESPEASY_P2P 1 // (1/0) enables the ESP Easy P2P protocol
#define FEATURE_ARDUINO_OTA 1 // enables the Arduino OTA capabilities
#define FEATURE_THINGSPEAK_EVENT 1 // generate an event when requesting last value of a field in thingspeak via SendToHTTP(e.g. sendToHTTP,api.thingspeak.com,80,/channels/1667332/fields/5/last)
// #define FEATURE_SD 1 // Enable SD card support
// #define FEATURE_DOWNLOAD 1 // Enable downloading a file from an url

#ifdef BUILD_GIT
# undef BUILD_GIT
Expand Down
7 changes: 7 additions & 0 deletions src/src/CustomBuild/define_plugin_sets.h
Original file line number Diff line number Diff line change
Expand Up @@ -3316,5 +3316,12 @@ To create/register a plugin, you have to :
*/


#ifndef FEATURE_THINGSPEAK_EVENT
#ifdef LIMIT_BUILD_SIZE
#define FEATURE_THINGSPEAK_EVENT 0
#else
#define FEATURE_THINGSPEAK_EVENT 1
#endif
#endif

#endif // CUSTOMBUILD_DEFINE_PLUGIN_SETS_H
31 changes: 31 additions & 0 deletions src/src/Helpers/Networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,38 @@ int http_authenticate(const String& logIdentifier,
// Generate event with the HTTP return code
// e.g. http#hostname=401
eventQueue.addMove(strformat(F("http#%s=%d"), host.c_str(), httpCode));

#if FEATURE_THINGSPEAK_EVENT
Comment thread
chromoxdor marked this conversation as resolved.
// Generate event with the response of a
// thingspeak request (https://de.mathworks.com/help/thingspeak/readlastfieldentry.html &
// https://de.mathworks.com/help/thingspeak/readdata.html)
// e.g. command for a specific field: "sendToHTTP,api.thingspeak.com,80,/channels/1637928/fields/5/last.csv"
// command for all fields: "sendToHTTP,api.thingspeak.com,80,/channels/1637928/feeds/last.csv"
// where first eventvalue is the channel number and the second to the nineth event values
// are the field values
// Example of the event: "EVENT: ThingspeakReply=1637928,5,24.2,12,900,..."
// ^ ^ └------┬------┘
// channel number ┘ | └ received values
// field number (only available for a "single-value-event")
// In rules you can grep the reply by "On ThingspeakReply Do ..."

if (httpCode == 200 && equals(host, F("api.thingspeak.com")) && uri.endsWith(F("/last.csv"))) {
String result = http.getString();
const int posTimestamp = result.lastIndexOf(':');
if (posTimestamp >= 0) {
result = parseStringToEndKeepCase(result.substring(posTimestamp), 3);
if (uri.indexOf(F("fields")) >= 0) { //when there is a single field call add the field number before the value
result = parseStringKeepCase(uri, 4, '/') + "," + result;
}
eventQueue.addMove(strformat(
F("ThingspeakReply=%s,%s"),
parseStringKeepCase(uri, 2, '/').c_str(),
result.c_str()));
}
}
#endif
}

#ifndef BUILD_NO_DEBUG
log_http_result(http, logIdentifier, host + ':' + port, HttpMethod, httpCode, EMPTY_STRING);
#endif
Expand Down
2 changes: 1 addition & 1 deletion static/espeasy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var commonCommands = ["AccessInfo", "Background", "Build", "ClearAccessBlock", "
"ControllerEnable", "DateTime", "Debug", "Dec", "DeepSleep", "DisablePriorityTask", "DNS", "DST", "EraseSDKWiFi", "ExecuteRules", "Gateway", "I2Cscanner", "Inc",
"IP", "Let", "Load", "LogEntry", "LogPortStatus", "LoopTimerSet", "LoopTimerSet_ms", "MemInfo", "MemInfoDetail", "Name", "Password", "PostToHTTP", "Publish",
"Reboot", "Reset", "Save", "SendTo", "SendToHTTP", "SendToUDP", "Settings", "Subnet", "Subscribe", "TaskClear", "TaskClearAll",
"TaskDisable", "TaskEnable", "TaskRun", "TaskValueSet", "TaskValueSetAndRun", "TimerPause", "TimerResume", "TimerSet", "TimerSet_ms", "TimeZone",
"TaskDisable", "TaskEnable", "TaskRun", "TaskValueSet", "TaskValueSetAndRun", "ThingspeakReply", "TimerPause", "TimerResume", "TimerSet", "TimerSet_ms", "TimeZone",
"UdpPort", "UdpTest", "Unit", "UseNTP", "WdConfig", "WdRead", "WiFi", "WiFiAPkey", "WiFiAllowAP", "WiFiAPMode", "WiFiConnect", "WiFiDisconnect", "WiFiKey",
"WiFiKey2", "WiFiScan", "WiFiSSID", "WiFiSSID2", "WiFiSTAMode", "WiFi#Disconnected",
"Event", "AsyncEvent",
Expand Down
Loading