Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/net_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ NetManagerTask::NetManagerTask(LcdTask &lcd, LedManagerTask &led, TimeManager &t
_apClients(0),
_state(NetState::Starting),
_ipaddress(""),
_macaddress(""),
_clientDisconnects(0),
_clientRetry(false),
_clientRetryTime(0),
Expand Down Expand Up @@ -118,6 +119,7 @@ void NetManagerTask::wifiStartAccessPoint()
char tmpStr[40];
sprintf(tmpStr, "%d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3]);
_ipaddress = tmpStr;
_macaddress = WiFi.macAddress();

DEBUG.printf("AP IP Address: %s\n", tmpStr);
DEBUG.printf("Channel: %d\n", WiFi.channel());
Expand Down Expand Up @@ -187,6 +189,7 @@ void NetManagerTask::haveNetworkConnection(IPAddress myAddress)
char tmpStr[40];
sprintf(tmpStr, "%d.%d.%d.%d", myAddress[0], myAddress[1], myAddress[2], myAddress[3]);
_ipaddress = tmpStr;
_macaddress = WiFi.macAddress();

DEBUG.print("Connected, IP: ");
DEBUG.println(tmpStr);
Expand All @@ -210,11 +213,13 @@ void NetManagerTask::wifiOnStationModeConnected(const WiFiEventStationModeConnec
void NetManagerTask::wifiOnStationModeGotIP(const WiFiEventStationModeGotIP &event)
{
haveNetworkConnection(WiFi.localIP());
_macaddress = WiFi.macAddress();
StaticJsonDocument<128> doc;
doc["wifi_client_connected"] = (int)net.isWifiClientConnected();
doc["eth_connected"] = (int)net.isWiredConnected();
doc["net_connected"] = (int)net.isWifiClientConnected();
doc["ipaddress"] = net.getIp();
doc["macaddress"] = net.getMac();
event_send(doc);

// Clear any error state
Expand Down Expand Up @@ -467,6 +472,7 @@ void NetManagerTask::onNetEvent(WiFiEvent_t event, arduino_event_info_t &info)
DBUG(ETH.linkSpeed());
DBUGLN("Mbps");
haveNetworkConnection(ETH.localIP());
_macaddress = ETH.macAddress();
_ethConnected = true;
wifiStop();
break;
Expand Down
4 changes: 4 additions & 0 deletions src/net_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class NetManagerTask : public MicroTasks::Task
// Network state
NetState _state;
String _ipaddress;
String _macaddress;

DNSServer _dnsServer; // Create class DNS server, captive portal re-direct
bool _dnsServerStarted;
Expand Down Expand Up @@ -214,6 +215,9 @@ class NetManagerTask : public MicroTasks::Task
String getIp() {
return _ipaddress;
}
String getMac() {
return _macaddress;
}
};

extern NetManagerTask net;
Expand Down
1 change: 1 addition & 0 deletions src/web_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ void buildStatus(DynamicJsonDocument &doc) {
doc["eth_connected"] = (int)net.isWiredConnected();
doc["net_connected"] = (int)net.isWifiClientConnected();
doc["ipaddress"] = net.getIp();
doc["macaddress"] = net.getMac();

doc["emoncms_connected"] = (int)emoncms_connected;
doc["packets_sent"] = packets_sent;
Expand Down