Skip to content

Commit

Permalink
don't unsubscribe to avoid missing update
Browse files Browse the repository at this point in the history
  • Loading branch information
Yattien committed Apr 7, 2020
1 parent 466b6c2 commit d7cd85f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version v16

- Fix MQTT subscription

## Version v15

- Changed use unique AP name
Expand Down
18 changes: 8 additions & 10 deletions ESPEInk_ESP8266.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ WiFiClient espClient;
PubSubClient mqttClient(espClient);

// -----------------------------------------------------------------------------------------------------
const int FW_VERSION = 15; // for OTA
const int FW_VERSION = 16; // for OTA
// -----------------------------------------------------------------------------------------------------
const char *CONFIG_FILE = "/config.json";
const float TICKS_PER_SECOND = 80000000; // 80 MHz processor
Expand Down Expand Up @@ -74,9 +74,7 @@ void setup() {
getUpdate();
initializeSpi();
myIP = WiFi.localIP();

mqttClient.setServer(ctx.mqttServer, ctx.mqttPort);
mqttClient.setCallback(callback);
setupMqtt();

Serial.println("Setup complete.");
}
Expand Down Expand Up @@ -248,6 +246,12 @@ void initializeSpi() {
SPI.begin();
}

// -----------------------------------------------------------------------------------------------------
void setupMqtt() {
mqttClient.setServer(ctx.mqttServer, ctx.mqttPort);
mqttClient.setCallback(callback);
}

// -----------------------------------------------------------------------------------------------------
void initializeWebServer() {
server.on("/", handleBrowserCall);
Expand Down Expand Up @@ -396,12 +400,6 @@ void reconnect() {
void disconnect() {
if (mqttClient.connected()) {
Serial.println("Disconnecting from MQTT...");
boolean rc = mqttClient.unsubscribe(ctx.mqttUpdateStatusTopic);
if (rc) {
Serial.printf(" unsubscribed from %s\r\n", ctx.mqttUpdateStatusTopic);
} else {
Serial.printf(" unsubscription from %s failed: %d\r\n", ctx.mqttUpdateStatusTopic, rc);
}
mqttClient.disconnect();
delay(100);
}
Expand Down

0 comments on commit d7cd85f

Please sign in to comment.