Browse Source

mqtt+api: move action handler (#2158)

mcspr-patch-1
Max Prokhorov 4 years ago
committed by GitHub
parent
commit
8f4f1beb54
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 7 deletions
  1. +5
    -4
      code/espurna/api.ino
  2. +1
    -0
      code/espurna/espurna.ino
  3. +2
    -3
      code/espurna/mqtt.ino
  4. +9
    -0
      code/espurna/rpc.h
  5. +29
    -0
      code/espurna/rpc.ino

+ 5
- 4
code/espurna/api.ino View File

@ -11,6 +11,7 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#include "api.h"
#include "system.h"
#include "web.h"
#include "rpc.h"
#include "ws.h"
typedef struct {
@ -150,12 +151,12 @@ void _onRPC(AsyncWebServerRequest *request) {
if (request->hasParam("action")) {
AsyncWebParameter* p = request->getParam("action");
String action = p->value();
const auto action = p->value();
DEBUG_MSG_P(PSTR("[RPC] Action: %s\n"), action.c_str());
if (action.equals("reboot")) {
response = 200;
deferredReset(100, CUSTOM_RESET_RPC);
if (rpcHandleAction(action)) {
response = 204;
}
}


+ 1
- 0
code/espurna/espurna.ino View File

@ -52,6 +52,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "ota.h"
#include "relay.h"
#include "rfm69.h"
#include "rpc.h"
#include "rpnrules.h"
#include "rtcmem.h"
#include "thermostat.h"


+ 2
- 3
code/espurna/mqtt.ino View File

@ -18,6 +18,7 @@ Updated secure client support by Niek van der Maas < mail at niekvandermaas dot
#include "system.h"
#include "mqtt.h"
#include "ntp.h"
#include "rpc.h"
#include "ws.h"
#include "libs/SecureClientHelpers.h"
@ -523,9 +524,7 @@ void _mqttCallback(unsigned int type, const char * topic, const char * payload)
// Actions
if (t.equals(MQTT_TOPIC_ACTION)) {
if (strcmp(payload, MQTT_ACTION_RESET) == 0) {
deferredReset(100, CUSTOM_RESET_MQTT);
}
rpcHandleAction(payload);
}
}


+ 9
- 0
code/espurna/rpc.h View File

@ -0,0 +1,9 @@
/*
Part of MQTT and API modules
*/
#pragma once
bool rpcHandleAction(const String& action);

+ 29
- 0
code/espurna/rpc.ino View File

@ -0,0 +1,29 @@
/*
Part of MQTT and API modules
*/
#if MQTT_SUPPORT || API_SUPPORT
#include <Schedule.h>
#include "system.h"
#include "utils.h"
#include "rpc.h"
bool rpcHandleAction(const String& action) {
bool result = false;
if (action.equals("reboot")) {
result = true;
schedule_function([]() {
deferredReset(100, CUSTOM_RESET_RPC);
});
} else if (action.equals("heartbeat")) {
result = true;
schedule_function(heartbeat);
}
return result;
}
#endif // MQTT_SUPPORT || API_SUPPORT

Loading…
Cancel
Save