Skip to content

Commit 16e5fec

Browse files
committed
fix: handle unregistered actions and retried actions
1 parent 029adc7 commit 16e5fec

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/BytebeamArduino.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,17 @@ bool BytebeamArduino::handleActions(char* actionReceivedStr) {
10121012
BytebeamLogger::Debug(__FILE__, __func__, "payloadStr : %s", payloadStr);
10131013
#endif
10141014

1015+
int32_t actionIdVal = (int32_t)(atoi(idStr));
1016+
int32_t lastKnownActionIdVal = (int32_t)(atoi(this->lastKnownActionId));
1017+
1018+
BytebeamLogger::Debug(__FILE__, __func__, "actionIdVal : %ld, lastKnownActionIdVal : %ld\n",actionIdVal, lastKnownActionIdVal);
1019+
1020+
// just ignore the previous actions if triggered again
1021+
if (actionIdVal <= lastKnownActionIdVal) {
1022+
BytebeamLogger::Error(__FILE__, __func__, "Ignoring %s Action", name);
1023+
return true;
1024+
}
1025+
10151026
int actionIterator = 0;
10161027
while(this->actionFuncs[actionIterator].name) {
10171028
if (!strcmp(this->actionFuncs[actionIterator].name, name)) {
@@ -1022,9 +1033,15 @@ bool BytebeamArduino::handleActions(char* actionReceivedStr) {
10221033
}
10231034

10241035
if(this->actionFuncs[actionIterator].name == NULL) {
1025-
BytebeamLogger::Error(__FILE__, __func__, "invalid action : %s", name);
1036+
BytebeamLogger::Error(__FILE__, __func__, "Invalid Action : %s", name);
1037+
1038+
// publish action failed response indicating unregistered action
1039+
publishActionFailed(idStr, "Unregistered Action");
10261040
}
10271041

1042+
// update the last known action id
1043+
strcpy(this->lastKnownActionId, idStr);
1044+
10281045
// release the allocated memory :)
10291046
free(idStr);
10301047
free(payloadStr);

src/BytebeamArduino.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
/* This macro is used to specify the maximum length of bytebeam mqtt topic string */
2222
#define BYTEBEAM_MQTT_TOPIC_STR_LEN 200
2323

24+
/* This macro is used to specify the maximum length of bytebeam action id string */
25+
#define BYTEBEAM_ACTION_ID_STR_LEN 20
26+
2427
/* This macro is used to specify the maximum number of actions that need to be handled for particular device */
2528
#define BYTEBEAM_NUMBER_OF_ACTIONS 10
2629

@@ -160,6 +163,7 @@ class BytebeamArduino : private PubSubClient,
160163
char* deviceConfigStr;
161164
bool isClientActive;
162165
bool isOTAEnable;
166+
char lastKnownActionId[BYTEBEAM_ACTION_ID_STR_LEN];
163167

164168
#ifdef BYTEBEAM_ARDUINO_ARCH_ESP32
165169
#ifdef BYTEBEAM_ARDUINO_USE_WIFI

0 commit comments

Comments
 (0)