@@ -92,6 +92,7 @@ const uint32_t WiFiFastResponseTimeoutMillis = 20; // SPI timeout when when the
9292const uint32_t WiFiWaitReadyMillis = 100 ;
9393const uint32_t WiFiStartupMillis = 15000 ; // Formatting the SPIFFS partition can take up to 10s.
9494const uint32_t WiFiStableMillis = 100 ;
95+ const uint32_t WiFiStatusPollMillis = 500 ; // Poll interval for status details of the WiFi module
9596
9697const unsigned int MaxHttpConnections = 4 ;
9798
@@ -287,7 +288,7 @@ WiFiInterface::WiFiInterface(Platform& p) noexcept
287288 : platform(p), bufferOut(nullptr ), bufferIn(nullptr ), uploader(nullptr ), espWaitingTask(nullptr ),
288289 ftpDataPort(0 ), closeDataPort(false ),
289290 requestedMode(WiFiState::disabled), currentMode(WiFiState::disabled), activated(false ),
290- espStatusChanged(false ), spiTxUnderruns(0 ), spiRxOverruns(0 ), serialRunning(false ), debugMessageChars(0 )
291+ espStatusChanged(false ), rssi(INT8_MIN), spiTxUnderruns(0 ), spiRxOverruns(0 ), serialRunning(false ), debugMessageChars(0 )
291292{
292293 wifiInterface = this ;
293294
@@ -326,16 +327,18 @@ WiFiInterface::WiFiInterface(Platform& p) noexcept
326327constexpr ObjectModelTableEntry WiFiInterface::objectModelTable[] =
327328{
328329 // These entries must be in alphabetical order
329- { " actualIP" , OBJECT_MODEL_FUNC (self->ipAddress ), ObjectModelEntryFlags::none },
330- { " firmwareVersion" , OBJECT_MODEL_FUNC (self->wiFiServerVersion ), ObjectModelEntryFlags::none },
331- { " gateway" , OBJECT_MODEL_FUNC (self->gateway ), ObjectModelEntryFlags::none },
332- { " mac" , OBJECT_MODEL_FUNC (self->macAddress ), ObjectModelEntryFlags::none },
333- { " state" , OBJECT_MODEL_FUNC (self->GetStateName ()), ObjectModelEntryFlags::none },
334- { " subnet" , OBJECT_MODEL_FUNC (self->netmask ), ObjectModelEntryFlags::none },
335- { " type" , OBJECT_MODEL_FUNC_NOSELF (" wifi" ), ObjectModelEntryFlags::none },
330+ { " actualIP" , OBJECT_MODEL_FUNC (self->ipAddress ), ObjectModelEntryFlags::none },
331+ { " firmwareVersion" , OBJECT_MODEL_FUNC (self->wiFiServerVersion ), ObjectModelEntryFlags::none },
332+ { " gateway" , OBJECT_MODEL_FUNC (self->gateway ), ObjectModelEntryFlags::none },
333+ { " mac" , OBJECT_MODEL_FUNC (self->macAddress ), ObjectModelEntryFlags::none },
334+ { " numReconnects" , OBJECT_MODEL_FUNC ((uint32_t )self->reconnectCount ), ObjectModelEntryFlags::none },
335+ { " signal" , OBJECT_MODEL_FUNC ((int32_t )self->rssi ), ObjectModelEntryFlags::none },
336+ { " state" , OBJECT_MODEL_FUNC (self->GetStateName ()), ObjectModelEntryFlags::none },
337+ { " subnet" , OBJECT_MODEL_FUNC (self->netmask ), ObjectModelEntryFlags::none },
338+ { " type" , OBJECT_MODEL_FUNC_NOSELF (" wifi" ), ObjectModelEntryFlags::none },
336339};
337340
338- constexpr uint8_t WiFiInterface::objectModelTableDescriptor[] = { 1 , 7 };
341+ constexpr uint8_t WiFiInterface::objectModelTableDescriptor[] = { 1 , 9 };
339342
340343DEFINE_GET_OBJECT_MODEL_TABLE (WiFiInterface)
341344
@@ -717,7 +720,6 @@ void WiFiInterface::Spin() noexcept
717720 if (rc > 0 )
718721 {
719722 SafeStrncpy (wiFiServerVersion, status.Value ().versionText , ARRAY_SIZE (wiFiServerVersion));
720- macAddress.SetFromBytes (status.Value ().macAddress );
721723
722724 // Set the hostname before anything else is done
723725 rc = SendCommand (NetworkCommand::networkSetHostName, 0 , 0 , 0 , reprap.GetNetwork ().GetHostname (), HostNameLength, nullptr , 0 );
@@ -846,6 +848,19 @@ void WiFiInterface::Spin() noexcept
846848 }
847849 }
848850 }
851+
852+ // Update details that change constantly about the WiFi module
853+ if (millis () - lastStatusPoll >= WiFiStatusPollMillis)
854+ {
855+ Receiver<NetworkStatusResponse> status;
856+ const uint32_t rc = SendCommand (NetworkCommand::networkGetStatus, 0 , 0 , nullptr , 0 , status);
857+ rssi = status.Value ().rssi ;
858+ if (rc > offsetof (NetworkStatusResponse, netmask))
859+ {
860+ reconnectCount = status.Value ().numReconnects ;
861+ }
862+ lastStatusPoll = millis ();
863+ }
849864 }
850865 break ;
851866
@@ -867,19 +882,41 @@ void WiFiInterface::Spin() noexcept
867882 {
868883 // Get our IP address, this needs to be correct for FTP to work
869884 Receiver<NetworkStatusResponse> status;
870- if (SendCommand (NetworkCommand::networkGetStatus, 0 , 0 , nullptr , 0 , status) > 0 )
885+ const uint32_t rc = SendCommand (NetworkCommand::networkGetStatus, 0 , 0 , nullptr , 0 , status);
886+ if (rc > 0 )
871887 {
872888 ipAddress.SetV4LittleEndian (status.Value ().ipAddress );
889+ macAddress.SetFromBytes (status.Value ().macAddress ); // MAC address for AP and STA are separate and different
873890 SafeStrncpy (actualSsid, status.Value ().ssid , SsidLength);
891+
892+ if (rc > offsetof (NetworkStatusResponse, netmask))
893+ {
894+ netmask.SetV4LittleEndian (status.Value ().netmask );
895+ gateway.SetV4LittleEndian (status.Value ().gateway );
896+ usingDhcp = status.Value ().usingDhcpc ;
897+ }
874898 }
875899 InitSockets ();
876900 reconnectCount = 0 ;
877901 platform.MessageF (NetworkInfoMessage, " WiFi module is %s%s, IP address %s\n " ,
878902 TranslateWiFiState (currentMode),
879903 actualSsid,
880904 IP4String (ipAddress).c_str ());
905+
906+ lastStatusPoll = 0 ;
881907 }
882908 break ;
909+ case WiFiState::idle:
910+ {
911+ uint8_t zero[6 ];
912+ memset (zero, 0 , sizeof (zero));
913+ macAddress.SetFromBytes (zero);
914+ SetIPAddress (DefaultIpAddress, DefaultNetMask, DefaultGateway);
915+ strcpy (actualSsid, " (unknown)" );
916+ reconnectCount = 0 ;
917+ rssi = INT8_MIN;
918+ usingDhcp = false ;
919+ }
883920
884921 default :
885922 if (requestedMode != WiFiState::connected)
@@ -969,7 +1006,8 @@ void WiFiInterface::Diagnostics(MessageType mtype) noexcept
9691006 {
9701007 Receiver<NetworkStatusResponse> status;
9711008 status.Value ().clockReg = 0xFFFFFFFF ; // older WiFi firmware doesn't return this value, so preset it
972- if (SendCommand (NetworkCommand::networkGetStatus, 0 , 0 , nullptr , 0 , status) > 0 )
1009+ const uint32_t rc = SendCommand (NetworkCommand::networkGetStatus, 0 , 0 , nullptr , 0 , status);
1010+ if (rc > 0 )
9731011 {
9741012 NetworkStatusResponse& r = status.Value ();
9751013 r.versionText [ARRAY_UPB (r.versionText )] = 0 ;
@@ -979,19 +1017,51 @@ void WiFiInterface::Diagnostics(MessageType mtype) noexcept
9791017 platform.MessageF (mtype, " WiFi Vcc %.2f, reset reason %s\n " , (double )((float )r.vcc /1024 ), TranslateEspResetReason (r.resetReason ));
9801018 platform.MessageF (mtype, " WiFi flash size %" PRIu32 " , free heap %" PRIu32 " \n " , r.flashSize , r.freeHeap );
9811019
1020+ platform.MessageF (mtype, " rc size: %lu offset: %u\n " , rc, offsetof (NetworkStatusResponse, netmask));
1021+
9821022 if (currentMode == WiFiState::connected || currentMode == WiFiState::runningAsAccessPoint)
9831023 {
984- platform.MessageF (mtype, " WiFi IP address %s\n " , IP4String (r.ipAddress ).c_str ());
1024+ if (rc > offsetof (NetworkStatusResponse, netmask))
1025+ {
1026+ platform.MessageF (mtype, " WiFi IP address %s, netmask %s, gateway %s%s\n " ,
1027+ IP4String (r.ipAddress ).c_str (), IP4String (r.netmask ).c_str (), IP4String (r.gateway ).c_str (),
1028+ currentMode == WiFiState::connected ? (r.usingDhcpc ? " (via DHCP)" : " (set manually)" ) : " " );
1029+ }
1030+ else
1031+ {
1032+ platform.MessageF (mtype, " WiFi IP address %s\n " , IP4String (r.ipAddress ).c_str ());
1033+ }
9851034 }
9861035
1036+ constexpr const char * SleepModes[4 ] = { " unknown" , " none" , " light" , " modem" };
1037+ constexpr const char * ConnectionModes[4 ] = { " none" , " 802.11b" , " 802.11g" , " 802.11n" };
1038+
9871039 if (currentMode == WiFiState::connected)
9881040 {
989- constexpr const char * SleepModes[4 ] = { " unknown" , " none" , " light" , " modem" };
990- constexpr const char * ConnectionModes[4 ] = { " none" , " 802.11b" , " 802.11g" , " 802.11n" };
991- platform.MessageF (mtype, " WiFi signal strength %ddBm, mode %s, reconnections %u, sleep mode %s\n " , (int )r.rssi , ConnectionModes[r.phyMode ], reconnectCount, SleepModes[r.sleepMode ]);
1041+ if (rc > offsetof (NetworkStatusResponse, netmask))
1042+ {
1043+ platform.MessageF (mtype, " WiFi signal strength %ddBm, mode %s, reconnections %u, sleep mode %s, channel %u (%s), auth %s\n " ,
1044+ (int )r.rssi , ConnectionModes[r.phyMode ], reconnectCount, SleepModes[r.sleepMode ],
1045+ r.channel , static_cast <HTMode>(r.ht ) == HTMode::HT20 ? " 20 MHz" : " 40 MHz" , GetWiFiAuthFriendlyStr (r.auth ));
1046+ }
1047+ else
1048+ {
1049+ platform.MessageF (mtype, " WiFi signal strength %ddBm, mode %s, reconnections %u, sleep mode %s\n " , (int )r.rssi , ConnectionModes[r.phyMode ], reconnectCount, SleepModes[r.sleepMode ]);
1050+ }
9921051 }
9931052 else if (currentMode == WiFiState::runningAsAccessPoint)
9941053 {
1054+ if (rc > offsetof (NetworkStatusResponse, netmask))
1055+ {
1056+ platform.MessageF (mtype, " WiFi mode %s, sleep mode %s, channel %u (%s), auth %s\n " ,
1057+ ConnectionModes[r.phyMode ], SleepModes[r.sleepMode ], r.channel ,
1058+ static_cast <HTMode>(r.ht ) == HTMode::HT20 ? " 20 MHz" : " 40 MHz" , GetWiFiAuthFriendlyStr (r.auth ));
1059+ }
1060+ else
1061+ {
1062+ platform.MessageF (mtype, " WiFi mode %s, sleep mode %s\n " , ConnectionModes[r.phyMode ], SleepModes[r.sleepMode ]);
1063+ }
1064+
9951065 platform.MessageF (mtype, " Connected clients %u\n " , (unsigned int )r.numClients );
9961066 }
9971067 // status, ssid and hostName not displayed
@@ -1105,7 +1175,7 @@ void WiFiInterface::EspRequestsTransfer() noexcept
11051175void WiFiInterface::SetIPAddress (IPAddress p_ip, IPAddress p_netmask, IPAddress p_gateway) noexcept
11061176{
11071177 ipAddress = p_ip;
1108- usingDhcp = ipAddress. IsNull ();
1178+ usingDhcp = false ; // Mirror the value returned by the ESP module
11091179 netmask = p_netmask;
11101180 gateway = p_gateway;
11111181}
0 commit comments