From 772816b6955d9dee2908572038b257893bae23fc Mon Sep 17 00:00:00 2001 From: Jaime Date: Mon, 19 Aug 2024 17:35:34 -0400 Subject: [PATCH 1/2] mqtt command throttling --- .../ovms_server_v3/src/ovms_server_v3.cpp | 14 ++++++++++++-- .../components/ovms_server_v3/src/ovms_server_v3.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/vehicle/OVMS.V3/components/ovms_server_v3/src/ovms_server_v3.cpp b/vehicle/OVMS.V3/components/ovms_server_v3/src/ovms_server_v3.cpp index b72ef62b8..de184f453 100644 --- a/vehicle/OVMS.V3/components/ovms_server_v3/src/ovms_server_v3.cpp +++ b/vehicle/OVMS.V3/components/ovms_server_v3/src/ovms_server_v3.cpp @@ -137,8 +137,13 @@ static void OvmsServerV3MongooseCallback(struct mg_connection *nc, int ev, void msg->topic.p, (int) msg->payload.len, msg->payload.p); if (MyOvmsServerV3) { - MyOvmsServerV3->IncomingMsg(std::string(msg->topic.p,msg->topic.len), - std::string(msg->payload.p,msg->payload.len)); + if (MyOvmsServerV3->m_accept_command == 0) + { + MyOvmsServerV3->m_accept_command = 2; + MyOvmsServerV3->IncomingMsg( + std::string(msg->topic.p,msg->topic.len), + std::string(msg->payload.p,msg->payload.len)); + } } if (msg->qos == 1) { @@ -210,6 +215,7 @@ OvmsServerV3::OvmsServerV3(const char* name) m_notify_data_waitcomp = 0; m_notify_data_waittype = NULL; m_notify_data_waitentry = NULL; + m_accept_command = 0; ESP_LOGI(TAG, "OVMS Server v3 running"); @@ -877,6 +883,10 @@ void OvmsServerV3::NetmanStop(std::string event, void* data) void OvmsServerV3::Ticker1(std::string event, void* data) { + if (m_accept_command > 0) + { + m_accept_command--; + } if (m_connretry > 0) { if (MyNetManager.m_connected_any) diff --git a/vehicle/OVMS.V3/components/ovms_server_v3/src/ovms_server_v3.h b/vehicle/OVMS.V3/components/ovms_server_v3/src/ovms_server_v3.h index af843d280..fa2763fbb 100644 --- a/vehicle/OVMS.V3/components/ovms_server_v3/src/ovms_server_v3.h +++ b/vehicle/OVMS.V3/components/ovms_server_v3/src/ovms_server_v3.h @@ -96,6 +96,7 @@ class OvmsServerV3 : public OvmsServer OvmsMutex m_mgconn_mutex; int m_connretry; bool m_sendall; + int m_accept_command; int m_msgid; int m_lasttx; int m_lasttx_sendall; From 4e47ec2bdfea0adecf648874378e7c5d7958704c Mon Sep 17 00:00:00 2001 From: Jaime Date: Wed, 21 Aug 2024 15:28:55 -0400 Subject: [PATCH 2/2] fix code style --- .../components/ovms_server_v3/src/ovms_server_v3.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vehicle/OVMS.V3/components/ovms_server_v3/src/ovms_server_v3.cpp b/vehicle/OVMS.V3/components/ovms_server_v3/src/ovms_server_v3.cpp index de184f453..927bc58ea 100644 --- a/vehicle/OVMS.V3/components/ovms_server_v3/src/ovms_server_v3.cpp +++ b/vehicle/OVMS.V3/components/ovms_server_v3/src/ovms_server_v3.cpp @@ -139,10 +139,10 @@ static void OvmsServerV3MongooseCallback(struct mg_connection *nc, int ev, void { if (MyOvmsServerV3->m_accept_command == 0) { - MyOvmsServerV3->m_accept_command = 2; - MyOvmsServerV3->IncomingMsg( - std::string(msg->topic.p,msg->topic.len), - std::string(msg->payload.p,msg->payload.len)); + MyOvmsServerV3->m_accept_command = 2; + MyOvmsServerV3->IncomingMsg( + std::string(msg->topic.p,msg->topic.len), + std::string(msg->payload.p,msg->payload.len)); } } if (msg->qos == 1) @@ -885,7 +885,7 @@ void OvmsServerV3::Ticker1(std::string event, void* data) { if (m_accept_command > 0) { - m_accept_command--; + m_accept_command--; } if (m_connretry > 0) {