add sensor for wifi signal strength
This commit is contained in:
parent
e129097b52
commit
9b1ecf73ce
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json",
|
"$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json",
|
||||||
"name": "ha-mqtt",
|
"name": "ha-mqtt",
|
||||||
"version": "1.6.0",
|
"version": "1.7.0",
|
||||||
"description": "Home Assistant classes for integration with MQTT auto discovery",
|
"description": "Home Assistant classes for integration with MQTT auto discovery",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
20
src/esp.h
20
src/esp.h
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
#include "TaskScheduler.h"
|
#include "TaskScheduler.h"
|
||||||
#include "ha.h"
|
#include "ha.h"
|
||||||
|
|
||||||
@ -9,6 +10,7 @@ namespace HaESP {
|
|||||||
struct {
|
struct {
|
||||||
bool heapStats = false;
|
bool heapStats = false;
|
||||||
bool restartInfo = false;
|
bool restartInfo = false;
|
||||||
|
bool wifiInfo = false;
|
||||||
} activeSensors;
|
} activeSensors;
|
||||||
|
|
||||||
Task tHeap(5 * TASK_MINUTE, TASK_FOREVER, []() {
|
Task tHeap(5 * TASK_MINUTE, TASK_FOREVER, []() {
|
||||||
@ -28,6 +30,10 @@ namespace HaESP {
|
|||||||
Sensor::mapSensors["restart_reason"]->updateState(ESP.getResetReason().c_str());
|
Sensor::mapSensors["restart_reason"]->updateState(ESP.getResetReason().c_str());
|
||||||
}, &ts);
|
}, &ts);
|
||||||
|
|
||||||
|
Task tWifi(3 * TASK_MINUTE, TASK_FOREVER, []() {
|
||||||
|
Sensor::mapSensors["wifi_signal_strength"]->updateState(to_string(WiFi.RSSI()).c_str());
|
||||||
|
}, &ts);
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
Builder<T>& heapStats(Builder<T>& builder) {
|
Builder<T>& heapStats(Builder<T>& builder) {
|
||||||
auto heap = new Sensor{ "Heap fragmentation", "heap_fragmentation" };
|
auto heap = new Sensor{ "Heap fragmentation", "heap_fragmentation" };
|
||||||
@ -60,6 +66,19 @@ namespace HaESP {
|
|||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
Builder<T>& wifiInfo(Builder<T>& builder) {
|
||||||
|
builder.addDiagnostic(Builder<Sensor>::instance((
|
||||||
|
new Sensor{ "WiFi Signal (RSSI)", "wifi_signal_strength" }))
|
||||||
|
.withDeviceClass("signal_strength")
|
||||||
|
.withUnitMeasure("dBm")
|
||||||
|
.withPrecision(0)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
activeSensors.wifiInfo = true;
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
Builder<Button>& restartButton() {
|
Builder<Button>& restartButton() {
|
||||||
return Builder<Button>::instance(new Button{"Restart", "restart",
|
return Builder<Button>::instance(new Button{"Restart", "restart",
|
||||||
[](const char* msg) {
|
[](const char* msg) {
|
||||||
@ -72,5 +91,6 @@ namespace HaESP {
|
|||||||
void enableSensors() {
|
void enableSensors() {
|
||||||
if (activeSensors.heapStats) tHeap.enable();
|
if (activeSensors.heapStats) tHeap.enable();
|
||||||
if (activeSensors.restartInfo) tRestartInfo.enable();
|
if (activeSensors.restartInfo) tRestartInfo.enable();
|
||||||
|
if (activeSensors.wifiInfo) tWifi.enable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user