Skip to content
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

[pull] mega from letscontrolit:mega #172

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion docs/source/Plugin/P000_commands.repl
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,16 @@
"
Publish","
:green:`Rules`","
Send command using MQTT broker service. Uses the first enabled MQTT Controller.
Send command using MQTT broker service. The 'Will Retain' option as configured in the MQTT Controller settings is used. Uses the first enabled MQTT Controller.

``Publish,<topic>[,<payload>]``"
"
PublishR","
:green:`Rules`","
Send command using MQTT broker service, with the MQTT 'Will Retain' flag enabled. Uses the first enabled MQTT Controller.

``PublishR,<topic>[,<payload>]``"
"
PutToHTTP","
:green:`Rules`","
*Syntax format 1:*
Expand Down
10 changes: 5 additions & 5 deletions docs/source/Rules/Rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2020,14 +2020,14 @@ Added 2024/02/05

* Examples:

Single channel: ``"sendtohttp,api.thingspeak.com,80,channels/1637928/fields/1.csv?end=2024-01-01%2023:59:00&results=1``
=> gets the value of field 1 at (or the last entry before) 23:59:00 of the channel 1637928
Single channel: ``SendToHTTP,api.thingspeak.com,80,channels/143789/fields/1.csv?end=2024-01-01%2023:59:00&results=1``
=> gets the value of field 1 at (or the last entry before) 23:59:00 of the channel 143789

All channels: ``"sendtohttp,api.thingspeak.com,80,channels/1637928/feeds.csv?end=2024-01-01%2023:59:00&results=1``
=> gets the value of each field of the channel 1637928 at (or the last entry before) 23:59:00
All channels: ``SendToHTTP,api.thingspeak.com,80,channels/143789/feeds.csv?end=2024-01-01%2023:59:00&results=1``
=> gets the value of each field of the channel 143789 at (or the last entry before) 23:59:00

.. note::
``csv`` and ``result=1`` are mandatory!
``csv`` and ``results=1`` are mandatory!

Convert curl POST command to PostToHTTP
---------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/src/Commands/InternalCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ bool InternalCommands::executeInternalCommand()
case ESPEasy_cmd_e::pulse: COMMAND_CASE_A(Command_GPIO_Pulse, 3); // GPIO.h
#if FEATURE_MQTT
case ESPEasy_cmd_e::publish: COMMAND_CASE_A(Command_MQTT_Publish, -1); // MQTT.h
case ESPEasy_cmd_e::publishr: COMMAND_CASE_A(Command_MQTT_PublishR, -1); // MQTT.h
#endif // if FEATURE_MQTT
#if FEATURE_PUT_TO_HTTP
case ESPEasy_cmd_e::puttohttp: COMMAND_CASE_A(Command_HTTP_PutToHTTP, -1); // HTTP.h
Expand Down
1 change: 1 addition & 0 deletions src/src/Commands/InternalCommands_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ const char Internal_commands_p[] PROGMEM =
"pulse|"
#if FEATURE_MQTT
"publish|"
"publishr|"
#endif // #if FEATURE_MQTT
#if FEATURE_PUT_TO_HTTP
"puttohttp|"
Expand Down
1 change: 1 addition & 0 deletions src/src/Commands/InternalCommands_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ enum class ESPEasy_cmd_e : uint8_t {
pulse,
#if FEATURE_MQTT
publish,
publishr,
#endif // #if FEATURE_MQTT
#if FEATURE_PUT_TO_HTTP
puttohttp,
Expand Down
18 changes: 13 additions & 5 deletions src/src/Commands/MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@
#include "../Helpers/StringConverter.h"


const __FlashStringHelper * Command_MQTT_Publish(struct EventStruct *event, const char *Line)
const __FlashStringHelper* Command_MQTT_Publish(struct EventStruct *event, const char *Line) {
return Command_MQTT_Publish_handler(event, Line, false);
}

const __FlashStringHelper* Command_MQTT_PublishR(struct EventStruct *event, const char *Line) {
return Command_MQTT_Publish_handler(event, Line, true);
}

const __FlashStringHelper* Command_MQTT_Publish_handler(struct EventStruct *event, const char *Line, const bool forceRetain)
{
// ToDo TD-er: Not sure about this function, but at least it sends to an existing MQTTclient
controllerIndex_t enabledMqttController = firstEnabledMQTT_ControllerIndex();
Expand All @@ -34,13 +42,13 @@ const __FlashStringHelper * Command_MQTT_Publish(struct EventStruct *event, cons
const String topic = parseStringKeepCase(Line, 2);
const String value = tolerantParseStringKeepCase(Line, 3);
# ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_DEBUG, concat(F("Publish: "), topic) + value);
#endif
addLog(LOG_LEVEL_DEBUG, strformat(F("Publish%c: %s:%s"), forceRetain ? 'R' : ' ', topic.c_str(), value.c_str()));
# endif

if (!topic.isEmpty()) {

bool mqtt_retainFlag;
{
bool mqtt_retainFlag = forceRetain;
if (!forceRetain) {
// Place the ControllerSettings in a scope to free the memory as soon as we got all relevant information.
MakeControllerSettings(ControllerSettings); //-V522
if (!AllocatedControllerSettings()) {
Expand Down
13 changes: 9 additions & 4 deletions src/src/Commands/MQTT.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@

#if FEATURE_MQTT

const __FlashStringHelper * Command_MQTT_Publish(struct EventStruct *event,
const char *Line);
const __FlashStringHelper* Command_MQTT_Publish(struct EventStruct *event,
const char *Line);
const __FlashStringHelper* Command_MQTT_PublishR(struct EventStruct *event,
const char *Line);
const __FlashStringHelper* Command_MQTT_Publish_handler(struct EventStruct *event,
const char *Line,
const bool forceRetain);

const __FlashStringHelper * Command_MQTT_Subscribe(struct EventStruct *event,
const char* Line);
const __FlashStringHelper* Command_MQTT_Subscribe(struct EventStruct *event,
const char *Line);

#endif // if FEATURE_MQTT

Expand Down