Skip to content

Commit

Permalink
Merge branch 'mega' into bugfix/IPv6_ESP32_address
Browse files Browse the repository at this point in the history
  • Loading branch information
TD-er authored Jan 30, 2024
2 parents eee0d49 + 481fe3b commit 711bedb
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 7 deletions.
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 @@ -3324,5 +3324,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
// 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

0 comments on commit 711bedb

Please sign in to comment.