Browse Source

Adding support for cyclic RSSI via MQTT and log

master
Torsten Stauder 4 years ago
parent
commit
ac31a8b243
  1. 12
      src/Mqtt.cpp
  2. 12
      src/Wlan.cpp
  3. 2
      src/main.cpp
  4. 1
      src/settings.h

12
src/Mqtt.cpp

@ -35,6 +35,7 @@ static bool Mqtt_Enabled = true;
static void Mqtt_ClientCallback(const char *topic, const byte *payload, uint32_t length);
static bool Mqtt_Reconnect(void);
static void Mqtt_PostHeartbeatViaMqtt(void);
static void Mqtt_PostWiFiRssi(void);
void Mqtt_Init() {
#ifdef MQTT_ENABLE
@ -114,6 +115,7 @@ void Mqtt_Cyclic(void) {
Mqtt_Reconnect();
Mqtt_PubSubClient.loop();
Mqtt_PostHeartbeatViaMqtt();
Mqtt_PostWiFiRssi();
}
#endif
}
@ -175,6 +177,16 @@ bool publishMqtt(const char *topic, uint32_t payload, bool retained) {
#endif
}
// Cyclic posting of WiFi-signal-strength
void Mqtt_PostWiFiRssi(void) {
static uint32_t lastMqttRssiTimestamp = 0;
if (!lastMqttRssiTimestamp || (millis() - lastMqttRssiTimestamp >= 60000)) {
lastMqttRssiTimestamp = millis();
publishMqtt((char *) FPSTR(topicWiFiRssiState), Wlan_GetRssi(), false);
}
}
/* Cyclic posting via MQTT that ESP is still alive. Use case: when ESPuino is switched off, it will post via
MQTT it's gonna be offline now. But when unplugging ESPuino e.g. openHAB doesn't know ESPuino is offline.
One way to recognize this is to determine, when a topic has been updated for the last time. So by

12
src/Wlan.cpp

@ -24,6 +24,10 @@ bool accessPointStarted = false;
void accessPointStart(const char *SSID, IPAddress ip, IPAddress netmask);
bool getWifiEnableStatusFromNVS(void);
void writeWifiStatusToNVS(bool wifiStatus);
bool Wlan_IsConnected(void);
int8_t Wlan_GetRssi(void);
uint32_t lastPrintRssiTimestamp = 0;
void Wlan_Init(void) {
wifiEnabled = getWifiEnableStatusFromNVS();
@ -104,6 +108,14 @@ void Wlan_Cyclic(void) {
wifiNeedsRestart = false;
}
if (Wlan_IsConnected()) {
if (millis() - lastPrintRssiTimestamp >= 60000) {
lastPrintRssiTimestamp = millis();
snprintf(Log_Buffer, Log_BufferLength, "RSSI: %d dBm", Wlan_GetRssi());
Log_Println(Log_Buffer, LOGLEVEL_DEBUG);
}
}
}
void Wlan_ToggleEnable(void) {

2
src/main.cpp

@ -184,7 +184,7 @@ void setup() {
Serial.println(F(" | |___ ___) | | __/ | |_| | | | | | | | | (_) |"));
Serial.println(F(" |_____| |____/ |_| \\__,_| |_| |_| |_| \\___/ "));
Serial.println(F(" Rfid-controlled musicplayer\n"));
Serial.println(F(" Rev 20210708-2\n"));
Serial.println(F(" Rev 20210708-3\n"));
// print wake-up reason
printWakeUpReason();

1
src/settings.h

@ -213,6 +213,7 @@
constexpr const char topicRepeatModeState[] PROGMEM = "State/ESPuino/RepeatMode";
constexpr const char topicLedBrightnessCmnd[] PROGMEM = "Cmnd/ESPuino/LedBrightness";
constexpr const char topicLedBrightnessState[] PROGMEM = "State/ESPuino/LedBrightness";
constexpr const char topicWiFiRssiState[] PROGMEM = "State/ESPuino/WifiRssi";
#ifdef MEASURE_BATTERY_VOLTAGE
constexpr const char topicBatteryVoltage[] PROGMEM = "State/ESPuino/Voltage";
#endif

Loading…
Cancel
Save