Add Webcam stats as sensors. (Can be used in home assistant.) (#22744)

This commit is contained in:
anishsane 2025-01-01 18:51:48 +05:30 committed by GitHub
parent 1a482364bc
commit 01154e9497
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 0 deletions

View File

@ -1503,6 +1503,18 @@ void WcUpdateStats(void) {
WcStats.camcnt = 0;
}
void WcSensorStats(void) {
if (!Wc.up) { return; }
ResponseAppend_P(PSTR(",\"CAMERA\":{"
"\"" D_WEBCAM_STATS_FPS "\":%d,"
"\"" D_WEBCAM_STATS_CAMFAIL "\":%d,"
"\"" D_WEBCAM_STATS_JPEGFAIL "\":%d,"
"\"" D_WEBCAM_STATS_CLIENTFAIL "\":%d}"),
WcStats.camfps, WcStats.camfail,
WcStats.jpegfail, WcStats.clientfail);
}
const char HTTP_WEBCAM_FPS[] PROGMEM = "{s}%s " D_FRAME_RATE "{m}%d " D_UNIT_FPS "{e}";
void WcStatsShow(void) {
@ -1532,6 +1544,8 @@ bool Xdrv81(uint32_t function) {
break;
case FUNC_EVERY_SECOND:
WcUpdateStats();
case FUNC_JSON_APPEND:
WcSensorStats();
case FUNC_WEB_SENSOR:
WcStatsShow();
break;

View File

@ -2950,6 +2950,18 @@ void WcUpdateStats(void) {
Wc.loopcounter = 0;
}
void WcSensorStats(void) {
if (!Wc.up) { return; }
ResponseAppend_P(PSTR(",\"CAMERA\":{"
"\"" D_WEBCAM_STATS_FPS "\":%d,"
"\"" D_WEBCAM_STATS_CAMFAIL "\":%d,"
"\"" D_WEBCAM_STATS_JPEGFAIL "\":%d,"
"\"" D_WEBCAM_STATS_CLIENTFAIL "\":%d}"),
WcStats.camfps, WcStats.camfail,
WcStats.jpegfail, WcStats.clientfail);
}
#ifndef D_WEBCAM_STATE
#define D_WEBCAM_STATE "State"
#define D_WEBCAM_POWEREDOFF "PowerOff"
@ -2994,6 +3006,9 @@ bool Xdrv99(uint32_t function) {
case FUNC_EVERY_SECOND:
WcUpdateStats();
break;
case FUNC_JSON_APPEND:
WcSensorStats();
break;
case FUNC_WEB_SENSOR:
WcStatsShow();
break;