Skip to content

Commit

Permalink
Merge pull request #18 from peteh/feature/bssid
Browse files Browse the repository at this point in the history
Best ap connect and bssid view
  • Loading branch information
peteh authored Apr 3, 2024
2 parents 0458666 + 7d09678 commit 10e09e8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# doorman

Doorman is an ESP8266 based mqtt bridge for TCS door control systems (<https://www.tcsag.de/>).
Doorman is an ESP32 or ESP8266 based mqtt bridge for TCS door control systems (<https://www.tcsag.de/>).

![doorman opener](doc/doorman.gif)

Expand Down
15 changes: 13 additions & 2 deletions doorman/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ bool g_wifiConnected = false;
bool g_mqttConnected = false;
unsigned long g_lastWifiConnect = 0;

String g_bssid = "";
// TODO: wifi auto config
// TODO: publish persistant

Expand Down Expand Up @@ -393,7 +394,7 @@ void callback(char *topic, byte *payload, unsigned int length)
g_config.mqttDisconnectCounter = 0;
g_config.wifiDisconnectCounter = 0;
saveSettings(g_config);
g_mqttView.publishDiagnostics(g_config);
g_mqttView.publishDiagnostics(g_config, g_bssid.c_str());
}

// publish config when homeassistant comes online and needs the configuration again
Expand Down Expand Up @@ -451,8 +452,15 @@ void setup()

WiFi.setHostname(composeClientID().c_str());
WiFi.mode(WIFI_STA);
#ifdef ESP32
// select the AP with the strongest signal
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL);
#endif

WiFi.begin(wifi_ssid, wifi_pass);


log_info("Connecting to wifi...");
// TODO: really forever? What if we want to go back to autoconnect?
while (!connectToWifi())
Expand All @@ -467,6 +475,8 @@ void setup()

log_info("Connected to SSID: %s", wifi_ssid);
log_info("IP address: %s", WiFi.localIP().toString().c_str());
g_bssid = WiFi.BSSIDstr();

char configUrl[256];
snprintf(configUrl, sizeof(configUrl), "http://%s/", WiFi.localIP().toString().c_str());
g_mqttView.getDevice().setConfigurationUrl(configUrl);
Expand Down Expand Up @@ -583,7 +593,8 @@ void loop()
if (!g_mqttConnected)
{
// now we are successfully reconnected and publish our counters
g_mqttView.publishDiagnostics(g_config);
g_bssid = WiFi.BSSIDstr();
g_mqttView.publishDiagnostics(g_config, g_bssid.c_str());
}
g_mqttConnected = true;

Expand Down
14 changes: 11 additions & 3 deletions doorman/src/mqttview.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class MqttView
m_diagnosticsResetButton(&m_device, "diagnostics_reset_btn", "Reset Counters"),
m_diagnosticsRestartCounter(&m_device, "diagnostics_restart_counter", "Restart Counter"),
m_diagnosticsWifiDisconnectCounter(&m_device, "diagnostics_wifidisconnect_counter", "WiFi Disconnect Counter"),
m_diagnosticsMqttDisconnectCounter(&m_device, "diagnostics_mqttdisconnect_counter", "MQTT Disconnect Counter")
m_diagnosticsMqttDisconnectCounter(&m_device, "diagnostics_mqttdisconnect_counter", "MQTT Disconnect Counter"),
m_diagnosticsBssid(&m_device, "diagnostics_bssid", "BSSID")
{

m_device.setSWVersion(VERSION);
Expand Down Expand Up @@ -107,6 +108,9 @@ class MqttView
m_diagnosticsWifiDisconnectCounter.setEntityType(EntityCategory::DIAGNOSTIC);
m_diagnosticsWifiDisconnectCounter.setStateClass(MqttSensor::StateClass::TOTAL);
m_diagnosticsWifiDisconnectCounter.setIcon("mdi:counter");

m_diagnosticsBssid.setEntityType(EntityCategory::DIAGNOSTIC);
m_diagnosticsBssid.setIcon("mdi:wifi");
}

MqttDevice &getDevice()
Expand Down Expand Up @@ -251,6 +255,7 @@ class MqttView
publishConfig(m_diagnosticsRestartCounter);
publishConfig(m_diagnosticsWifiDisconnectCounter);
publishConfig(m_diagnosticsMqttDisconnectCounter);
publishConfig(m_diagnosticsBssid);

delay(1000);

Expand All @@ -266,7 +271,7 @@ class MqttView

publishConfigValues(config);

publishDiagnostics(config);
publishDiagnostics(config, "");
}

void publishConfigValues(Config &config)
Expand All @@ -280,11 +285,12 @@ class MqttView
publishMqttConfigState(m_configCodePartyMode, config.codePartyMode);
}

void publishDiagnostics(Config &g_config)
void publishDiagnostics(Config &g_config, const char* bssid)
{
publishMqttCounterState(m_diagnosticsRestartCounter, g_config.restartCounter);
publishMqttCounterState(m_diagnosticsWifiDisconnectCounter, g_config.wifiDisconnectCounter);
publishMqttCounterState(m_diagnosticsMqttDisconnectCounter, g_config.mqttDisconnectCounter);
publishMqttState(m_diagnosticsBssid, bssid);
}

void publishPartyMode(bool partyMode)
Expand Down Expand Up @@ -356,6 +362,8 @@ class MqttView
MqttSensor m_diagnosticsRestartCounter;
MqttSensor m_diagnosticsWifiDisconnectCounter;
MqttSensor m_diagnosticsMqttDisconnectCounter;
MqttSensor m_diagnosticsBssid;


void publishConfig(MqttEntity &entity)
{
Expand Down
2 changes: 1 addition & 1 deletion doorman/src/platform.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <Arduino.h>

#define VERSION "2024.1.2"
#define VERSION "2024.4.0"

#ifdef ESP8266
#define PIN_BUS_READ D5
Expand Down

0 comments on commit 10e09e8

Please sign in to comment.