Skip to content

Commit

Permalink
Swap RSSI to an accessor method instead of saving + format
Browse files Browse the repository at this point in the history
  • Loading branch information
tyeth committed Jun 14, 2024
1 parent 69953ce commit cd6498c
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 31 deletions.
9 changes: 5 additions & 4 deletions src/Wippersnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,12 @@ void Wippersnapper::getMacAddr() {
/****************************************************************************/
/*!
@brief Gets the network's RSSI.
@return int32_t RSSI value
*/
/****************************************************************************/
void Wippersnapper::getRSSI() {
int32_t Wippersnapper::getRSSI() {
WS_DEBUG_PRINTLN("ERROR: Please define a network interface!");
return 0;
}

/****************************************************************************/
Expand Down Expand Up @@ -2401,7 +2403,7 @@ void Wippersnapper::runNetFSM() {
WS_LED_STATUS_WIFI_CONNECTING);
}
WS_DEBUG_PRINT("SSID found! RSSI: ");
WS_DEBUG_PRINTLN(WS._RSSI);
WS_DEBUG_PRINTLN(WS.getRSSI());
// Attempt to connect to wireless network
maxAttempts = 5;
while (maxAttempts > 0) {
Expand Down Expand Up @@ -2567,9 +2569,8 @@ void Wippersnapper::pingBroker() {
runNetFSM();
}
_prv_ping = millis();
getRSSI(); // update RSSI
WS_DEBUG_PRINT("WiFi RSSI: ");
WS_DEBUG_PRINTLN(WS._RSSI);
WS_DEBUG_PRINTLN(WS.getRSSI());
}
// blink status LED every STATUS_LED_KAT_BLINK_TIME millis
if (millis() > (_prvKATBlink + STATUS_LED_KAT_BLINK_TIME)) {
Expand Down
3 changes: 1 addition & 2 deletions src/Wippersnapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class Wippersnapper {
void disconnect();

virtual void getMacAddr();
virtual void getRSSI();
virtual int32_t getRSSI();
virtual void setupMQTTClient(const char *clientID);

virtual ws_status_t networkStatus();
Expand Down Expand Up @@ -362,7 +362,6 @@ class Wippersnapper {
ws_uart *_uartComponent; ///< Instance of UART class

// TODO: does this really need to be global?
int32_t _RSSI = 0; ///< RSSI value of the network connection
uint8_t _macAddr[6]; /*!< Unique network iface identifier */
char sUID[13]; /*!< Unique network iface identifier */
const char *_boardId; /*!< Adafruit IO+ board string */
Expand Down
7 changes: 2 additions & 5 deletions src/network_interfaces/Wippersnapper_AIRLIFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class Wippersnapper_AIRLIFT : public Wippersnapper {
// Was the network within secrets.json found?
for (int i = 0; i < n; ++i) {
if (strcmp(_ssid, WiFi.SSID(i)) == 0) {
WS._RSSI = WiFi.RSSI(i);
return true;
}
}
Expand Down Expand Up @@ -225,12 +224,10 @@ class Wippersnapper_AIRLIFT : public Wippersnapper {
/********************************************************/
/*!
@brief Gets the current network RSSI value
@return int32_t RSSI value
*/
/********************************************************/
void getRSSI() {
// test if this fails when disconnected or returns something sensible
WS._RSSI = WiFi.RSSI();
}
int32_t getRSSI() { return WiFi.RSSI(); }

/********************************************************/
/*!
Expand Down
7 changes: 2 additions & 5 deletions src/network_interfaces/Wippersnapper_ESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ class Wippersnapper_ESP32 : public Wippersnapper {
// Was the network within secrets.json found?
for (int i = 0; i < n; ++i) {
if (strcmp(_ssid, WiFi.SSID(i).c_str()) == 0) {
WS._RSSI = WiFi.RSSI(i);
return true;
}
}
Expand Down Expand Up @@ -143,12 +142,10 @@ class Wippersnapper_ESP32 : public Wippersnapper {
/********************************************************/
/*!
@brief Gets the current network RSSI value
@return int32_t RSSI value
*/
/********************************************************/
void getRSSI() {
// test if this fails when disconnected or returns something sensible
WS._RSSI = WiFi.RSSI();
}
int32_t getRSSI() { return WiFi.RSSI(); }

/********************************************************/
/*!
Expand Down
7 changes: 2 additions & 5 deletions src/network_interfaces/Wippersnapper_ESP8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ class Wippersnapper_ESP8266 : public Wippersnapper {
// Was the network within secrets.json found?
for (int i = 0; i < n; ++i) {
if (strcmp(_ssid, WiFi.SSID(i).c_str()) == 0) {
WS._RSSI = WiFi.RSSI(i);
return true;
}
}
Expand Down Expand Up @@ -166,12 +165,10 @@ class Wippersnapper_ESP8266 : public Wippersnapper {
/********************************************************/
/*!
@brief Gets the current network RSSI value
@return int32_t RSSI value
*/
/********************************************************/
void getRSSI() {
// test if this fails when disconnected or returns something sensible
WS._RSSI = WiFi.RSSI();
}
int32_t getRSSI() { return WiFi.RSSI(); }

/*******************************************************************/
/*!
Expand Down
7 changes: 2 additions & 5 deletions src/network_interfaces/Wippersnapper_WIFININA.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ class Wippersnapper_WIFININA : public Wippersnapper {
// Was the network within secrets.json found?
for (int i = 0; i < n; ++i) {
if (strcmp(_ssid, WiFi.SSID(i)) == 0) {
WS._RSSI = WiFi.RSSI(i);
return true;
}
}
Expand Down Expand Up @@ -190,12 +189,10 @@ class Wippersnapper_WIFININA : public Wippersnapper {
/********************************************************/
/*!
@brief Gets the current network RSSI value
@return int32_t RSSI value
*/
/********************************************************/
void getRSSI() {
// test if this fails when disconnected or returns something sensible
WS._RSSI = WiFi.RSSI();
}
int32_t getRSSI() { return WiFi.RSSI(); }

/********************************************************/
/*!
Expand Down
7 changes: 2 additions & 5 deletions src/network_interfaces/ws_networking_pico.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ class ws_networking_pico : public Wippersnapper {
// Was the network within secrets.json found?
for (int i = 0; i < n; ++i) {
if (strcmp(_ssid, WiFi.SSID(i)) == 0) {
WS._RSSI = WiFi.RSSI(i);
return true;
}
}
Expand Down Expand Up @@ -142,12 +141,10 @@ class ws_networking_pico : public Wippersnapper {
/********************************************************/
/*!
@brief Gets the current network RSSI value
@return int32_t RSSI value
*/
/********************************************************/
void getRSSI() {
// test if this fails when disconnected or returns something sensible
WS._RSSI = WiFi.RSSI();
}
int32_t getRSSI() { return WiFi.RSSI(); }

/********************************************************/
/*!
Expand Down

0 comments on commit cd6498c

Please sign in to comment.