Browse Source

Add OTA support over MQTT

pull/1424/head
Niek van der Maas 5 years ago
parent
commit
db9a76d5f8
2 changed files with 32 additions and 0 deletions
  1. +5
    -0
      code/espurna/config/general.h
  2. +27
    -0
      code/espurna/ota.ino

+ 5
- 0
code/espurna/config/general.h View File

@ -537,6 +537,10 @@
#define OTA_PORT 8266 // OTA port
#endif
#ifndef OTA_MQTT_SUPPORT
#define OTA_MQTT_SUPPORT 0 // No support by default
#endif
#define OTA_GITHUB_FP "D7:9F:07:61:10:B3:92:93:E3:49:AC:89:84:5B:03:80:C1:9E:2F:8B"
// -----------------------------------------------------------------------------
@ -763,6 +767,7 @@
#define MQTT_TOPIC_SPEED "speed"
#define MQTT_TOPIC_IRIN "irin"
#define MQTT_TOPIC_IROUT "irout"
#define MQTT_TOPIC_OTA "ota"
// Light module
#define MQTT_TOPIC_CHANNEL "channel"


+ 27
- 0
code/espurna/ota.ino View File

@ -158,6 +158,10 @@ void _otaFrom(const char * host, unsigned int port, const char * url) {
}
void _otaFrom(String url) {
if (!url.startsWith("http://") && !url.startsWith("https://")) {
DEBUG_MSG_P(PSTR("[OTA] Incorrect URL specified\n"));
return;
}
// Port from protocol
unsigned int port = 80;
@ -197,6 +201,25 @@ void _otaInitCommands() {
#endif // TERMINAL_SUPPORT
#if OTA_MQTT_SUPPORT
void _otaMQTTCallback(unsigned int type, const char * topic, const char * payload) {
if (type == MQTT_CONNECT_EVENT) {
mqttSubscribe(MQTT_TOPIC_OTA);
}
if (type == MQTT_MESSAGE_EVENT) {
// Match topic
String t = mqttMagnitude((char *) topic);
if (t.equals(MQTT_TOPIC_OTA)) {
DEBUG_MSG_P(PSTR("[OTA] Initiating from URL: %s\n"), payload);
_otaFrom(payload);
}
}
}
#endif // OTA_MQTT_SUPPORT
// -----------------------------------------------------------------------------
void otaSetup() {
@ -207,6 +230,10 @@ void otaSetup() {
_otaInitCommands();
#endif
#if OTA_MQTT_SUPPORT
mqttRegister(_otaMQTTCallback);
#endif
// Main callbacks
espurnaRegisterLoop(_otaLoop);
espurnaRegisterReload(_otaConfigure);


Loading…
Cancel
Save