Skip to content

Commit

Permalink
Merge pull request PhracturedBlue#8 from simone1999/patch-3
Browse files Browse the repository at this point in the history
Patch 3
  • Loading branch information
simone1999 authored Dec 29, 2018
2 parents 7f8f1e3 + 7ae8518 commit a8d3239
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 13 additions & 12 deletions src/ESP8266MQTTMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,18 +501,6 @@ const char *ESP8266MQTTMesh::build_mesh_ssid(char buf[32], uint8_t *mac) {
return buf;
}

void ESP8266MQTTMesh::HandleMessages(const char *topic, const char *msg) {
if(strstr(topic,"Ping") == topic){
String topic = "Ping";
publish(topic.c_str(), String(1).c_str());
}else if(strstr(topic,"Restart") == topic){
ESP.restart();
while(1){}
}else{
callback(topic, msg);
}
}

void ESP8266MQTTMesh::parse_message(const char *topic, const char *msg) {
int inTopicLen = strlen(inTopic);
if (strstr(topic, inTopic) != topic) {
Expand Down Expand Up @@ -544,6 +532,19 @@ void ESP8266MQTTMesh::parse_message(const char *topic, const char *msg) {
}
}

void ESP8266MQTTMesh::HandleMessages(const char *topic, const char *msg) {
if(strstr(topic,"Ping") == topic){
dbgPrintln(EMMDBG_MSG, "answering Ping!");
String topic = "Ping";
publish(topic.c_str(), String(1).c_str());
}else if(strstr(topic,"Restart") == topic){
dbgPrintln(EMMDBG_MSG, "Got Restart Command, restarting now");
die();
}else{
callback(topic, msg);
}
}

void ESP8266MQTTMesh::connect_mqtt() {
dbgPrintln(EMMDBG_MQTT, "Attempting MQTT connection (" + mqtt_server + ":" + String(mqtt_port) + ")...");
// Attempt to connect
Expand Down
2 changes: 1 addition & 1 deletion src/ESP8266MQTTMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class ESP8266MQTTMesh {
std::function<void(const char *topic, const char *msg)> callback;

bool wifiConnected() { return (WiFi.status() == WL_CONNECTED); }
void die() { while(1) {} }
void die() { ESP.restart(); while(1) {} }

uint32_t lfsr(uint32_t seed, uint8_t b);
uint32_t encrypt_id(uint32_t id);
Expand Down

0 comments on commit a8d3239

Please sign in to comment.