publish wifi rssi
This commit is contained in:
@@ -39,4 +39,5 @@
|
|||||||
|
|
||||||
#define mqtt_topic_reset "/maintenance/reset"
|
#define mqtt_topic_reset "/maintenance/reset"
|
||||||
#define mqtt_topic_uptime "/maintenance/uptime"
|
#define mqtt_topic_uptime "/maintenance/uptime"
|
||||||
|
#define mqtt_topic_wifi_rssi "/maintenance/wifiRssi"
|
||||||
#define mqtt_topic_freeheap "/maintenance/freeHeap"
|
#define mqtt_topic_freeheap "/maintenance/freeHeap"
|
||||||
16
Network.cpp
16
Network.cpp
@@ -7,11 +7,19 @@
|
|||||||
|
|
||||||
Network* Network::_inst = nullptr;
|
Network* Network::_inst = nullptr;
|
||||||
|
|
||||||
Network::Network(const NetworkDeviceType networkDevice, Preferences *preferences)
|
Network::Network(const NetworkDeviceType networkDevice, Preferences *preferences, const String& maintenancePathPrefix)
|
||||||
: _preferences(preferences)
|
: _preferences(preferences)
|
||||||
{
|
{
|
||||||
_inst = this;
|
_inst = this;
|
||||||
_hostname = _preferences->getString(preference_hostname);
|
_hostname = _preferences->getString(preference_hostname);
|
||||||
|
|
||||||
|
memset(_maintenancePathPrefix, 0, sizeof(_maintenancePathPrefix));
|
||||||
|
|
||||||
|
size_t len = maintenancePathPrefix.length();
|
||||||
|
for(int i=0; i < len; i++)
|
||||||
|
{
|
||||||
|
_maintenancePathPrefix[i] = maintenancePathPrefix.charAt(i);
|
||||||
|
}
|
||||||
setupDevice(networkDevice);
|
setupDevice(networkDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,6 +155,12 @@ int Network::update()
|
|||||||
_presenceCsv = nullptr;
|
_presenceCsv = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(_device->signalStrength() != 127 && ts - _lastMaintenancePublish > 2000)
|
||||||
|
{
|
||||||
|
publishInt(_maintenancePathPrefix, mqtt_topic_wifi_rssi, _device->signalStrength());
|
||||||
|
_lastMaintenancePublish = ts;
|
||||||
|
}
|
||||||
|
|
||||||
_device->mqttClient()->loop();
|
_device->mqttClient()->loop();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ enum class NetworkDeviceType
|
|||||||
class Network
|
class Network
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Network(const NetworkDeviceType networkDevice, Preferences* preferences);
|
explicit Network(const NetworkDeviceType networkDevice, Preferences* preferences, const String& maintenancePathPrefix);
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
int update();
|
int update();
|
||||||
@@ -63,6 +63,7 @@ private:
|
|||||||
char _mqttUser[31] = {0};
|
char _mqttUser[31] = {0};
|
||||||
char _mqttPass[31] = {0};
|
char _mqttPass[31] = {0};
|
||||||
char _mqttPresencePrefix[181] = {0};
|
char _mqttPresencePrefix[181] = {0};
|
||||||
|
char _maintenancePathPrefix[181] = {0};
|
||||||
int _networkTimeout = 0;
|
int _networkTimeout = 0;
|
||||||
std::vector<MqttReceiver*> _mqttReceivers;
|
std::vector<MqttReceiver*> _mqttReceivers;
|
||||||
char* _presenceCsv = nullptr;
|
char* _presenceCsv = nullptr;
|
||||||
@@ -72,4 +73,5 @@ private:
|
|||||||
std::map<String, String> _initTopics;
|
std::map<String, String> _initTopics;
|
||||||
|
|
||||||
unsigned long _lastConnectedTs = 0;
|
unsigned long _lastConnectedTs = 0;
|
||||||
|
unsigned long _lastMaintenancePublish = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
3
main.cpp
3
main.cpp
@@ -173,7 +173,8 @@ void setup()
|
|||||||
// const NetworkDeviceType networkDevice = NetworkDeviceType::WiFi;
|
// const NetworkDeviceType networkDevice = NetworkDeviceType::WiFi;
|
||||||
const NetworkDeviceType networkDevice = digitalRead(NETWORK_SELECT) == HIGH ? NetworkDeviceType::WiFi : NetworkDeviceType::W5500;
|
const NetworkDeviceType networkDevice = digitalRead(NETWORK_SELECT) == HIGH ? NetworkDeviceType::WiFi : NetworkDeviceType::W5500;
|
||||||
|
|
||||||
network = new Network(networkDevice, preferences);
|
const String mqttLockPath = preferences->getString(preference_mqtt_lock_path);
|
||||||
|
network = new Network(networkDevice, preferences, mqttLockPath);
|
||||||
network->initialize();
|
network->initialize();
|
||||||
networkLock = new NetworkLock(network, preferences);
|
networkLock = new NetworkLock(network, preferences);
|
||||||
networkLock->initialize();
|
networkLock->initialize();
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public:
|
|||||||
virtual void update() = 0;
|
virtual void update() = 0;
|
||||||
|
|
||||||
virtual bool isConnected() = 0;
|
virtual bool isConnected() = 0;
|
||||||
|
virtual int8_t signalStrength() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const uint16_t _mqttMaxBufferSize = 6144;
|
const uint16_t _mqttMaxBufferSize = 6144;
|
||||||
|
|||||||
@@ -165,3 +165,8 @@ void W5500Device::update()
|
|||||||
{
|
{
|
||||||
_maintainResult = Ethernet.maintain();
|
_maintainResult = Ethernet.maintain();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int8_t W5500Device::signalStrength()
|
||||||
|
{
|
||||||
|
return 127;
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ public:
|
|||||||
|
|
||||||
virtual bool isConnected();
|
virtual bool isConnected();
|
||||||
|
|
||||||
|
int8_t signalStrength() override;
|
||||||
|
|
||||||
virtual PubSubClient *mqttClient();
|
virtual PubSubClient *mqttClient();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -130,3 +130,8 @@ void WifiDevice::onDisconnected()
|
|||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int8_t WifiDevice::signalStrength()
|
||||||
|
{
|
||||||
|
return WiFi.RSSI();
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ public:
|
|||||||
|
|
||||||
virtual bool isConnected();
|
virtual bool isConnected();
|
||||||
|
|
||||||
|
int8_t signalStrength() override;
|
||||||
|
|
||||||
virtual PubSubClient *mqttClient();
|
virtual PubSubClient *mqttClient();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user