@@ -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,22 @@ 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+ if (rc > 0 )
858+ {
859+ rssi = status.Value ().rssi ;
860+ if (rc >= offsetof (NetworkStatusResponse, netmask))
861+ {
862+ reconnectCount = status.Value ().numReconnects ;
863+ }
864+ }
865+ lastStatusPoll = millis ();
866+ }
849867 }
850868 break ;
851869
@@ -867,19 +885,41 @@ void WiFiInterface::Spin() noexcept
867885 {
868886 // Get our IP address, this needs to be correct for FTP to work
869887 Receiver<NetworkStatusResponse> status;
870- if (SendCommand (NetworkCommand::networkGetStatus, 0 , 0 , nullptr , 0 , status) > 0 )
888+ const uint32_t rc = SendCommand (NetworkCommand::networkGetStatus, 0 , 0 , nullptr , 0 , status);
889+ if (rc > 0 )
871890 {
872891 ipAddress.SetV4LittleEndian (status.Value ().ipAddress );
892+ macAddress.SetFromBytes (status.Value ().macAddress ); // MAC address for AP and STA are separate and different
873893 SafeStrncpy (actualSsid, status.Value ().ssid , SsidLength);
894+
895+ if (rc > offsetof (NetworkStatusResponse, netmask))
896+ {
897+ netmask.SetV4LittleEndian (status.Value ().netmask );
898+ gateway.SetV4LittleEndian (status.Value ().gateway );
899+ usingDhcp = status.Value ().usingDhcpc ;
900+ }
874901 }
875902 InitSockets ();
876903 reconnectCount = 0 ;
877904 platform.MessageF (NetworkInfoMessage, " WiFi module is %s%s, IP address %s\n " ,
878905 TranslateWiFiState (currentMode),
879906 actualSsid,
880907 IP4String (ipAddress).c_str ());
908+
909+ lastStatusPoll = 0 ;
881910 }
882911 break ;
912+ case WiFiState::idle:
913+ {
914+ uint8_t zero[6 ];
915+ memset (zero, 0 , sizeof (zero));
916+ macAddress.SetFromBytes (zero);
917+ SetIPAddress (DefaultIpAddress, DefaultNetMask, DefaultGateway);
918+ strcpy (actualSsid, " (unknown)" );
919+ reconnectCount = 0 ;
920+ rssi = INT8_MIN;
921+ usingDhcp = false ;
922+ }
883923
884924 default :
885925 if (requestedMode != WiFiState::connected)
@@ -969,7 +1009,8 @@ void WiFiInterface::Diagnostics(MessageType mtype) noexcept
9691009 {
9701010 Receiver<NetworkStatusResponse> status;
9711011 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 )
1012+ const uint32_t rc = SendCommand (NetworkCommand::networkGetStatus, 0 , 0 , nullptr , 0 , status);
1013+ if (rc > 0 )
9731014 {
9741015 NetworkStatusResponse& r = status.Value ();
9751016 r.versionText [ARRAY_UPB (r.versionText )] = 0 ;
@@ -981,17 +1022,47 @@ void WiFiInterface::Diagnostics(MessageType mtype) noexcept
9811022
9821023 if (currentMode == WiFiState::connected || currentMode == WiFiState::runningAsAccessPoint)
9831024 {
984- platform.MessageF (mtype, " WiFi IP address %s\n " , IP4String (r.ipAddress ).c_str ());
1025+ if (rc > offsetof (NetworkStatusResponse, netmask))
1026+ {
1027+ platform.MessageF (mtype, " WiFi IP address %s, netmask %s, gateway %s%s\n " ,
1028+ IP4String (r.ipAddress ).c_str (), IP4String (r.netmask ).c_str (), IP4String (r.gateway ).c_str (),
1029+ currentMode == WiFiState::connected ? (r.usingDhcpc ? " (via DHCP)" : " (set manually)" ) : " " );
1030+ }
1031+ else
1032+ {
1033+ platform.MessageF (mtype, " WiFi IP address %s\n " , IP4String (r.ipAddress ).c_str ());
1034+ }
9851035 }
9861036
1037+ constexpr const char * SleepModes[4 ] = { " unknown" , " none" , " light" , " modem" };
1038+ constexpr const char * ConnectionModes[4 ] = { " none" , " 802.11b" , " 802.11g" , " 802.11n" };
1039+
9871040 if (currentMode == WiFiState::connected)
9881041 {
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 ]);
1042+ if (rc > offsetof (NetworkStatusResponse, netmask))
1043+ {
1044+ platform.MessageF (mtype, " WiFi signal strength %ddBm, mode %s, reconnections %u, sleep mode %s, channel %u (%s), auth %s\n " ,
1045+ (int )r.rssi , ConnectionModes[r.phyMode ], reconnectCount, SleepModes[r.sleepMode ],
1046+ r.channel , static_cast <HTMode>(r.ht ) == HTMode::HT20 ? " 20 MHz" : " 40 MHz" , GetWiFiAuthFriendlyStr (r.auth ));
1047+ }
1048+ else
1049+ {
1050+ 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 ]);
1051+ }
9921052 }
9931053 else if (currentMode == WiFiState::runningAsAccessPoint)
9941054 {
1055+ if (rc > offsetof (NetworkStatusResponse, netmask))
1056+ {
1057+ platform.MessageF (mtype, " WiFi mode %s, sleep mode %s, channel %u (%s), auth %s\n " ,
1058+ ConnectionModes[r.phyMode ], SleepModes[r.sleepMode ], r.channel ,
1059+ static_cast <HTMode>(r.ht ) == HTMode::HT20 ? " 20 MHz" : " 40 MHz" , GetWiFiAuthFriendlyStr (r.auth ));
1060+ }
1061+ else
1062+ {
1063+ platform.MessageF (mtype, " WiFi mode %s, sleep mode %s\n " , ConnectionModes[r.phyMode ], SleepModes[r.sleepMode ]);
1064+ }
1065+
9951066 platform.MessageF (mtype, " Connected clients %u\n " , (unsigned int )r.numClients );
9961067 }
9971068 // status, ssid and hostName not displayed
@@ -1105,7 +1176,7 @@ void WiFiInterface::EspRequestsTransfer() noexcept
11051176void WiFiInterface::SetIPAddress (IPAddress p_ip, IPAddress p_netmask, IPAddress p_gateway) noexcept
11061177{
11071178 ipAddress = p_ip;
1108- usingDhcp = ipAddress. IsNull ();
1179+ usingDhcp = false ; // Mirror the value returned by the ESP module
11091180 netmask = p_netmask;
11101181 gateway = p_gateway;
11111182}
0 commit comments