Skip to content

Commit

Permalink
Fixed a bug where if the WiFi connected at a very specific point the …
Browse files Browse the repository at this point in the history
…panel wouldn't go forther with the boot process
  • Loading branch information
tpanajott committed Sep 10, 2024
1 parent 471f485 commit a31ebe0
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 14 deletions.
Binary file modified docker/web/nspanelmanager/data_file.bin
Binary file not shown.
Binary file modified docker/web/nspanelmanager/firmware.bin
Binary file not shown.
Binary file modified docker/web/nspanelmanager/merged_flash.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion firmware/NSPanelManagerFirmware/include/nspm-bin-version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define NSPanelManagerFirmwareVersion "0.1.150"
#define NSPanelManagerFirmwareVersion "0.1.152"
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,13 @@ void MqttManager::_taskMqttRunTask(void *param) {

bool MqttManager::_connect() {
if (!MqttManager::_hasStarted) {
LOG_DEBUG("MQTT Manager has not yet started. Will not try to connect to MQTT Server.");
return false;
}

// Stop processing if not connected to WiFi
if (!WiFi.isConnected()) {
LOG_DEBUG("WiFi is not yet connected. Will not try to connect to MQTT Server.");
return false;
}

Expand Down Expand Up @@ -228,6 +230,7 @@ bool MqttManager::_connect() {
MqttManager::_mqttClient->setSocketTimeout(5); // Set tighter timeout. Default: 15 seconds.
Serial.println(NSPMConfig::instance->mqtt_server.c_str());
MqttManager::_mqttClient->setServer(NSPMConfig::instance->mqtt_server.c_str(), NSPMConfig::instance->mqtt_port);
LOG_DEBUG("Will try to connect to MQTT Server '", NSPMConfig::instance->mqtt_server.c_str(), "' as user '", NSPMConfig::instance->mqtt_username.c_str(), "' with password '", NSPMConfig::instance->mqtt_password.c_str(), "'.");
MqttManager::_mqttClient->connect(mqtt_device_name.c_str(), NSPMConfig::instance->mqtt_username.c_str(), NSPMConfig::instance->mqtt_password.c_str(), NSPMConfig::instance->mqtt_availability_topic.c_str(), 1, true, offline_message_buffer);
vTaskDelay(1000 / portTICK_PERIOD_MS);
if (MqttManager::connected()) {
Expand Down
Binary file modified firmware/NSPanelManagerFirmware/merged-flash.bin
Binary file not shown.
28 changes: 15 additions & 13 deletions firmware/NSPanelManagerFirmware/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,24 +259,26 @@ void taskManageWifiAndMqtt(void *param) {
Serial.println(config.wifi_ssid.c_str());
WiFi.begin(config.wifi_ssid.c_str(), config.wifi_psk.c_str());
vTaskDelay(2000 / portTICK_PERIOD_MS);
if (WiFi.isConnected()) {
Serial.println("Connected to WiFi!");
LOG_INFO("Connected to WiFi ", config.wifi_ssid.c_str());
Serial.print("Connected to WiFi ");
Serial.println(config.wifi_ssid.c_str());
LOG_INFO("IP Address: ", WiFi.localIP().toString());
LOG_INFO("Netmask: ", WiFi.subnetMask().toString());
LOG_INFO("Gateway: ", WiFi.gatewayIP().toString());

// We successfully connected to WiFi. Init the rest of the components.
webMan.init(NSPanelManagerFirmwareVersion);
mqttManager.start();
} else {
if (!WiFi.isConnected()) {
LOG_ERROR("Failed to connect to WiFi. Will try again in 5 seconds");
Serial.println("Failed to connect to WiFi. Will try again in 5 seconds");
vTaskDelay(5000 / portTICK_PERIOD_MS);
}
}

if (WiFi.isConnected()) {
Serial.println("Connected to WiFi!");
LOG_INFO("Connected to WiFi ", config.wifi_ssid.c_str());
Serial.print("Connected to WiFi ");
Serial.println(config.wifi_ssid.c_str());
LOG_INFO("IP Address: ", WiFi.localIP().toString());
LOG_INFO("Netmask: ", WiFi.subnetMask().toString());
LOG_INFO("Gateway: ", WiFi.gatewayIP().toString());

// We successfully connected to WiFi. Init the rest of the components.
webMan.init(NSPanelManagerFirmwareVersion);
mqttManager.start();
}
} else if (!config.wifi_ssid.empty() && !WiFi.isConnected() && millis() - lastWiFiconnected >= 180 * 1000) {
// Three minutes or more has passed since last successfull WiFi connection. Start the AP by breaking the loop.
startAndManageWiFiAccessPoint();
Expand Down

0 comments on commit a31ebe0

Please sign in to comment.