From 3cef308f40cabe4008c495e714636e68fead9b5c Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Mon, 10 Oct 2022 12:34:57 +0200 Subject: [PATCH 01/69] Update with cortex commands. Additional implementations still required --- src/Arancino.cpp | 1307 +++++++++++++------------------------ src/Arancino.h | 130 ++-- src/ArancinoDefinitions.h | 16 +- 3 files changed, 549 insertions(+), 904 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index d0bc7b0..cbdd858 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -110,11 +110,14 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg) { #else char* useFreeRtos = "0"; #endif + + /* char* keys[] = {fw_lib_ver,fw_name,fw_ver,fw_build_time,fw_core_ver, mcu_family, fw_use_freertos}; char* values[] = {LIB_VERSION, _metadata.fwname,_metadata.fwversion,str_build_time,(char*)ARANCINO_CORE_VERSION,(char*)MCU_FAMILY,(char*)useFreeRtos}; start(keys,values,7); started = true; + */ strcpy(LOG_LEVEL,getModuleLogLevel()); #if defined(USEFREERTOS) @@ -137,25 +140,6 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg) { void ArancinoClass::start(char **keys, char **values, int len) { - ArancinoPacket packet; - do - { - // try to start comunication every 2,5 seconds. - delay(2500); - - packet = executeCommand(START_COMMAND, NULL, keys, values, NULL, len, false, STRING_ARRAY); - if (packet.responseCode == RSP_OK) - { - // timestamp from arancino module - memcpy(timestamp, packet.response.stringArray[1], 13); - char tmst_part[5]; - memcpy(tmst_part, timestamp, 4); // first 4 digits of epoch - tmst_sup = atoi(tmst_part); - tmst_inf = atoi(×tamp[4]); // last 9 digits of epoch - millis_previous = millis(); - } - } while (packet.isError == true || packet.responseCode != RSP_OK); - free(packet); } #if defined(USEFREERTOS) @@ -189,7 +173,7 @@ void ArancinoClass::startScheduler() } #endif -/******** API ADVANCED :: DEBUG OPTIONS *********/ +/******** API BASIC :: DEBUG OPTIONS *********/ void ArancinoClass::enableDebugMessages(bool sendViaCommMode){ if (sendViaCommMode){ @@ -220,194 +204,134 @@ void ArancinoClass::disableDebugMessages(){ _dbgSerial = NULL; } -/******** API BASIC :: MSET *********/ - -ArancinoPacket ArancinoClass::mset(char **keys, char **values, int len, bool isPersistent) -{ - if ((keys == NULL) || (values == NULL) || (len <= 0)) - return invalidCommandErrorPacket; - if (isPersistent) - return executeCommand(MSET_PERS_COMMAND, NULL, keys, values, NULL, len, arancino_id_prefix, VOID); - else - return executeCommand(MSET_COMMAND, NULL, keys, values, NULL, len, arancino_id_prefix, VOID); -} - -/******** API BASIC :: MGET *********/ - -template <> -ArancinoPacket ArancinoClass::mget(char **keys, int len) -{ - if ((keys == NULL) || (len <= 0)) - return invalidCommandErrorPacket; - return executeCommand(MGET_COMMAND, NULL, keys, NULL, NULL, len, arancino_id_prefix, STRING_ARRAY); -} - -template <> -char **ArancinoClass::mget(char **keys, int len) -{ - ArancinoPacket packet = mget(keys, len); - if (packet.isError) - return NULL; - return packet.response.stringArray; -} /******** API BASIC :: SET *********/ -ArancinoPacket ArancinoClass::set(char *key, int value, bool isPersistent) +ArancinoPacket ArancinoClass::set(char *key, int value, bool isAck, bool isPersistent, char* type) { char str[20] = ""; itoa(value, str, 10); - return set(key, str, isPersistent); + return set(key, str, isAck, isPersistent); } -ArancinoPacket ArancinoClass::set(char *key, uint32_t value, bool isPersistent) +ArancinoPacket ArancinoClass::set(char *key, uint32_t value, bool isAck, bool isPersistent, char* type) { char str[20] = ""; itoa(value, str, 10); - return set(key, str, isPersistent); + return set(key, str, isAck, isPersistent); } -ArancinoPacket ArancinoClass::set(char *key, long value, bool isPersistent) +ArancinoPacket ArancinoClass::set(char *key, long value, bool isAck, bool isPersistent, char* type) { char str[20] = ""; itoa(value, str, 10); - return set(key, str, isPersistent); + return set(key, str, isAck, isPersistent); } -ArancinoPacket ArancinoClass::set(char *key, float value, bool isPersistent) +ArancinoPacket ArancinoClass::set(char *key, float value, bool isAck, bool isPersistent, char* type) { char str[20] = ""; _floatToString(value, decimal_digits, str); - return set(key, str, isPersistent); + return set(key, str, isAck, isPersistent); } -ArancinoPacket ArancinoClass::set(char *key, double value, bool isPersistent) +ArancinoPacket ArancinoClass::set(char *key, double value, bool isAck, bool isPersistent, char* type) { char str[20] = ""; _doubleToString(value, decimal_digits, str); - return set(key, str, isPersistent); + return set(key, str, isAck, isPersistent); } -ArancinoPacket ArancinoClass::set(char *key, char *value, bool isPersistent) +ArancinoPacket ArancinoClass::set(char *key, char *value, bool isAck, bool isPersistent, char* type) { - return __set(key, value, isPersistent); -} - -ArancinoPacket ArancinoClass::__set(char *key, char *value, bool isPersistent) -{ - if (key == NULL && value == NULL && strcmp(key, "") == 0) + if (key == NULL || value == NULL || strcmp(key, "") == 0) return invalidCommandErrorPacket; - if (isPersistent) - return executeCommand(SET_PERS_COMMAND, key, value, NULL, arancino_id_prefix, VOID); - else - return executeCommand(SET_COMMAND, key, value, NULL, arancino_id_prefix, VOID); -} - -/******** API BASIC :: GET *********/ -template <> -ArancinoPacket ArancinoClass::get(char *key) -{ - if (key == NULL && strcmp(key, "") == 0) - return invalidCommandErrorPacket; - char *param = NULL; - return executeCommand(GET_COMMAND, key, param, param, arancino_id_prefix, STRING); + ArancinoCFG cfg; + cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; + cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; + cfg.type = type; + return executeCommand(SET_COMMAND, key, NULL, value, true, true, cfg, VOID_RESPONSE); } -template <> -char *ArancinoClass::get(char *key) -{ - ArancinoPacket packet = get(key); - if (!packet.isError) - return packet.response.string; - else - return NULL; -} -/******** API BASIC :: SETRESERVED *********/ +/******** API BASIC :: MSET *********/ -ArancinoPacket ArancinoClass::setReserved(char *key, char *value, bool id_prefix) +ArancinoPacket ArancinoClass::mset(char **keys, char **values, int len, bool isPersistent, char* type ) { - if (key == NULL && value == NULL && strcmp(key, "") == 0) + if ((keys == NULL) || (values == NULL) || (len <= 0)) return invalidCommandErrorPacket; - return executeCommand(SETRESERVED_COMMAND, key, value, NULL, id_prefix, VOID); + + ArancinoCFG cfg; + cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; + cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; + cfg.type = type; + return executeCommand(SET_COMMAND, keys, NULL, values, len, true, true, cfg, VOID_RESPONSE); } -/******** API BASIC :: GETRESERVED *********/ +/******** API BASIC :: GET *********/ template <> -ArancinoPacket ArancinoClass::getReserved(char *key, bool id_prefix) +ArancinoPacket ArancinoClass::get(char* key, bool isPersistent, char* type) { if (key == NULL && strcmp(key, "") == 0) return invalidCommandErrorPacket; - return executeCommand(GETRESERVED_COMMAND, key, NULL, NULL, id_prefix, STRING); + + ArancinoCFG cfg; + cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; + cfg.type = type; + return executeCommand(GET_COMMAND, key, NULL, NULL, true, false, cfg, KEY_VALUE_RESPONSE); } -template <> -char *ArancinoClass::getReserved(char *key, bool id_prefix) +template <> char *ArancinoClass::get(char* key, bool isPersistent, char* type) { - ArancinoPacket packet = getReserved(key, id_prefix); + ArancinoPacket packet = get(key, isPersistent, type); if (!packet.isError) return packet.response.string; else return NULL; } -char *ArancinoClass::getModuleVersion() -{ - char key[strlen(MODVERS_KEY) + 1]; - strcpy(key, MODVERS_KEY); - char *retString = getReserved(key, false); - return retString; -} - -char *ArancinoClass::getModuleLogLevel() -{ - char key[strlen(MODLOGLVL_KEY) + 1]; - strcpy(key, MODLOGLVL_KEY); - char *retString = getReserved(key, false); - return retString; -} +/******** API BASIC :: MGET *********/ -char *ArancinoClass::getModuleEnvironment() +template <> ArancinoPacket ArancinoClass::mget(char **keys, int len, bool isPersistent, const char* type) { - char key[strlen(MODENV_KEY) + 1]; - strcpy(key, MODENV_KEY); - char *retString = getReserved(key, false); - return retString; -} + if ((keys == NULL) || (len <= 0)) + return invalidCommandErrorPacket; -char *ArancinoClass::getBlinkId() -{ - char key[strlen(BLINK_ID_KEY) + 1]; - strcpy(key, BLINK_ID_KEY); - char *retString = getReserved(key, true); - return retString; + ArancinoCFG cfg; + cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; + cfg.type = type; + return executeCommand(GET_COMMAND, keys, NULL, NULL, len, true, false, cfg, KEY_VALUE_RESPONSE); } -/******** API BASIC :: SETRESERVED *********/ - -ArancinoPacket ArancinoClass::setBlinkId(int value) +template <> char **ArancinoClass::mget(char** keys, int len, bool isPersistent, const char* type) { - char str[20] = ""; - itoa(value, str, 10); - return setReserved(BLINK_ID_KEY, str, true); + ArancinoPacket packet = mget(keys, len, isPersistent, type); + if (packet.isError) + return NULL; + return packet.response.stringArray; } /******** API BASIC :: DEL *********/ template <> -ArancinoPacket ArancinoClass::del(char *key) +ArancinoPacket ArancinoClass::del(char* key, bool isAck, bool isPersistent, const char* type) { if (key == NULL && strcmp(key, "") == 0) return invalidCommandErrorPacket; - return executeCommand(DEL_COMMAND, key, NULL, NULL, arancino_id_prefix, INT); + + ArancinoCFG cfg; + cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; + cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; + cfg.type = type; + return executeCommand(DEL_COMMAND, key, NULL, NULL, true, false, cfg, KEY_RESPONSE); } template <> -int ArancinoClass::del(char *key) +int ArancinoClass::del(char* key, bool isAck, bool isPersistent, const char* type) { - ArancinoPacket packet = del(key); + ArancinoPacket packet = del(key, isAck, isPersistent, type); if (!packet.isError) return packet.response.integer; else @@ -416,198 +340,113 @@ int ArancinoClass::del(char *key) /******** API BASIC :: HSET *********/ -ArancinoPacket ArancinoClass::hset(char *key, char *field, int value, bool isPersistent) +ArancinoPacket ArancinoClass::hset(char *key, char *field, int value, bool isAck, bool isPersistent, const char* type) { char str[20]; itoa(value, str, 10); - return hset(key, field, str); + return hset(key, field, str, isAck, isPersistent, type); } -ArancinoPacket ArancinoClass::hset(char *key, char *field, float value, bool isPersistent) +ArancinoPacket ArancinoClass::hset(char *key, char *field, float value, bool isAck, bool isPersistent, const char* type) { char str[20] = ""; _floatToString(value, decimal_digits, str); return hset(key, field, str); } -ArancinoPacket ArancinoClass::hset(char *key, char *field, double value, bool isPersistent) +ArancinoPacket ArancinoClass::hset(char *key, char *field, double value, bool isAck, bool isPersistent, const char* type) { char str[20] = ""; _doubleToString(value, decimal_digits, str); - return hset(key, field, str); + return hset(key, field, str, isAck, isPersistent, type); } -ArancinoPacket ArancinoClass::hset(char *key, char *field, uint32_t value, bool isPersistent) +ArancinoPacket ArancinoClass::hset(char *key, char *field, uint32_t value, bool isAck, bool isPersistent, const char* type) { char str[20]; itoa(value, str, 10); - return hset(key, field, str); + return hset(key, field, str, isAck, isPersistent, type); } -ArancinoPacket ArancinoClass::hset(char *key, char *field, long value, bool isPersistent) +ArancinoPacket ArancinoClass::hset(char *key, char *field, long value, bool isAck, bool isPersistent, const char* type) { char str[20]; itoa(value, str, 10); - return hset(key, field, str); + return hset(key, field, str, isAck, isPersistent, type); } -ArancinoPacket ArancinoClass::hset(char *key, char *field, char *value, bool isPersistent) +ArancinoPacket ArancinoClass::hset(char *key, char *field, char *value, bool isAck, bool isPersistent, const char* type) { - if (key == NULL && field == NULL && value == NULL && strcmp(key, "") == 0 && strcmp(field, "") == 0) + if (key == NULL && field == NULL || value == NULL || strcmp(key, "") == 0 || strcmp(field, "") == 0) return invalidCommandErrorPacket; - if (isPersistent) - return executeCommand(HSET_PERS_COMMAND, key, field, value, arancino_id_prefix, VOID); - else - return executeCommand(HSET_COMMAND, key, field, value, arancino_id_prefix, VOID); + + ArancinoCFG cfg; + cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; + cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; + cfg.type = type; + return executeCommand(HSET_COMMAND, key, field, value, true, true, cfg, VOID_RESPONSE); } /******** API BASIC :: HGET *********/ template <> -ArancinoPacket ArancinoClass::hget(char *key, char *field) +ArancinoPacket ArancinoClass::hget(char *key, char *field, bool isPersistent, const char* type) { - if (key == NULL && field == NULL && strcmp(key, "") == 0 && strcmp(field, "") == 0) + if (key == NULL || field == NULL || strcmp(key, "") == 0 || strcmp(field, "") == 0) return invalidCommandErrorPacket; - return executeCommand(HGET_COMMAND, key, field, NULL, arancino_id_prefix, STRING); -} -template <> -char *ArancinoClass::hget(char *key, char *field) -{ - ArancinoPacket packet = hget(key, field); - if (!packet.isError) - return packet.response.string; - else - return NULL; + ArancinoCFG cfg; + cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; + cfg.type = type; + return executeCommand(HGET_COMMAND, key, field, NULL, true, true, cfg, KEY_VALUE_RESPONSE); } -/******** API BASIC :: HGETALL PACKET *********/ - template <> -ArancinoPacket ArancinoClass::hgetall(char *key) +char *ArancinoClass::hget(char *key, char *field, bool isPersistent, const char* type) { - if (key == NULL && strcmp(key, "") == 0) - return invalidCommandErrorPacket; - char *param = NULL; - return executeCommand(HGETALL_COMMAND, key, param, param, arancino_id_prefix, STRING_ARRAY); -} - -template <> -char **ArancinoClass::hgetall(char *key) -{ - ArancinoPacket packet = hgetall(key); + ArancinoPacket packet = hget(key, field, isPersistent, type); if (!packet.isError) - return packet.response.stringArray; + return packet.response.string; else return NULL; } -/******** API BASIC :: HKEYS *********/ - -template <> -ArancinoPacket ArancinoClass::hkeys(char *key) -{ - if (key == NULL && strcmp(key, "") == 0) - return invalidCommandErrorPacket; - char *param = NULL; - return executeCommand(HKEYS_COMMAND, key, param, param, arancino_id_prefix, STRING_ARRAY); -} - -template <> -char **ArancinoClass::hkeys(char *key) -{ - ArancinoPacket packet = hkeys(key); - char **retArray; - if (!packet.isError) - retArray = packet.response.stringArray; - else - retArray = NULL; - return retArray; -} - -/******** API BASIC :: HVALS *********/ - -template <> -ArancinoPacket ArancinoClass::hvals(char *key) -{ - if (key == NULL && strcmp(key, "") == 0) - return invalidCommandErrorPacket; - char *param = NULL; - return executeCommand(HVALS_COMMAND, key, param, param, arancino_id_prefix, STRING_ARRAY); -} - -template <> -char **ArancinoClass::hvals(char *key) -{ - ArancinoPacket packet = hvals(key); - char **retArray; - if (!packet.isError) - retArray = packet.response.stringArray; - else - retArray = NULL; - return retArray; -} - /******** API BASIC :: HDEL *********/ template <> -ArancinoPacket ArancinoClass::hdel(char *key, char *field) +ArancinoPacket ArancinoClass::hdel(char *key, char *field, bool isAck, bool isPersistent) { if (key == NULL && field == NULL && strcmp(key, "") == 0 && strcmp(field, "") == 0) return invalidCommandErrorPacket; - return executeCommand(HDEL_COMMAND, key, field, NULL, arancino_id_prefix, INT); + + ArancinoCFG cfg; + cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; + cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; + return executeCommand(HDEL_COMMAND, key, field, NULL, true, true, cfg, FIELDS_RESPONSE); } template <> -int ArancinoClass::hdel(char *key, char *field) +int ArancinoClass::hdel(char *key, char *field, bool isAck, bool isPersistent) { - ArancinoPacket packet = hdel(key, field); + ArancinoPacket packet = hdel(key, field, isAck, isPersistent); int retValue = 0; if (!packet.isError) retValue = packet.response.integer; return retValue; } -/******** API BASIC :: KEYS PACKET *********/ - -template <> -ArancinoPacket ArancinoClass::keys(char *pattern) -{ - if (pattern == NULL && strcmp(pattern, "") == 0) - return invalidCommandErrorPacket; - char *param = NULL; - return executeCommand(KEYS_COMMAND, pattern, param, param, false, STRING_ARRAY); -} - -template <> -char **ArancinoClass::keys(char *pattern) -{ - ArancinoPacket packet = keys(pattern); - if (!packet.isError) - return packet.response.stringArray; - else - return NULL; -} - /******** API BASIC :: PUBLISH *********/ -ArancinoPacket ArancinoClass::__publish(char *channel, char *msg) -{ - if (channel == NULL && msg == NULL && strcmp(channel, "") == 0) - return invalidCommandErrorPacket; - return executeCommand(PUBLISH_COMMAND, channel, msg, NULL, arancino_id_prefix, INT); -} - template <> -ArancinoPacket ArancinoClass::publish(char *channel, char *msg) +ArancinoPacket ArancinoClass::publish(char *channel, char *msg, bool isAck) { - return __publish(channel, msg); + return __publish(channel, msg, isAck); } template <> -int ArancinoClass::publish(char *channel, char *msg) +int ArancinoClass::publish(char *channel, char *msg, bool isAck) { - ArancinoPacket packet = __publish(channel, msg); + ArancinoPacket packet = __publish(channel, msg, isAck); if (!packet.isError) return packet.response.integer; else @@ -615,19 +454,19 @@ int ArancinoClass::publish(char *channel, char *msg) } template <> -ArancinoPacket ArancinoClass::publish(char *channel, double msg) +ArancinoPacket ArancinoClass::publish(char *channel, double msg, bool isAck) { char str[20] = ""; _doubleToString(msg, decimal_digits, str); - return __publish(channel, str); + return __publish(channel, str, isAck); } template <> -int ArancinoClass::publish(char *channel, double msg) +int ArancinoClass::publish(char *channel, double msg, bool isAck) { char str[20] = ""; _doubleToString(msg, decimal_digits, str); - ArancinoPacket packet = __publish(channel, str); + ArancinoPacket packet = __publish(channel, str, isAck); if (!packet.isError) return packet.response.integer; else @@ -635,19 +474,19 @@ int ArancinoClass::publish(char *channel, double msg) } template <> -ArancinoPacket ArancinoClass::publish(char *channel, int msg) +ArancinoPacket ArancinoClass::publish(char *channel, int msg, bool isAck) { char str[20] = ""; itoa(msg, str, 10); - return __publish(channel, str); + return __publish(channel, str, isAck); } template <> -int ArancinoClass::publish(char *channel, int msg) +int ArancinoClass::publish(char *channel, int msg, bool isAck) { char str[20] = ""; itoa(msg, str, 10); - ArancinoPacket packet = __publish(channel, str); + ArancinoPacket packet = __publish(channel, str, isAck); if (!packet.isError) return packet.response.integer; else @@ -655,19 +494,19 @@ int ArancinoClass::publish(char *channel, int msg) } template <> -ArancinoPacket ArancinoClass::publish(char *channel, uint32_t msg) +ArancinoPacket ArancinoClass::publish(char *channel, uint32_t msg, bool isAck) { char str[20] = ""; itoa(msg, str, 10); - return __publish(channel, str); + return __publish(channel, str, isAck); } template <> -int ArancinoClass::publish(char *channel, uint32_t msg) +int ArancinoClass::publish(char *channel, uint32_t msg, bool isAck) { char str[20] = ""; itoa(msg, str, 10); - ArancinoPacket packet = __publish(channel, str); + ArancinoPacket packet = __publish(channel, str, isAck); if (!packet.isError) return packet.response.integer; else @@ -675,49 +514,69 @@ int ArancinoClass::publish(char *channel, uint32_t msg) } template <> -ArancinoPacket ArancinoClass::publish(char *channel, long msg) +ArancinoPacket ArancinoClass::publish(char *channel, long msg, bool isAck) { char str[20] = ""; itoa(msg, str, 10); - return __publish(channel, str); + return __publish(channel, str, isAck); } template <> -int ArancinoClass::publish(char *channel, long msg) +int ArancinoClass::publish(char *channel, long msg, bool isAck) { char str[20] = ""; itoa(msg, str, 10); - ArancinoPacket packet = __publish(channel, str); + ArancinoPacket packet = __publish(channel, str, isAck); if (!packet.isError) return packet.response.integer; else return 0; } +ArancinoPacket ArancinoClass::__publish(char *channel, char *msg, bool isAck) +{ + if (channel == NULL || msg == NULL || strcmp(channel, "") == 0) + return invalidCommandErrorPacket; + + StaticJsonDocument cmd_doc; + JsonObject cmd_args = cmd_doc.createNestedObject("args"); + cmd_doc["cmd"] = PUBLISH_COMMAND; + JsonArray cmd_items = cmd_args.createNestedArray("items"); + JsonObject items_obj = cmd_items.createNestedObject(); + items_obj["channel"] = channel; + items_obj["message"] = msg; + + JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); + cmd_cfg["ack"] = isAck? 0 : 1; + return executeCommand(cmd_doc, CLIENTS_RESPONSE); +} + /******** API BASIC :: FLUSH *********/ -ArancinoPacket ArancinoClass::flush() +ArancinoPacket ArancinoClass::flush(bool isAck, bool isPersistent) { - char *param = NULL; - return executeCommand(FLUSH_COMMAND, param, param, param, false, VOID); + ArancinoCFG cfg; + cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; + cfg.persistent = isPersistent ? CFG_TRUE : CFG_FALSE; + return executeCommand(FLUSH_COMMAND, NULL, NULL, NULL, false, false, cfg, VOID_RESPONSE); } /******** API BASIC :: STORE *********/ template <> -ArancinoPacket ArancinoClass::store(char *key, int value) +ArancinoPacket ArancinoClass::store(char *key, int value, char* timestamp, bool isAck,) { char str[20] = ""; itoa(value, str, 10); - return __store(key, str); + return __store(key, str, timestamp, isAck); } template <> -char *ArancinoClass::store(char *key, int value) +char *ArancinoClass::store(char *key, int value, char* timestamp, bool isAck) { char str[20] = ""; itoa(value, str, 10); - ArancinoPacket packet = __store(key, str); + ArancinoPacket packet = __store(key, str, timestamp, isAck); if (!packet.isError) return packet.response.string; else @@ -725,19 +584,19 @@ char *ArancinoClass::store(char *key, int value) } template <> -ArancinoPacket ArancinoClass::store(char *key, uint32_t value) +ArancinoPacket ArancinoClass::store(char *key, uint32_t value, bool isAck, char* timestamp) { char str[20] = ""; itoa(value, str, 10); - return __store(key, str); + return __store(key, str, timestamp, isAck); } template <> -char *ArancinoClass::store(char *key, uint32_t value) +char *ArancinoClass::store(char *key, uint32_t value, char* timestamp, bool isAck) { char str[20] = ""; itoa(value, str, 10); - ArancinoPacket packet = __store(key, str); + ArancinoPacket packet = __store(key, str, timestamp, isAck); if (!packet.isError) return packet.response.string; else @@ -745,19 +604,19 @@ char *ArancinoClass::store(char *key, uint32_t value) } template <> -ArancinoPacket ArancinoClass::store(char *key, long value) +ArancinoPacket ArancinoClass::store(char *key, long value, bool isAck, char* timestamp) { char str[20] = ""; itoa(value, str, 10); - return __store(key, str); + return __store(key, str, timestamp, isAck); } template <> -char *ArancinoClass::store(char *key, long value) +char *ArancinoClass::store(char *key, long value, char* timestamp, bool isAck) { char str[20] = ""; itoa(value, str, 10); - ArancinoPacket packet =__store(key, str); + ArancinoPacket packet = __store(key, str, timestamp, isAck); if (!packet.isError) return packet.response.string; else @@ -765,189 +624,202 @@ char *ArancinoClass::store(char *key, long value) } template <> -ArancinoPacket ArancinoClass::store(char *key, float value) +ArancinoPacket ArancinoClass::store(char *key, float value, char* timestamp, bool isAck) { char str[20] = ""; _floatToString(value, decimal_digits, str); - return __store(key, str); + return __store(key, str, timestamp, isAck); } template <> -char *ArancinoClass::store(char *key, float value) +char *ArancinoClass::store(char *key, float value, bool isAck, char* timestamp) { char str[20] = ""; _floatToString(value, decimal_digits, str); - ArancinoPacket packet = __store(key, str); + ArancinoPacket packet = __store(key, str, timestamp, isAck); if (!packet.isError) return packet.response.string; else return NULL; } -template <> -ArancinoPacket ArancinoClass::store(char *key, double value) -{ - char str[20] = ""; - _doubleToString(value, decimal_digits, str); - return __store(key, str); -} +ArancinoPacket ArancinoClass::__store( char* key, char* value, char* timestamp, bool isAck) { -template <> -char *ArancinoClass::store(char *key, double value) -{ - char str[20] = ""; - _doubleToString(value, decimal_digits, str); - ArancinoPacket packet = __store(key, str); - if (!packet.isError) - return packet.response.string; - else - return NULL; -} + if(timestamp==NULL){ + timestamp = getTimestamp(); + } -template<> ArancinoPacket ArancinoClass::store( char* key, int value,char* timestamp) { - char str[20] = ""; - itoa(value, str, 10); - return __store(key, str,timestamp); -} + if(key == NULL || value == NULL || strcmp(key, "") == 0){ + return invalidCommandErrorPacket; + } -template<> char* ArancinoClass::store(char* key, int value,char* timestamp){ - char str[20] = ""; - itoa(value, str, 10); - ArancinoPacket packet = __store(key, str,timestamp); - if (!packet.isError) - return packet.response.string; - else - return NULL; -} + StaticJsonDocument cmd_doc; + JsonObject cmd_args = cmd_doc.createNestedObject("args"); + cmd_doc["cmd"] = STORE_COMMAND; + JsonArray cmd_items = cmd_args.createNestedArray("items"); + JsonObject items_obj = cmd_items.createNestedObject(); + items_obj["key"] = key; + items_obj["value"] = value; + items_obj["ts"] = timestamp; -template<> ArancinoPacket ArancinoClass::store( char* key, uint32_t value,char* timestamp) { - char str[20] = ""; - itoa(value, str, 10); - return __store(key, str,timestamp); + JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); + cmd_cfg["ack"] = isAck? 0 : 1; + return executeCommand(cmd_doc, ITEMS_RESPONSE); } -template<> char* ArancinoClass::store(char* key, uint32_t value,char* timestamp){ - char str[20] = ""; - itoa(value, str, 10); - ArancinoPacket packet = __store(key, str,timestamp); - if (!packet.isError) - return packet.response.string; - else - return NULL; -} +/******** API BASIC :: MSTORE *********/ -template<> ArancinoPacket ArancinoClass::store( char* key, long value,char* timestamp) { - char str[20] = ""; - itoa(value, str, 10); - return __store(key, str,timestamp); -} +template <> +ArancinoPacket ArancinoClass::mstore(char** keys, char** values, int len, char* timestamp, bool isAck) +{ + if(timestamp==NULL){ + timestamp = getTimestamp(); + } -template<> char* ArancinoClass::store(char* key, long value,char* timestamp){ - char str[20] = ""; - itoa(value, str, 10); - ArancinoPacket packet =__store(key, str,timestamp); - if (!packet.isError) - return packet.response.string; - else - return NULL; -} + if ((keys == NULL) || (values == NULL) || (len <= 0)) + { + return invalidCommandErrorPacket; + } -template<> ArancinoPacket ArancinoClass::store( char* key, float value,char* timestamp) { - char str[20] = ""; - _floatToString(value, decimal_digits, str); - return __store(key, str,timestamp); -} + StaticJsonDocument cmd_doc; + JsonObject cmd_args = cmd_doc.createNestedObject("args"); + cmd_doc["cmd"] = STORE_COMMAND; + JsonArray cmd_items = cmd_args.createNestedArray("items"); + for (int i=0; i char* ArancinoClass::store(char* key, float value,char* timestamp){ - char str[20] = ""; - _floatToString(value, decimal_digits, str); - ArancinoPacket packet = __store(key, str,timestamp); - if (!packet.isError) - return packet.response.string; - else - return NULL; + JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); + cmd_cfg["ack"] = isAck? 0 : 1; + return executeCommand(cmd_doc, ITEMS_RESPONSE); } -template<> ArancinoPacket ArancinoClass::store( char* key, double value,char* timestamp) { - char str[20] = ""; - _doubleToString(value, decimal_digits, str); - return __store(key, str,timestamp); +template<> +void ArancinoClass::mstore(char** keys, char** values, int len, char* timestamp, bool isAck) { + if(timestamp==NULL){ + timestamp = getTimestamp(); + } + if ((keys == NULL) || (values == NULL) || (len <= 0)) { + return; + } + ArancinoPacket packet = mstore(keys, values, len, timestamp, isAck); + free (packet); } -template<> char* ArancinoClass::store(char* key, double value,char* timestamp){ - char str[20] = ""; - _doubleToString(value, decimal_digits, str); - ArancinoPacket packet = __store(key, str,timestamp); +template <> +char **ArancinoClass::mstore(char** keys, char** values, int len, char* timestamp, bool isAck) +{ + if(timestamp==NULL){ + timestamp = getTimestamp(); + } + if ((keys == NULL) || (values == NULL) || (len <= 0)) { + return; + } + ArancinoPacket packet = mstore(keys, values, len, timestamp, isAck); if (!packet.isError) - return packet.response.string; + return packet.response.stringArray; else return NULL; } -ArancinoPacket ArancinoClass::__store( char* key, char* value, char* timestamp) { - - char* ts; +/******** API BASIC :: STORETAGS *********/ +ArancinoPacket ArancinoClass::storetags(char *key, char **tags, char **values, int len, char* timestamp, bool isAck) +{ if(timestamp==NULL){ - ts=getTimestamp(); + timestamp = getTimestamp(); } - else{ - ts = timestamp; + if ((key == NULL) || (tags == NULL) || (values == NULL) || (len <= 0)) + return invalidCommandErrorPacket; + + StaticJsonDocument cmd_doc; + JsonObject cmd_args = cmd_doc.createNestedObject("args"); + cmd_doc["cmd"] = STORETAGS_COMMAND; + JsonArray cmd_items = cmd_args.createNestedArray("items"); + for (int i=0; i(key, value, true, true, "rsvd"); } -/******** API BASIC :: MSTORE *********/ +/******** API BASIC :: GETRESERVED *********/ template <> -ArancinoPacket ArancinoClass::mstore(char **keys, char **values, int len) +ArancinoPacket ArancinoClass::getReserved(char *key, bool id_prefix) { - char *ts = getTimestamp(); - if ((keys == NULL) || (values == NULL) || (len <= 0)) - { + if (key == NULL && strcmp(key, "") == 0) return invalidCommandErrorPacket; - } - return executeCommand(MSTORE_COMMAND, NULL, keys, values, ts, len, false, STRING_ARRAY); -} -// template<> ArancinoPacket ArancinoClass::mstore (char** keys, char** values, int len,char* timestamp) { -// char* ts = timestamp; -// if ((keys == NULL) || (values == NULL) || (len <= 0)) { -// return invalidCommandErrorPacket; -// } -// return executeCommand(MSTORE_COMMAND, NULL, keys, values, ts, len, false, STRING_ARRAY); -// } - -template<> void ArancinoClass::mstore(char** keys, char** values, int len,char* timestamp) { - char* ts = timestamp; - if ((keys == NULL) || (values == NULL) || (len <= 0)) { - //return invalidCommandErrorPacket; - - } - return executeCommandFast(MSTORE_COMMAND, NULL, keys, values, ts, len, false, STRING_ARRAY); + + return get(key, true, "rsvd"); } template <> -char **ArancinoClass::mstore(char **key, char **value, int len) +char *ArancinoClass::getReserved(char *key, bool id_prefix) { - ArancinoPacket packet = mstore(key, value, len); + ArancinoPacket packet = getReserved(key, id_prefix); if (!packet.isError) - return packet.response.stringArray; + return packet.response.string; else return NULL; } -/******** API BASIC :: STORETAGS *********/ +char *ArancinoClass::getModuleVersion() +{ + char key[strlen(MODVERS_KEY) + 1]; + strcpy(key, MODVERS_KEY); + char *retString = getReserved(key, false); + return retString; +} -ArancinoPacket ArancinoClass::storetags(char *key, char **tags, char **values, int len) +char *ArancinoClass::getModuleLogLevel() { - char *ts = getTimestamp(); - if ((key == NULL) || (tags == NULL) || (values == NULL) || (len <= 0)) - return invalidCommandErrorPacket; - return executeCommand(STORETAGS_COMMAND, key, tags, values, ts, len, false, VOID); + char key[strlen(MODLOGLVL_KEY) + 1]; + strcpy(key, MODLOGLVL_KEY); + char *retString = getReserved(key, false); + return retString; +} + +char *ArancinoClass::getModuleEnvironment() +{ + char key[strlen(MODENV_KEY) + 1]; + strcpy(key, MODENV_KEY); + char *retString = getReserved(key, false); + return retString; +} + +char *ArancinoClass::getBlinkId() +{ + char key[strlen(BLINK_ID_KEY) + 1]; + strcpy(key, BLINK_ID_KEY); + char *retString = getReserved(key, true); + return retString; +} + +/******** API BASIC :: SETRESERVED *********/ + +ArancinoPacket ArancinoClass::setBlinkId(int value) +{ + char str[20] = ""; + itoa(value, str, 10); + return setReserved(BLINK_ID_KEY, str, true); } /******** API UTILITY :: FREE *********/ @@ -1181,459 +1053,222 @@ char *ArancinoClass::getTimestamp() return timestamp; } -/*char* ArancinoClass::getTimestamp() { - - unsigned long ts = rtc.getEpoch(); //10 digits - unsigned long mls_tmp = (millis() - millis_start) % 1000; - unsigned int ts_inf = ts % 1000000000; //last 9 digits of epoch - unsigned int ts_sup = ts/1000000000; //first digits of epoch - unsigned int mls =mls_tmp; //+ timestampMillis ; //millis + delta; - if(mls > 999){ //millis + delta is greater than 1 seconds (1000) - ts_inf=ts_inf+1; - if(ts_inf> 999999999){ - ts_sup=ts_sup+1; - ts_inf=0; - } - } - mls=mls % 1000; //last 3 digits of millis - - itoa(ts_sup, timestamp, 10); - char ts_tmp[9]; - sprintf(ts_tmp, "%09d", ts_inf); - strcat(timestamp, ts_tmp); - char mill[6]; - sprintf(mill, "%03d", mls); - strcat(timestamp, mill); - //itoa(ts, timestamp, 10); - return timestamp; -}*/ - /******** INTERNAL UTILS :: FREE *********/ -ArancinoPacket ArancinoClass::executeCommand(char *command, char *param1, char **params2, char **params3, char *param4, int len, bool id_prefix, int type_return) -{ - int commandLength = strlen(command); - int strLength = commandLength + 1; - int param1_length = 0; - int param4_length = 0; - uint8_t idSize = strlen(id); - - if (param1 != NULL) - { - param1_length = strlen(param1); - if (id_prefix) - { - param1_length += idSize + 1; - } - strLength += param1_length + 1; - } - - // Calculating Cortex Protocol command length - for (int i = 0; i < len; i++) - { - char *param2 = params2[i]; - char *param3 = NULL; - if (params3 != NULL) - param3 = params3[i]; - - int param2_length = strlen(param2); - if (id_prefix && param1 == NULL) - { - param2_length += idSize + 1; - } - int param3_length = 0; - if (params3 != NULL) - param3_length = strlen(param3); - // For every key-value pair the length of both tag and value is added - // two 1s are added in order to take into account the % chr and - // the # and @ chrs in the case of last tag or last value respectively - strLength += param2_length + 1; - if (params3 != NULL) - strLength += param3_length + 1; - } +ArancinoPacket ArancinoClass::executeCommand(char* cmd, char* key, char* field, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type){ + StaticJsonDocument cmd_doc; + StaticJsonDocument rsp_doc; + _buildArancinoJson(cmd_doc, cmd, key, field, argsHasItems, itemsHasDict, cfg); - if (param4 != NULL) - { - param4_length = strlen(param4); - strLength += param4_length + 1; - } - - char *str = (char *)calloc(strLength, sizeof(char)); - - strcpy(str, command); - if (param1 != NULL) - { - strcat(str, dataSplitStr); - if (id_prefix) - { - strcat(str, id); - strcat(str, ID_SEPARATOR); - } - strcat(str, param1); + #if defined(USEFREERTOS) + if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) { + #endif + _iface->_sendArancinoCommand(cmd_doc); + if(cmd_doc["cfg"]["ack"] == 1) + _iface->_receiveArancinoResponse(rsp_doc); + #if defined(USEFREERTOS) + giveCommMutex(); } - strcat(str, dataSplitStr); - // Points to the memory area where tags have to be written - char *params2Pointer = str + commandLength + strlen(dataSplitStr); - if (param1 != NULL) - params2Pointer += param1_length + strlen(dataSplitStr); - - // Points at the end of the string less the space reserved to timestamp - char *params3Pointer = NULL; - if (params3 != NULL) - params3Pointer = str + strLength; - if (param4 != NULL) - params3Pointer = params3Pointer - param4_length - strlen(endTXStr); - - // The string to send is built in 1 single loop. - // keys are copied from first to last (left to right in string) - // and values are copied from last to first (right to left in string) - for (int i = 0; i < len; i++) - { - char *param2 = params2[i]; - char *param3 = NULL; - if (params3 != NULL) - param3 = params3[len - (i + 1)]; - - if (id_prefix && param1 == NULL) - { - strcat(params2Pointer, id); - strcat(params2Pointer, ID_SEPARATOR); - } - strcat(params2Pointer, param2); - - if (i == len - 1) - { // If it's the last key we have to use #(\4) instead of %(\16) - if (params3 != NULL) - strcat(params2Pointer, dataSplitStr); - } - else - { - strcat(params2Pointer, arraySplitStr); - } - - // We use memcpy rather than strcat here because it would append \0, - // thus terminating the string prematurely - if (params3 != NULL) - { - params3Pointer -= strlen(param3) + 1; - - memcpy(params3Pointer, param3, strlen(param3)); + #endif - if (i != 0) - { - memcpy(params3Pointer + strlen(param3), arraySplitStr, 1); - } - } - } - // timestamp - if (param4 != NULL) - { - strcat(str, dataSplitStr); - strcat(str, param4); - } - strcat(str, endTXStr); + if(rsp_doc.isNull()) + return communicationErrorPacket; + + ArancinoPacket packet = createArancinoPacket(rsp_doc, response_type); + return packet; +} - char *message = NULL; - if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) - { - _iface->sendArancinoCommand(str); - message = _iface->receiveArancinoResponse(END_TX_CHAR); +ArancinoPacket executeCommand(char* cmd, char** keys, char** fields, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type){ + StaticJsonDocument cmd_doc; + StaticJsonDocument rsp_doc; + _buildArancinoJson(cmd_doc, cmd, keys, fields, len, argsHasItems, itemsHasDict, cfg); + + #if defined(USEFREERTOS) + if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) { + #endif + _iface->_sendArancinoCommand(cmd_doc); + if(cmd_doc["cfg"]["ack"] == 1) + _iface->_receiveArancinoResponse(rsp_doc); + #if defined(USEFREERTOS) giveCommMutex(); } + #endif - free(str); - - if (message == NULL) + if(rsp_doc.isNull()) return communicationErrorPacket; - - ArancinoPacket packet = createArancinoPacket(message, type_return); - - free(message); - + + ArancinoPacket packet = createArancinoPacket(rsp_doc, response_type); return packet; } +ArancinoPacket executeCommand(JsonDocument& cmd_doc, int response_type){ + StaticJsonDocument rsp_doc; -void ArancinoClass::executeCommandFast(char* command, char* param1, char** params2, char** params3, char* param4, int len, bool id_prefix, int type_return){ - int commandLength = strlen(command); - int strLength = commandLength + 1; - int param1_length = 0; - int param4_length = 0; - uint8_t idSize = strlen(id); - - if(param1 != NULL){ - param1_length = strlen(param1); - if(id_prefix){ - param1_length += idSize + 1; - } - strLength += param1_length + 1; - } - - // Calculating Cortex Protocol command length - for (int i = 0; i < len; i ++) { - char* param2 = params2[i]; - char* param3 = NULL; - if(params3 != NULL) - param3 = params3[i]; - - int param2_length = strlen(param2); - if(id_prefix && param1 == NULL){ - param2_length += idSize + 1; - } - int param3_length = 0; - if(params3 != NULL) - param3_length = strlen(param3); - // For every key-value pair the length of both tag and value is added - // two 1s are added in order to take into account the % chr and - // the # and @ chrs in the case of last tag or last value respectively - strLength += param2_length + 1; - if(params3 != NULL) - strLength +=param3_length + 1; + #if defined(USEFREERTOS) + if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) { + #endif + _iface->_sendArancinoCommand(cmd_doc); + if(cmd_doc["cfg"]["ack"] == 1) + _iface->_receiveArancinoResponse(rsp_doc); + #if defined(USEFREERTOS) + giveCommMutex(); } + #endif - if(param4 != NULL){ - param4_length = strlen(param4); - strLength += param4_length + 1; - } + if(rsp_doc.isNull()) + return communicationErrorPacket; + + ArancinoPacket packet = createArancinoPacket(rsp_doc, response_type); + return packet; +} - char* str = (char*) calloc(strLength, sizeof(char)); +ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, int response_type){ + ArancinoPacket packet; - strcpy(str, command); - if(param1 != NULL){ - strcat(str, dataSplitStr); - if(id_prefix){ - strcat(str, id); - strcat(str, ID_SEPARATOR); + switch(response_type){ + case VOID_RESPONSE: { + ArancinoPacket temp = {false, response_dict["rsp_code"], VOID, {.string = NULL}}; + packet = temp; + break; } - strcat(str, param1); - } - strcat(str, dataSplitStr); - // Points to the memory area where tags have to be written - char* params2Pointer = str + commandLength + strlen(dataSplitStr); - if(param1 != NULL) - params2Pointer += param1_length + strlen(dataSplitStr); - - // Points at the end of the string less the space reserved to timestamp - char* params3Pointer = NULL; - if(params3 != NULL) - params3Pointer = str + strLength; - if(param4 != NULL) - params3Pointer = params3Pointer - param4_length - strlen(endTXStr); - - // The string to send is built in 1 single loop. - // keys are copied from first to last (left to right in string) - // and values are copied from last to first (right to left in string) - for(int i = 0; i < len; i ++) { - char* param2 = params2[i]; - char* param3 = NULL; - if(params3 != NULL) - param3 = params3[len - (i + 1)]; - - if(id_prefix && param1 == NULL){ - strcat(params2Pointer, id); - strcat(params2Pointer, ID_SEPARATOR); + case KEY_VALUE_RESPONSE: { + JsonArray resp_items = response_dict["args"]["items"]; + int resp_size = resp_items.size(); + if (resp_size > 0 && resp_size < 2) { + ArancinoPacket temp = {false, response_dict["rsp_code"], STRING, {.string = resp_items[0]["value"]}}; + packet = temp; + } else if (resp_size > 1) { + const char* resp_values[resp_size]; + for (int i=0; i 0 && resp_size < 2) { + ArancinoPacket temp = {false, response_dict["rsp_code"], STRING, {.string = response_dict["args"]["items"][0]["value"]}}; + packet = temp; + } else if (resp_size > 1) { + const char* resp_values[resp_size]; + for (int i=0; isendArancinoCommand(str); - giveCommMutex(); - } - - free(str); - -} - - -ArancinoPacket ArancinoClass::executeCommand(char* command, char* param1, char* param2, char* param3, bool id_prefix, int type_return){ - int commandLength = strlen(command); - int param1_length = 0; - uint8_t idSize = strlen(id); - - if (param1 != NULL) - { - param1_length = strlen(param1); - if (id_prefix) - { - param1_length += idSize + 1; + case ITEMS_RESPONSE: { + JsonArray resp_items = response_dict["args"]["items"]; + if (resp_size > 0 && resp_size < 2) { + ArancinoPacket temp = {false, response_dict["rsp_code"], STRING, {.string = resp_items[0]}}; + packet = temp; + } else if (resp_size > 1) { + const char* resp_values[resp_size]; + for (int i=0; isendArancinoCommand(str); - message = _iface->receiveArancinoResponse(END_TX_CHAR); - giveCommMutex(); + default: + return invalidCommandErrorPacket; } - - free(str); - - if (message == NULL) - return communicationErrorPacket; - // parse response - ArancinoPacket packet = createArancinoPacket(message, type_return); - - free(message); - - return packet; -} - -void ArancinoClass::executeCommandFast(char* command, char* param1, char* param2, char* param3, bool id_prefix, int type_return){ - int commandLength = strlen(command); - int param1_length = 0; - uint8_t idSize = strlen(id); - if(param1 != NULL){ - param1_length = strlen(param1); - if(id_prefix){ - param1_length += idSize + 1; - } - } - int param2_length = 0; - if(param2 != NULL) - param2_length=strlen(param2); - int param3_length = 0; - if(param3 != NULL) - param3_length=strlen(param3); - int strLength = commandLength + 1 + param1_length + 1 + param2_length + 1 + param3_length + 1 + 1; - - char* str = (char *)calloc(strLength, sizeof(char)); - - - #if defined(__SAMD21G18A__) - if(!digitalRead(DBG_PIN)){ - Serial.print(SENT_STRING); - } - #endif +} - strcpy(str, command); - if(param1 != NULL){ - strcat(str, dataSplitStr); - if(id_prefix){ - strcat(str, id); - strcat(str, ID_SEPARATOR); +void ArancinoClass::_buildArancinoJson(JsonDocument& cmd_doc, char* cmd, char* key, char* field, char* value, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg){ + JsonObject cmd_args = cmd_doc.createNestedObject("args"); + cmd_doc["cmd"] = cmd; + + if (argsHasItems){ + JsonArray cmd_items = cmd_args.createNestedArray("items"); + if (itemsHasDict){ + JsonObject items_obj = cmd_items.createNestedObject(); + + if (key){ + items_obj["key"] = key; + } + + if (field){ + items_obj["field"] = field; + } + + if(value){ + items_obj["value"] = value; + } + } else { + cmd_items.add(key); + } + } + + JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); + if (cfg.pers){ + cmd_cfg["pers"] = cfg.pers == CFG_FALSE ? 0 : 1; + } + if (cfg.ack){ + cmd_cfg["ack"] = cfg.ack == CFG_FALSE ? 0 : 1; + } + if (cfg.type){ + cmd_cfg["type"] = cfg.type; + } +} + +void ArancinoClass::_buildArancinoJson(JsonDocument& cmd_doc, char* cmd, char** keys, char** fields, char** values, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg){ + JsonObject cmd_args = cmd_doc.createNestedObject("args"); + cmd_doc["cmd"] = cmd; + + if (argsHasItems){ + JsonArray cmd_items = cmd_args.createNestedArray("items"); + if (itemsHasDict){ + for (int i=0; isendArancinoCommand(str); - giveCommMutex(); } - free(str); - -} - -ArancinoPacket ArancinoClass::createArancinoPacket(char* message, int type_return){ - ArancinoPacket packet; - if (message == NULL) - return communicationErrorPacket; - if (type_return == VOID) - { - ArancinoPacket temp = {false, _getResponseCode(message), VOID, {.string = NULL}}; - packet = temp; + JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); + if (cfg.pers){ + cmd_cfg["pers"] = cfg.pers == CFG_FALSE ? 0 : 1; } - else if (type_return == INT) - { - char *messageParsed = _parse(message); - ArancinoPacket temp = {false, _getResponseCode(message), INT, {.integer = atoi(messageParsed)}}; - free(messageParsed); - packet = temp; + if (cfg.ack){ + cmd_cfg["ack"] = cfg.ack == CFG_FALSE ? 0 : 1; } - else if (type_return == STRING) - { - ArancinoPacket temp = {false, _getResponseCode(message), STRING, {.string = _parse(message)}}; - packet = temp; - } - else if (type_return == STRING_ARRAY) - { - ArancinoPacket temp = {false, _getResponseCode(message), STRING_ARRAY, {.stringArray = _parseArray(_parse(message))}}; - packet = temp; + if (cfg.type){ + cmd_cfg["type"] = cfg.type; } - else - { - ArancinoPacket temp = invalidCommandErrorPacket; - packet = temp; - } - return packet; } void ArancinoClass::systemReset(){ diff --git a/src/Arancino.h b/src/Arancino.h index 23dca98..a8809b5 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -32,6 +32,8 @@ under the License #include #include +#include + //#define USEFREERTOS #if defined(USEFREERTOS) #if defined(__SAMD21G18A__) @@ -95,6 +97,12 @@ typedef struct { char* tzoffset; } ArancinoMetadata; +typedef struct { + uint8_t pers = CFG_UNSET; + uint8_t ack = CFG_UNSET; + const char* type = CFG_UNSET; + //const char* signature +} ArancinoCFG; @@ -122,89 +130,70 @@ class ArancinoClass { void begin(ArancinoMetadata amdata, ArancinoConfig aconfig); void begin(ArancinoMetadata amdata); - //MSET - ArancinoPacket mset(char** keys, char** values, int len, bool isPersistent = false); + ArancinoPacket set(char* key, int value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket set(char* key, double value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket set(char* key, float value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket set(char* key, long value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket set(char* key, uint32_t value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket set(char* key, char* value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); - ArancinoPacket set(char* key, int value, bool isPersistent = false); - ArancinoPacket set(char* key, double value, bool isPersistent = false); - ArancinoPacket set(char* key, float value, bool isPersistent = false); - ArancinoPacket set(char* key, long value, bool isPersistent = false); - ArancinoPacket set(char* key, char* value, bool isPersistent = false); - ArancinoPacket set(char* key, uint32_t value, bool isPersistent = false); + //MSET + ArancinoPacket mset(char** keys, char** values, int len, bool isAck, bool isPersistent = false, const char* type = "appl"); //GET - template T get(char* key); + template T get(char* key, bool isPersistent = false, const char* type = "appl"); - //GETRESERVED - char* getModuleVersion(); - char* getModuleLogLevel(); - char* getModuleEnvironment(); - char* getBlinkId(); - - //SETRESERVED - ArancinoPacket setBlinkId(int value) ; + //MGET + template T mget(char** keys, int len, bool isPersistent = false, const char* type = "appl"); //DEL - template T del(char* key); + template T del(char* key, bool isAck = true, bool isPersistent = false, const char* type = "appl"); //HSET - ArancinoPacket hset(char* key, char* field, char* value, bool isPersistent = false); - ArancinoPacket hset(char* key, char* field, int value, bool isPersistent = false); - ArancinoPacket hset(char* key, char* field, float value, bool isPersistent = false); - ArancinoPacket hset(char* key, char* field, double value, bool isPersistent = false); - ArancinoPacket hset(char* key, char* field, uint32_t value, bool isPersistent = false); - ArancinoPacket hset(char* key, char* field, long value, bool isPersistent = false); - - //MGET - template T mget(char** keys, int len); + ArancinoPacket hset(char* key, char* field, char* value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket hset(char* key, char* field, int value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket hset(char* key, char* field, float value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket hset(char* key, char* field, double value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket hset(char* key, char* field, uint32_t value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket hset(char* key, char* field, long value, bool isAck = true, bool isPersistent = false, const char* type = "appl"; //HGET - template T hget(char* key, char* field); - - //HGETALL - template T hgetall(char* key); - - //HKEYS - template T hkeys(char* key); - - //HVALS - template T hvals(char* key); + template T hget(char* key, char* field, bool isPersistent = true, const char* type = "appl"); //HDEL - template T hdel(char* key, char* field); - - //KEYS - template T keys(char* pattern="*"); + template T hdel(char* key, char* field, bool isAck = true, bool isPersistent = false); //PUBLISH - template T publish(char* channel, char* msg); - template T publish(char* channel, double msg); - template T publish(char* channel, int msg); - template T publish(char* channel, uint32_t msg); - template T publish(char* channel, long msg); + template T publish(char* channel, char* msg, bool isAck = true); + template T publish(char* channel, double msg, bool isAck = true); + template T publish(char* channel, int msg, bool isAck = true); + template T publish(char* channel, uint32_t msg, bool isAck = true); + template T publish(char* channel, long msg, bool isAck = true); //FLUSH - ArancinoPacket flush(void); + ArancinoPacket flush(bool isAck = true, bool isPersistent = false); //STORE - template T store(char* key, int value); - template T store(char* key, uint32_t value); - template T store(char* key, double value); - template T store(char* key, float value); - template T store(char* key, long value); - - template T store(char* key, int value,char* timestamp); - template T store(char* key, uint32_t value,char* timestamp); - template T store(char* key, double value,char* timestamp); - template T store(char* key, float value,char* timestamp); - template T store(char* key, long value,char* timestamp); + template T store(char* key, int value, bool isAck = true, char* timestamp = NULL, bool isAck = true); + template T store(char* key, uint32_t value, bool isAck = true, char* timestamp = NULL, bool isAck = true); + template T store(char* key, double value, bool isAck = true, char* timestamp = NULL, bool isAck = true); + template T store(char* key, float value, bool isAck = true, char* timestamp = NULL, bool isAck = true); + template T store(char* key, long value, bool isAck = true, char* timestamp = NULL, bool isAck = true); //MSTORE - template T mstore(char** keys, char** values, int len); - template T mstore(char** keys, char** values, int len,char* timestamp); + template T mstore(char** keys, char** values, int len, char* timestamp = NULL, bool isAck = true); //STORE TAGS - ArancinoPacket storetags(char* key, char** tags, char** values, int len); + ArancinoPacket storetags(char* key, char** tags, char** values, int len, char* timestamp = NULL, bool isAck = true); + + //GETRESERVED + char* getModuleVersion(); + char* getModuleLogLevel(); + char* getModuleEnvironment(); + char* getBlinkId(); + + //SETRESERVED + ArancinoPacket setBlinkId(int value) ; /***** DEBUG OPTIONS *****/ @@ -274,8 +263,8 @@ class ArancinoClass { void _freePacket(ArancinoPacket packet); ArancinoPacket __set(char* key, char* value, bool isPersistent); - ArancinoPacket __publish(char* channel, char* msg); - ArancinoPacket __store(char* key, char* value,char* timestamp=NULL); + ArancinoPacket __publish(char* channel, char* msg, bool isAck = true); + ArancinoPacket __store(char* key, char* value, char* timestamp=NULL, bool isAck = true); template T getReserved(char* key, bool id_prefix); @@ -299,12 +288,19 @@ class ArancinoClass { void taskResume(); //execute command - ArancinoPacket executeCommand(char* command_id, char* param1, char** params2, char** params3, char* param4, int len, bool id_prefix, int response_type); - ArancinoPacket executeCommand(char* command_id, char* param1, char* param2, char*param3, bool id_prefix, int response_type); - void executeCommandFast(char* command, char* param1, char* param2, char* param3, bool id_prefix, int type_return); - void executeCommandFast(char* command, char* param1, char** params2, char** params3, char* param4, int len, bool id_prefix, int type_return); + ArancinoPacket createArancinoPacket(char* response_raw, int response_type); + ArancinoPacket executeCommand(const char* cmd, char* key, char* field, const char* value, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type); + ArancinoPacket executeCommand(const char* cmd, char** keys, char** fields, char** values, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type); + ArancinoPacket executeCommand(JsonDocument& cmd_doc, int response_type); + ArancinoPacket createArancinoPacket(JsonDocument& response_dict, int response_type); + + + void _buildArancinoJson(JsonDocument& doc, const char* cmd, const char* key, const char* field, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg); + void _buildArancinoJson(JsonDocument& doc, const char* cmd, const char** keys, const char** fields, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg); + + //Protocol interface ArancinoIface* _iface; diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index 5e04b02..dfafacb 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -128,4 +128,18 @@ under the License #define MQTT_MAX_RETRIES 100 #define BLUETOOTH_MAX_RETRIES 100 -#define ID_SIZE IDSIZE*2 //IDSIZE will be provided by microcontroller-id library \ No newline at end of file +#define ID_SIZE IDSIZE*2 //IDSIZE will be provided by microcontroller-id library + +//MsgPack +#define CMD_DOC_SIZE 512 +#define RSP_DOC_SIZE 256 +#define CFG_UNSET 0 +#define CFG_TRUE 1 +#define CFG_FALSE 2 + +#define VOID_RESPONSE 0 +#define KEY_VALUE_RESPONSE 1 +#define KEY_RESPONSE 2 +#define FIELDS_ITEMS_RESPONSE 3 +#define ITEMS_RESPONSE 4 +#define CLIENTS_RESPONSE 5 \ No newline at end of file From f497670b972e71205267340588838ad72f3f75a7 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Thu, 13 Oct 2022 16:30:42 +0200 Subject: [PATCH 02/69] Initial support for ESP32 --- src/Arancino.cpp | 13 ++++++++++--- src/Arancino.h | 10 ++++++++++ src/ArancinoDefinitions.h | 16 ++++++++++++++++ src/ArancinoTasks.cpp | 10 +++++++--- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index bdb49c9..9f55cda 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -71,6 +71,9 @@ void ArancinoClass::begin(ArancinoMetadata _amdata) } void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg) { +#if defined(ARDUINO_ARCH_ESP32) + esp_task_wdt_init(120, true); +#endif MicroID.getUniqueIDString(id, ID_SIZE/2); _iface->ifaceBegin(); @@ -127,9 +130,9 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg) { } //TASK ArancinoTasks _atask; - xTaskCreate(_atask.deviceIdentification, "identification", 256, NULL, ARANCINO_TASK_PRIORITY, &arancinoHandle1); - xTaskCreate(_atask.interoception, "interoception", 256, NULL, ARANCINO_TASK_PRIORITY, &arancinoHandle2); - xTaskCreate(_atask.sendHeartbeat, "heartbeat", 256, NULL, ARANCINO_TASK_PRIORITY, &arancinoHandle3); + xTaskCreate(_atask.deviceIdentification, "identification", IDENTIFICATION_STACK, NULL, ARANCINO_TASK_PRIORITY, &arancinoHandle1); + xTaskCreate(_atask.interoception, "interoception", INTEROCEPTION_STACK, NULL, ARANCINO_TASK_PRIORITY, &arancinoHandle2); + xTaskCreate(_atask.sendHeartbeat, "heartbeat", HEARTBEAT_STACK, NULL, ARANCINO_TASK_PRIORITY, &arancinoHandle3); #endif } @@ -183,6 +186,8 @@ void ArancinoClass::startScheduler() vTaskStartScheduler(); #elif defined(ARDUINO_ARANCINOV12_H743ZI) || defined(ARDUINO_ARANCINOV12_H743ZI2) vTaskStartScheduler(); +#elif defined(ARDUINO_ARCH_ESP32) + #else #error "FreeRTOS not supported on the selected board!" #endif @@ -1016,6 +1021,8 @@ void *ArancinoClass::calloc(size_t nmemb, size_t _size) uint8_t *ptr = (uint8_t *)malloc(nmemb * (_size)); memset(ptr, 0, nmemb); // clear the buffer #pte4c0 return ptr; +#elif defined(ARDUINO_ARCH_ESP32) + return std::calloc(nmemb, _size); #else return pvPortCalloc(nmemb, _size); #endif diff --git a/src/Arancino.h b/src/Arancino.h index 7817da0..ab803f1 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -30,7 +30,11 @@ under the License #include #include #include +#if defined(ARDUINO_ARCH_ESP32) +#include +#else #include +#endif //#define USEFREERTOS #if defined(USEFREERTOS) @@ -70,6 +74,12 @@ extern "C" { #include #endif +#if defined(ARDUINO_ARCH_ESP32) +#include +#define pvPortMalloc std::malloc +#define vPortFree std::free +#endif + //Power Mode enum POWER_MODE { BATTERY = 0, diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index 6812eb5..4143a4a 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -36,6 +36,11 @@ under the License #define SERIAL_PORT Serial #endif #define SERIAL_DEBUG Serial1 +#elif defined(ARDUINO_ARCH_ESP32) +#define BAUDRATE 115200 +#define TIMEOUT 10000 +#define SERIAL_PORT Serial +#define SERIAL_DEBUG Serial1 #else #define BAUDRATE 256000 #define TIMEOUT 10000 @@ -124,7 +129,18 @@ under the License //MAX UNSIGNED LONG VALUE #define MAX_UNSIGNED_LONG_VALUE 4294967295 +#if defined(ARDUINO_ARCH_ESP32) +//ESP32 configMAX_PRIORITIES is 25 +#define ARANCINO_TASK_PRIORITY 20 +#define IDENTIFICATION_STACK configMINIMAL_STACK_SIZE * 4 +#define INTEROCEPTION_STACK configMINIMAL_STACK_SIZE * 4 +#define HEARTBEAT_STACK configMINIMAL_STACK_SIZE * 4 +#else #define ARANCINO_TASK_PRIORITY 2 +#define IDENTIFICATION_STACK 256 +#define INTEROCEPTION_STACK 256 +#define HEARTBEAT_STACK 256 +#endif #define MQTT_MAX_RETRIES 100 #define BLUETOOTH_MAX_RETRIES 100 diff --git a/src/ArancinoTasks.cpp b/src/ArancinoTasks.cpp index a974841..95e2d55 100644 --- a/src/ArancinoTasks.cpp +++ b/src/ArancinoTasks.cpp @@ -22,7 +22,11 @@ under the License #if defined(__SAMD21G18A__) #include #endif +#if defined(ARDUINO_ARCH_ESP32) +#include +#else #include +#endif #if defined(ARDUINO_ARANCINOV12_H743ZI) || defined(ARDUINO_ARANCINOV12_H743ZI2) #include "stm32yyxx_ll_adc.h" #define CALX_TEMP 25 @@ -41,7 +45,7 @@ void ArancinoTasks::deviceIdentification(void *pvPramaters){ while (1) { char* value = Arancino.getBlinkId(); - if(!strcmp(value,"1")){ + if(value != NULL && !strcmp(value,"1")){ for(int i=0;i < 20; i++){ #if defined (ARDUINO_ARANCINO_VOLANTE) digitalWrite(LED_BUILTIN,LOW); @@ -66,7 +70,7 @@ void ArancinoTasks::deviceIdentification(void *pvPramaters){ void ArancinoTasks::interoception(void *pvPramaters){ while (1) { - #if !defined(ARDUINO_ARANCINO_VOLANTE) && !defined(ARDUINO_ARCH_RP2040) + #if !defined(ARDUINO_ARANCINO_VOLANTE) && !defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_ESP32) //free memory int memory_free = xPortGetFreeHeapSize(); char mem_free[20]; @@ -87,7 +91,7 @@ void ArancinoTasks::interoception(void *pvPramaters){ char mem_used_key[]="MEM_USED"; char mem_tot_key[]="MEM_TOT"; char temp_key[]="TEMP"; - #if defined(ARDUINO_ARANCINO_VOLANTE) || defined(ARDUINO_ARCH_RP2040) + #if defined(ARDUINO_ARANCINO_VOLANTE) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_ESP32) char* keys[] = {mem_tot_key,temp_key}; char* values[] = {mem_tot,temp}; ArancinoPacket acpkt = Arancino.mstore(keys,values,2); From 7512dfe0cf96a2cc794bb06c7bd2ca0eab814ef1 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Fri, 14 Oct 2022 10:13:43 +0200 Subject: [PATCH 03/69] Implemented ESP32 custom serial definition --- src/Arancino.h | 1 + src/ArancinoDefinitions.h | 22 ++++++++++++++++++++-- src/ArancinoInterface.cpp | 10 ++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Arancino.h b/src/Arancino.h index ab803f1..6947a6c 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -75,6 +75,7 @@ extern "C" { #endif #if defined(ARDUINO_ARCH_ESP32) +#include #include #define pvPortMalloc std::malloc #define vPortFree std::free diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index 4143a4a..cc66f5b 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -37,10 +37,28 @@ under the License #endif #define SERIAL_DEBUG Serial1 #elif defined(ARDUINO_ARCH_ESP32) +/* + Enable CUSTOM_SERIAL if you want to use a custom serial port + other than Serial1 (SERIAL_PORT defined below) +*/ +#define CUSTOM_SERIAL + #define BAUDRATE 115200 #define TIMEOUT 10000 -#define SERIAL_PORT Serial -#define SERIAL_DEBUG Serial1 + +#if defined(CUSTOM_SERIAL) +#define SERIAL_PORT SerialPort +#define UARTx 1 //UART1 +#define UART_TX 13 +#define UART_RX 15 +#else +/* + If CUSTOM_SERIAL is disabled and you want to use a standard + serial (e.g. Serial 1) define it here: +*/ +#define SERIAL_PORT Serial1 +#endif +#define SERIAL_DEBUG Serial #else #define BAUDRATE 256000 #define TIMEOUT 10000 diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index dd95d26..4be1f6d 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -21,6 +21,10 @@ under the License #include "ArancinoInterface.h" #include +#if defined(ARDUINO_ARCH_ESP32) && defined(CUSTOM_SERIAL) +HardwareSerial SERIAL_PORT(UARTx); +#endif + /* All the interface specific methods should be placed here */ @@ -83,7 +87,13 @@ void SerialIface::setSerialPort(Stream& serialPort){ void SerialIface::setSerialPort(){ //default implementation for Arancino boards #if defined (SERIAL_PORT) && defined(BAUDRATE) && defined (TIMEOUT) + + #if defined(ARDUINO_ARCH_ESP32) && defined(UART_RX) && defined(UART_TX) + SERIAL_PORT.begin(BAUDRATE, SERIAL_8N1, UART_RX, UART_TX); + #else SERIAL_PORT.begin(BAUDRATE); + #endif + SERIAL_PORT.setTimeout(TIMEOUT); this->_serialPort = &SERIAL_PORT; #endif From 7a05784342ebd41c5ad2c830e394123a9dc43440 Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Fri, 14 Oct 2022 10:19:47 +0200 Subject: [PATCH 04/69] Additional implementation for cortex commands. Further implementations required --- src/Arancino.cpp | 388 ++++++++++++++------------------------ src/Arancino.h | 79 ++++---- src/ArancinoDefinitions.h | 6 +- src/ArancinoInterface.cpp | 41 ++-- src/ArancinoInterface.h | 15 +- 5 files changed, 198 insertions(+), 331 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index cbdd858..d78476b 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -63,17 +63,20 @@ void ArancinoClass::delay(long milli){ /******** API BASIC :: BEGIN *********/ -void ArancinoClass::begin(ArancinoMetadata _amdata) +void ArancinoClass::begin(ArancinoMetadata _amdata, char* custom_v1, char* custom_v2) { ArancinoConfig _acfg; // setting default configuration value begin(_amdata, _acfg); } -void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg) { +void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, char* custom_v1, char* custom_v2) { MicroID.getUniqueIDString(id, ID_SIZE/2); _iface->ifaceBegin(); + + return; + arancino_id_prefix = _acfg.USE_PORT_ID_PREFIX_KEY; decimal_digits = _acfg.DECIMAL_DIGITS; @@ -93,13 +96,6 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg) { strcat(str_build_time, " "); strcat(str_build_time, _metadata.tzoffset); - char fw_lib_ver[]="FW_LIB_VER"; - char fw_name[]="FW_NAME"; - char fw_ver[]="FW_VER"; - char fw_build_time[]="FW_BUILD_TIME"; - char fw_core_ver[]="FW_CORE_VER"; - char mcu_family[]="MCU_FAMILY"; - char fw_use_freertos[]="FW_USE_FREERTOS"; #if defined(USEFREERTOS) if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { @@ -111,14 +107,32 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg) { char* useFreeRtos = "0"; #endif - /* - char* keys[] = {fw_lib_ver,fw_name,fw_ver,fw_build_time,fw_core_ver, mcu_family, fw_use_freertos}; - char* values[] = {LIB_VERSION, _metadata.fwname,_metadata.fwversion,str_build_time,(char*)ARANCINO_CORE_VERSION,(char*)MCU_FAMILY,(char*)useFreeRtos}; + StaticJsonDocumentcmd_doc; + //Build start json + cmd_doc["cmd"] = START_COMMAND; + JsonObject cmd_args = cmd_doc.createNestedObject("args"); + cmd_args["port_id"] = id; + cmd_args["fw_mcu_family"] = (char*)MCU_FAMILY; + cmd_args["fw_lib_ver"] = LIB_VERSION; + cmd_args["fw_name"] = _metadata.fwname; + cmd_args["fw_ver"] = _metadata.fwversion; + cmd_args["fw_build_time"] = str_build_time; + cmd_args["fw_core_ver"] = (char*)ARANCINO_CORE_VERSION; + cmd_args["fw_crtx_ver"] = CRTX_VERSION; + if(custom_v1) + cmd_args["CUSTOM_KEY_1"] = custom_v1; + if(custom_v2) + cmd_args["CUSTOM_KEY_2"] = custom_v2; + JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); + + //Hard coded. Secure mode is not available yet + cmd_cfg["scr_mod"] = 0; + cmd_cfg["crt_sig"] = "None"; + cmd_cfg["crt_dev"] = "None"; - start(keys,values,7); + start(cmd_doc); started = true; - */ - + strcpy(LOG_LEVEL,getModuleLogLevel()); #if defined(USEFREERTOS) /* All the FreeRTOS initialization should be put here, at the end of the @@ -138,8 +152,45 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg) { /******** API BASIC :: START *********/ -void ArancinoClass::start(char **keys, char **values, int len) -{ +void ArancinoClass::start(JsonDocument& cmd_doc) { + ArancinoPacket packet; + do + { + StaticJsonDocumentrsp_doc; + bool error; + + #if defined(USEFREERTOS) + if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) { + #endif + _iface->sendArancinoCommand(cmd_doc); + error = _iface->receiveArancinoResponse(rsp_doc); + #if defined(USEFREERTOS) + giveCommMutex(); + } + #endif + + if (!error) { + //Handle start response + if (rsp_doc["rsp_code"] == 100){ + strcpy(DAEMON_VER, rsp_doc["args"]["dmn_ver"]); + strcpy(DAEMON_ENV, rsp_doc["args"]["dmn_env"]); + + //Timestamp handling + const char* ts = rsp_doc["cfg"]["ts"]; + memcpy(timestamp, ts, 4); + char tmst_part[5]; + memcpy(tmst_part, timestamp, 4); + tmst_sup = atoi(tmst_part); // first 4 digits of epoch + tmst_inf = atoi(×tamp[4]); // last 4 digits of epoch + millis_previous = millis(); + } + } + + //Retry communication every 2.5 seconds of blocking delay + delay(2500); + } while (packet.isError == true || packet.responseCode != RSP_OK); + free(packet); + } #if defined(USEFREERTOS) @@ -257,7 +308,7 @@ ArancinoPacket ArancinoClass::set(char *key, char *value, bool isAck, bool isPer /******** API BASIC :: MSET *********/ -ArancinoPacket ArancinoClass::mset(char **keys, char **values, int len, bool isPersistent, char* type ) +ArancinoPacket ArancinoClass::mset(char **keys, char **values, int len, bool isAck, bool isPersistent, char* type ) { if ((keys == NULL) || (values == NULL) || (len <= 0)) return invalidCommandErrorPacket; @@ -294,7 +345,7 @@ template <> char *ArancinoClass::get(char* key, bool isPersistent, char* type) /******** API BASIC :: MGET *********/ -template <> ArancinoPacket ArancinoClass::mget(char **keys, int len, bool isPersistent, const char* type) +template <> ArancinoPacket ArancinoClass::mget(char **keys, int len, bool isPersistent, char* type) { if ((keys == NULL) || (len <= 0)) return invalidCommandErrorPacket; @@ -305,7 +356,7 @@ template <> ArancinoPacket ArancinoClass::mget(char **keys, int return executeCommand(GET_COMMAND, keys, NULL, NULL, len, true, false, cfg, KEY_VALUE_RESPONSE); } -template <> char **ArancinoClass::mget(char** keys, int len, bool isPersistent, const char* type) +template <> char **ArancinoClass::mget(char** keys, int len, bool isPersistent, char* type) { ArancinoPacket packet = mget(keys, len, isPersistent, type); if (packet.isError) @@ -316,7 +367,7 @@ template <> char **ArancinoClass::mget(char** keys, int len, bool isPersistent, /******** API BASIC :: DEL *********/ template <> -ArancinoPacket ArancinoClass::del(char* key, bool isAck, bool isPersistent, const char* type) +ArancinoPacket ArancinoClass::del(char* key, bool isAck, bool isPersistent, char* type) { if (key == NULL && strcmp(key, "") == 0) return invalidCommandErrorPacket; @@ -329,7 +380,7 @@ ArancinoPacket ArancinoClass::del(char* key, bool isAck, bool is } template <> -int ArancinoClass::del(char* key, bool isAck, bool isPersistent, const char* type) +int ArancinoClass::del(char* key, bool isAck, bool isPersistent, char* type) { ArancinoPacket packet = del(key, isAck, isPersistent, type); if (!packet.isError) @@ -340,42 +391,42 @@ int ArancinoClass::del(char* key, bool isAck, bool isPersistent, const char* typ /******** API BASIC :: HSET *********/ -ArancinoPacket ArancinoClass::hset(char *key, char *field, int value, bool isAck, bool isPersistent, const char* type) +ArancinoPacket ArancinoClass::hset(char *key, char *field, int value, bool isAck, bool isPersistent, char* type) { char str[20]; itoa(value, str, 10); return hset(key, field, str, isAck, isPersistent, type); } -ArancinoPacket ArancinoClass::hset(char *key, char *field, float value, bool isAck, bool isPersistent, const char* type) +ArancinoPacket ArancinoClass::hset(char *key, char *field, float value, bool isAck, bool isPersistent, char* type) { char str[20] = ""; _floatToString(value, decimal_digits, str); return hset(key, field, str); } -ArancinoPacket ArancinoClass::hset(char *key, char *field, double value, bool isAck, bool isPersistent, const char* type) +ArancinoPacket ArancinoClass::hset(char *key, char *field, double value, bool isAck, bool isPersistent, char* type) { char str[20] = ""; _doubleToString(value, decimal_digits, str); return hset(key, field, str, isAck, isPersistent, type); } -ArancinoPacket ArancinoClass::hset(char *key, char *field, uint32_t value, bool isAck, bool isPersistent, const char* type) +ArancinoPacket ArancinoClass::hset(char *key, char *field, uint32_t value, bool isAck, bool isPersistent, char* type) { char str[20]; itoa(value, str, 10); return hset(key, field, str, isAck, isPersistent, type); } -ArancinoPacket ArancinoClass::hset(char *key, char *field, long value, bool isAck, bool isPersistent, const char* type) +ArancinoPacket ArancinoClass::hset(char *key, char *field, long value, bool isAck, bool isPersistent, char* type) { char str[20]; itoa(value, str, 10); return hset(key, field, str, isAck, isPersistent, type); } -ArancinoPacket ArancinoClass::hset(char *key, char *field, char *value, bool isAck, bool isPersistent, const char* type) +ArancinoPacket ArancinoClass::hset(char *key, char *field, char *value, bool isAck, bool isPersistent, char* type) { if (key == NULL && field == NULL || value == NULL || strcmp(key, "") == 0 || strcmp(field, "") == 0) return invalidCommandErrorPacket; @@ -390,7 +441,7 @@ ArancinoPacket ArancinoClass::hset(char *key, char *field, char *value, bool isA /******** API BASIC :: HGET *********/ template <> -ArancinoPacket ArancinoClass::hget(char *key, char *field, bool isPersistent, const char* type) +ArancinoPacket ArancinoClass::hget(char *key, char *field, bool isPersistent, char* type) { if (key == NULL || field == NULL || strcmp(key, "") == 0 || strcmp(field, "") == 0) return invalidCommandErrorPacket; @@ -402,7 +453,7 @@ ArancinoPacket ArancinoClass::hget(char *key, char *field, bool } template <> -char *ArancinoClass::hget(char *key, char *field, bool isPersistent, const char* type) +char *ArancinoClass::hget(char *key, char *field, bool isPersistent, char* type) { ArancinoPacket packet = hget(key, field, isPersistent, type); if (!packet.isError) @@ -557,14 +608,14 @@ ArancinoPacket ArancinoClass::flush(bool isAck, bool isPersistent) { ArancinoCFG cfg; cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; - cfg.persistent = isPersistent ? CFG_TRUE : CFG_FALSE; + cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; return executeCommand(FLUSH_COMMAND, NULL, NULL, NULL, false, false, cfg, VOID_RESPONSE); } /******** API BASIC :: STORE *********/ template <> -ArancinoPacket ArancinoClass::store(char *key, int value, char* timestamp, bool isAck,) +ArancinoPacket ArancinoClass::store(char *key, int value, char* timestamp, bool isAck) { char str[20] = ""; itoa(value, str, 10); @@ -584,7 +635,7 @@ char *ArancinoClass::store(char *key, int value, char* timestamp, bool isAck) } template <> -ArancinoPacket ArancinoClass::store(char *key, uint32_t value, bool isAck, char* timestamp) +ArancinoPacket ArancinoClass::store(char *key, uint32_t value, char* timestamp, bool isAck) { char str[20] = ""; itoa(value, str, 10); @@ -604,7 +655,7 @@ char *ArancinoClass::store(char *key, uint32_t value, char* timestamp, bool isAc } template <> -ArancinoPacket ArancinoClass::store(char *key, long value, bool isAck, char* timestamp) +ArancinoPacket ArancinoClass::store(char *key, long value, char* timestamp, bool isAck) { char str[20] = ""; itoa(value, str, 10); @@ -632,7 +683,7 @@ ArancinoPacket ArancinoClass::store(char *key, float value, char } template <> -char *ArancinoClass::store(char *key, float value, bool isAck, char* timestamp) +char *ArancinoClass::store(char *key, float value, char* timestamp, bool isAck) { char str[20] = ""; _floatToString(value, decimal_digits, str); @@ -705,7 +756,7 @@ void ArancinoClass::mstore(char** keys, char** values, int len, char* timestamp, if ((keys == NULL) || (values == NULL) || (len <= 0)) { return; } - ArancinoPacket packet = mstore(keys, values, len, timestamp, isAck); + ArancinoPacket packet = mstore(keys, values, len, timestamp, isAck); free (packet); } @@ -716,9 +767,9 @@ char **ArancinoClass::mstore(char** keys, char** values, int len, char* timestam timestamp = getTimestamp(); } if ((keys == NULL) || (values == NULL) || (len <= 0)) { - return; + return NULL; } - ArancinoPacket packet = mstore(keys, values, len, timestamp, isAck); + ArancinoPacket packet = mstore(keys, values, len, timestamp, isAck); if (!packet.isError) return packet.response.stringArray; else @@ -757,13 +808,13 @@ ArancinoPacket ArancinoClass::setReserved(char *key, char *value) { if (key == NULL && value == NULL && strcmp(key, "") == 0) return invalidCommandErrorPacket; - return set(key, value, true, true, "rsvd"); + return set(key, value, true, true, "rsvd"); } /******** API BASIC :: GETRESERVED *********/ template <> -ArancinoPacket ArancinoClass::getReserved(char *key, bool id_prefix) +ArancinoPacket ArancinoClass::getReserved(char *key) { if (key == NULL && strcmp(key, "") == 0) return invalidCommandErrorPacket; @@ -772,9 +823,9 @@ ArancinoPacket ArancinoClass::getReserved(char *key, bool id_pre } template <> -char *ArancinoClass::getReserved(char *key, bool id_prefix) +char *ArancinoClass::getReserved(char *key) { - ArancinoPacket packet = getReserved(key, id_prefix); + ArancinoPacket packet = getReserved(key); if (!packet.isError) return packet.response.string; else @@ -785,7 +836,7 @@ char *ArancinoClass::getModuleVersion() { char key[strlen(MODVERS_KEY) + 1]; strcpy(key, MODVERS_KEY); - char *retString = getReserved(key, false); + char *retString = getReserved(key); return retString; } @@ -793,7 +844,7 @@ char *ArancinoClass::getModuleLogLevel() { char key[strlen(MODLOGLVL_KEY) + 1]; strcpy(key, MODLOGLVL_KEY); - char *retString = getReserved(key, false); + char *retString = getReserved(key); return retString; } @@ -801,7 +852,7 @@ char *ArancinoClass::getModuleEnvironment() { char key[strlen(MODENV_KEY) + 1]; strcpy(key, MODENV_KEY); - char *retString = getReserved(key, false); + char *retString = getReserved(key); return retString; } @@ -809,7 +860,7 @@ char *ArancinoClass::getBlinkId() { char key[strlen(BLINK_ID_KEY) + 1]; strcpy(key, BLINK_ID_KEY); - char *retString = getReserved(key, true); + char *retString = getReserved(key); return retString; } @@ -819,7 +870,7 @@ ArancinoPacket ArancinoClass::setBlinkId(int value) { char str[20] = ""; itoa(value, str, 10); - return setReserved(BLINK_ID_KEY, str, true); + return setReserved(BLINK_ID_KEY, str); } /******** API UTILITY :: FREE *********/ @@ -1055,17 +1106,20 @@ char *ArancinoClass::getTimestamp() /******** INTERNAL UTILS :: FREE *********/ -ArancinoPacket ArancinoClass::executeCommand(char* cmd, char* key, char* field, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type){ +ArancinoPacket ArancinoClass::executeCommand(char* cmd, char* key, char* field, char* value, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type){ StaticJsonDocument cmd_doc; StaticJsonDocument rsp_doc; - _buildArancinoJson(cmd_doc, cmd, key, field, argsHasItems, itemsHasDict, cfg); + _buildArancinoJson(cmd_doc, cmd, key, field, value, argsHasItems, itemsHasDict, cfg); #if defined(USEFREERTOS) if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) { #endif - _iface->_sendArancinoCommand(cmd_doc); + _iface->sendArancinoCommand(cmd_doc); + + SerialUSB.println(); + if(cmd_doc["cfg"]["ack"] == 1) - _iface->_receiveArancinoResponse(rsp_doc); + //_iface->receiveArancinoResponse(rsp_doc); #if defined(USEFREERTOS) giveCommMutex(); } @@ -1078,17 +1132,17 @@ ArancinoPacket ArancinoClass::executeCommand(char* cmd, char* key, char* field, return packet; } -ArancinoPacket executeCommand(char* cmd, char** keys, char** fields, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type){ +ArancinoPacket ArancinoClass::executeCommand(char* cmd, char** keys, char** fields, char** values, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type){ StaticJsonDocument cmd_doc; StaticJsonDocument rsp_doc; - _buildArancinoJson(cmd_doc, cmd, keys, fields, len, argsHasItems, itemsHasDict, cfg); + _buildArancinoJson(cmd_doc, cmd, keys, fields, values, len, argsHasItems, itemsHasDict, cfg); #if defined(USEFREERTOS) if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) { #endif - _iface->_sendArancinoCommand(cmd_doc); + //_iface->sendArancinoCommand(cmd_doc); if(cmd_doc["cfg"]["ack"] == 1) - _iface->_receiveArancinoResponse(rsp_doc); + //_iface->receiveArancinoResponse(rsp_doc); #if defined(USEFREERTOS) giveCommMutex(); } @@ -1101,15 +1155,15 @@ ArancinoPacket executeCommand(char* cmd, char** keys, char** fields, int len, bo return packet; } -ArancinoPacket executeCommand(JsonDocument& cmd_doc, int response_type){ +ArancinoPacket ArancinoClass::executeCommand(JsonDocument& cmd_doc, int response_type){ StaticJsonDocument rsp_doc; #if defined(USEFREERTOS) if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) { #endif - _iface->_sendArancinoCommand(cmd_doc); + //_iface->sendArancinoCommand(cmd_doc); if(cmd_doc["cfg"]["ack"] == 1) - _iface->_receiveArancinoResponse(rsp_doc); + //_iface->receiveArancinoResponse(rsp_doc); #if defined(USEFREERTOS) giveCommMutex(); } @@ -1127,20 +1181,25 @@ ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, switch(response_type){ case VOID_RESPONSE: { + // SET - HSET - FLUSH - STORETAGS* ArancinoPacket temp = {false, response_dict["rsp_code"], VOID, {.string = NULL}}; packet = temp; break; } case KEY_VALUE_RESPONSE: { + // GET - MGET - HGET JsonArray resp_items = response_dict["args"]["items"]; int resp_size = resp_items.size(); if (resp_size > 0 && resp_size < 2) { - ArancinoPacket temp = {false, response_dict["rsp_code"], STRING, {.string = resp_items[0]["value"]}}; + char* value = (char*) calloc(strlen(resp_items[0]["value"]), sizeof(char)); + strcpy(value, resp_items[0]["value"]); + ArancinoPacket temp = {false, response_dict["rsp_code"], STRING, {.string = value}}; packet = temp; } else if (resp_size > 1) { - const char* resp_values[resp_size]; + char* resp_values[resp_size]; for (int i=0; i 0 && resp_size < 2) { - ArancinoPacket temp = {false, response_dict["rsp_code"], STRING, {.string = response_dict["args"]["items"][0]["value"]}}; - packet = temp; - } else if (resp_size > 1) { - const char* resp_values[resp_size]; - for (int i=0; i 0 && resp_size < 2) { - ArancinoPacket temp = {false, response_dict["rsp_code"], STRING, {.string = resp_items[0]}}; + char* value = (char*) calloc(strlen(resp_items[0]), sizeof(char)); + strcpy(value, resp_items[0]); + ArancinoPacket temp = {false, response_dict["rsp_code"], STRING, {.string = value}}; packet = temp; } else if (resp_size > 1) { - const char* resp_values[resp_size]; + char* resp_values[resp_size]; for (int i=0; i 0) - { - ++digit; - _val /= 10; - } - return digit; -} - void ArancinoClass::_printDebugMessage(char* value) { if (_isDebug && _commMode){ __publish(MONITOR_KEY, value); @@ -1338,165 +1382,9 @@ void ArancinoClass::_printDebugMessage(char* value) { } } -int ArancinoClass::_getResponseCode(char *message) -{ - int value = -1; - int separatorIndex = -1; - char *temp = NULL; - char *charAddr = strchr(message, DATA_SPLIT_CHAR); // address of DATA_SPLIT_CHAR - if (charAddr == NULL) // NO DATA_SPLIT_CHAR - { - charAddr = strchr(message, END_TX_CHAR); //-> search for END_TX_CHAR - } - - if (charAddr != NULL) - { - separatorIndex = charAddr - message; // index of DATA_SPLIT_CHAR/END_TX_CHAR on message string - temp = (char *)calloc(separatorIndex + 1, sizeof(char)); - strncpy(temp, message, separatorIndex + 1); - temp[separatorIndex] = '\0'; // replace separator with null-character - - value = atoi(temp); - free(temp); - } - else - { - value = -1; // error - } - - return value; -} - -char *ArancinoClass::_parse(char *message) -{ - - char *status = NULL; - char *value = NULL; - int DSCIndex; // DATA_SPLIT_CHAR index - char *charAddr = strchr(message, DATA_SPLIT_CHAR); // address of DATA_SPLIT_CHAR - - if (charAddr != NULL) - { - DSCIndex = charAddr - message; // index of DATA_SPLIT_CHAR on message string - } - else - { - DSCIndex = -1; // DATA_SPLIT_CHAR not found --> received only 'status' - } - - int messageLength = strlen(message); - - if (DSCIndex == -1) - { - status = (char *)calloc(messageLength + 1, sizeof(char)); // response = [STATUS] + @ - strncpy(status, message, messageLength); - status[messageLength] = '\0'; // replace END_TX_CHAR with '\0' - } - else - { - status = (char *)calloc(DSCIndex + 1, sizeof(char)); // response = [STATUS] + # + [VALUE] + @ - strncpy(status, message, DSCIndex); - status[DSCIndex] = '\0'; // replace DATA_SPLIT_CHAR with '\0' - - value = (char *)calloc(messageLength - DSCIndex - 1, sizeof(char)); - strncpy(value, &message[DSCIndex + 1], messageLength - (DSCIndex + 2)); - value[messageLength - (DSCIndex + 2)] = '\0'; // replace END_TX_CHAR with '\0' - } - - free(status); - - if (strcmp(value, nullStr) == 0) - { - free(value); - return NULL; - } - else - { - return value; - } -} - -char **ArancinoClass::_parseArray(char *data) -{ - char **arrayParsed = NULL; - char *tempArray; - - char *previousDSCIndex = data; - char *DSCIndex = data; - - int fieldCount = data != NULL; // at least 1 field - int maxLength = 0; - - if (data != NULL) - { - - // get the key count - do - { - DSCIndex = strchr(previousDSCIndex, DATA_SPLIT_CHAR); - - if (DSCIndex != NULL) - { - ++fieldCount; - if (DSCIndex - previousDSCIndex > maxLength) - maxLength = DSCIndex - previousDSCIndex; - } - else if (int(strlen(previousDSCIndex)) > maxLength) - { - maxLength = strlen(previousDSCIndex); - } - previousDSCIndex = DSCIndex + 1; - - } while (DSCIndex != NULL); - - /* - * Alloco un elemento in più (fieldCount + 1). - * Nel primo elemento inserisco la lunghezza del vettore; - * Il valore di ritorno della funzione sarà l'elemento 1 del vettore (e non l'elemento 0) - */ - arrayParsed = (char **)malloc((fieldCount + 1) * sizeof(char *)); // user must free! - tempArray = (char *)malloc((fieldCount + 1) * (maxLength + 1) * sizeof(char)); // user must free! - arrayParsed[0] = (char *)fieldCount; - - previousDSCIndex = data; - - for (int i = 1; i < (fieldCount + 1); ++i) - { - arrayParsed[i] = tempArray + ((i - 1) * (maxLength + 1)); - DSCIndex = strchr(previousDSCIndex + 1, DATA_SPLIT_CHAR); - - if (DSCIndex != NULL) - { - if (strncmp(previousDSCIndex, nullStr, DSCIndex - previousDSCIndex) == 0) - { - arrayParsed[i] = NULL; - } - else - { - strncpy(arrayParsed[i], previousDSCIndex, DSCIndex - previousDSCIndex); - arrayParsed[i][DSCIndex - previousDSCIndex] = '\0'; - } - previousDSCIndex = DSCIndex + 1; - } - else - { - strcpy(arrayParsed[i], previousDSCIndex); - } - } - - if (data != NULL) - { - free(data); - } - } - - return (data != NULL && arrayParsed != NULL) ? &arrayParsed[1] : NULL; -} - +#if defined(USEFREERTOS) BaseType_t ArancinoClass::takeCommMutex(TickType_t timeout) { -#if defined(USEFREERTOS) - if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { if (CommMutex != NULL) @@ -1517,10 +1405,8 @@ BaseType_t ArancinoClass::takeCommMutex(TickType_t timeout) */ return pdTRUE; } -#else - return pdTRUE; -#endif } +#endif void ArancinoClass::giveCommMutex() { diff --git a/src/Arancino.h b/src/Arancino.h index a8809b5..0595d37 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -100,7 +100,7 @@ typedef struct { typedef struct { uint8_t pers = CFG_UNSET; uint8_t ack = CFG_UNSET; - const char* type = CFG_UNSET; + char* type = CFG_UNSET; //const char* signature } ArancinoCFG; @@ -127,38 +127,38 @@ class ArancinoClass { void attachInterface(ArancinoIface& iface); //BEGIN - void begin(ArancinoMetadata amdata, ArancinoConfig aconfig); - void begin(ArancinoMetadata amdata); + void begin(ArancinoMetadata amdata, ArancinoConfig aconfig, char* custom_v1 = NULL, char* custom_v2 = NULL); + void begin(ArancinoMetadata amdata, char* custom_v1 = NULL, char* custom_v2 = NULL); - ArancinoPacket set(char* key, int value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); - ArancinoPacket set(char* key, double value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); - ArancinoPacket set(char* key, float value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); - ArancinoPacket set(char* key, long value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); - ArancinoPacket set(char* key, uint32_t value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); - ArancinoPacket set(char* key, char* value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket set(char* key, int value, bool isAck = true, bool isPersistent = false, char* type = "appl"); + ArancinoPacket set(char* key, double value, bool isAck = true, bool isPersistent = false, char* type = "appl"); + ArancinoPacket set(char* key, float value, bool isAck = true, bool isPersistent = false, char* type = "appl"); + ArancinoPacket set(char* key, long value, bool isAck = true, bool isPersistent = false, char* type = "appl"); + ArancinoPacket set(char* key, uint32_t value, bool isAck = true, bool isPersistent = false, char* type = "appl"); + ArancinoPacket set(char* key, char* value, bool isAck = true, bool isPersistent = false, char* type = "appl"); //MSET - ArancinoPacket mset(char** keys, char** values, int len, bool isAck, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket mset(char** keys, char** values, int len, bool isAck, bool isPersistent = false, char* type = "appl"); //GET - template T get(char* key, bool isPersistent = false, const char* type = "appl"); + template T get(char* key, bool isPersistent = false, char* type = "appl"); //MGET - template T mget(char** keys, int len, bool isPersistent = false, const char* type = "appl"); + template T mget(char** keys, int len, bool isPersistent = false, char* type = "appl"); //DEL - template T del(char* key, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + template T del(char* key, bool isAck = true, bool isPersistent = false, char* type = "appl"); //HSET - ArancinoPacket hset(char* key, char* field, char* value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); - ArancinoPacket hset(char* key, char* field, int value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); - ArancinoPacket hset(char* key, char* field, float value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); - ArancinoPacket hset(char* key, char* field, double value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); - ArancinoPacket hset(char* key, char* field, uint32_t value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); - ArancinoPacket hset(char* key, char* field, long value, bool isAck = true, bool isPersistent = false, const char* type = "appl"; + ArancinoPacket hset(char* key, char* field, char* value, bool isAck = true, bool isPersistent = false, char* type = "appl"); + ArancinoPacket hset(char* key, char* field, int value, bool isAck = true, bool isPersistent = false, char* type = "appl"); + ArancinoPacket hset(char* key, char* field, float value, bool isAck = true, bool isPersistent = false, char* type = "appl"); + ArancinoPacket hset(char* key, char* field, double value, bool isAck = true, bool isPersistent = false, char* type = "appl"); + ArancinoPacket hset(char* key, char* field, uint32_t value, bool isAck = true, bool isPersistent = false, char* type = "appl"); + ArancinoPacket hset(char* key, char* field, long value, bool isAck = true, bool isPersistent = false, char* type = "appl"); //HGET - template T hget(char* key, char* field, bool isPersistent = true, const char* type = "appl"); + template T hget(char* key, char* field, bool isPersistent = true, char* type = "appl"); //HDEL template T hdel(char* key, char* field, bool isAck = true, bool isPersistent = false); @@ -174,11 +174,11 @@ class ArancinoClass { ArancinoPacket flush(bool isAck = true, bool isPersistent = false); //STORE - template T store(char* key, int value, bool isAck = true, char* timestamp = NULL, bool isAck = true); - template T store(char* key, uint32_t value, bool isAck = true, char* timestamp = NULL, bool isAck = true); - template T store(char* key, double value, bool isAck = true, char* timestamp = NULL, bool isAck = true); - template T store(char* key, float value, bool isAck = true, char* timestamp = NULL, bool isAck = true); - template T store(char* key, long value, bool isAck = true, char* timestamp = NULL, bool isAck = true); + template T store(char* key, int value, char* timestamp = NULL, bool isAck = true); + template T store(char* key, uint32_t value, char* timestamp = NULL, bool isAck = true); + template T store(char* key, double value, char* timestamp = NULL, bool isAck = true); + template T store(char* key, float value, char* timestamp = NULL, bool isAck = true); + template T store(char* key, long value, char* timestamp = NULL, bool isAck = true); //MSTORE template T mstore(char** keys, char** values, int len, char* timestamp = NULL, bool isAck = true); @@ -244,10 +244,8 @@ class ArancinoClass { unsigned long millis_previous; char LOG_LEVEL[10]="INFO"; - const char dataSplitStr[2] = {DATA_SPLIT_CHAR, '\0'}; - const char arraySplitStr[2] = {ARRAY_SPLIT_CHAR, '\0'}; - const char endTXStr[2] = {END_TX_CHAR, '\0'}; - const char nullStr[2] = {NULL_CHAR, '\0'}; + char DAEMON_VER[10]; + char DAEMON_ENV[10]; ArancinoMetadata _metadata = { (char*)"", @@ -256,7 +254,7 @@ class ArancinoClass { }; //START - void start(char** keys, char** values, int len); + void start(JsonDocument& cmd_doc); //API WRAPPED void _freeArray(char** _array); @@ -267,22 +265,18 @@ class ArancinoClass { ArancinoPacket __store(char* key, char* value, char* timestamp=NULL, bool isAck = true); - template T getReserved(char* key, bool id_prefix); - ArancinoPacket setReserved( char* key, char* value, bool id_prefix); + template T getReserved(char* key); + ArancinoPacket setReserved( char* key, char* value); //INTERNAL UTILS void _doubleToString(double value, unsigned int _nDecimal, char* str); //truncation! void _floatToString(float value, unsigned int _nDecimal, char* str); - int _getDigit(long value); void _printDebugMessage(char* value); - - int _getResponseCode(char* data); - - char* _parse(char* message); - char** _parseArray(char* message); + #if defined(USEFREERTOS) //The entire prototype would be ill-formed if freertos is not defined BaseType_t takeCommMutex(TickType_t timeout); + #endif void giveCommMutex(); void taskSuspend(); void taskResume(); @@ -291,14 +285,13 @@ class ArancinoClass { ArancinoPacket createArancinoPacket(char* response_raw, int response_type); - ArancinoPacket executeCommand(const char* cmd, char* key, char* field, const char* value, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type); - ArancinoPacket executeCommand(const char* cmd, char** keys, char** fields, char** values, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type); + ArancinoPacket executeCommand(char* cmd, char* key, char* field, char* value, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type); + ArancinoPacket executeCommand(char* cmd, char** keys, char** fields, char** values, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type); ArancinoPacket executeCommand(JsonDocument& cmd_doc, int response_type); ArancinoPacket createArancinoPacket(JsonDocument& response_dict, int response_type); - - void _buildArancinoJson(JsonDocument& doc, const char* cmd, const char* key, const char* field, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg); - void _buildArancinoJson(JsonDocument& doc, const char* cmd, const char** keys, const char** fields, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg); + void _buildArancinoJson(JsonDocument& doc, char* cmd, char* key, char* field, char* value, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg); + void _buildArancinoJson(JsonDocument& doc, char* cmd, char** keys, char** fields, char** values, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg); //Protocol interface diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index dfafacb..ff412ed 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -103,6 +103,7 @@ under the License #define MODENV_KEY (char*)"___MODENV___" #define BLINK_ID_KEY (char*)"___BLINK_ID___" #define LIB_VERSION (char*)"2.0.0" //library version +#define CRTX_VERSION (char*)"1.0.0" //cortex version //RESPONSE CODE #define INVALID_VALUE_ERROR -4 @@ -141,5 +142,6 @@ under the License #define KEY_VALUE_RESPONSE 1 #define KEY_RESPONSE 2 #define FIELDS_ITEMS_RESPONSE 3 -#define ITEMS_RESPONSE 4 -#define CLIENTS_RESPONSE 5 \ No newline at end of file +#define FIELDS_RESPONSE 4 +#define ITEMS_RESPONSE 5 +#define CLIENTS_RESPONSE 6 \ No newline at end of file diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index 914f148..252ccb6 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -31,7 +31,7 @@ void SerialIface::ifaceBegin(){ //Nothing to initialize here. } -void SerialIface::sendArancinoCommand(char* command){ +void SerialIface::sendArancinoCommand(JsonDocument& command){ //check communication timeout with arancino module if (comm_timeout){ /* @@ -45,7 +45,7 @@ void SerialIface::sendArancinoCommand(char* command){ comm_timeout=false; } //command must terminate with '\0'! - this->_serialPort->write(command, strlen(command)); //excluded '\0' + serializeJsonPretty(command, *_serialPort); #if defined(USEFREERTOS) && defined(USE_TINYUSB) if (xTaskGetSchedulerState() != taskSCHEDULER_RUNNING) @@ -55,30 +55,13 @@ void SerialIface::sendArancinoCommand(char* command){ #endif } -char* SerialIface::receiveArancinoResponse(char terminator){ - char* response = NULL; //must be freed - String str = ""; - str = this->_serialPort->readStringUntil(terminator); - if( str == ""){ - //enable timeout check - comm_timeout = true; - } - else { - int responseLength = strlen(str.begin()); - if (responseLength > 0) - { - response = (char *)Arancino.calloc(responseLength + 1 + 1, sizeof(char)); - strcpy(response, str.begin()); - response[responseLength] = END_TX_CHAR; - response[responseLength + 1] = '\0'; - } - } - return response; +bool SerialIface::receiveArancinoResponse(JsonDocument& response){ + + DeserializationError error = deserializeMsgPack(response, *_serialPort); + comm_timeout = error; //Deserialization may not always fail due to comm timeout, but just in case + return error; } -void SerialIface::setSerialTimeout(int timeout){ - this->_serialTimeout = timeout; -} void SerialIface::setSerialPort(Stream& serialPort){ this->_serialPort = &serialPort; @@ -88,14 +71,14 @@ void SerialIface::setSerialPort(){ //default implementation for Arancino boards #if defined (SERIAL_PORT) && defined(BAUDRATE) && defined (TIMEOUT) SERIAL_PORT.begin(BAUDRATE); - SERIAL_PORT.setTimeout(_serialTimeout); - this->_serialTimeout = TIMEOUT; + SERIAL_PORT.setTimeout(TIMEOUT); this->_serialPort = &SERIAL_PORT; #endif } -/******** MQTT interface *********/ +/******** MQTT interface *********/ +/* //Static variables definition char* MqttIface::_inputBuffer; bool MqttIface::_newIncomingMessage = false; @@ -226,9 +209,10 @@ void MqttIface::_reconnect(){ } } } - +*/ /******** Bluetooth interface *********/ +/* void BluetoothIface::setBLESerial(Stream& bleUart){ this->_bleSerial = &bleUart; } @@ -262,3 +246,4 @@ char* BluetoothIface::receiveArancinoResponse(char terminator){ } return response; } +*/ \ No newline at end of file diff --git a/src/ArancinoInterface.h b/src/ArancinoInterface.h index ea9da04..6250aa1 100644 --- a/src/ArancinoInterface.h +++ b/src/ArancinoInterface.h @@ -24,12 +24,13 @@ under the License #include #include #include +#include class ArancinoIface{ public: virtual void ifaceBegin() = 0; - virtual void sendArancinoCommand(char* command) = 0; - virtual char* receiveArancinoResponse(char terminator) = 0; + virtual void sendArancinoCommand(JsonDocument& command) = 0; + virtual bool receiveArancinoResponse(JsonDocument& response) = 0; }; /******** INTERFACES *********/ @@ -40,20 +41,20 @@ class SerialIface : public ArancinoIface { Is a time period which a sent command can waits for the response. It's expressed in milliseconds. */ - void setSerialTimeout(int timeout); void setSerialPort(); void setSerialPort(Stream& serialPort); private: void ifaceBegin(); - void sendArancinoCommand(char* command); - char* receiveArancinoResponse(char terminator); + void sendArancinoCommand(JsonDocument& command); + bool receiveArancinoResponse(JsonDocument& response); Stream* _serialPort; - int _serialTimeout = 10000; bool comm_timeout = false; }; +/* + class MqttIface : public ArancinoIface, public PubSubClient { public: void setNetworkClient(Client& networkClient); @@ -100,5 +101,5 @@ class BluetoothIface : public ArancinoIface { Stream* _bleSerial; unsigned int _timeoutCounter = 0; }; - +*/ #endif /* ARANCINOINTERFACE_H_ */ \ No newline at end of file From 892c49a8517c728731ddffb10b52efdc19966392 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Fri, 28 Oct 2022 10:03:48 +0200 Subject: [PATCH 05/69] Added checks on null pointers --- src/Arancino.cpp | 34 ++++++++++++++++++++++++++++++---- src/ArancinoInterface.cpp | 5 ++++- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index 9f55cda..79c2f1b 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -119,7 +119,12 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg) { start(keys,values,7); started = true; - strcpy(LOG_LEVEL,getModuleLogLevel()); + char* _log_level = getModuleLogLevel(); + if (_log_level != NULL) + { + strcpy(LOG_LEVEL, _log_level); + } + #if defined(USEFREERTOS) /* All the FreeRTOS initialization should be put here, at the end of the the ArancinoClass::begin method. @@ -1344,8 +1349,11 @@ ArancinoPacket ArancinoClass::executeCommand(char *command, char *param1, char * #if defined(USEFREERTOS) if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) { #endif + if (str != NULL) + { _iface->sendArancinoCommand(str); message = _iface->receiveArancinoResponse(END_TX_CHAR); + } #if defined(USEFREERTOS) giveCommMutex(); } @@ -1475,7 +1483,10 @@ void ArancinoClass::executeCommandFast(char* command, char* param1, char** param #if defined(USEFREERTOS) if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) { #endif + if (str != NULL) + { _iface->sendArancinoCommand(str); + } #if defined(USEFREERTOS) giveCommMutex(); } @@ -1534,8 +1545,11 @@ ArancinoPacket ArancinoClass::executeCommand(char* command, char* param1, char* #if defined(USEFREERTOS) if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) { #endif + if (str != NULL) + { _iface->sendArancinoCommand(str); - message = _iface->receiveArancinoResponse(END_TX_CHAR); + } + message = _iface->receiveArancinoResponse(END_TX_CHAR); #if defined(USEFREERTOS) giveCommMutex(); } @@ -1595,7 +1609,10 @@ void ArancinoClass::executeCommandFast(char* command, char* param1, char* param2 #if defined(USEFREERTOS) if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) { #endif + if (str != NULL) + { _iface->sendArancinoCommand(str); + } #if defined(USEFREERTOS) giveCommMutex(); } @@ -1617,7 +1634,16 @@ ArancinoPacket ArancinoClass::createArancinoPacket(char* message, int type_retur else if (type_return == INT) { char *messageParsed = _parse(message); - ArancinoPacket temp = {false, _getResponseCode(message), INT, {.integer = atoi(messageParsed)}}; + ArancinoPacket temp; + if (messageParsed != NULL) + { + temp = {false, _getResponseCode(message), INT, {.integer = atoi(messageParsed)}}; + } + else + { + temp = {false, _getResponseCode(message), INT, {.integer = 0}}; + } + free(messageParsed); packet = temp; } @@ -1773,7 +1799,7 @@ char *ArancinoClass::_parse(char *message) free(status); - if (strcmp(value, nullStr) == 0) + if (value != NULL && strcmp(value, nullStr) == 0) { free(value); return NULL; diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index 4be1f6d..024eb2c 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -246,7 +246,10 @@ void BluetoothIface::ifaceBegin(){ } void BluetoothIface::sendArancinoCommand(char* command){ - _bleSerial->write(command, strlen(command)); + if (_bleSerial != NULL && command != NULL) + { + _bleSerial->write(command, strlen(command)); + } } char* BluetoothIface::receiveArancinoResponse(char terminator){ From 32c6ed766d467244695b9b3769b898c2ef771cab Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Mon, 31 Oct 2022 12:13:30 +0100 Subject: [PATCH 06/69] Fixed mqtt response string terminator char and timeout on slow mqtt response --- src/ArancinoDefinitions.h | 2 +- src/ArancinoInterface.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index cc66f5b..11d2ae2 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -160,7 +160,7 @@ under the License #define HEARTBEAT_STACK 256 #endif -#define MQTT_MAX_RETRIES 100 +#define MQTT_MAX_RETRIES 500 #define BLUETOOTH_MAX_RETRIES 100 #define ID_SIZE IDSIZE*2 //IDSIZE will be provided by microcontroller-id library \ No newline at end of file diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index 024eb2c..f69c876 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -169,6 +169,7 @@ char* MqttIface::receiveArancinoResponse(char terminator){ if (counter < MQTT_MAX_RETRIES){ this->loop(); counter++; + delay(10); } else { //No need for cleanup: no message was received nor memory allocated for it return NULL; @@ -186,10 +187,9 @@ void MqttIface::_arancinoCallback(char* topic, byte* payload, unsigned int lengt //should check whether the message is "reset" or no other messages will be sent here? Arancino.systemReset(); } else if (!strcmp(topic, _inputTopic)){ - _inputBuffer = (char*)Arancino.calloc(length+2, sizeof(char)); + _inputBuffer = (char*)Arancino.calloc(length + 1, sizeof(char)); memcpy(_inputBuffer, payload, length); - _inputBuffer[length] = END_TX_CHAR; - _inputBuffer[length+1] = '\0'; + _inputBuffer[length] = '\0'; _newIncomingMessage = true; } } From 428112f39aab58991a9019ce11084d3cac5ba8cd Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Wed, 2 Nov 2022 10:09:43 +0100 Subject: [PATCH 07/69] Use ESP api for retrieve heap size --- src/ArancinoTasks.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/ArancinoTasks.cpp b/src/ArancinoTasks.cpp index 95e2d55..99420bd 100644 --- a/src/ArancinoTasks.cpp +++ b/src/ArancinoTasks.cpp @@ -70,15 +70,22 @@ void ArancinoTasks::deviceIdentification(void *pvPramaters){ void ArancinoTasks::interoception(void *pvPramaters){ while (1) { - #if !defined(ARDUINO_ARANCINO_VOLANTE) && !defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_ESP32) + #if !defined(ARDUINO_ARANCINO_VOLANTE) && !defined(ARDUINO_ARCH_RP2040) //free memory int memory_free = xPortGetFreeHeapSize(); char mem_free[20]; - itoa(memory_free,mem_free,10); + itoa(memory_free, mem_free, 10); + //used memory - int memory_used=configTOTAL_HEAP_SIZE-memory_free; +#if defined(ARDUINO_ARCH_ESP32) + int memory_used = ESP.getHeapSize() - memory_free; +#else + int memory_used = configTOTAL_HEAP_SIZE - memory_free; +#endif + char mem_used[20]; itoa(memory_used, mem_used, 10); + #endif //mcu temperature float temperature = arancinoTask.mcuTemp(); @@ -86,12 +93,18 @@ void ArancinoTasks::interoception(void *pvPramaters){ dtostrf(temperature,4,2,temp); //total memory char mem_tot[20]; + +#if defined(ARDUINO_ARCH_ESP32) + itoa(ESP.getHeapSize(), mem_tot, 10); +#else itoa(configTOTAL_HEAP_SIZE, mem_tot, 10); +#endif + char mem_free_key[]="MEM_FREE"; char mem_used_key[]="MEM_USED"; char mem_tot_key[]="MEM_TOT"; char temp_key[]="TEMP"; - #if defined(ARDUINO_ARANCINO_VOLANTE) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_ESP32) + #if defined(ARDUINO_ARANCINO_VOLANTE) || defined(ARDUINO_ARCH_RP2040) char* keys[] = {mem_tot_key,temp_key}; char* values[] = {mem_tot,temp}; ArancinoPacket acpkt = Arancino.mstore(keys,values,2); From 836b8c2cf493c513610fa4e8a3168cfa087abc02 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Wed, 2 Nov 2022 10:47:24 +0100 Subject: [PATCH 08/69] Added ESP32 MQTT example --- .../18-MQTT/MQTT_ESP32/MQTT_ESP32.ino | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 examples/Arancino/18-MQTT/MQTT_ESP32/MQTT_ESP32.ino diff --git a/examples/Arancino/18-MQTT/MQTT_ESP32/MQTT_ESP32.ino b/examples/Arancino/18-MQTT/MQTT_ESP32/MQTT_ESP32.ino new file mode 100644 index 0000000..b074467 --- /dev/null +++ b/examples/Arancino/18-MQTT/MQTT_ESP32/MQTT_ESP32.ino @@ -0,0 +1,86 @@ +/* + SPDX-license-identifier: Apache-2.0 + + Copyright (C) 2021 SmartMe.IO + + Authors: Marco Calapristi + + Licensed under the Apache License, Version 2.0 (the "License"); you may + not use this file except in compliance with the License. You may obtain + a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + License for the specific language governing permissions and limitations + under the License +*/ + +/* + Arancino MQTT example + + This sketch shows how to use Arancino Protocol via MQTT. + In this example an Ethernet shield was used, but any network client should work just fine. + + In order to do that you should first set up a MqttIface and then attach it to Arancino Library as shown below +*/ + +#include +#include +#include + +// Change these values accordingly with your network. +const char* ssid = "ssid"; +const char* password = "YourPassword!"; + +WiFiClient arancinoClient; +PubSubClient client(arancinoClient); + +MqttIface iface; + +ArancinoMetadata amdata = { + .fwname = "Mqtt ESP32 Example", + .fwversion = "1.0.0", + .tzoffset = "+1000" +}; + +void setup() +{ + Serial.begin(115200); + Serial.print("Connecting to " + (String)ssid); + + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + Arancino.enableDebugMessages(Serial); + Arancino.println("Started"); + + //Set up the MQTT client + iface.setDaemonID("87654321"); + iface.setBrokerAddress("192.168.137.249"); //You can use domain names as well + iface.setUsername("arancino-daemon"); + iface.setPassword("12345678"); + iface.setPort(1883); + iface.setNetworkClient(arancinoClient); + Arancino.attachInterface(iface); + + Arancino.begin(amdata); +} + +void loop() { + Arancino.set("foo", "bar"); + Arancino.println("SET: foo -> bar"); + delay(1000); + + char* value = Arancino.get("foo"); + Arancino.print("GET: foo -> "); + Arancino.println(value); + Arancino.free(value); //frees memory + + delay(1000); +} From 075e5679c6a13f0f936393f99235bb60b2d75c16 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Wed, 2 Nov 2022 12:02:40 +0100 Subject: [PATCH 09/69] Increased priority for arancino tasks --- src/ArancinoDefinitions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index 11d2ae2..71a12bd 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -154,7 +154,7 @@ under the License #define INTEROCEPTION_STACK configMINIMAL_STACK_SIZE * 4 #define HEARTBEAT_STACK configMINIMAL_STACK_SIZE * 4 #else -#define ARANCINO_TASK_PRIORITY 2 +#define ARANCINO_TASK_PRIORITY configMAX_PRIORITIES - 1 #define IDENTIFICATION_STACK 256 #define INTEROCEPTION_STACK 256 #define HEARTBEAT_STACK 256 From 29d0f814c2d70e97d8a9953d66d46aa170914550 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Thu, 3 Nov 2022 11:20:31 +0100 Subject: [PATCH 10/69] Added ESP32 MQTT w/ FreeRTOS example --- .../18-MQTT/MQTT_ESP32/MQTT_ESP32.ino | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 examples/Arancino_FreeRTOS/18-MQTT/MQTT_ESP32/MQTT_ESP32.ino diff --git a/examples/Arancino_FreeRTOS/18-MQTT/MQTT_ESP32/MQTT_ESP32.ino b/examples/Arancino_FreeRTOS/18-MQTT/MQTT_ESP32/MQTT_ESP32.ino new file mode 100644 index 0000000..18f5f41 --- /dev/null +++ b/examples/Arancino_FreeRTOS/18-MQTT/MQTT_ESP32/MQTT_ESP32.ino @@ -0,0 +1,96 @@ +/* + SPDX-license-identifier: Apache-2.0 + + Copyright (C) 2021 SmartMe.IO + + Authors: Marco Calapristi + + Licensed under the Apache License, Version 2.0 (the "License"); you may + not use this file except in compliance with the License. You may obtain + a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + License for the specific language governing permissions and limitations + under the License +*/ + +/* + Arancino MQTT example + + This sketch shows how to use Arancino Protocol via MQTT. + In this example an Ethernet shield was used, but any network client should work just fine. + + In order to do that you should first set up a MqttIface and then attach it to Arancino Library as shown below +*/ + +#include +#include +#include + +// Change these values accordingly with your network. +const char* ssid = "ssid"; +const char* password = "YourPassword!"; + +WiFiClient arancinoClient; +PubSubClient client(arancinoClient); + +MqttIface iface; + +ArancinoMetadata amdata = { + .fwname = "Mqtt ESP32 w/ FreeRTOS Example", + .fwversion = "1.0.0", + .tzoffset = "+1000" +}; + +//FreeRtos +TaskHandle_t otherLoopHandle; +void otherLoop(void *pvParameters); + +void setup() +{ + Serial.begin(115200); + Serial.print("Connecting to " + (String)ssid); + + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + Arancino.enableDebugMessages(Serial); + Arancino.println("Started"); + + //Set up the MQTT client + iface.setDaemonID("87654321"); + iface.setBrokerAddress("192.168.211.41"); //You can use domain names as well + iface.setUsername("arancino-daemon"); + iface.setPassword("12345678"); + iface.setPort(1883); + iface.setNetworkClient(arancinoClient); + Arancino.attachInterface(iface); + + Arancino.begin(amdata); + xTaskCreate(otherLoop, "otherLoop", configMINIMAL_STACK_SIZE * 2, NULL, 1, &otherLoopHandle); + Arancino.startScheduler(); +} + +void loop() { + Arancino.set("foo", "bar"); + Arancino.println("SET: foo -> bar"); + delay(1000); +} + +void otherLoop(void *pvParameters) { + while (1) { + char* value = Arancino.get("foo"); + Arancino.print("GET: foo -> "); + Arancino.println(value); + Arancino.free(value); //frees memory + + delay(1000); + } +} From 187eec3e10f07f916d2aca8194f3bf78dd97f17c Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Fri, 11 Nov 2022 16:21:45 +0100 Subject: [PATCH 11/69] Release MsgPack --- src/Arancino.cpp | 218 +++++++++++++++++++++++--------------- src/Arancino.h | 21 ++-- src/ArancinoDefinitions.h | 5 +- src/ArancinoInterface.cpp | 80 +++++--------- src/ArancinoInterface.h | 11 +- src/ArancinoTasks.cpp | 165 +++++++++++++++++++++++------ src/ArancinoTasks.h | 16 ++- 7 files changed, 326 insertions(+), 190 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index d78476b..8adbb6d 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -75,26 +75,13 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, char* MicroID.getUniqueIDString(id, ID_SIZE/2); _iface->ifaceBegin(); - return; - - arancino_id_prefix = _acfg.USE_PORT_ID_PREFIX_KEY; - decimal_digits = _acfg.DECIMAL_DIGITS; - - _metadata = _amdata; - - int arancinocoreversionLength = 0; // assuming is not defined - - #ifdef ARANCINO_CORE_VERSION - arancinocoreversionLength += strlen(ARANCINO_CORE_VERSION); - #endif - // firmware build time - char str_build_time[strlen(__DATE__) + 1 + strlen(__TIME__) + 1 + strlen(_metadata.tzoffset)] = ""; + char str_build_time[strlen(__DATE__) + 1 + strlen(__TIME__) + 1 + strlen(_amdata.tzoffset)] = ""; strcpy(str_build_time, __DATE__); strcat(str_build_time, " "); strcat(str_build_time, __TIME__); strcat(str_build_time, " "); - strcat(str_build_time, _metadata.tzoffset); + strcat(str_build_time, _amdata.tzoffset); #if defined(USEFREERTOS) if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) @@ -102,9 +89,10 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, char* CommMutex = xSemaphoreCreateMutex(); } - char* useFreeRtos = "1"; + //TODO: this should be notified to module + bool useFreeRtos = true; #else - char* useFreeRtos = "0"; + bool useFreeRtos = false; #endif StaticJsonDocumentcmd_doc; @@ -114,11 +102,12 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, char* cmd_args["port_id"] = id; cmd_args["fw_mcu_family"] = (char*)MCU_FAMILY; cmd_args["fw_lib_ver"] = LIB_VERSION; - cmd_args["fw_name"] = _metadata.fwname; - cmd_args["fw_ver"] = _metadata.fwversion; + cmd_args["fw_name"] = _amdata.fwname; + cmd_args["fw_ver"] = _amdata.fwversion; cmd_args["fw_build_time"] = str_build_time; cmd_args["fw_core_ver"] = (char*)ARANCINO_CORE_VERSION; cmd_args["fw_crtx_ver"] = CRTX_VERSION; + cmd_args["use_freertos"] = useFreeRtos ? 1 : 0; if(custom_v1) cmd_args["CUSTOM_KEY_1"] = custom_v1; if(custom_v2) @@ -133,7 +122,7 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, char* start(cmd_doc); started = true; - strcpy(LOG_LEVEL,getModuleLogLevel()); + //strcpy(LOG_LEVEL,getModuleLogLevel()); #if defined(USEFREERTOS) /* All the FreeRTOS initialization should be put here, at the end of the the ArancinoClass::begin method. @@ -153,9 +142,12 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, char* /******** API BASIC :: START *********/ void ArancinoClass::start(JsonDocument& cmd_doc) { - ArancinoPacket packet; + bool isError = true; do { + //Retry communication every 2.5 seconds of blocking delay + delay(2500); + StaticJsonDocumentrsp_doc; bool error; @@ -169,28 +161,27 @@ void ArancinoClass::start(JsonDocument& cmd_doc) { } #endif - if (!error) { + if (error == DeserializationError::Ok) { //Handle start response if (rsp_doc["rsp_code"] == 100){ - strcpy(DAEMON_VER, rsp_doc["args"]["dmn_ver"]); - strcpy(DAEMON_ENV, rsp_doc["args"]["dmn_env"]); + isError = false; + const char* d_ver = rsp_doc["args"]["dmn_ver"]; + const char* d_env = rsp_doc["args"]["dmn_env"]; + strcpy(DAEMON_VER, d_ver); + strcpy(DAEMON_ENV, d_env); //Timestamp handling const char* ts = rsp_doc["cfg"]["ts"]; - memcpy(timestamp, ts, 4); + + memcpy(timestamp, ts, 13); char tmst_part[5]; memcpy(tmst_part, timestamp, 4); tmst_sup = atoi(tmst_part); // first 4 digits of epoch tmst_inf = atoi(×tamp[4]); // last 4 digits of epoch - millis_previous = millis(); + millis_previous = millis(); } } - - //Retry communication every 2.5 seconds of blocking delay - delay(2500); - } while (packet.isError == true || packet.responseCode != RSP_OK); - free(packet); - + } while (isError == true); } #if defined(USEFREERTOS) @@ -302,7 +293,7 @@ ArancinoPacket ArancinoClass::set(char *key, char *value, bool isAck, bool isPer cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; cfg.type = type; - return executeCommand(SET_COMMAND, key, NULL, value, true, true, cfg, VOID_RESPONSE); + return executeCommand(SET_COMMAND, key, NULL, value, isAck, true, true, cfg, VOID_RESPONSE); } @@ -317,7 +308,7 @@ ArancinoPacket ArancinoClass::mset(char **keys, char **values, int len, bool isA cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; cfg.type = type; - return executeCommand(SET_COMMAND, keys, NULL, values, len, true, true, cfg, VOID_RESPONSE); + return executeCommand(SET_COMMAND, keys, NULL, values, len, isAck, true, true, cfg, VOID_RESPONSE); } /******** API BASIC :: GET *********/ @@ -331,7 +322,7 @@ ArancinoPacket ArancinoClass::get(char* key, bool isPersistent, ArancinoCFG cfg; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; cfg.type = type; - return executeCommand(GET_COMMAND, key, NULL, NULL, true, false, cfg, KEY_VALUE_RESPONSE); + return executeCommand(GET_COMMAND, key, NULL, NULL, true, true, false, cfg, KEY_VALUE_RESPONSE); } template <> char *ArancinoClass::get(char* key, bool isPersistent, char* type) @@ -353,7 +344,7 @@ template <> ArancinoPacket ArancinoClass::mget(char **keys, int ArancinoCFG cfg; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; cfg.type = type; - return executeCommand(GET_COMMAND, keys, NULL, NULL, len, true, false, cfg, KEY_VALUE_RESPONSE); + return executeCommand(GET_COMMAND, keys, NULL, NULL, len, true, true, false, cfg, KEY_VALUE_RESPONSE); } template <> char **ArancinoClass::mget(char** keys, int len, bool isPersistent, char* type) @@ -376,7 +367,7 @@ ArancinoPacket ArancinoClass::del(char* key, bool isAck, bool is cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; cfg.type = type; - return executeCommand(DEL_COMMAND, key, NULL, NULL, true, false, cfg, KEY_RESPONSE); + return executeCommand(DEL_COMMAND, key, NULL, NULL, isAck, true, false, cfg, KEY_RESPONSE); } template <> @@ -435,7 +426,7 @@ ArancinoPacket ArancinoClass::hset(char *key, char *field, char *value, bool isA cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; cfg.type = type; - return executeCommand(HSET_COMMAND, key, field, value, true, true, cfg, VOID_RESPONSE); + return executeCommand(HSET_COMMAND, key, field, value, isAck, true, true, cfg, VOID_RESPONSE); } /******** API BASIC :: HGET *********/ @@ -449,7 +440,7 @@ ArancinoPacket ArancinoClass::hget(char *key, char *field, bool ArancinoCFG cfg; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; cfg.type = type; - return executeCommand(HGET_COMMAND, key, field, NULL, true, true, cfg, KEY_VALUE_RESPONSE); + return executeCommand(HGET_COMMAND, key, field, NULL, true, true, true, cfg, KEY_VALUE_RESPONSE); } template <> @@ -473,7 +464,7 @@ ArancinoPacket ArancinoClass::hdel(char *key, char *field, bool ArancinoCFG cfg; cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; - return executeCommand(HDEL_COMMAND, key, field, NULL, true, true, cfg, FIELDS_RESPONSE); + return executeCommand(HDEL_COMMAND, key, field, NULL, isAck, true, true, cfg, FIELDS_RESPONSE); } template <> @@ -599,7 +590,7 @@ ArancinoPacket ArancinoClass::__publish(char *channel, char *msg, bool isAck) JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); cmd_cfg["ack"] = isAck? 0 : 1; - return executeCommand(cmd_doc, CLIENTS_RESPONSE); + return executeCommand(cmd_doc, isAck, CLIENTS_RESPONSE); } /******** API BASIC :: FLUSH *********/ @@ -609,7 +600,7 @@ ArancinoPacket ArancinoClass::flush(bool isAck, bool isPersistent) ArancinoCFG cfg; cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; - return executeCommand(FLUSH_COMMAND, NULL, NULL, NULL, false, false, cfg, VOID_RESPONSE); + return executeCommand(FLUSH_COMMAND, NULL, NULL, NULL, isAck, false, false, cfg, VOID_RESPONSE); } /******** API BASIC :: STORE *********/ @@ -715,7 +706,8 @@ ArancinoPacket ArancinoClass::__store( char* key, char* value, char* timestamp, JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); cmd_cfg["ack"] = isAck? 0 : 1; - return executeCommand(cmd_doc, ITEMS_RESPONSE); + cmd_cfg["type"] = "tse"; + return executeCommand(cmd_doc, isAck, ITEMS_RESPONSE); } /******** API BASIC :: MSTORE *********/ @@ -745,7 +737,8 @@ ArancinoPacket ArancinoClass::mstore(char** keys, char** values, JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); cmd_cfg["ack"] = isAck? 0 : 1; - return executeCommand(cmd_doc, ITEMS_RESPONSE); + cmd_cfg["type"] = "tse"; + return executeCommand(cmd_doc, isAck, ITEMS_RESPONSE); } template<> @@ -789,6 +782,7 @@ ArancinoPacket ArancinoClass::storetags(char *key, char **tags, char **values, i StaticJsonDocument cmd_doc; JsonObject cmd_args = cmd_doc.createNestedObject("args"); cmd_doc["cmd"] = STORETAGS_COMMAND; + cmd_args["key"] = key; JsonArray cmd_items = cmd_args.createNestedArray("items"); for (int i=0; i cmd_doc; - StaticJsonDocument rsp_doc; _buildArancinoJson(cmd_doc, cmd, key, field, value, argsHasItems, itemsHasDict, cfg); #if defined(USEFREERTOS) - if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) { + while (!takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE); #endif - _iface->sendArancinoCommand(cmd_doc); - - SerialUSB.println(); - - if(cmd_doc["cfg"]["ack"] == 1) - //_iface->receiveArancinoResponse(rsp_doc); - #if defined(USEFREERTOS) - giveCommMutex(); + _iface->sendArancinoCommand(cmd_doc); + + StaticJsonDocument rsp_doc; + if(isAck){ + bool error = true; + int counter = 0; + while (error && counter < 5){ + counter++; + error = _iface->receiveArancinoResponse(rsp_doc); + } + if(error) + return communicationErrorPacket; } + + #if defined(USEFREERTOS) + giveCommMutex(); #endif if(rsp_doc.isNull()) return communicationErrorPacket; - ArancinoPacket packet = createArancinoPacket(rsp_doc, response_type); + ArancinoPacket packet = createArancinoPacket(rsp_doc, response_type); return packet; } -ArancinoPacket ArancinoClass::executeCommand(char* cmd, char** keys, char** fields, char** values, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type){ +ArancinoPacket ArancinoClass::executeCommand(char* cmd, char** keys, char** fields, char** values, int len, bool isAck, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type){ StaticJsonDocument cmd_doc; - StaticJsonDocument rsp_doc; _buildArancinoJson(cmd_doc, cmd, keys, fields, values, len, argsHasItems, itemsHasDict, cfg); #if defined(USEFREERTOS) - if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) { + while (!takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE); #endif - //_iface->sendArancinoCommand(cmd_doc); - if(cmd_doc["cfg"]["ack"] == 1) - //_iface->receiveArancinoResponse(rsp_doc); - #if defined(USEFREERTOS) - giveCommMutex(); + _iface->sendArancinoCommand(cmd_doc); + + StaticJsonDocument rsp_doc; + if(isAck){ + bool error = true; + int counter = 0; + while (error && counter < 5){ + counter++; + error = _iface->receiveArancinoResponse(rsp_doc); + } + if(error) + return communicationErrorPacket; } + + #if defined(USEFREERTOS) + giveCommMutex(); #endif if(rsp_doc.isNull()) @@ -1155,18 +1165,54 @@ ArancinoPacket ArancinoClass::executeCommand(char* cmd, char** keys, char** fiel return packet; } -ArancinoPacket ArancinoClass::executeCommand(JsonDocument& cmd_doc, int response_type){ - StaticJsonDocument rsp_doc; +ArancinoPacket ArancinoClass::executeCommand(JsonDocument& cmd_doc, bool isAck, int response_type){ + #if defined(USEFREERTOS) + while (!takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE); + #endif + _iface->sendArancinoCommand(cmd_doc); + StaticJsonDocument rsp_doc; + if(isAck){ + bool error = true; + int counter = 0; + while (error && counter < 5){ + counter++; + error = _iface->receiveArancinoResponse(rsp_doc); + } + if(error) + return communicationErrorPacket; + } + #if defined(USEFREERTOS) - if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) { + giveCommMutex(); #endif - //_iface->sendArancinoCommand(cmd_doc); - if(cmd_doc["cfg"]["ack"] == 1) - //_iface->receiveArancinoResponse(rsp_doc); + + if(rsp_doc.isNull()) + return communicationErrorPacket; + + ArancinoPacket packet = createArancinoPacket(rsp_doc, response_type); + return packet; +} + +ArancinoPacket ArancinoClass::executeCommand(JsonDocument& cmd_doc, JsonDocument& rsp_doc, bool isAck, int response_type){ #if defined(USEFREERTOS) - giveCommMutex(); + while (!takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE); + #endif + _iface->sendArancinoCommand(cmd_doc); + + if(isAck){ + bool error = true; + int counter = 0; + while (error && counter < 5){ + counter++; + error = _iface->receiveArancinoResponse(rsp_doc); + } + if(error) + return communicationErrorPacket; } + + #if defined(USEFREERTOS) + giveCommMutex(); #endif if(rsp_doc.isNull()) @@ -1191,15 +1237,17 @@ ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, JsonArray resp_items = response_dict["args"]["items"]; int resp_size = resp_items.size(); if (resp_size > 0 && resp_size < 2) { - char* value = (char*) calloc(strlen(resp_items[0]["value"]), sizeof(char)); - strcpy(value, resp_items[0]["value"]); - ArancinoPacket temp = {false, response_dict["rsp_code"], STRING, {.string = value}}; + const char* value = resp_items[0]["value"]; + char* ret_value = (char*) calloc(strlen(value), sizeof(char)); + strcpy(ret_value, value); + ArancinoPacket temp = {false, response_dict["rsp_code"], STRING, {.string = ret_value}}; packet = temp; } else if (resp_size > 1) { char* resp_values[resp_size]; for (int i=0; i 0 && resp_size < 2) { - char* value = (char*) calloc(strlen(resp_items[0]), sizeof(char)); - strcpy(value, resp_items[0]); - ArancinoPacket temp = {false, response_dict["rsp_code"], STRING, {.string = value}}; + const char* value = resp_items[0]; + char* ret_value = (char*) calloc(strlen(value), sizeof(char)); + strcpy(ret_value, value); + ArancinoPacket temp = {false, response_dict["rsp_code"], STRING, {.string = ret_value}}; packet = temp; } else if (resp_size > 1) { char* resp_values[resp_size]; for (int i=0; iprint(value); } diff --git a/src/Arancino.h b/src/Arancino.h index 0595d37..c0ae903 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -72,6 +72,8 @@ extern "C" { #include #endif +#include "ArancinoTasks.h" + //Power Mode enum POWER_MODE { BATTERY = 0, @@ -127,8 +129,8 @@ class ArancinoClass { void attachInterface(ArancinoIface& iface); //BEGIN - void begin(ArancinoMetadata amdata, ArancinoConfig aconfig, char* custom_v1 = NULL, char* custom_v2 = NULL); - void begin(ArancinoMetadata amdata, char* custom_v1 = NULL, char* custom_v2 = NULL); + void begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, char* custom_v1 = NULL, char* custom_v2 = NULL); + void begin(ArancinoMetadata _amdata, char* custom_v1 = NULL, char* custom_v2 = NULL); ArancinoPacket set(char* key, int value, bool isAck = true, bool isPersistent = false, char* type = "appl"); ArancinoPacket set(char* key, double value, bool isAck = true, bool isPersistent = false, char* type = "appl"); @@ -247,12 +249,6 @@ class ArancinoClass { char DAEMON_VER[10]; char DAEMON_ENV[10]; - ArancinoMetadata _metadata = { - (char*)"", - (char*)"", - (char*)"+0000" - }; - //START void start(JsonDocument& cmd_doc); @@ -260,7 +256,6 @@ class ArancinoClass { void _freeArray(char** _array); void _freePacket(ArancinoPacket packet); - ArancinoPacket __set(char* key, char* value, bool isPersistent); ArancinoPacket __publish(char* channel, char* msg, bool isAck = true); ArancinoPacket __store(char* key, char* value, char* timestamp=NULL, bool isAck = true); @@ -285,9 +280,10 @@ class ArancinoClass { ArancinoPacket createArancinoPacket(char* response_raw, int response_type); - ArancinoPacket executeCommand(char* cmd, char* key, char* field, char* value, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type); - ArancinoPacket executeCommand(char* cmd, char** keys, char** fields, char** values, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type); - ArancinoPacket executeCommand(JsonDocument& cmd_doc, int response_type); + ArancinoPacket executeCommand(char* cmd, char* key, char* field, char* value, bool isAck, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type); + ArancinoPacket executeCommand(char* cmd, char** keys, char** fields, char** values, int len, bool isAck, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type); + ArancinoPacket executeCommand(JsonDocument& cmd_doc, bool isAck, int response_type); + ArancinoPacket executeCommand(JsonDocument& cmd_doc, JsonDocument& rsp_doc, bool isAck, int response_type); ArancinoPacket createArancinoPacket(JsonDocument& response_dict, int response_type); void _buildArancinoJson(JsonDocument& doc, char* cmd, char* key, char* field, char* value, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg); @@ -332,6 +328,7 @@ class ArancinoClass { // int _publish(int channel, char* msg); // int _publish(char* channel, char* msg); + friend class ArancinoTasks; }; extern ArancinoClass Arancino; diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index ff412ed..2b9f6c3 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -37,7 +37,7 @@ under the License #endif #define SERIAL_DEBUG Serial1 #else -#define BAUDRATE 256000 +//#define BAUDRATE 256000 #define TIMEOUT 10000 #define SERIAL_PORT Serial #define SERIAL_DEBUG Serial1 @@ -81,7 +81,7 @@ under the License #define RSP_OK 100 #define RSP_HSET_NEW 101 #define RSP_HSET_UPD 102 -#define ERR 200 //Generic Error +#define ERR_GENERIC 200 //Generic Error #define ERR_NULL 201 //Null value #define ERR_SET 202 //Error during SET #define ERR_CMD_NOT_FND 203 //Command Not Found @@ -126,6 +126,7 @@ under the License #define ARANCINO_TASK_PRIORITY 2 +#define SERIAL_MAX_RETRIES 10 #define MQTT_MAX_RETRIES 100 #define BLUETOOTH_MAX_RETRIES 100 diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index 252ccb6..de237e5 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -32,20 +32,7 @@ void SerialIface::ifaceBegin(){ } void SerialIface::sendArancinoCommand(JsonDocument& command){ - //check communication timeout with arancino module - if (comm_timeout){ - /* - Flush data on serial communication to avoid of lost - synchronization between arancino library and arancino module. - By this way I prevent to receive reposonse of a previous sent command. - */ - while(this->_serialPort->available() > 0){ - this->_serialPort->read(); - } - comm_timeout=false; - } - //command must terminate with '\0'! - serializeJsonPretty(command, *_serialPort); + serializeMsgPack(command, *_serialPort); #if defined(USEFREERTOS) && defined(USE_TINYUSB) if (xTaskGetSchedulerState() != taskSCHEDULER_RUNNING) @@ -58,7 +45,6 @@ void SerialIface::sendArancinoCommand(JsonDocument& command){ bool SerialIface::receiveArancinoResponse(JsonDocument& response){ DeserializationError error = deserializeMsgPack(response, *_serialPort); - comm_timeout = error; //Deserialization may not always fail due to comm timeout, but just in case return error; } @@ -70,7 +56,7 @@ void SerialIface::setSerialPort(Stream& serialPort){ void SerialIface::setSerialPort(){ //default implementation for Arancino boards #if defined (SERIAL_PORT) && defined(BAUDRATE) && defined (TIMEOUT) - SERIAL_PORT.begin(BAUDRATE); + //SERIAL_PORT.begin(BAUDRATE); SERIAL_PORT.setTimeout(TIMEOUT); this->_serialPort = &SERIAL_PORT; #endif @@ -78,7 +64,7 @@ void SerialIface::setSerialPort(){ /******** MQTT interface *********/ -/* + //Static variables definition char* MqttIface::_inputBuffer; bool MqttIface::_newIncomingMessage = false; @@ -90,6 +76,7 @@ void MqttIface::ifaceBegin(){ setClient(*_client); setServer(_broker, _port); setCallback(_arancinoCallback); + setBufferSize(CMD_DOC_SIZE); //+1 because of \n _inputTopic = (char*)Arancino.calloc(strlen("arancino/cortex/") + strlen(_daemonID) + strlen(Arancino.id) + strlen("/rsp_to_mcu") + 2, sizeof(char)); @@ -114,11 +101,6 @@ void MqttIface::ifaceBegin(){ this->subscribe(_serviceTopic); //arancino/service/dID this->subscribe(_inputTopic); - //strcat(_serviceTopic, "/"); - //strcat(_serviceTopic, Arancino.id); - - //this->subscribe(_serviceTopic); //arancino/service/dID/cID - char* discoverytopic = (char*)Arancino.calloc(strlen("arancino/discovery/") + strlen(_daemonID)+1, sizeof(char)); strcpy(discoverytopic, "arancino/discovery/"); strcat(discoverytopic, _daemonID); @@ -126,10 +108,12 @@ void MqttIface::ifaceBegin(){ Arancino.free(discoverytopic); } -void MqttIface::sendArancinoCommand(char* command){ +void MqttIface::sendArancinoCommand(JsonDocument& command){ int counter = 0; + char buff[CMD_DOC_SIZE]; + serializeMsgPack(command, buff); while (counter < MQTT_MAX_RETRIES){ - if (this->publish(_outputTopic, command)){ + if (this->publish(_outputTopic, buff)){ return; } Arancino.println("Failed to send message, retrying."); @@ -141,7 +125,7 @@ void MqttIface::sendArancinoCommand(char* command){ this->_reconnect(); } -char* MqttIface::receiveArancinoResponse(char terminator){ +bool MqttIface::receiveArancinoResponse(JsonDocument& response){ int counter = 0; while(!_newIncomingMessage){ if (counter < MQTT_MAX_RETRIES){ @@ -149,13 +133,14 @@ char* MqttIface::receiveArancinoResponse(char terminator){ counter++; } else { //No need for cleanup: no message was received nor memory allocated for it - return NULL; + return true; } } - //Clean this before going out. _inputBuffer will be freed by caller function _newIncomingMessage = false; - return _inputBuffer; + bool error = deserializeMsgPack(response, _inputBuffer, sizeof(_inputBuffer)); + Arancino.free(_inputBuffer); + return error; } void MqttIface::_arancinoCallback(char* topic, byte* payload, unsigned int length){ @@ -164,10 +149,8 @@ void MqttIface::_arancinoCallback(char* topic, byte* payload, unsigned int lengt //should check whether the message is "reset" or no other messages will be sent here? Arancino.systemReset(); } else if (!strcmp(topic, _inputTopic)){ - _inputBuffer = (char*)Arancino.calloc(length+2, sizeof(char)); + _inputBuffer = (char*)Arancino.calloc(length, sizeof(char)); memcpy(_inputBuffer, payload, length); - _inputBuffer[length] = END_TX_CHAR; - _inputBuffer[length+1] = '\0'; _newIncomingMessage = true; } } @@ -209,10 +192,10 @@ void MqttIface::_reconnect(){ } } } -*/ + /******** Bluetooth interface *********/ -/* + void BluetoothIface::setBLESerial(Stream& bleUart){ this->_bleSerial = &bleUart; } @@ -224,26 +207,21 @@ void BluetoothIface::ifaceBegin(){ #endif } -void BluetoothIface::sendArancinoCommand(char* command){ - _bleSerial->write(command, strlen(command)); +void BluetoothIface::sendArancinoCommand(JsonDocument& command){ + serializeMsgPack(command, *_bleSerial); } -char* BluetoothIface::receiveArancinoResponse(char terminator){ - char* response = NULL; - String str = ""; - str = _bleSerial->readStringUntil(terminator); +bool BluetoothIface::receiveArancinoResponse(JsonDocument& response){ + DeserializationError error = deserializeMsgPack(response, *_bleSerial); - int responseLenght = strlen(str.begin()); - if (responseLenght > 0){ + if(error){ + if (++_timeoutCounter == BLUETOOTH_MAX_RETRIES){ + //For each serial timeout this will get incremented - board will reset after a certain number of timeouts + Arancino.systemReset(); + } + } else { _timeoutCounter = 0; - response = (char*) Arancino.calloc(responseLenght+1+1, sizeof(char)); - strcpy(response, str.begin()); - response[responseLenght] = END_TX_CHAR; - response[responseLenght+1] = '\0'; - } else if (++_timeoutCounter == BLUETOOTH_MAX_RETRIES){ - //For each serial timeout this will get incremented - board will reset after a certain number of timeouts - Arancino.systemReset(); } - return response; -} -*/ \ No newline at end of file + + return error; +} \ No newline at end of file diff --git a/src/ArancinoInterface.h b/src/ArancinoInterface.h index 6250aa1..941c47c 100644 --- a/src/ArancinoInterface.h +++ b/src/ArancinoInterface.h @@ -53,7 +53,6 @@ class SerialIface : public ArancinoIface { bool comm_timeout = false; }; -/* class MqttIface : public ArancinoIface, public PubSubClient { public: @@ -66,8 +65,8 @@ class MqttIface : public ArancinoIface, public PubSubClient { private: void ifaceBegin(); - void sendArancinoCommand(char* command); - char* receiveArancinoResponse(char terminator); + void sendArancinoCommand(JsonDocument& command); + bool receiveArancinoResponse(JsonDocument& response); void _reconnect(); @@ -94,12 +93,12 @@ class BluetoothIface : public ArancinoIface { private: void ifaceBegin(); - void sendArancinoCommand(char* command); - char* receiveArancinoResponse(char terminator); + void sendArancinoCommand(JsonDocument& command); + bool receiveArancinoResponse(JsonDocument& response); bool comm_timeout = false; Stream* _bleSerial; unsigned int _timeoutCounter = 0; }; -*/ + #endif /* ARANCINOINTERFACE_H_ */ \ No newline at end of file diff --git a/src/ArancinoTasks.cpp b/src/ArancinoTasks.cpp index a974841..31f64a5 100644 --- a/src/ArancinoTasks.cpp +++ b/src/ArancinoTasks.cpp @@ -34,14 +34,38 @@ under the License #if defined(USEFREERTOS) -ArancinoTasks arancinoTask; +DynamicJsonDocument* ArancinoTasks::cmd_doc; +DynamicJsonDocument* ArancinoTasks::rsp_doc; +SemaphoreHandle_t ArancinoTasks::jsonMutex; + + +ArancinoTasks::ArancinoTasks(){ + cmd_doc = new DynamicJsonDocument(CMD_DOC_SIZE); + rsp_doc = new DynamicJsonDocument(RSP_DOC_SIZE); + jsonMutex = xSemaphoreCreateMutex(); + +} void ArancinoTasks::deviceIdentification(void *pvPramaters){ pinMode(LED_BUILTIN,OUTPUT); while (1) { - char* value = Arancino.getBlinkId(); - if(!strcmp(value,"1")){ + xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); + (*cmd_doc).clear(); + JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); + (*cmd_doc)["cmd"] = GET_COMMAND; + JsonArray cmd_items = cmd_args.createNestedArray("items"); + cmd_items.add(BLINK_ID_KEY); + + JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); + cmd_cfg["pers"] = 1; + cmd_cfg["type"] = "rsvd"; + + ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), true, KEY_VALUE_RESPONSE); + xSemaphoreGive(jsonMutex); + + + if(!strcmp(rsp.response.string, "1")){ for(int i=0;i < 20; i++){ #if defined (ARDUINO_ARANCINO_VOLANTE) digitalWrite(LED_BUILTIN,LOW); @@ -56,9 +80,27 @@ void ArancinoTasks::deviceIdentification(void *pvPramaters){ #endif vTaskDelay(200); } - Arancino.setBlinkId(0); + + xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); + (*cmd_doc).clear(); + JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); + (*cmd_doc)["cmd"] = SET_COMMAND; + JsonArray cmd_items = cmd_args.createNestedArray("items"); + JsonObject items_obj = cmd_items.createNestedObject(); + items_obj["key"] = BLINK_ID_KEY; + items_obj["value"] = 0; + //cmd_items.add(BLINK_ID_KEY); + + JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); + cmd_cfg["pers"] = 1; + cmd_cfg["type"] = "rsvd"; + cmd_cfg["ack"] = 0; + + ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, VOID_RESPONSE); + xSemaphoreGive(jsonMutex); + } - Arancino.free(value); + Arancino.free(rsp); vTaskDelay(10000); //wait 10 seconds (non-blocking delay) } } @@ -67,36 +109,65 @@ void ArancinoTasks::interoception(void *pvPramaters){ while (1) { #if !defined(ARDUINO_ARANCINO_VOLANTE) && !defined(ARDUINO_ARCH_RP2040) - //free memory int memory_free = xPortGetFreeHeapSize(); - char mem_free[20]; - itoa(memory_free,mem_free,10); - //used memory int memory_used=configTOTAL_HEAP_SIZE-memory_free; - char mem_used[20]; - itoa(memory_used, mem_used, 10); #endif - //mcu temperature - float temperature = arancinoTask.mcuTemp(); - char temp[20]; - dtostrf(temperature,4,2,temp); - //total memory - char mem_tot[20]; - itoa(configTOTAL_HEAP_SIZE, mem_tot, 10); - char mem_free_key[]="MEM_FREE"; - char mem_used_key[]="MEM_USED"; - char mem_tot_key[]="MEM_TOT"; - char temp_key[]="TEMP"; + + float temperature = mcuTemp(); + #if defined(ARDUINO_ARANCINO_VOLANTE) || defined(ARDUINO_ARCH_RP2040) - char* keys[] = {mem_tot_key,temp_key}; - char* values[] = {mem_tot,temp}; - ArancinoPacket acpkt = Arancino.mstore(keys,values,2); + xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); + char* ts = Arancino.getTimestamp(); + (*cmd_doc).clear(); + JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); + (*cmd_doc)["cmd"] = STORE_COMMAND; + JsonArray cmd_items = cmd_args.createNestedArray("items"); + JsonObject memfree_obj = cmd_items.createNestedObject(); + JsonObject temp_obj = cmd_items.createNestedObject(); + + memfree_obj["key"] = "MEM_TOT"; + memfree_obj["value"] = configTOTAL_HEAP_SIZE; + memfree_obj["ts"] = ts; + temp_obj["key"] = "TEMP"; + temp_obj["value"] = temperature; + temp_obj["ts"] = ts; + JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); + cmd_cfg["ack"] = 0; + cmd_cfg["type"] = "tse"; + + ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, ITEMS_RESPONSE); + xSemaphoreGive(jsonMutex); + #else - char* keys[] = {mem_free_key,mem_used_key,mem_tot_key,temp_key}; - char* values[] = {mem_free,mem_used,mem_tot,temp}; - ArancinoPacket acpkt = Arancino.mstore(keys,values,4); + xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); + char* ts = Arancino.getTimestamp(); + (*cmd_doc).clear(); + JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); + (*cmd_doc)["cmd"] = STORE_COMMAND; + JsonArray cmd_items = cmd_args.createNestedArray("items"); + JsonObject memfree_obj = cmd_items.createNestedObject(); + JsonObject temp_obj = cmd_items.createNestedObject(); + + memfree_obj["key"] = "MEM_TOT"; + memfree_obj["value"] = configTOTAL_HEAP_SIZE; + memfree_obj["ts"] = ts; + temp_obj["key"] = "TEMP"; + temp_obj["value"] = temperature; + temp_obj["ts"] = ts; + temp_obj["key"] = "MEM_FREE"; + temp_obj["value"] = xPortGetFreeHeapSize(); + temp_obj["ts"] = ts; + temp_obj["key"] = "MEM_USED"; + temp_obj["value"] = configTOTAL_HEAP_SIZE-memory_free; + temp_obj["ts"] = ts; + JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); + cmd_cfg["ack"] = 0; + cmd_cfg["type"] = "tse"; + + ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, ITEMS_RESPONSE); + xSemaphoreGive(jsonMutex); #endif - Arancino.free(acpkt); + Arancino.free(rsp); vTaskDelay(60000); //wait 60 seconds (non-blocking delay) } @@ -107,11 +178,41 @@ void ArancinoTasks::sendHeartbeat(void *pvPramaters){ char topic[idSize + 5]; //ID_SIZE + '_HBx' + '\0' strcpy(topic, Arancino.id); strcat(topic, "_HB0"); + while (1) { + xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); topic[idSize+3] = '0'; //If the topic structure isn't changed i know exactly the byte I'm supposed to change - Arancino.publish(topic, Arancino.getTimestamp()); - topic[idSize+3] = '1'; - Arancino.publish(topic, Arancino.getTimestamp()); + + (*cmd_doc).clear(); + JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); + (*cmd_doc)["cmd"] = PUBLISH_COMMAND; + JsonArray cmd_items = cmd_args.createNestedArray("items"); + JsonObject items_obj = cmd_items.createNestedObject(); + items_obj["channel"] = topic; + items_obj["message"] = Arancino.getTimestamp(); + + JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); + cmd_cfg["ack"] = 0; + + ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, CLIENTS_RESPONSE); + + topic[idSize+3] = '1'; //If the topic structure isn't changed i know exactly the byte I'm supposed to change + + (*cmd_doc).clear(); + cmd_args = (*cmd_doc).createNestedObject("args"); + (*cmd_doc)["cmd"] = PUBLISH_COMMAND; + cmd_items = cmd_args.createNestedArray("items"); + items_obj = cmd_items.createNestedObject(); + items_obj["channel"] = topic; + items_obj["message"] = Arancino.getTimestamp(); + + cmd_cfg = (*cmd_doc).createNestedObject("cfg"); + cmd_cfg["ack"] = 0; + + rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, CLIENTS_RESPONSE); + + xSemaphoreGive(jsonMutex); + vTaskDelay(10000); } } diff --git a/src/ArancinoTasks.h b/src/ArancinoTasks.h index f2f96fd..49bf42c 100644 --- a/src/ArancinoTasks.h +++ b/src/ArancinoTasks.h @@ -18,16 +18,26 @@ License for the specific language governing permissions and limitations under the License */ -#include +#ifndef ARANCINOTASKS_H_ +#define ARANCINOTASKS_H_ + #include +#include + class ArancinoTasks{ public: + ArancinoTasks(); static void deviceIdentification(void *pvPramaters); static void interoception(void *pvPramaters); static void sendHeartbeat(void *pvPramaters); private: - float mcuTemp(); - bool temp_initialized = false; //temp inizialized + static float mcuTemp(); + static DynamicJsonDocument* cmd_doc; + static DynamicJsonDocument* rsp_doc; + #ifdef USEFREERTOS + static SemaphoreHandle_t jsonMutex; + #endif }; +#endif \ No newline at end of file From a6f458c17caca35976057f732fb899bb5aea709d Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Fri, 11 Nov 2022 16:50:50 +0100 Subject: [PATCH 12/69] Removed deprecated functions --- examples/Arancino/04-KEYS/KEYS/KEYS.ino | 90 ------------ .../04-KEYS/KEYS_Packet/KEYS_Packet.ino | 117 ---------------- .../{10-HDEL => 07-HDEL}/HDEL/HDEL.ino | 0 .../HDEL_Packet/HDEL_Packet.ino | 0 .../Arancino/07-HGETALL/HGETALL/HGETALL.ino | 72 ---------- .../HGETALL_Packet/HGETALL_Packet.ino | 91 ------------ .../{11-FLUSH => 08-FLUSH}/FLUSH/FLUSH.ino | 0 .../FLUSH_Packet/FLUSH_Packet.ino | 0 examples/Arancino/08-HKEYS/HKEYS/HKEYS.ino | 71 ---------- .../08-HKEYS/HKEYS_Packet/HKEYS_Packet.ino | 85 ------------ examples/Arancino/09-HVALS/HVALS/HVALS.ino | 69 --------- .../09-HVALS/HVALS_Packet/HVALS_Packet.ino | 85 ------------ .../PUBLISH/PUBLISH.ino | 0 .../PUBLISH_Packet/PUBLISH_Packet.ino | 0 .../{13-MSET => 10-MSET}/MSET/MSET.ino | 0 .../{14-MGET => 11-MGET}/MGET/MGET.ino | 0 .../MGET_Packet/MGET_Packet.ino | 0 .../{15-STORE => 12-STORE}/STORE/STORE.ino | 0 .../STORE_Packet/STORE_Packet.ino | 0 .../STORETAGS/STORETAGS.ino | 0 .../STORETAGS_Packet/STORETAGS_Packet.ino | 0 .../MSTORE/MSTORE.ino | 0 .../MSTORE_Packet/MSTORE_Packet.ino | 0 .../{18-MQTT => 15-MQTT}/MQTT/MQTT.ino | 0 .../MQTT_ESP32/MQTT_ESP32.ino | 0 .../BLUETOOTH/BLUETOOTH.ino | 0 .../Arancino_FreeRTOS/04-KEYS/KEYS/KEYS.ino | 101 -------------- .../04-KEYS/KEYS_Packet/KEYS_Packet.ino | 131 ------------------ .../{10-HDEL => 07-HDEL}/HDEL/HDEL.ino | 0 .../HDEL_Packet/HDEL_Packet.ino | 0 .../07-HGETALL/HGETALL/HGETALL.ino | 83 ----------- .../HGETALL_Packet/HGETALL_Packet.ino | 102 -------------- .../{11-FLUSH => 08-FLUSH}/FLUSH/FLUSH.ino | 0 .../FLUSH_Packet/FLUSH_Packet.ino | 0 .../08-HKEYS/HKEYS/HKEYS.ino | 82 ----------- .../08-HKEYS/HKEYS_Packet/HKEYS_Packet.ino | 96 ------------- .../09-HVALS/HVALS/HVALS.ino | 81 ----------- .../09-HVALS/HVALS_Packet/HVALS_Packet.ino | 96 ------------- .../PUBLISH/PUBLISH.ino | 0 .../PUBLISH_Packet/PUBLISH_Packet.ino | 0 .../{13-MSET => 10-MSET}/MSET/MSET.ino | 0 .../{14-MGET => 11-MGET}/MGET/MGET.ino | 0 .../MGET_Packet/MGET_Packet.ino | 0 .../{15-STORE => 12-STORE}/STORE/STORE.ino | 0 .../STORE_Packet/STORE_Packet.ino | 0 .../STORETAGS/STORETAGS.ino | 0 .../STORETAGS_Packet/STORETAGS_Packet.ino | 0 .../MSTORE/MSTORE.ino | 0 .../MSTORE_Packet/MSTORE_Packet.ino | 0 .../{18-MQTT => 15-MQTT}/MQTT/MQTT.ino | 0 .../MQTT_ESP32/MQTT_ESP32.ino | 0 .../BLUETOOTH/BLUETOOTH.ino | 0 52 files changed, 1452 deletions(-) delete mode 100644 examples/Arancino/04-KEYS/KEYS/KEYS.ino delete mode 100644 examples/Arancino/04-KEYS/KEYS_Packet/KEYS_Packet.ino rename examples/Arancino/{10-HDEL => 07-HDEL}/HDEL/HDEL.ino (100%) rename examples/Arancino/{10-HDEL => 07-HDEL}/HDEL_Packet/HDEL_Packet.ino (100%) delete mode 100644 examples/Arancino/07-HGETALL/HGETALL/HGETALL.ino delete mode 100644 examples/Arancino/07-HGETALL/HGETALL_Packet/HGETALL_Packet.ino rename examples/Arancino/{11-FLUSH => 08-FLUSH}/FLUSH/FLUSH.ino (100%) rename examples/Arancino/{11-FLUSH => 08-FLUSH}/FLUSH_Packet/FLUSH_Packet.ino (100%) delete mode 100644 examples/Arancino/08-HKEYS/HKEYS/HKEYS.ino delete mode 100644 examples/Arancino/08-HKEYS/HKEYS_Packet/HKEYS_Packet.ino delete mode 100644 examples/Arancino/09-HVALS/HVALS/HVALS.ino delete mode 100644 examples/Arancino/09-HVALS/HVALS_Packet/HVALS_Packet.ino rename examples/Arancino/{12-PUBLISH => 09-PUBLISH}/PUBLISH/PUBLISH.ino (100%) rename examples/Arancino/{12-PUBLISH => 09-PUBLISH}/PUBLISH_Packet/PUBLISH_Packet.ino (100%) rename examples/Arancino/{13-MSET => 10-MSET}/MSET/MSET.ino (100%) rename examples/Arancino/{14-MGET => 11-MGET}/MGET/MGET.ino (100%) rename examples/Arancino/{14-MGET => 11-MGET}/MGET_Packet/MGET_Packet.ino (100%) rename examples/Arancino/{15-STORE => 12-STORE}/STORE/STORE.ino (100%) rename examples/Arancino/{15-STORE => 12-STORE}/STORE_Packet/STORE_Packet.ino (100%) rename examples/Arancino/{16-STORETAGS => 13-STORETAGS}/STORETAGS/STORETAGS.ino (100%) rename examples/Arancino/{16-STORETAGS => 13-STORETAGS}/STORETAGS_Packet/STORETAGS_Packet.ino (100%) rename examples/Arancino/{17-MSTORE => 14-MSTORE}/MSTORE/MSTORE.ino (100%) rename examples/Arancino/{17-MSTORE => 14-MSTORE}/MSTORE_Packet/MSTORE_Packet.ino (100%) rename examples/Arancino/{18-MQTT => 15-MQTT}/MQTT/MQTT.ino (100%) rename examples/Arancino/{18-MQTT => 15-MQTT}/MQTT_ESP32/MQTT_ESP32.ino (100%) rename examples/Arancino/{19-BLUETOOTH => 16-BLUETOOTH}/BLUETOOTH/BLUETOOTH.ino (100%) delete mode 100644 examples/Arancino_FreeRTOS/04-KEYS/KEYS/KEYS.ino delete mode 100644 examples/Arancino_FreeRTOS/04-KEYS/KEYS_Packet/KEYS_Packet.ino rename examples/Arancino_FreeRTOS/{10-HDEL => 07-HDEL}/HDEL/HDEL.ino (100%) rename examples/Arancino_FreeRTOS/{10-HDEL => 07-HDEL}/HDEL_Packet/HDEL_Packet.ino (100%) delete mode 100644 examples/Arancino_FreeRTOS/07-HGETALL/HGETALL/HGETALL.ino delete mode 100644 examples/Arancino_FreeRTOS/07-HGETALL/HGETALL_Packet/HGETALL_Packet.ino rename examples/Arancino_FreeRTOS/{11-FLUSH => 08-FLUSH}/FLUSH/FLUSH.ino (100%) rename examples/Arancino_FreeRTOS/{11-FLUSH => 08-FLUSH}/FLUSH_Packet/FLUSH_Packet.ino (100%) delete mode 100644 examples/Arancino_FreeRTOS/08-HKEYS/HKEYS/HKEYS.ino delete mode 100644 examples/Arancino_FreeRTOS/08-HKEYS/HKEYS_Packet/HKEYS_Packet.ino delete mode 100644 examples/Arancino_FreeRTOS/09-HVALS/HVALS/HVALS.ino delete mode 100644 examples/Arancino_FreeRTOS/09-HVALS/HVALS_Packet/HVALS_Packet.ino rename examples/Arancino_FreeRTOS/{12-PUBLISH => 09-PUBLISH}/PUBLISH/PUBLISH.ino (100%) rename examples/Arancino_FreeRTOS/{12-PUBLISH => 09-PUBLISH}/PUBLISH_Packet/PUBLISH_Packet.ino (100%) rename examples/Arancino_FreeRTOS/{13-MSET => 10-MSET}/MSET/MSET.ino (100%) rename examples/Arancino_FreeRTOS/{14-MGET => 11-MGET}/MGET/MGET.ino (100%) rename examples/Arancino_FreeRTOS/{14-MGET => 11-MGET}/MGET_Packet/MGET_Packet.ino (100%) rename examples/Arancino_FreeRTOS/{15-STORE => 12-STORE}/STORE/STORE.ino (100%) rename examples/Arancino_FreeRTOS/{15-STORE => 12-STORE}/STORE_Packet/STORE_Packet.ino (100%) rename examples/Arancino_FreeRTOS/{16-STORETAGS => 13-STORETAGS}/STORETAGS/STORETAGS.ino (100%) rename examples/Arancino_FreeRTOS/{16-STORETAGS => 13-STORETAGS}/STORETAGS_Packet/STORETAGS_Packet.ino (100%) rename examples/Arancino_FreeRTOS/{17-MSTORE => 14-MSTORE}/MSTORE/MSTORE.ino (100%) rename examples/Arancino_FreeRTOS/{17-MSTORE => 14-MSTORE}/MSTORE_Packet/MSTORE_Packet.ino (100%) rename examples/Arancino_FreeRTOS/{18-MQTT => 15-MQTT}/MQTT/MQTT.ino (100%) rename examples/Arancino_FreeRTOS/{18-MQTT => 15-MQTT}/MQTT_ESP32/MQTT_ESP32.ino (100%) rename examples/Arancino_FreeRTOS/{19-BLUETOOTH => 16-BLUETOOTH}/BLUETOOTH/BLUETOOTH.ino (100%) diff --git a/examples/Arancino/04-KEYS/KEYS/KEYS.ino b/examples/Arancino/04-KEYS/KEYS/KEYS.ino deleted file mode 100644 index 48987a7..0000000 --- a/examples/Arancino/04-KEYS/KEYS/KEYS.ino +++ /dev/null @@ -1,90 +0,0 @@ -/* - SPDX-license-identifier: Apache-2.0 - - Copyright (C) 2019 SmartMe.IO - - Authors: Andrea Cannistra - - Licensed under the Apache License, Version 2.0 (the "License"); you may - not use this file except in compliance with the License. You may obtain - a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - License for the specific language governing permissions and limitations - under the License -*/ - -/* - Returns all the keys matching the pattern. - Supported glob-style patterns: - - h?llo matches hello, hallo and hxllo - h*llo matches hllo and heeeello - h[ae]llo matches hello and hallo, but not hillo - h[^e]llo matches hallo, hbllo, ... but not hello - h[a-b]llo matches hallo and hbllo - - Use \ to escape special characters if you want to match them verbatim. - - - char** keys(String pattern) - - Parameters - - pattern: the pattern used to find matching keys. - - - Return value - char** reply: - - list of keys matching pattern. -*/ - -#include - -//Arancino interface -SerialIface iface; - -ArancinoMetadata amdata = { - .fwname = "04.1 - Keys Example", - .fwversion = "1.0.1", - .tzoffset = "+1000" -}; - -void setup() { - - iface.setSerialPort(); - Arancino.attachInterface(iface); - - Arancino.enableDebugMessages(); - Arancino.begin(amdata); - - Arancino.set("EX_04_1_pressure", 1023); - Arancino.set("EX_04_1_humidity", 67.5); - Arancino.set("EX_04_1_temperature", 24.4); - -} - -void loop(){ - - char** keys = Arancino.keys(); - for (int i = 0; i < Arancino.getArraySize(keys); i++) { - Arancino.println(keys[i]); - } - //pressure - //humidity - //temperature - Arancino.free(keys); //delete the array from memory - - delay(1000); //wait 1 seconds - - keys = Arancino.keys("EX_04_1_temp*"); //return all the keys that contains "temp" pattern - for (int i = 0; i < Arancino.getArraySize(keys) ; i++) { - Arancino.println(keys[i]); //temperature - } - - Arancino.free(keys); //delete the array from memory - - delay(1000); //wait 1 seconds - -} diff --git a/examples/Arancino/04-KEYS/KEYS_Packet/KEYS_Packet.ino b/examples/Arancino/04-KEYS/KEYS_Packet/KEYS_Packet.ino deleted file mode 100644 index 63290a0..0000000 --- a/examples/Arancino/04-KEYS/KEYS_Packet/KEYS_Packet.ino +++ /dev/null @@ -1,117 +0,0 @@ -/* - SPDX-license-identifier: Apache-2.0 - - Copyright (C) 2019 SmartMe.IO - - Authors: Dario Gogliandolo - - Licensed under the Apache License, Version 2.0 (the "License"); you may - not use this file except in compliance with the License. You may obtain - a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - License for the specific language governing permissions and limitations - under the License -*/ -/* -Returns all the keys matching the pattern. - -ArancinoPacket keysPacket(char* pattern) - -Supported glob-style patterns: - -h?llo matches hello, hallo and hxllo -h*llo matches hllo and heeeello -h[ae]llo matches hello and hallo, but not hillo -h[^e]llo matches hallo, hbllo, ... but not hello -h[a-b]llo matches hallo and hbllo -Use \ to escape special characters if you want to match them verbatim. - -Parameters: - - pattern: the pattern used to find matching keys. - -Return value: -ArancinoPacket reply: ArancinoPacket containing: - - isError: API call outcome (true or false); - - responseCode: the response code value. (Response code -> https://git.smartme.io/smartme.io/arancino/arancino-library#variables) - - responseType: STRING_ARRAY; - - response.stringArray: char** pointer to the string array of keys matching pattern. -*/ -#include - -//Arancino interface -SerialIface iface; - -ArancinoMetadata amdata = { - .fwname = "04.2 - Keys w/ Packet Example", - .fwversion = "1.0.1", - .tzoffset = "+1000" -}; - -void setup() { - - iface.setSerialPort(); - Arancino.attachInterface(iface); - - Arancino.enableDebugMessages(); - Arancino.begin(amdata); - - Arancino.set("EX_04_2_pressure", 1023); - Arancino.set("EX_04_2_humidity", 67.5); - Arancino.set("EX_04_2_temperature", 24.4); - -} - -void loop(){ - - ArancinoPacket apckt = Arancino.keys(); - char** keys = apckt.response.stringArray; - - if (apckt.isError == 0){ - - Arancino.println("KEYS OK"); - Arancino.print("Response code: "); - Arancino.println(apckt.responseCode); - Arancino.print("Response type: "); - Arancino.println(apckt.responseType); - for (int i = 0; i < Arancino.getArraySize(keys); i++) { - Arancino.println(keys[i]); - } - //pressure - //humidity - //temperature - } - else{ - Arancino.println("KEYS ERROR"); - } - - Arancino.free(apckt); - - delay(1000); //wait 1 seconds - - apckt = Arancino.keys("EX_04_2_temp*"); - keys = apckt.response.stringArray; - - if (apckt.isError == 0){ - - Arancino.println("KEYS OK"); - Arancino.print("Response code: "); - Arancino.println(apckt.responseCode); - Arancino.print("Response type: "); - Arancino.println(apckt.responseType); - for (int i = 0; i < Arancino.getArraySize(keys); i++) { - Arancino.println(keys[i]); - } - } - else{ - Arancino.println("KEYS ERROR"); - } - - Arancino.free(apckt); - delay(1000); //wait 1 seconds - -} diff --git a/examples/Arancino/10-HDEL/HDEL/HDEL.ino b/examples/Arancino/07-HDEL/HDEL/HDEL.ino similarity index 100% rename from examples/Arancino/10-HDEL/HDEL/HDEL.ino rename to examples/Arancino/07-HDEL/HDEL/HDEL.ino diff --git a/examples/Arancino/10-HDEL/HDEL_Packet/HDEL_Packet.ino b/examples/Arancino/07-HDEL/HDEL_Packet/HDEL_Packet.ino similarity index 100% rename from examples/Arancino/10-HDEL/HDEL_Packet/HDEL_Packet.ino rename to examples/Arancino/07-HDEL/HDEL_Packet/HDEL_Packet.ino diff --git a/examples/Arancino/07-HGETALL/HGETALL/HGETALL.ino b/examples/Arancino/07-HGETALL/HGETALL/HGETALL.ino deleted file mode 100644 index eec6264..0000000 --- a/examples/Arancino/07-HGETALL/HGETALL/HGETALL.ino +++ /dev/null @@ -1,72 +0,0 @@ -/* - SPDX-license-identifier: Apache-2.0 - - Copyright (C) 2019 SmartMe.IO - - Authors: Andrea Cannistra - - Licensed under the Apache License, Version 2.0 (the "License"); you may - not use this file except in compliance with the License. You may obtain - a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - License for the specific language governing permissions and limitations - under the License -*/ - -/* - Returns all fields and values of the hash stored at key. In the returned value, every field name is followed by its value. - - - char** hgetall( char* key ) - - Parameters - - key: the name of the key which holds the hash. - - Return value - char** reply: - - list of fields and values matching key. -*/ - -#include - -//Arancino interface -SerialIface iface; - -ArancinoMetadata amdata = { - .fwname = "07.1 - HGetAll Example", - .fwversion = "1.0.1", - .tzoffset = "+1000" -}; - -void setup() { - - iface.setSerialPort(); - Arancino.attachInterface(iface); - - Arancino.enableDebugMessages(); - Arancino.begin(amdata); - - Arancino.hset("EX_07_1_foo", "bar", "yeah"); - Arancino.hset("EX_07_1_foo", "baz", "whoo"); - -} - -void loop(){ - - char** values = Arancino.hgetall("EX_07_1_foo"); - int arraySize = Arancino.getArraySize(values); - for (int i = 0; i < arraySize; i += 2) - { - Arancino.print("foo "); - Arancino.print(values[i]); - Arancino.print(" = "); - Arancino.println(values[i + 1]); - } - Arancino.free(values); //delete the array from memory - - delay(5000); //wait 5 seconds - -} diff --git a/examples/Arancino/07-HGETALL/HGETALL_Packet/HGETALL_Packet.ino b/examples/Arancino/07-HGETALL/HGETALL_Packet/HGETALL_Packet.ino deleted file mode 100644 index 336070b..0000000 --- a/examples/Arancino/07-HGETALL/HGETALL_Packet/HGETALL_Packet.ino +++ /dev/null @@ -1,91 +0,0 @@ -/* - SPDX-license-identifier: Apache-2.0 - - Copyright (C) 2019 SmartMe.IO - - Authors: Dario Gogliandolo - - Licensed under the Apache License, Version 2.0 (the "License"); you may - not use this file except in compliance with the License. You may obtain - a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - License for the specific language governing permissions and limitations - under the License -*/ - -/* -Returns all fields and values of the hash stored at key. In the returned value, every field name is followed by its value. - -ArancinoPacket hgetallPacket(char* key ) - -Parameters: - - key: the name of the key which holds the hash. - -Return value -ArancinoPacket reply: ArancinoPacket containing: - - isError: API call outcome (true or false); - - responseCode: the response code value. (Response code -> https://git.smartme.io/smartme.io/arancino/arancino-library#variables) - - responseType: STRING_ARRAY; - - response.stringArray: char** pointer that can contain the string array of field and value matching key -*/ - -#include - -//Arancino interface -SerialIface iface; - -ArancinoMetadata amdata = { - .fwname = "07.2 - HGetAll w/ Packet Example", - .fwversion = "1.0.1", - .tzoffset = "+1000" -}; - -void setup() { - - iface.setSerialPort(); - Arancino.attachInterface(iface); - - Arancino.enableDebugMessages(); - Arancino.begin(amdata); - - Arancino.hset("EX_07_02_foo", "bar", "yeah"); - Arancino.hset("EX_07_02_foo", "baz", "whoo"); - -} - -void loop(){ - - ArancinoPacket apckt = Arancino.hgetall("EX_07_02_foo"); - - if (!apckt.isError){ - - Arancino.println("HGETALL OK"); - Arancino.print("Response code: "); - Arancino.println(apckt.responseCode); - Arancino.print("Response type: "); - Arancino.println(apckt.responseType); - - char** values = apckt.response.stringArray; - int arraySize = Arancino.getArraySize(values); - - for (int i = 0; i < arraySize; i += 2){ - Arancino.print("foo "); - Arancino.print(values[i]); - Arancino.print(" = "); - Arancino.println(values[i + 1]); - } - } - else{ - Arancino.print("HGETALL ERROR"); - } - - Arancino.free(apckt); //delete the array from memory - - delay(1000); //wait 1 seconds - -} diff --git a/examples/Arancino/11-FLUSH/FLUSH/FLUSH.ino b/examples/Arancino/08-FLUSH/FLUSH/FLUSH.ino similarity index 100% rename from examples/Arancino/11-FLUSH/FLUSH/FLUSH.ino rename to examples/Arancino/08-FLUSH/FLUSH/FLUSH.ino diff --git a/examples/Arancino/11-FLUSH/FLUSH_Packet/FLUSH_Packet.ino b/examples/Arancino/08-FLUSH/FLUSH_Packet/FLUSH_Packet.ino similarity index 100% rename from examples/Arancino/11-FLUSH/FLUSH_Packet/FLUSH_Packet.ino rename to examples/Arancino/08-FLUSH/FLUSH_Packet/FLUSH_Packet.ino diff --git a/examples/Arancino/08-HKEYS/HKEYS/HKEYS.ino b/examples/Arancino/08-HKEYS/HKEYS/HKEYS.ino deleted file mode 100644 index 061c50c..0000000 --- a/examples/Arancino/08-HKEYS/HKEYS/HKEYS.ino +++ /dev/null @@ -1,71 +0,0 @@ -/* -SPDX-license-identifier: Apache-2.0 - -Copyright (C) 2019 SmartMe.IO - -Authors: Andrea Cannistra - -Licensed under the Apache License, Version 2.0 (the "License"); you may -not use this file except in compliance with the License. You may obtain -a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -License for the specific language governing permissions and limitations -under the License -*/ - -/* -Returns all field names in the hash stored at key. - -- char** hkeys( char* key ) - -Parameters -- key: the name of the key which holds the hash. - -Return value - char** reply: -- list of fields matching key. - -*/ - -#include - -//Arancino interface -SerialIface iface; - -ArancinoMetadata amdata = { - .fwname = "08.1 - HKeys Example", - .fwversion = "1.0.1", - .tzoffset = "+1000" -}; - -void setup() { - - iface.setSerialPort(); - Arancino.attachInterface(iface); - - Arancino.enableDebugMessages(); - Arancino.begin(amdata); - - Arancino.hset("EX_08_1_foo","bar","yeah"); - Arancino.hset("EX_08_1_foo","baz","whoo"); - -} - -void loop(){ - - char** fields = Arancino.hkeys("EX_08_1_foo"); - for (int i = 0; i < Arancino.getArraySize(fields); i++) { - Arancino.print("EX_08_1_foo -> "); - Arancino.println(fields[i]); - // foo -> bar - // foo -> baz - } - Arancino.free(fields); - - delay(5000); //wait 5 seconds - -} diff --git a/examples/Arancino/08-HKEYS/HKEYS_Packet/HKEYS_Packet.ino b/examples/Arancino/08-HKEYS/HKEYS_Packet/HKEYS_Packet.ino deleted file mode 100644 index 7481ec6..0000000 --- a/examples/Arancino/08-HKEYS/HKEYS_Packet/HKEYS_Packet.ino +++ /dev/null @@ -1,85 +0,0 @@ -/* - SPDX-license-identifier: Apache-2.0 - - Copyright (C) 2019 SmartMe.IO - - Authors: Dario Gogliandolo - - Licensed under the Apache License, Version 2.0 (the "License"); you may - not use this file except in compliance with the License. You may obtain - a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - License for the specific language governing permissions and limitations - under the License -*/ -/* -Returns all field names in the hash stored at key. - -ArancinoPacket hkeysPacket( String key ) - -Parameters: - - key: the name of the key which holds the hash. - -Return value -ArancinoPacket reply: ArancinoPacket containing: - - isError: API call outcome (true or false); - - responseCode: the response code value. (Response code -> https://git.smartme.io/smartme.io/arancino/arancino-library#variables) - - responseType: STRING_ARRAY; - - response.stringArray: char** pointer to the string array of fields matching key. -*/ -#include - -//Arancino interface -SerialIface iface; - -ArancinoMetadata amdata = { - .fwname = "08.2 - HKeys w/ Packet Example", - .fwversion = "1.0.1", - .tzoffset = "+1000" -}; - -void setup() { - - iface.setSerialPort(); - Arancino.attachInterface(iface); - - Arancino.enableDebugMessages(); - Arancino.begin(amdata); - - Arancino.hset("EX_08_2_foo","bar","yeah"); - Arancino.hset("EX_08_2_foo","baz","whoo"); - -} - -void loop(){ - - ArancinoPacket apckt = Arancino.hkeys("EX_08_2_foo"); - char** fields = apckt.response.stringArray; - if (!apckt.isError) - { - Arancino.println("HKEYS OK"); - Arancino.print("Response code: "); - Arancino.println(apckt.responseCode); - Arancino.print("Response type: "); - Arancino.println(apckt.responseType); - for (int i = 0; i < Arancino.getArraySize(fields); i++) { - Arancino.print("EX_08_2_foo -> "); - Arancino.println(fields[i]); - // foo -> bar - // foo -> baz - } - } - else - { - Arancino.println("HKEYS ERROR"); - } - - Arancino.free(apckt); - delay(5000); //wait 5 seconds - -} diff --git a/examples/Arancino/09-HVALS/HVALS/HVALS.ino b/examples/Arancino/09-HVALS/HVALS/HVALS.ino deleted file mode 100644 index 5f9a016..0000000 --- a/examples/Arancino/09-HVALS/HVALS/HVALS.ino +++ /dev/null @@ -1,69 +0,0 @@ -/* - SPDX-license-identifier: Apache-2.0 - - Copyright (C) 2019 SmartMe.IO - - Authors: Andrea Cannistra - - Licensed under the Apache License, Version 2.0 (the "License"); you may - not use this file except in compliance with the License. You may obtain - a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - License for the specific language governing permissions and limitations - under the License -*/ - -/* - Returns all field names in the hash stored at key. - - - char** hvals( char* key ) - - Parameters - - key: the name of the key which holds the hash. - - Return value - char* reply: - - list of values matching key. -*/ - -#include - -//Arancino interface -SerialIface iface; - -ArancinoMetadata amdata = { - .fwname = "09.1 - HVals Example", - .fwversion = "1.0.1", - .tzoffset = "+1000" -}; - -void setup() { - - iface.setSerialPort(); - Arancino.attachInterface(iface); - - Arancino.enableDebugMessages(); - Arancino.begin(amdata); - - Arancino.hset("EX_09_1_foo", "bar", "yeah"); - Arancino.hset("EX_09_1_foo", "baz", "whoo"); - -} - -void loop(){ - - char** values = Arancino.hvals("EX_09_1_foo"); - for (int i = 0; i < Arancino.getArraySize(values); i++) { - Arancino.print("EX_09_1_foo -> "); - Arancino.println(values[i]); - // foo -> yeah - // foo -> whoo - } - Arancino.free(values); - - delay(5000); //wait 5 seconds -} diff --git a/examples/Arancino/09-HVALS/HVALS_Packet/HVALS_Packet.ino b/examples/Arancino/09-HVALS/HVALS_Packet/HVALS_Packet.ino deleted file mode 100644 index 1679539..0000000 --- a/examples/Arancino/09-HVALS/HVALS_Packet/HVALS_Packet.ino +++ /dev/null @@ -1,85 +0,0 @@ -/* - SPDX-license-identifier: Apache-2.0 - - Copyright (C) 2019 SmartMe.IO - - Authors: Dario Gogliandolo - - Licensed under the Apache License, Version 2.0 (the "License"); you may - not use this file except in compliance with the License. You may obtain - a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - License for the specific language governing permissions and limitations - under the License -*/ -/* -Returns all values in the hash stored at key. - -ArancinoPacket hvalsPacket(char* key ) - -Parameters: - - key: the name of the key which holds the hash. - -Return value -ArancinoPacket reply: ArancinoPacket containing: - - isError: API call outcome (true or false); - - responseCode: the response code value. (Response code -> https://git.smartme.io/smartme.io/arancino/arancino-library#variables) - - responseType: STRING_ARRAY; - - response.stringArray: char** pointer to the string array of values matching key. -*/ -#include - -//Arancino interface -SerialIface iface; - -ArancinoMetadata amdata = { - .fwname = "09.2 - HVals w/ Packet Example", - .fwversion = "1.0.1", - .tzoffset = "+1000" -}; - - -void setup() { - - iface.setSerialPort(); - Arancino.attachInterface(iface); - - Arancino.enableDebugMessages(); - Arancino.begin(amdata); - - Arancino.hset("EX_09_2_foo", "bar", "yeah"); - Arancino.hset("EX_09_2_foo", "baz", "whoo"); - -} - -void loop(){ - - ArancinoPacket apckt = Arancino.hvals("EX_09_2_foo"); - char** values = apckt.response.stringArray; - - if (!apckt.isError){ - - Arancino.println("HVALS OK"); - Arancino.print("Response code: "); - Arancino.println(apckt.responseCode); - Arancino.print("Response type: "); - Arancino.println(apckt.responseType); - for (int i = 0; i < Arancino.getArraySize(values); i++) { - Arancino.print("EX_09_2_foo -> "); - Arancino.println(values[i]); - // foo -> yeah - // foo -> whoo - } - } - else{ - Arancino.println("HVALS ERROR"); - } - - Arancino.free(apckt); - delay(5000); //wait 5 seconds -} diff --git a/examples/Arancino/12-PUBLISH/PUBLISH/PUBLISH.ino b/examples/Arancino/09-PUBLISH/PUBLISH/PUBLISH.ino similarity index 100% rename from examples/Arancino/12-PUBLISH/PUBLISH/PUBLISH.ino rename to examples/Arancino/09-PUBLISH/PUBLISH/PUBLISH.ino diff --git a/examples/Arancino/12-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino b/examples/Arancino/09-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino similarity index 100% rename from examples/Arancino/12-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino rename to examples/Arancino/09-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino diff --git a/examples/Arancino/13-MSET/MSET/MSET.ino b/examples/Arancino/10-MSET/MSET/MSET.ino similarity index 100% rename from examples/Arancino/13-MSET/MSET/MSET.ino rename to examples/Arancino/10-MSET/MSET/MSET.ino diff --git a/examples/Arancino/14-MGET/MGET/MGET.ino b/examples/Arancino/11-MGET/MGET/MGET.ino similarity index 100% rename from examples/Arancino/14-MGET/MGET/MGET.ino rename to examples/Arancino/11-MGET/MGET/MGET.ino diff --git a/examples/Arancino/14-MGET/MGET_Packet/MGET_Packet.ino b/examples/Arancino/11-MGET/MGET_Packet/MGET_Packet.ino similarity index 100% rename from examples/Arancino/14-MGET/MGET_Packet/MGET_Packet.ino rename to examples/Arancino/11-MGET/MGET_Packet/MGET_Packet.ino diff --git a/examples/Arancino/15-STORE/STORE/STORE.ino b/examples/Arancino/12-STORE/STORE/STORE.ino similarity index 100% rename from examples/Arancino/15-STORE/STORE/STORE.ino rename to examples/Arancino/12-STORE/STORE/STORE.ino diff --git a/examples/Arancino/15-STORE/STORE_Packet/STORE_Packet.ino b/examples/Arancino/12-STORE/STORE_Packet/STORE_Packet.ino similarity index 100% rename from examples/Arancino/15-STORE/STORE_Packet/STORE_Packet.ino rename to examples/Arancino/12-STORE/STORE_Packet/STORE_Packet.ino diff --git a/examples/Arancino/16-STORETAGS/STORETAGS/STORETAGS.ino b/examples/Arancino/13-STORETAGS/STORETAGS/STORETAGS.ino similarity index 100% rename from examples/Arancino/16-STORETAGS/STORETAGS/STORETAGS.ino rename to examples/Arancino/13-STORETAGS/STORETAGS/STORETAGS.ino diff --git a/examples/Arancino/16-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino b/examples/Arancino/13-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino similarity index 100% rename from examples/Arancino/16-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino rename to examples/Arancino/13-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino diff --git a/examples/Arancino/17-MSTORE/MSTORE/MSTORE.ino b/examples/Arancino/14-MSTORE/MSTORE/MSTORE.ino similarity index 100% rename from examples/Arancino/17-MSTORE/MSTORE/MSTORE.ino rename to examples/Arancino/14-MSTORE/MSTORE/MSTORE.ino diff --git a/examples/Arancino/17-MSTORE/MSTORE_Packet/MSTORE_Packet.ino b/examples/Arancino/14-MSTORE/MSTORE_Packet/MSTORE_Packet.ino similarity index 100% rename from examples/Arancino/17-MSTORE/MSTORE_Packet/MSTORE_Packet.ino rename to examples/Arancino/14-MSTORE/MSTORE_Packet/MSTORE_Packet.ino diff --git a/examples/Arancino/18-MQTT/MQTT/MQTT.ino b/examples/Arancino/15-MQTT/MQTT/MQTT.ino similarity index 100% rename from examples/Arancino/18-MQTT/MQTT/MQTT.ino rename to examples/Arancino/15-MQTT/MQTT/MQTT.ino diff --git a/examples/Arancino/18-MQTT/MQTT_ESP32/MQTT_ESP32.ino b/examples/Arancino/15-MQTT/MQTT_ESP32/MQTT_ESP32.ino similarity index 100% rename from examples/Arancino/18-MQTT/MQTT_ESP32/MQTT_ESP32.ino rename to examples/Arancino/15-MQTT/MQTT_ESP32/MQTT_ESP32.ino diff --git a/examples/Arancino/19-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino b/examples/Arancino/16-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino similarity index 100% rename from examples/Arancino/19-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino rename to examples/Arancino/16-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino diff --git a/examples/Arancino_FreeRTOS/04-KEYS/KEYS/KEYS.ino b/examples/Arancino_FreeRTOS/04-KEYS/KEYS/KEYS.ino deleted file mode 100644 index 6251262..0000000 --- a/examples/Arancino_FreeRTOS/04-KEYS/KEYS/KEYS.ino +++ /dev/null @@ -1,101 +0,0 @@ -/* - SPDX-license-identifier: Apache-2.0 - - Copyright (C) 2019 SmartMe.IO - - Authors: Andrea Cannistra - - Licensed under the Apache License, Version 2.0 (the "License"); you may - not use this file except in compliance with the License. You may obtain - a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - License for the specific language governing permissions and limitations - under the License -*/ - -/* - Returns all the keys matching the pattern. - Supported glob-style patterns: - - h?llo matches hello, hallo and hxllo - h*llo matches hllo and heeeello - h[ae]llo matches hello and hallo, but not hillo - h[^e]llo matches hallo, hbllo, ... but not hello - h[a-b]llo matches hallo and hbllo - - Use \ to escape special characters if you want to match them verbatim. - - - char** keys(String pattern) - - Parameters - - pattern: the pattern used to find matching keys. - - - Return value - char** reply: - - list of keys matching pattern. -*/ - -#include - -//Arancino interface -SerialIface iface; - -ArancinoMetadata amdata = { - .fwname = "04.1 - Keys Example", - .fwversion = "1.0.1", - .tzoffset = "+1000" -}; - -//FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); - -void setup() { - - iface.setSerialPort(); - Arancino.attachInterface(iface); - - Arancino.enableDebugMessages(); - Arancino.begin(amdata); - - Arancino.set("EX_04_1_pressure", 1023); - Arancino.set("EX_04_1_humidity", 67.5); - Arancino.set("EX_04_1_temperature", 24.4); - - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); - Arancino.startScheduler(); -} - -void loop(){ - //empty -} - -void loopTask(void *pvParameters){ - while(1){ - - char** keys = Arancino.keys(); - for (int i = 0; i < Arancino.getArraySize(keys); i++) { - Arancino.println(keys[i]); - } - //pressure - //humidity - //temperature - Arancino.free(keys); //delete the array from memory - - vTaskDelay(1000); //wait 1 seconds - - keys = Arancino.keys("EX_04_1_temp*"); //return all the keys that contains "temp" pattern - for (int i = 0; i < Arancino.getArraySize(keys) ; i++) { - Arancino.println(keys[i]); //temperature - } - - Arancino.free(keys); //delete the array from memory - - vTaskDelay(1000); //wait 1 seconds - } -} diff --git a/examples/Arancino_FreeRTOS/04-KEYS/KEYS_Packet/KEYS_Packet.ino b/examples/Arancino_FreeRTOS/04-KEYS/KEYS_Packet/KEYS_Packet.ino deleted file mode 100644 index 7862611..0000000 --- a/examples/Arancino_FreeRTOS/04-KEYS/KEYS_Packet/KEYS_Packet.ino +++ /dev/null @@ -1,131 +0,0 @@ -/* - SPDX-license-identifier: Apache-2.0 - - Copyright (C) 2019 SmartMe.IO - - Authors: Dario Gogliandolo - - Licensed under the Apache License, Version 2.0 (the "License"); you may - not use this file except in compliance with the License. You may obtain - a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - License for the specific language governing permissions and limitations - under the License -*/ -/* -Returns all the keys matching the pattern. - -ArancinoPacket keysPacket(char* pattern) - -Supported glob-style patterns: - -h?llo matches hello, hallo and hxllo -h*llo matches hllo and heeeello -h[ae]llo matches hello and hallo, but not hillo -h[^e]llo matches hallo, hbllo, ... but not hello -h[a-b]llo matches hallo and hbllo -Use \ to escape special characters if you want to match them verbatim. - -Parameters: - - pattern: the pattern used to find matching keys. - -Return value: -ArancinoPacket reply: ArancinoPacket containing: - - isError: API call outcome (true or false); - - responseCode: the response code value. (Response code -> https://git.smartme.io/smartme.io/arancino/arancino-library#variables) - - responseType: STRING_ARRAY; - - response.stringArray: char** pointer to the string array of keys matching pattern. -*/ -#include - -//Arancino interface -SerialIface iface; - -ArancinoMetadata amdata = { - .fwname = "04.2 - Keys w/ Packet Example", - .fwversion = "1.0.1", - .tzoffset = "+1000" -}; - -//FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); - -void setup() { - - iface.setSerialPort(); - Arancino.attachInterface(iface); - - Arancino.enableDebugMessages(); - Arancino.begin(amdata); - - Arancino.set("EX_04_2_pressure", 1023); - Arancino.set("EX_04_2_humidity", 67.5); - Arancino.set("EX_04_2_temperature", 24.4); - - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); - Arancino.startScheduler(); - -} - -void loop(){ - //empty -} - -void loopTask(void *pvParameters){ - while(1){ - - ArancinoPacket apckt = Arancino.keys(); - char** keys = apckt.response.stringArray; - - if (apckt.isError == 0){ - - Arancino.println("KEYS OK"); - Arancino.print("Response code: "); - Arancino.println(apckt.responseCode); - Arancino.print("Response type: "); - Arancino.println(apckt.responseType); - for (int i = 0; i < Arancino.getArraySize(keys); i++) { - Arancino.println(keys[i]); - } - //pressure - //humidity - //temperature - } - else{ - Arancino.println("KEYS ERROR"); - } - - Arancino.free(apckt); - - vTaskDelay(1000); //wait 1 seconds - - apckt = Arancino.keys("EX_04_2_temp*"); - keys = apckt.response.stringArray; - - if (apckt.isError == 0){ - - Arancino.println("KEYS OK"); - Arancino.print("Response code: "); - Arancino.println(apckt.responseCode); - Arancino.print("Response type: "); - Arancino.println(apckt.responseType); - for (int i = 0; i < Arancino.getArraySize(keys); i++) { - Arancino.println(keys[i]); - } - // temperature - - } - else{ - Arancino.println("KEYS ERROR"); - } - - Arancino.free(apckt); - vTaskDelay(1000); //wait 1 seconds - } -} diff --git a/examples/Arancino_FreeRTOS/10-HDEL/HDEL/HDEL.ino b/examples/Arancino_FreeRTOS/07-HDEL/HDEL/HDEL.ino similarity index 100% rename from examples/Arancino_FreeRTOS/10-HDEL/HDEL/HDEL.ino rename to examples/Arancino_FreeRTOS/07-HDEL/HDEL/HDEL.ino diff --git a/examples/Arancino_FreeRTOS/10-HDEL/HDEL_Packet/HDEL_Packet.ino b/examples/Arancino_FreeRTOS/07-HDEL/HDEL_Packet/HDEL_Packet.ino similarity index 100% rename from examples/Arancino_FreeRTOS/10-HDEL/HDEL_Packet/HDEL_Packet.ino rename to examples/Arancino_FreeRTOS/07-HDEL/HDEL_Packet/HDEL_Packet.ino diff --git a/examples/Arancino_FreeRTOS/07-HGETALL/HGETALL/HGETALL.ino b/examples/Arancino_FreeRTOS/07-HGETALL/HGETALL/HGETALL.ino deleted file mode 100644 index af95833..0000000 --- a/examples/Arancino_FreeRTOS/07-HGETALL/HGETALL/HGETALL.ino +++ /dev/null @@ -1,83 +0,0 @@ -/* - SPDX-license-identifier: Apache-2.0 - - Copyright (C) 2019 SmartMe.IO - - Authors: Andrea Cannistra - - Licensed under the Apache License, Version 2.0 (the "License"); you may - not use this file except in compliance with the License. You may obtain - a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - License for the specific language governing permissions and limitations - under the License -*/ - -/* - Returns all fields and values of the hash stored at key. In the returned value, every field name is followed by its value. - - - char** hgetall( char* key ) - - Parameters - - key: the name of the key which holds the hash. - - Return value - char** reply: - - list of fields and values matching key. -*/ - -#include - -//Arancino interface -SerialIface iface; - -ArancinoMetadata amdata = { - .fwname = "07.1 - HGetAll Example", - .fwversion = "1.0.1", - .tzoffset = "+1000" -}; - -//FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); - -void setup() { - - iface.setSerialPort(); - Arancino.attachInterface(iface); - - Arancino.enableDebugMessages(); - Arancino.begin(amdata); - - Arancino.hset("EX_07_1_foo", "bar", "yeah"); - Arancino.hset("EX_07_1_foo", "baz", "whoo"); - - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); - Arancino.startScheduler(); - -} - -void loop(){ - //empty -} - -void loopTask(void *pvParameters){ - while(1){ - char** values = Arancino.hgetall("EX_07_1_foo"); - int arraySize = Arancino.getArraySize(values); - for (int i = 0; i < arraySize; i += 2) - { - Arancino.print("foo "); - Arancino.print(values[i]); - Arancino.print(" = "); - Arancino.println(values[i + 1]); - } - Arancino.free(values); //delete the array from memory - - vTaskDelay(5000); //wait 5 seconds - } -} diff --git a/examples/Arancino_FreeRTOS/07-HGETALL/HGETALL_Packet/HGETALL_Packet.ino b/examples/Arancino_FreeRTOS/07-HGETALL/HGETALL_Packet/HGETALL_Packet.ino deleted file mode 100644 index b681a77..0000000 --- a/examples/Arancino_FreeRTOS/07-HGETALL/HGETALL_Packet/HGETALL_Packet.ino +++ /dev/null @@ -1,102 +0,0 @@ -/* - SPDX-license-identifier: Apache-2.0 - - Copyright (C) 2019 SmartMe.IO - - Authors: Dario Gogliandolo - - Licensed under the Apache License, Version 2.0 (the "License"); you may - not use this file except in compliance with the License. You may obtain - a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - License for the specific language governing permissions and limitations - under the License -*/ - -/* -Returns all fields and values of the hash stored at key. In the returned value, every field name is followed by its value. - -ArancinoPacket hgetallPacket(char* key ) - -Parameters: - - key: the name of the key which holds the hash. - -Return value -ArancinoPacket reply: ArancinoPacket containing: - - isError: API call outcome (true or false); - - responseCode: the response code value. (Response code -> https://git.smartme.io/smartme.io/arancino/arancino-library#variables) - - responseType: STRING_ARRAY; - - response.stringArray: char** pointer that can contain the string array of field and value matching key -*/ - -#include - -//Arancino interface -SerialIface iface; - -ArancinoMetadata amdata = { - .fwname = "07.2 - HGetAll w/ Packet Example", - .fwversion = "1.0.1", - .tzoffset = "+1000" -}; - -//FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); - -void setup() { - - iface.setSerialPort(); - Arancino.attachInterface(iface); - - Arancino.enableDebugMessages(); - Arancino.begin(amdata); - - Arancino.hset("EX_07_02_foo", "bar", "yeah"); - Arancino.hset("EX_07_02_foo", "baz", "whoo"); - - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); - Arancino.startScheduler(); -} - -void loop(){ - //empty -} - -void loopTask(void *pvParameters){ - while(1){ - - ArancinoPacket apckt = Arancino.hgetall("EX_07_02_foo"); - - if (!apckt.isError){ - - Arancino.println("HGETALL OK"); - Arancino.print("Response code: "); - Arancino.println(apckt.responseCode); - Arancino.print("Response type: "); - Arancino.println(apckt.responseType); - - char** values = apckt.response.stringArray; - int arraySize = Arancino.getArraySize(values); - - for (int i = 0; i < arraySize; i += 2){ - Arancino.print("foo "); - Arancino.print(values[i]); - Arancino.print(" = "); - Arancino.println(values[i + 1]); - } - } - else{ - Arancino.print("HGETALL ERROR"); - } - - Arancino.free(apckt); //delete the array from memory - - vTaskDelay(1000); //wait 1 seconds - } -} diff --git a/examples/Arancino_FreeRTOS/11-FLUSH/FLUSH/FLUSH.ino b/examples/Arancino_FreeRTOS/08-FLUSH/FLUSH/FLUSH.ino similarity index 100% rename from examples/Arancino_FreeRTOS/11-FLUSH/FLUSH/FLUSH.ino rename to examples/Arancino_FreeRTOS/08-FLUSH/FLUSH/FLUSH.ino diff --git a/examples/Arancino_FreeRTOS/11-FLUSH/FLUSH_Packet/FLUSH_Packet.ino b/examples/Arancino_FreeRTOS/08-FLUSH/FLUSH_Packet/FLUSH_Packet.ino similarity index 100% rename from examples/Arancino_FreeRTOS/11-FLUSH/FLUSH_Packet/FLUSH_Packet.ino rename to examples/Arancino_FreeRTOS/08-FLUSH/FLUSH_Packet/FLUSH_Packet.ino diff --git a/examples/Arancino_FreeRTOS/08-HKEYS/HKEYS/HKEYS.ino b/examples/Arancino_FreeRTOS/08-HKEYS/HKEYS/HKEYS.ino deleted file mode 100644 index c8d3285..0000000 --- a/examples/Arancino_FreeRTOS/08-HKEYS/HKEYS/HKEYS.ino +++ /dev/null @@ -1,82 +0,0 @@ -/* -SPDX-license-identifier: Apache-2.0 - -Copyright (C) 2019 SmartMe.IO - -Authors: Andrea Cannistra - -Licensed under the Apache License, Version 2.0 (the "License"); you may -not use this file except in compliance with the License. You may obtain -a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -License for the specific language governing permissions and limitations -under the License -*/ - -/* -Returns all field names in the hash stored at key. - -- char** hkeys( char* key ) - -Parameters -- key: the name of the key which holds the hash. - -Return value - char** reply: -- list of fields matching key. - -*/ - -#include - -//Arancino interface -SerialIface iface; - -ArancinoMetadata amdata = { - .fwname = "08.1 - HKeys Example", - .fwversion = "1.0.1", - .tzoffset = "+1000" -}; - -//FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); - -void setup() { - - iface.setSerialPort(); - Arancino.attachInterface(iface); - - Arancino.enableDebugMessages(); - Arancino.begin(amdata); - - Arancino.hset("EX_08_1_foo","bar","yeah"); - Arancino.hset("EX_08_1_foo","baz","whoo"); - - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); - Arancino.startScheduler(); - -} - -void loop(){ - //empty -} - -void loopTask(void *pvParameters) { - while(1){ - char** fields = Arancino.hkeys("EX_08_1_foo"); - for (int i = 0; i < Arancino.getArraySize(fields); i++) { - Arancino.print("EX_08_1_foo -> "); - Arancino.println(fields[i]); - // foo -> bar - // foo -> baz - } - Arancino.free(fields); - - vTaskDelay(5000); //wait 5 seconds - } -} diff --git a/examples/Arancino_FreeRTOS/08-HKEYS/HKEYS_Packet/HKEYS_Packet.ino b/examples/Arancino_FreeRTOS/08-HKEYS/HKEYS_Packet/HKEYS_Packet.ino deleted file mode 100644 index 2d79bb4..0000000 --- a/examples/Arancino_FreeRTOS/08-HKEYS/HKEYS_Packet/HKEYS_Packet.ino +++ /dev/null @@ -1,96 +0,0 @@ -/* - SPDX-license-identifier: Apache-2.0 - - Copyright (C) 2019 SmartMe.IO - - Authors: Dario Gogliandolo - - Licensed under the Apache License, Version 2.0 (the "License"); you may - not use this file except in compliance with the License. You may obtain - a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - License for the specific language governing permissions and limitations - under the License -*/ -/* -Returns all field names in the hash stored at key. - -ArancinoPacket hkeysPacket( String key ) - -Parameters: - - key: the name of the key which holds the hash. - -Return value -ArancinoPacket reply: ArancinoPacket containing: - - isError: API call outcome (true or false); - - responseCode: the response code value. (Response code -> https://git.smartme.io/smartme.io/arancino/arancino-library#variables) - - responseType: STRING_ARRAY; - - response.stringArray: char** pointer to the string array of fields matching key. -*/ -#include - -//Arancino interface -SerialIface iface; - -ArancinoMetadata amdata = { - .fwname = "08.2 - HKeys w/ Packet Example", - .fwversion = "1.0.1", - .tzoffset = "+1000" -}; - -//FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); - -void setup() { - - iface.setSerialPort(); - Arancino.attachInterface(iface); - - Arancino.enableDebugMessages(); - Arancino.begin(amdata); - - Arancino.hset("EX_08_2_foo","bar","yeah"); - Arancino.hset("EX_08_2_foo","baz","whoo"); - - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); - Arancino.startScheduler(); - -} - -void loop(){ - //empty -} - -void loopTask(void *pvParameters) { - while(1){ - ArancinoPacket apckt = Arancino.hkeys("EX_08_2_foo"); - char** fields = apckt.response.stringArray; - if (!apckt.isError) - { - Arancino.println("HKEYS OK"); - Arancino.print("Response code: "); - Arancino.println(apckt.responseCode); - Arancino.print("Response type: "); - Arancino.println(apckt.responseType); - for (int i = 0; i < Arancino.getArraySize(fields); i++) { - Arancino.print("EX_08_2_foo -> "); - Arancino.println(fields[i]); - // foo -> bar - // foo -> baz - } - } - else - { - Arancino.println("HKEYS ERROR"); - } - - Arancino.free(apckt); - vTaskDelay(5000); //wait 5 seconds - } -} diff --git a/examples/Arancino_FreeRTOS/09-HVALS/HVALS/HVALS.ino b/examples/Arancino_FreeRTOS/09-HVALS/HVALS/HVALS.ino deleted file mode 100644 index ab7d716..0000000 --- a/examples/Arancino_FreeRTOS/09-HVALS/HVALS/HVALS.ino +++ /dev/null @@ -1,81 +0,0 @@ -/* - SPDX-license-identifier: Apache-2.0 - - Copyright (C) 2019 SmartMe.IO - - Authors: Andrea Cannistra - - Licensed under the Apache License, Version 2.0 (the "License"); you may - not use this file except in compliance with the License. You may obtain - a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - License for the specific language governing permissions and limitations - under the License -*/ - -/* - Returns all field names in the hash stored at key. - - - char** hvals( char* key ) - - Parameters - - key: the name of the key which holds the hash. - - Return value - char* reply: - - list of values matching key. -*/ - -#include - -//Arancino interface -SerialIface iface; - -ArancinoMetadata amdata = { - .fwname = "09.1 - HVals Example", - .fwversion = "1.0.1", - .tzoffset = "+1000" -}; - -//FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); - -void setup() { - - iface.setSerialPort(); - Arancino.attachInterface(iface); - - Arancino.enableDebugMessages(); - Arancino.begin(amdata); - - Arancino.hset("EX_09_1_foo", "bar", "yeah"); - Arancino.hset("EX_09_1_foo", "baz", "whoo"); - - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); - Arancino.startScheduler(); - -} - -void loop(){ - //empty -} - -void loopTask(void *pvParameters) { - while(1){ - char** values = Arancino.hvals("EX_09_1_foo"); - for (int i = 0; i < Arancino.getArraySize(values); i++) { - Arancino.print("EX_09_1_foo -> "); - Arancino.println(values[i]); - // foo -> yeah - // foo -> whoo - } - Arancino.free(values); - - vTaskDelay(5000); //wait 5 seconds - } -} diff --git a/examples/Arancino_FreeRTOS/09-HVALS/HVALS_Packet/HVALS_Packet.ino b/examples/Arancino_FreeRTOS/09-HVALS/HVALS_Packet/HVALS_Packet.ino deleted file mode 100644 index a97adcd..0000000 --- a/examples/Arancino_FreeRTOS/09-HVALS/HVALS_Packet/HVALS_Packet.ino +++ /dev/null @@ -1,96 +0,0 @@ -/* - SPDX-license-identifier: Apache-2.0 - - Copyright (C) 2019 SmartMe.IO - - Authors: Dario Gogliandolo - - Licensed under the Apache License, Version 2.0 (the "License"); you may - not use this file except in compliance with the License. You may obtain - a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - License for the specific language governing permissions and limitations - under the License -*/ -/* -Returns all values in the hash stored at key. - -ArancinoPacket hvalsPacket(char* key ) - -Parameters: - - key: the name of the key which holds the hash. - -Return value -ArancinoPacket reply: ArancinoPacket containing: - - isError: API call outcome (true or false); - - responseCode: the response code value. (Response code -> https://git.smartme.io/smartme.io/arancino/arancino-library#variables) - - responseType: STRING_ARRAY; - - response.stringArray: char** pointer to the string array of values matching key. -*/ -#include - -//Arancino interface -SerialIface iface; - -ArancinoMetadata amdata = { - .fwname = "09.2 - HVals w/ Packet Example", - .fwversion = "1.0.1", - .tzoffset = "+1000" -}; - -//FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); - -void setup() { - - iface.setSerialPort(); - Arancino.attachInterface(iface); - - Arancino.enableDebugMessages(); - Arancino.begin(amdata); - - Arancino.hset("EX_09_2_foo", "bar", "yeah"); - Arancino.hset("EX_09_2_foo", "baz", "whoo"); - - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); - Arancino.startScheduler(); -} - -void loop(){ - //empty -} - -void loopTask(void *pvParameters) { - while(1){ - - ArancinoPacket apckt = Arancino.hvals("EX_09_2_foo"); - char** values = apckt.response.stringArray; - - if (!apckt.isError){ - - Arancino.println("HVALS OK"); - Arancino.print("Response code: "); - Arancino.println(apckt.responseCode); - Arancino.print("Response type: "); - Arancino.println(apckt.responseType); - for (int i = 0; i < Arancino.getArraySize(values); i++) { - Arancino.print("EX_09_2_foo -> "); - Arancino.println(values[i]); - // foo -> yeah - // foo -> whoo - } - } - else{ - Arancino.println("HVALS ERROR"); - } - - Arancino.free(apckt); - vTaskDelay(5000); //wait 5 seconds - } -} diff --git a/examples/Arancino_FreeRTOS/12-PUBLISH/PUBLISH/PUBLISH.ino b/examples/Arancino_FreeRTOS/09-PUBLISH/PUBLISH/PUBLISH.ino similarity index 100% rename from examples/Arancino_FreeRTOS/12-PUBLISH/PUBLISH/PUBLISH.ino rename to examples/Arancino_FreeRTOS/09-PUBLISH/PUBLISH/PUBLISH.ino diff --git a/examples/Arancino_FreeRTOS/12-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino b/examples/Arancino_FreeRTOS/09-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino similarity index 100% rename from examples/Arancino_FreeRTOS/12-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino rename to examples/Arancino_FreeRTOS/09-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino diff --git a/examples/Arancino_FreeRTOS/13-MSET/MSET/MSET.ino b/examples/Arancino_FreeRTOS/10-MSET/MSET/MSET.ino similarity index 100% rename from examples/Arancino_FreeRTOS/13-MSET/MSET/MSET.ino rename to examples/Arancino_FreeRTOS/10-MSET/MSET/MSET.ino diff --git a/examples/Arancino_FreeRTOS/14-MGET/MGET/MGET.ino b/examples/Arancino_FreeRTOS/11-MGET/MGET/MGET.ino similarity index 100% rename from examples/Arancino_FreeRTOS/14-MGET/MGET/MGET.ino rename to examples/Arancino_FreeRTOS/11-MGET/MGET/MGET.ino diff --git a/examples/Arancino_FreeRTOS/14-MGET/MGET_Packet/MGET_Packet.ino b/examples/Arancino_FreeRTOS/11-MGET/MGET_Packet/MGET_Packet.ino similarity index 100% rename from examples/Arancino_FreeRTOS/14-MGET/MGET_Packet/MGET_Packet.ino rename to examples/Arancino_FreeRTOS/11-MGET/MGET_Packet/MGET_Packet.ino diff --git a/examples/Arancino_FreeRTOS/15-STORE/STORE/STORE.ino b/examples/Arancino_FreeRTOS/12-STORE/STORE/STORE.ino similarity index 100% rename from examples/Arancino_FreeRTOS/15-STORE/STORE/STORE.ino rename to examples/Arancino_FreeRTOS/12-STORE/STORE/STORE.ino diff --git a/examples/Arancino_FreeRTOS/15-STORE/STORE_Packet/STORE_Packet.ino b/examples/Arancino_FreeRTOS/12-STORE/STORE_Packet/STORE_Packet.ino similarity index 100% rename from examples/Arancino_FreeRTOS/15-STORE/STORE_Packet/STORE_Packet.ino rename to examples/Arancino_FreeRTOS/12-STORE/STORE_Packet/STORE_Packet.ino diff --git a/examples/Arancino_FreeRTOS/16-STORETAGS/STORETAGS/STORETAGS.ino b/examples/Arancino_FreeRTOS/13-STORETAGS/STORETAGS/STORETAGS.ino similarity index 100% rename from examples/Arancino_FreeRTOS/16-STORETAGS/STORETAGS/STORETAGS.ino rename to examples/Arancino_FreeRTOS/13-STORETAGS/STORETAGS/STORETAGS.ino diff --git a/examples/Arancino_FreeRTOS/16-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino b/examples/Arancino_FreeRTOS/13-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino similarity index 100% rename from examples/Arancino_FreeRTOS/16-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino rename to examples/Arancino_FreeRTOS/13-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino diff --git a/examples/Arancino_FreeRTOS/17-MSTORE/MSTORE/MSTORE.ino b/examples/Arancino_FreeRTOS/14-MSTORE/MSTORE/MSTORE.ino similarity index 100% rename from examples/Arancino_FreeRTOS/17-MSTORE/MSTORE/MSTORE.ino rename to examples/Arancino_FreeRTOS/14-MSTORE/MSTORE/MSTORE.ino diff --git a/examples/Arancino_FreeRTOS/17-MSTORE/MSTORE_Packet/MSTORE_Packet.ino b/examples/Arancino_FreeRTOS/14-MSTORE/MSTORE_Packet/MSTORE_Packet.ino similarity index 100% rename from examples/Arancino_FreeRTOS/17-MSTORE/MSTORE_Packet/MSTORE_Packet.ino rename to examples/Arancino_FreeRTOS/14-MSTORE/MSTORE_Packet/MSTORE_Packet.ino diff --git a/examples/Arancino_FreeRTOS/18-MQTT/MQTT/MQTT.ino b/examples/Arancino_FreeRTOS/15-MQTT/MQTT/MQTT.ino similarity index 100% rename from examples/Arancino_FreeRTOS/18-MQTT/MQTT/MQTT.ino rename to examples/Arancino_FreeRTOS/15-MQTT/MQTT/MQTT.ino diff --git a/examples/Arancino_FreeRTOS/18-MQTT/MQTT_ESP32/MQTT_ESP32.ino b/examples/Arancino_FreeRTOS/15-MQTT/MQTT_ESP32/MQTT_ESP32.ino similarity index 100% rename from examples/Arancino_FreeRTOS/18-MQTT/MQTT_ESP32/MQTT_ESP32.ino rename to examples/Arancino_FreeRTOS/15-MQTT/MQTT_ESP32/MQTT_ESP32.ino diff --git a/examples/Arancino_FreeRTOS/19-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino b/examples/Arancino_FreeRTOS/16-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino similarity index 100% rename from examples/Arancino_FreeRTOS/19-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino rename to examples/Arancino_FreeRTOS/16-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino From ee7c8db1d432311d8e38053bcfcc4afb9ebee400 Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Fri, 11 Nov 2022 17:16:02 +0100 Subject: [PATCH 13/69] Updated docs --- README.md | 4 +- docs/CORTEX.md | 139 +----------------------------- docs/Cortex_Protocol/DEL.md | 88 +++++++++++++++++++ docs/Cortex_Protocol/FLUSH.md | 58 +++++++++++++ docs/Cortex_Protocol/GET.md | 113 ++++++++++++++++++++++++ docs/Cortex_Protocol/HDEL.md | 77 +++++++++++++++++ docs/Cortex_Protocol/HGET.md | 101 ++++++++++++++++++++++ docs/Cortex_Protocol/HSET.md | 138 +++++++++++++++++++++++++++++ docs/Cortex_Protocol/PUB.md | 70 +++++++++++++++ docs/Cortex_Protocol/README.md | 87 +++++++++++++++++++ docs/Cortex_Protocol/SET.md | 106 +++++++++++++++++++++++ docs/Cortex_Protocol/SIGN.md | 55 ++++++++++++ docs/Cortex_Protocol/START.md | 96 +++++++++++++++++++++ docs/Cortex_Protocol/STORE.md | 95 ++++++++++++++++++++ docs/Cortex_Protocol/STORETAGS.md | 71 +++++++++++++++ library.json | 2 +- library.properties | 2 +- 17 files changed, 1163 insertions(+), 139 deletions(-) create mode 100644 docs/Cortex_Protocol/DEL.md create mode 100644 docs/Cortex_Protocol/FLUSH.md create mode 100644 docs/Cortex_Protocol/GET.md create mode 100644 docs/Cortex_Protocol/HDEL.md create mode 100644 docs/Cortex_Protocol/HGET.md create mode 100644 docs/Cortex_Protocol/HSET.md create mode 100644 docs/Cortex_Protocol/PUB.md create mode 100644 docs/Cortex_Protocol/README.md create mode 100644 docs/Cortex_Protocol/SET.md create mode 100644 docs/Cortex_Protocol/SIGN.md create mode 100644 docs/Cortex_Protocol/START.md create mode 100644 docs/Cortex_Protocol/STORE.md create mode 100644 docs/Cortex_Protocol/STORETAGS.md diff --git a/README.md b/README.md index dde1cc4..e830d8f 100644 --- a/README.md +++ b/README.md @@ -18,14 +18,14 @@ Arancino Library allows to export/import data to/from the Linux environment usin - Insights -- [Cortex Protocol](CORTEX_PROTOCOL.md) +- [Cortex Protocol](docs/CORTEX.md) - [Debug](docs/DEBUG.md) - [Reserved Keys](docs/RESERVED_KEYS.md) ## Compatibility list -The Arancino Library `2.1.0` officially supports the following Arancino Core versions: +The Arancino Library `3.1.0` officially supports the following Arancino Core versions: |Board| Core Version | |--|--| | SAMD21 | 1.3.0 | diff --git a/docs/CORTEX.md b/docs/CORTEX.md index c2c1861..d8ca86a 100644 --- a/docs/CORTEX.md +++ b/docs/CORTEX.md @@ -1,139 +1,8 @@ ## Cortex Protocol -Arancino Library uses a simple protocol, called **Cortex**, to communicate with the Arancino Module over serial connection. Cortex Protocol is designed to be easy to read and processed. Arancino Library, Arancino Module and Cortex Protocol are designed to be monodirectional and synchronous. In this scenario the Arancino Library within the microcontroller acts as *master*, and the Arancino Module as *slave*. - - -Each command sent using Cortex Protocol is composed by a *command identifier* and one or more *parameters*. *Command identifiers* and *parameters* are separated by a separator character, and the command ends with an end character. Each command sent will receive a response, formed by a Response Code and one or more returned values. All the items are separated by the same separtor character and ends with the same end character. The commands receive Response within a timeout interval of `100ms`. If no Response is received, the Command will be skipped. - -### Commands identifier: - - -| API | Command Identifiers | -| ------------------ |:-------------:| -| [`begin`](#begin) | START | -| [`set`](#set) | SET | -| [`get`](#get) | GET | -| [`mset`](#mset) | MSET | -| [`mget`](#mget) | MGET | -| [`del`](#del) | DEL | -| [`keys`](#keys) | KEYS | -| [`hget`](#hget) | HGET | -| [`hset`](#hset) | HSET | -| [`hkeys`](#hkeys) | HKEYS | -| [`hvals`](#hvals) | HVALS | -| [`hdel`](#hdel) | HDEL | -| [`flush`](#flush) | FLUSH | -| [`publish`](#publish) | PUB | -| [`mset`](#mset) | MSET | -| [`mget`](#mget) | MGET | -| [`store`](#store) | STORE | -| [`storetags`](#storetags)| STORETAGS| - -### Commands separator chars -**Important**: Do not use these character codes to compose string values to pass to the API - -| Separator | Char Code | -| --------------------- |:-------------:| -| Command Sepatator | `4` | -| Array separator | `16` | -| NULL character | `25` | -| End of transmission | `30` | - - -### Response Codes -| Response Code | Type | Description | Note | -|-------|-----------|-------------|------| -| `100` | Success | Generic operation successfully completed || -| `101` | Success | Setted value into a new field || -| `103` | Success | Setted value into an existing field || -| `200` | Error | Generic Error | | -| `201` | Error | Retrivied Null Value | Deprecated| -| `202` | Error | Error during SET command || -| `203` | Error | Command not found || -| `204` | Error | Error during SET command || -| `205` | Error | Invalid parameter number || -| `206` | Error | Generic Redis Error || -| `207` | Error | Key exists in the Standard Data Store || -| `208` | Error | Key exists in the Persistent Data Store || -| `209` | Error | Non compatibility between Arancino Daemon and Library || -| `210` | Error | Generic Invalid Arguments || -| `211` | Error | Invalid Value || -| `212` | Error | Not yet implemented functionality || +Arancino Library uses a simple protocol, called **Cortex**, to communicate with the Arancino Module using multiple connection Interfaces (MQTT,Serial,Bluetooth). Cortex Protocol is designed to be easy to read and processed. Arancino Library, Arancino Module and Cortex Protocol are designed to be monodirectional and synchronous. In this scenario the Arancino Library within the microcontroller acts as *master*, and the Arancino Module as *slave*. +Each command sent using Cortex Protocol is composed by a *command identifier* and one or more *parameters*. *Command identifiers* and *parameters* are formatted inside a *JSON* and the message itself is compressed into a *MessagePack*. Each command sent will receive a response, formed by a Response Code and one or more returned values. The commands receive Response within a timeout interval. If no Response is received, the Command will be skipped. ### Commands and Protocol -As exaplained above, when an API function is called, a command is sent over the `SerialUSB` and a response is received. -In the next paragraphs, for simplicity we are considering each command returns an *OK* response and using the following representation for *Separator Codes*: - -- Command Sepatator → `4` → `#` -- Array separator → `16` → `%` -- End of transmission → `30` →` @` - -#### begin -- Command Sent: `START#####@` -- Response Received: `100@` - -#### set -- Command Sent: `SET##@` -- Response Received: `100@` - -#### get -- Command Sent: `GET#@` -- Response Received: `100#@` - -#### mset -- Command Sent: `MSET#%...%#%...%@` -- Response Received: `100#@` - -#### mget -- Command Sent: `MGET#%...%@` -- Response Received: `100##...#]@` - -#### del -- Command Sent: `DEL#@` -- Response Received: `100#1@` - -#### keys -- Command Sent: `KEYS#@` -- Response Received: `100[###]@` - -#### hset -- Command Sent: `HSET###@` -- Response Received: 101@ - -#### hget -- Command Sent: `HGET##@` -- Response Received: `100#@` - -#### hgetall -- Command Sent: `HGETALL#@` -- Response Received: `100####@` - -#### hkeys -- Command Sent: `HKEYS#@` -- Response Received: `100HKEYS#@` - -#### hvals -- Command Sent: `HVALS#@` -- Response Received: `100##@` - -#### hdel -- Command Sent: `HDEL##@` -- Response Received: `100#1@` - -#### flush -- Command Sent: `FLUSH@` -- Response Received: `100@` - -#### storetag -- Command Sent: `STORE##%%#%%#@` -- Response Received: `100@` - -- Command Sent: `STORE##%%#%%@` -- Response Received: `100@` - -#### store -- Command Sent: `STORE##@` -- Response Received: `100#@` - -- Command Sent: `STORE###@` -- Response Received: `100#@` +As exaplained above, when an API function is called, a command is sent over the `ArancinoInterface` and a response is received. +More details about the command structure and relative responses may be found in the [Cortex Protocol](Cortex_Protocol/README.md) section. \ No newline at end of file diff --git a/docs/Cortex_Protocol/DEL.md b/docs/Cortex_Protocol/DEL.md new file mode 100644 index 0000000..8645352 --- /dev/null +++ b/docs/Cortex_Protocol/DEL.md @@ -0,0 +1,88 @@ +# `DEL` +Delete the specified *keys*. + +>Note: +> +>- A *key* is ignored if it does not exist. +>- The specified *keys* will be deleted even if they were previously stored in a *persistent* way based on the `pers` configuration. You can only delete "application" keys (`"type":"appl"`) + +## **Command** + +**Arguments:** + +| Args Type | Desc | Mandatory | +| ----- | --------- | --------- | +| `items`: String Array | Array of *keys* to delete | **Yes** | + +**Configuration:** + +| Key | Desc | Mandatory | +| :------ | :-------------------------------------- | -------------------------------- | +| `pers:` Number | Allows to del keys from the persistent datatstore. To use only with `"type": "appl"`. Allowed values: `0` is *False* and `1` is *True* | **No** | +| `ack:` Number | Indicates whether a *response* (the ack) should be sent for the *command*. *True* by default. Allowed values: `0` is *False* and `1` is *True*| **No** | +| `sgntr`: String | Signature used for ECDSA Authentication | **No**: used only in *Secure Mode* | + +**Example:** + +```json + { + "cmd": "DEL", + "args":{ + "items":[ + "" + ] + }, + "cfg":{ + "ack": 1, + "pers": 0, + "sgntr": "" + } + } +``` + +```json + { + "cmd": "DEL", + "args":{ + "items":[ + "", "", "" + ] + }, + "cfg":{ + "ack": 0, + "pers": 1, + "sgntr": "" + } + } +``` + +## **Response** + +**Arguments:** Empty +| Key | Desc | Mandatory | +| ------- | ----------------------------------------- | -------------------------------- | +| `keys`: Number | Number of deleted keys | **Yes** | + +**Configuration:** + +| Key | Desc | Mandatory | +| ------- | ----------------------------------------- | -------------------------------- | +| `chlng` | Challenge useful to sign the next command | No: used only in Secure Protocol | + +**Examples:** + +```json + { + "rsp_code": "100", + "args":{ + "keys": + }, + "cfg":{ + "chlng": "" + } + } +``` + +>Note: +> +>- List of possible Error Codes for `DEL`: `200`,`206` **Da controllare per aggiunta anche di errori presenti durante il protocollo sicuro diff --git a/docs/Cortex_Protocol/FLUSH.md b/docs/Cortex_Protocol/FLUSH.md new file mode 100644 index 0000000..0599130 --- /dev/null +++ b/docs/Cortex_Protocol/FLUSH.md @@ -0,0 +1,58 @@ +#### `FLUSH` +Delete all the keys. + +>Note: +> +>- This command never fails. + +## **Command** + +**Arguments:** Empty + +**Configuration:** + +| Key | Desc | Mandatory | +| :------ | :-------------------------------------- | -------------------------------- | +| `pers:` Number | Allows to delete persistent or volatile keys. False by default. Allowed values: `0` is _False_ and `1` is _True_ | **No** | +| `ack:` Number | Indicates whether a *response* (the ack) should be sent for the *command*. *True* by default. Allowed values: `0` is *False* and `1` is *True*| **No** | +| `sgntr`: String | Signature used for ECDSA Authentication | No: used only in Secure Protocol | + +**Example:** + +```json + { + "cmd": "FLUSH", + "args":{}, + "cfg":{ + "pers": 0, + "ack": 1, + "sgntr": "" + } + } +``` + +## **Response** + +**Arguments:** None + +**Configuration:** + +| Key | Desc | Mandatory | +| ------- | ----------------------------------------- | -------------------------------- | +| `chlng`: String | Challenge useful to sign the next command | No: used only in Secure Protocol | + +**Examples:** + +```json + { + "rsp_code": "100", + "args":{}, + "cfg":{ + "chlng": "" + } + } +``` + +>Note: +> +>- List of possible Error Codes for `FLUSH`: `200`, `206` **Da controllare per l'aggiunta anche di errori presenti durante il protocollo sicuro diff --git a/docs/Cortex_Protocol/GET.md b/docs/Cortex_Protocol/GET.md new file mode 100644 index 0000000..b58622e --- /dev/null +++ b/docs/Cortex_Protocol/GET.md @@ -0,0 +1,113 @@ +# `GET` +Retrieves the *values* of *keys*. If the *key* does not exist the special value `null` is returned. + +>Note: +> +>- An error is returned if the value stored at *key* is not a string, because `GET` only handles string values. + +## Command** + +##### **Arguments:** + +| Args Type | Desc | Mandatory | +| ----- | --------- | --------- | +| `items`: String Array | Array of *keys* to retrieve | **Yes** | + +**Configuration:** + +| Key | Desc | Mandatory | +| :------ | :-------------------------------------- | -------------------------------- | +| `pers:` Number | Allows to get values from the persistent datastore. To use only with `"type": "appl"`. Allowed values: `0` is *False* and `1` is *True* | **No** | +| `type:` String | Represent the kind of the key. Availalble values are `appl:` for application key (default value), `stng` for application settings key, `rsvd` for reserved key used under the hood for operation. | **No** | | +| `sgntr`: String | Signature used for ECDSA Authentication | **No**: used only in *Secure Mode* | + +**Example:** + +Retrieving single *key* stored persistently +```json + { + "cmd": "GET", + "args":{ + "items": [ + "" + ] + }, + "cfg":{ + "pers": 1, + "type": "appl", + "sgntr": "" + } + } +``` + +Retrieving multiple *key* +```json + { + "cmd": "GET", + "args":{ + "items":[ + "", "", "" + ] + }, + "cfg":{ + "pers": 0, + "type": "appl", + "sgntr": "" + } + } +``` + +Retrieving a configuration/setting *key* +```json + { + "cmd": "GET", + "args":{ + "items":[ + "" + ] + }, + "cfg":{ + "type": "stng", + "sgntr": "" + } + } +``` + +## Response + +**Arguments:** + +| Args Type | Desc | Mandatory | +| ------- | -------------------------- | --------- | +| `items:` Array | Array of `Key-Value` pairs retrieved from the *keys* specified as *command* args | **Yes** | +| - `key:` String | Name of the *key* | **Yes** | +| - `value:` String | Value of the *key* | **Yes** | + + +**Configuration:** + +| Key | Desc | Mandatory | +| ------- | ----------------------------------------- | -------------------------------- | +| `chlng:` String | Challenge useful to sign the next command | **No**: used only in *Secure Mode* | + +**Examples:** + +```json + { + "rsp_code": "100", + "args":{ + "items":[ + {"key": "", "value": ""}, + {"key": "", "value": ""}, + {"key": "", "value": ""} + ] + }, + "cfg":{ + "chlng": "" + } + } +``` + +>Note: +> +>- List of possible Error Codes for `GET`: `200`, `201`, `206`, `207`, `208`, `210` **Da controllare per aggiunta anche di errori presenti durante il protocollo sicuro diff --git a/docs/Cortex_Protocol/HDEL.md b/docs/Cortex_Protocol/HDEL.md new file mode 100644 index 0000000..21c5117 --- /dev/null +++ b/docs/Cortex_Protocol/HDEL.md @@ -0,0 +1,77 @@ +# `HDEL` +Removes the specified field from the hash stored at key. + +>Note: +> +>- Specified fields that do not exist within this hash are ignored. + +## **Command** + +**Arguments:** + +| Key | Desc | Mandatory | +| ------- | ---------------------------------------- | --------- | +| `items:` Array | Array of `key-field` pairs to remove| **Yes** | +| - `key:` String | Name of the *key* | **Yes** | +| - `field:` String | Name of the *field* | **Yes** | + + +**Configuration:** + +| Key | Desc | Mandatory | +| :------ | :-------------------------------------- | -------------------------------- | +| `pers:` Number | Allows to get values from the persistent datastore. To use only with `"type": "appl"`. Allowed values: `0` is *False* and `1` is *True* | **No** | +| `ack:` Number | Indicates whether a *response* (the ack) should be sent for the *command*. *True* by default. Allowed values: `0` is *False* and `1` is *True*| **No** | +| `sgntr:` String | Signature used for ECDSA Authentication | No: used only in Secure Protocol | + +**Example:** + +```json + { + "cmd": "HDEL", + "args":{ + "items":[ + {"key": "", "field": ""}, + {"key": "", "field": ""} + {"key": "", "field": ""} + {"key": "", "field": ""} + ], + }, + "cfg":{ + "ack": 1, + "sgntr": "" + } + } +``` + +## Response + +**Arguments:** + +| Key | Desc | Mandatory | +| ------- | ----------------------------------------- | -------------------------------- | +| `fields`: Number | Number of deleted fields | **Yes** | + +**Configuration:** + +| Key | Desc | Mandatory | +| ------- | ----------------------------------------- | -------------------------------- | +| `chlng:` String | Challenge useful to sign the next command | No: used only in Secure Protocol | + +**Examples:** + +```json + { + "rsp_code": "100", + "args":{ + "fields": + }, + "cfg":{ + "chlng": "" + } + } +``` + +>Note: +> +>- List of possible Error Codes for `HDEL`: `200`, `206` **Da controllare per l'aggiunta anche di errori presenti durante il protocollo sicuro diff --git a/docs/Cortex_Protocol/HGET.md b/docs/Cortex_Protocol/HGET.md new file mode 100644 index 0000000..8b5226f --- /dev/null +++ b/docs/Cortex_Protocol/HGET.md @@ -0,0 +1,101 @@ +# `HGET` +Returns the values associated with fields in the hashes stored at keys. + +## **Command** + +**Arguments:** + +| Key | Desc | Mandatory | +| ----------------- | -------------------------- | --------- | +| `items:` Array | Array of `key-field` pairs | **Yes** | +| - `key:` String | Name of the *key* | **Yes** | +| - `field:` String | Name of the *field* | **Yes** | + +**Configuration:** + +| Key | Desc | Mandatory | +| :------ | :-------------------------------------- | -------------------------------- | +| `pers:` Number | Allows to get values from the persistent datastore. To use only with `"type": "appl"`. Allowed values: `0` is *False* and `1` is *True* | **No** | +| `type:` String | Represent the kind of the key. Availalble values are `appl:` for application key (default value), `stng` for application settings key, `rsvd` for reserved key used under the hood for operation. | **No** | | +| `sgntr:` String | Signature used for ECDSA Authentication | **No**: used only in *Secure Mode* | + + + +**Example:** + +Retrieving single *field* + +```json + { + "cmd": "HGET", + "args":{ + "items":[ + {"key": "", "field": ""} + ] + }, + "cfg":{ + "pers": 0, + "type": "appl", + "sgntr": "" + } + } +``` + +Retrieving multiple *fields* + +```json + { + "cmd": "HGET", + "args":{ + "items":[ + {"key": "", "field": ""}, + {"key": "", "field": ""}, + {"key": "", "field": ""} + ] + }, + "cfg":{ + "pers": 0, + "type": "appl", + "sgntr": "" + } + } +``` + +## **Response** + +**Arguments:** + +| Key | Desc | Mandatory | +| ----------------------- | ------------------------------------------------------------ | --------- +| `items:` Array | Array of `key-field-value` tuples retrieved from the *keys* and the *fields* specified as *command args* | **Yes** | +| - `key:` String | Name of the *key* | **Yes** | +| - `field:` String | Name of the *field* | **Yes** | +| - `value:` String | Value at the *key-field* | **Yes** | + +**Configuration:** + +| Key | Desc | Mandatory | +| ------- | ----------------------------------------- | -------------------------------- | +| `chlng:` String | Challenge useful to sign the next command | **No**: used only in *Secure Mode* | + +**Examples:** + +```json + { + "rsp_code": "100", + "args":{ + "items":[ + {"key": "", "field": "", "value": ""}, + {"key": "", "field": "", "value": ""}, + {"key": "", "field": "", "value": ""} + ] + }, + "cfg":{ + "chlng": "" + } + } +``` + +>Note: +> +>- List of possible Error Codes for `HGET`: `200`, `206` **Da controllare per l'aggiunta anche di errori presenti durante il protocollo sicuro diff --git a/docs/Cortex_Protocol/HSET.md b/docs/Cortex_Protocol/HSET.md new file mode 100644 index 0000000..ec446b3 --- /dev/null +++ b/docs/Cortex_Protocol/HSET.md @@ -0,0 +1,138 @@ +# `HSET` +Sets *field* in the hash stored at *key* to *value*. + +>Note: +> +>- If *key* does not exist, a new *key* holding a *hash* is created. +>- If *field* already exists in the *hash*, it is overwritten. +> When setting multiple *key* and all (or some) of they were previously stored in a different way (persistent/volatile) than now, a warning will be received as response + +## **Command** + +**Arguments:** + +| Data | | Desc | Mandatory | +| ------------ |-| -------------------------------- | --------- | +| `items:` Array | Array of `key-field-value` tuple | **Yes** | +| - `key:` String | Name of the *key* | **Yes** | +| - `field:` String | Name of the *field* | **Yes** | +| - `value:` String | Value at the *key-field* | **Yes** | + +**Configuration:** + +| Key | Desc | Mandatory | +| :----------- | :----------------------------------------------------------- | -------------------------------- | +| `type:` String | Represent the kind of the key. Availalble values are `appl:` for application key (default value), `stng` for application settings key, `rsvd` for reserved key used under the hood for operation. | **No** | +| `pers:` Number | Allows to store values in a persistent way. False by default. Allowed values: `0` is _False_ and `1` is _True_ | **No** | +| `ack:` Number | Indicates whether a *response* (the ack) should be sent for the *command*. *True* by default. Allowed values: `0` is *False* and `1` is *True*| **No** | +| `sgntr:` String | Signature used for ECDSA Authentication | **No**: used only in *Secure Mode* | + +**Examples:** + +Example of `HSET` command with a single _key-field-value_ set stored non-persistently + + +```json + { + "cmd": "HSET", + "args":{ + "items":[ + {"key": "", "field": "", "value": ""} + ] + }, + "cfg":{ + "type": "appl", + "pers": 0, + "ack": 1, + "sgntr": "" + } + } +``` + + +Example of `HSET` command with a single _key-field-value_ set stored persistently + +```json + { + "cmd": "HSET", + "args":{ + "items":[ + {"key": "", "field": "", "value": ""} + ] + }, + "cfg":{ + "type": "appl", + "pers": 1, + "ack": 1, + "sgntr": "" + } + } +``` + +Example of `HSET` command with a single _key-field-value_ set of settings values: + +```json + { + "cmd": "HSET", + "args":{ + "items":[ + {"key": "", "field": "", "value": ""} + ] + }, + "cfg":{ + "type": "stng", + "ack": 1, + "sgntr": "" + } + } +``` + +Example of `HSET` command with a multiple _key-field-value_ sets stored persistently. + +```json + { + "cmd": "HSET", + "args":{ + "items":[ + {"key":"", "field":"", "value":""}, + {"key":"", "field":"", "value":""}, + {"key":"", "field":"", "value":""}, + {"key":"", "field":"", "value":""} + ] + }, + "cfg":{ + "type": "appl", + "pers": 1, + "ack": 1, + "sgntr": "" + } + } +``` + +## **Response** + +**Arguments:** None + + +**Configuration:** + +| Required Key | Desc | Mandatory | +| ------------ | ----------------------------------------- | -------------------------------- | +| `chlng:` String | Challenge useful to sign the next command | **No**: used only in *Secure Mode* | + +**Examples:** + +```json + { + "rsp_code": "100", + "args":{}, + "cfg":{ + "chlng": "" + } + } +``` + + +>Note: +> +>- List of possible Error Codes for `HSET`: `200`, `206`, `207`, `208` **Da controllare per l'aggiunta anche di errori presenti durante il protocollo sicuro \ No newline at end of file diff --git a/docs/Cortex_Protocol/PUB.md b/docs/Cortex_Protocol/PUB.md new file mode 100644 index 0000000..4ef84e2 --- /dev/null +++ b/docs/Cortex_Protocol/PUB.md @@ -0,0 +1,70 @@ +#### `PUB` +Posts a message to the given channel. Return the number of clients that received the message. + +##### **`PUB` Command** + +**Arguments:** + +| Key | Desc | Mandatory | +| --------- | ------------------------------------ | --------- | +| `channel` | Channel where to publish the message | Yes | +| `message` | Message to publish | Yes | + +**Configuration:** + +| Key | Desc | Mandatory | +| :------ | :-------------------------------------- | -------------------------------- | +| `ack:` Number | Indicates whether a *response* (the ack) should be sent for the *command*. *True* by default. Allowed values: `0` is *False* and `1` is *True*| **No** | +| `sgntr` | Signature used for ECDSA Authentication | No: used only in Secure Protocol | + +**Example:** + +```json + { + "cmd": "PUB", + "args":{ + "items":[ + {"channel": "", "message": ""}, + {"channel": "", "message": ""} + ] + }, + "cfg":{ + "ack": 1, + "sgntr": "" + } + } +``` + +##### `PUB` Response + +**Arguments:** + +| Key | Desc | Mandatory | +| ----------- | -------------------------------------------- | --------- | +| `num_client` | Number of clients that received the message. | Yes | + +**Configuration:** + +| Key | Desc | Mandatory | +| ------- | ----------------------------------------- | -------------------------------- | +| `chlng` | Challenge useful to sign the next command | No: used only in Secure Protocol | + +**Examples:** + +```json + { + "rsp_code": "100", + "args":{ + "clients": + }, + "cfg":{ + "chlng": "" + } + } +``` + +>Note: +> +>- List of possible Error Codes for `PUB`: `200`, `206` **Da controllare per l'aggiunta anche di errori presenti durante il protocollo sicuro + +--- \ No newline at end of file diff --git a/docs/Cortex_Protocol/README.md b/docs/Cortex_Protocol/README.md new file mode 100644 index 0000000..19b148c --- /dev/null +++ b/docs/Cortex_Protocol/README.md @@ -0,0 +1,87 @@ +# Arancino Cortex Protocol + +Arancino Cortex is a simple protocol enabling the communication between two (or more) parts. Its name remember the cerebral cortex of the brain, which has the purpose to put in communication the right and the left hemispheres of the brain. + +Cortex could be used over serial, tcp, and other kind of connections, and it's used to make Arancino.cc Devices able to receive data from other devices (like Arancino Mignon) even simultaneously. In this case, Arancino.cc Board is intended as the right hemisphere, while the devices as if they were the "senses" of the left hemisphere. + +Due to its design, Cortex is monodirectional and synchronous; in this scenario the Arancino.cc Mignon (or other compatible devices) within a microcontroller acts as *Peripheral Unit*, and the Arancino.cc Board as *Main Unit*. The *Peripheral* device sends a *Command* and waits the *Main* for a *Response*, so for each *Command* there's a *Response*. + +Generically, could be more than one *peripheral unit* and only one *Main*, or at the minimum one *Main* and one *Peripheral*. As mentioned above the *Peripheral* sends one *Command* at time and receives a *Response* for each *Command*. Cortex *Commands* basically follows [Redis commands](https://redis.io/commands). *Commands* are mainly for storing data, and the storing can be setted to be *persistent* or *volatile*, for each *Command*. *Persistent* means that data can be retrievied also after a power off and on of *Main* device; *volatile* means that data are erased after a power off and on. + +## **Secure Authentication and Communication** + +Secure authentication between *peripheral units* and a *Main* allows to start a connection with the *Main* only to *peripheral units* previously choice , to achieve this is used the ECDSA (Elliptic Curve Digital Signature Algorithm). The *Main* receive device and signer certificates with the `START` command, verify the certificates validity and the presence of device public key in a whitelist, finally send back the response of the `START` command with a *challenge* (a random number codified with base64 encryption) in the configuration. When the *peripheral unit* receive the response with the *challenge* sign it with its private key and send it back in the `SIGN` command configuration (the *signature*), codified with base64 encryption. The *Main* receive the `SIGN` command and verify the correctness of the *signature*, then if it's verified the *peripheral unit* is authenticated and a *challenge* is send back in the response configuration. + +Secure communication is implemented with the help of the *challenge* present in the previous response configuration, every time that a command is sent from the *peripheral unit* it has to contain the *signature* of the *challenge* received with the previous *response*, starting with the *challenge* received in the `SIGN` *response*. + +The secure authentication and communication is used only when the flag `SCR_MOD` in the `START` response is 1 + +## Cortex Commands and Responses + +Cortex *Commands* are composed by *Command Identifier*, *Command Arguments* and *Command Configuration* meanwhile a *Response* is composed by *Response Code*, *Response Arguments* and *Response Configuration*. + +The format used to build both *Commands* and *Responses* is Json. Before the transmission, *Commands* and *Responses* are converted to [**MessagePack**](https://msgpack.org), an efficient binary serialization format smaller and faster than Json. + +- *Command Identifier* is used to identify the right action to execute in the *Main* device. + +- *Command Arguments* contains the parameters useful to execute the action identified by the *Command Identifier*. + +- *Command Configuration* has extra parameters for the configuration of *command* or *response*. + +- *Response Code* is a numeric code that indicates the success or the failure of a *Command*. + +- *Response Arguments* when used, contains the values of required by a *Command*. + +- *Response Configuration* used to send settings to the "peripheral" device for a specific "Command". + + +### Notes on Commands Configuration: + +#### Persistent +Persistent configuration, with the `pers` key, is used to indicates that the value will be stored persistently. The default value is `0`. +#### Type +Type configuration, with the `type` key, stands to indicates the kind of the key. At this version of protocol `type` has three possible values: +- Applicaiton Type (`appl`): it's the most used case, used when users want to set a value within application. `pers` configuration can only be used with this `type`. `appl` is the default value for `type` configuration. +- Setting Type (`stng`): used to store configuration parameters for the application i.e. mqtt host and port. This kind of key should be stored *persistenly*. if `type:stng`, `pers` configuration will be ignored. +- Reserved Type (`rsvd`): used under the hood to set key for operation purpose. if `type:rsvd`, `pers` configuration will be ignored. +#### Ack +Ack configuration must be understood as the will to want to receive a *Response* to the *Command*. There are cases in which to speed up communication it may be useful not to send a reply, to do so just set this parameter to *False*. + +#### Signature +Signature configuration is used when the communication is setted to be *Secure*. It contains the signature and by default expects a *Response* with the challenge, so the `ack` configuration will be ignored. + + +### Commands and Responses + +Commands List: +- [`START`](START.md) +- [`SIGN`](SIGN.md) +- [`SET`](SET.md) +- [`GET`](GET.md) +- [`DEL`](DEL.md) +- [`HSET`](HSET.md) +- [`HGET`](HGET.md) +- [`HDEL`](HDEL.md) +- [`STORE`](STORE.md) +- [`STORETAGS`](STORETAGS.md) +- [`PUB`](PUB.md) +- [`FLUSH`](FLUSH.md) + +### Response Codes + +| `rsp_code` | |Description | +|:-----------------:|:-------|:------------------------------------------| +| `100` | **OK** | Generic operation successfully completed. | +| `101` | **OK** | Set value into a new field. | +| `102` | **OK** | Set value into an existing field | +| `200` | **KO** | Generic Error | +| `201` | **KO** | Retrieved NULL value (deprecated) | +| `202` | **KO** | Error during *SET* command | +| `203` | **KO** | Command not found | +| `204` | **KO** | Command not received | +| `205` | **KO** | Invalid parameter number | +| `206` | **KO** | Generic Redis Error | +| `207` | **KO** | Key exists in the Standard Data Store | +| `208` | **KO** | Key exists in the Persistent Data Store | +| `209` | **KO** | Non compatibility between Arancino Module and Library | +| `210` | **KO** | Invalid arguments: incorrect, empty, or not equal number | diff --git a/docs/Cortex_Protocol/SET.md b/docs/Cortex_Protocol/SET.md new file mode 100644 index 0000000..db1b6cd --- /dev/null +++ b/docs/Cortex_Protocol/SET.md @@ -0,0 +1,106 @@ +# `SET` +Sets _keys_ to hold the string _values_. If _key_ already holds a _value_, it is overwritten, regardless of its type. `SET` works both in _persistent_ and in _volatile_ (_non-persistent_) but not at the same time. + +## **Command** + +**Arguments:** + +| Args Type | Desc | Mandatory | +| ------- | ------------------------------ | --------- | +| `items:` Array | Array of `key-value` pairs | **Yes** | +| - `key:` String | Name of the *key* | **Yes** | +| - `value:` String | Value of the *key* | **Yes** | + + + +**Configurations:** + +| Key | Desc | Default | Mandatory | +| :------ | :----------------------------------------------------------- |: -------|:--------- | +| `type:` String | Represent the kind of the key. Availalble values are `appl` for application key, `stng` for application settings key, `rsvd` for reserved key used under the hood for operation. | `appl` |**No** | +| `pers:` Number | Allows to store values in a persistent way. To use only with `"type": "appl"`. Allowed values: `0` is *False* and `1` is *True* | `0` (*False*) |**No** | +| `ack:` Number | Indicates whether a *response* (the ack) should be sent for the *command*. *True* by default. Allowed values: `0` is *False* and `1` is *True*| | `1` (*True*) |**No** | +| `sgntr:` String | Signature used for ECDSA Authentication | **No**: used only in *Secure Mode* | + +**Examples:** + +Example of `SET` command with a single _key-value_ pair stored non-persistently +```json + { + "cmd": "SET", + "args": { + "items":[ + {"key": "", "value": ""} + ] + }, + "cfg":{ + "type": "appl", + "pers": 0, + "ack": 1, + "sgntr": "" + } + } +``` + +Example of `SET` with a single _key-value_ pair stored persistently +```json + { + "cmd": "SET", + "args": { + "items":[ + {"key": "", "value": ""} + ] + }, + "cfg":{ + "type": "appl", + "pers": 1, + "ack": 1, + "sgntr": "" + } + } +``` + +Example of `SET` with a multiple _key-value_ pairs that are used as configuration, or application settings, values: +```json + { + "cmd": "SET", + "args":{ + "items":[ + {"key": "", "value": ""}, + {"key": "", "value": ""}, + {"key": "", "value": ""} + ] + }, + "cfg":{ + "type": "stng", + "sgntr": "" + } + } +``` + +## **Response** + +**Arguments:** None + +**Configuration:** + +| Key | Desc | Mandatory | +| ------- | ----------------------------------------- | ----------------------- | +| `chlng:` String | Challenge useful to sign the next command | **No**: used only in *Secure Mode* | + +**Examples:** + +Example of a response of a `SET` executed successfully. +```json + { + "rsp_code": "100", + "args":{}, + "cfg":{ + "chlng": "" + } + } +``` + +>Note: +> +>- List of possible [Error Codes](#response-codes) for `SET`: `200`, `201`, `206`, `207`, `208`, `210` diff --git a/docs/Cortex_Protocol/SIGN.md b/docs/Cortex_Protocol/SIGN.md new file mode 100644 index 0000000..769d48a --- /dev/null +++ b/docs/Cortex_Protocol/SIGN.md @@ -0,0 +1,55 @@ +# `SIGN` + +When *Secure mode* is enabled, the `SIGN` *Command* represent the second and last part of the `START` *Command*. It means to complete the ECDSA Authentication. It sends back to the *Main* the challenge received as *Response* for the `START` *Command*, signed with the *Peripheal* device's private key. + +>Note: +> +>- Present only after the `START` command and only in _Secure Mode_. + +## Command + +**Arguments:** None + +**Configurations:** + +| Key | Desc | Mandatory | +| ----- | --------------------------------------- | --------- | +| sgntr | Signature used for ECDSA Authentication | **Yes** | + +**Example:** + +```json + { + "cmd": "SIGN", + "args":{}, + "cfg":{ + "sgntr": "", + } + } +``` + +## Response + +**Arguments:** None + +**Configurations:** + +| Key | Desc | Mandatory | +| ------- | ----------------------------------------- | --------- | +| `chlng` | Challenge useful to sign the next command | **Yes** | + +**Examples:** + +```json + { + "rsp_code": "100", + "args":{}, + "cfg":{ + "chlng": "" + } + } +``` + +>Note: +> +>- List of possible Error Codes for `SIGN`: `???`, `???` diff --git a/docs/Cortex_Protocol/START.md b/docs/Cortex_Protocol/START.md new file mode 100644 index 0000000..2d70075 --- /dev/null +++ b/docs/Cortex_Protocol/START.md @@ -0,0 +1,96 @@ + +# `START` +*Peripheral* unit sends a request to start the communication with the *Main* unit. + +## Command + +**Arguments:** +| Key | Desc | Mandatory | +|:--------------------|:----------------------------|-----------------------------| +|`port_id`: String |The Unique ID of the *Port*/MCU| **Yes** | +|`fw_mcu_family`: String |The Family of the Microcontroller| **Yes** | +|`fw_lib_ver`: String |Version of the Library that implements Cortex Protocol on the MCU |**Yes** | +|`fw_name`: String |Name of the firmware running on the microcontroller|**Yes**| +|`fw_ver`: String |Version of the firmware running on the microcontroller|**Yes**| +|`fw_build_time` : String |Build date and time of the firmware running on the microcontroller|**Yes**| +|`fw_core_ver`: String |Version of the Arancino Core (Arduino) which the firmware is built on|**Yes**| +|`fw_crtx_ver`: String |Version of this protocol|**Yes**| + +**Configurations:** + +| Key | Desc | Mandatory | +|:--------------------|:----------------------------|-----------------------------| +|`scr_mod`: Number |Flag for _Secure Mode_, `1` is enabled `0` is disabled|**Yes**| +|`crt_sig`: String |Signer Certificate |**No**: Used only in *Secure Mode*| +|`crt_dev`: String |Device Certificate |**No**: Used only in *Secure Mode*| + + +>Notes: +>- You could pass custom keys other the one above specified (see how `CUSTOM_KEY_1` and `CUSTOM_KEY_2` are passed in the _Command Arguments_ in the example below). +>- `fw_mcu_family` at the moment could have the following values depending on the architecture of the *slave* device: `SAMD21`, `STM32`, `NRF52`. +>- `fw_lib_ver`, `fw_ver`, `fw_core_ver`, `crtx_ver` must implement Sem Ver 2.0 +>- `port_id` is retrivied with the [Microcontroller ID Arudino Library]([htt](https://github.com/smartmeio/microcontroller-id-library)) + +**Example:** + +```json + { + "cmd": "START", + "args":{ + "port_id": "", + "fw_mcu_family": "", + "fw_lib_ver": "", + "fw_name": "", + "fw_ver": "", + "fw_build_time": "", + "fw_core_ver": "", + "fw_crtx_ver": "", + "CUSTOM_KEY_1": "CUSTOM_VALUE_1", + "CUSTOM_KEY_2": "CUSTOM_VALUE_2" + }, + "cfg":{ + "scr_mod": "", + "crt_sig": "", + "crt_dev": "" + } + } +``` + + +## Response +**Arguments:** None + +**Configurations:** + +| Key | Desc | Mandatory | +|:--------------------|:----------------------------|-----------------------------| +|`ts`: Number |Timestamp used for synchronize the RTC of the Microcontroller|**Yes**| +|`log_lvl`: String |The Level of the Log to be used|**Yes**| +|`dmn_ver`: String |Version of the Daemon|**Yes**| +|`dmn_env`: String |Running environment|**Yes**| +|`chlng`:String |Challenge useful to sign the `SIGN` *Command* |**No**: Used only in *Secure Mode*| + +>Note: +> - Accepted values for `LOG_LVL` are: `ERORR`, `WARN`, `DEBUG` and `INFO`. +> - Accepted values for `DMN_ENV` are: `PROD`, `TEST` and `DEV`. +> - Version number must implement Sem Ver 2.0 + +**Examples:** + +```json + { + "rsp_code": "100", + "args": { + "dmn_ver": "", + "dmn_env": "" + }, + "cfg":{ + "ts": "", + "log_lvl": "", + "chlng": "" + } + } +``` + +>Note: +> - List of possible [Error Codes](#response-codes) for `START`: `200`, `203`, `204`, `205`, `209`, `210` diff --git a/docs/Cortex_Protocol/STORE.md b/docs/Cortex_Protocol/STORE.md new file mode 100644 index 0000000..c467f4a --- /dev/null +++ b/docs/Cortex_Protocol/STORE.md @@ -0,0 +1,95 @@ +# `STORE` +Store one or multiple value in a Time Series data structure at key + +## **Command** + +**Arguments:** + +| Key | Desc | Mandatory | +| ------- | ------------------------------ | --------- | +| `Key` | Redis key | Yes | +| `Value` | Redis value related to the key | Yes | +| `Ts` | UNIX timestamp | No | + + +| Args Type | Desc | Mandatory | +| ------- | ------------------------------ | --------- | +| `items` Array | Array of `key-value-timestamp` sets | **Yes** | +| | - `key:` String| **Yes** | +| | - `value:` Number | **Yes** | +| | - `timestamp:` Number | **No** | + + +**Configuration:** + +| Key | Desc | Mandatory | +| :------ | :-------------------------------------- | -------------------------------- | +| `ack:` Number | Indicates whether a *response* (the ack) should be sent for the *command*. *True* by default. Allowed values: `0` is *False* and `1` is *True*| **No** | +| `sgntr` | Signature used for ECDSA Authentication | No: used only in Secure Protocol | + +**Example:** + +Example of `STORE` command with a single _key-field-timestamp_ set + +```json + { + "cmd": "STORE", + "args":{ + "items":[ + {"key": "key-1", "value": "value-1", "ts": "timestamp-1"} + ] + }, + "cfg":{ + "ack": 1, + "sgntr": "" + } + } +``` + +Example of `STORE` command with a multiple *key-value-timestamp* sets + +```json + { + "cmd": "STORE", + "args":{ + "items":[ + {"key": "key-1", "value": "1", "ts": "timestamp-1"}, + {"key": "key-2", "value": "2", "ts": "timestamp-2"}, + {"key": "key-3", "value": "3.14", "ts": "timestamp-3"}, + {"key": "...", "value": "...", "ts": "..."} + ] + }, + "cfg":{ + "ack": 1, + "sgntr": "" + } + } +``` + +## **Response** + +**Arguments:** None + +**Configuration:** + +| Key | Desc | Mandatory | +| ------- | ----------------------------------------- | -------------------------------- | +| `chlng` | Challenge useful to sign the next command | No: used only in Secure Protocol | + +**Examples:** + +```json + { + "rsp_code": "100", + "args":{ + "items": ["", "", ""] + }, + "cfg":{ + "chlng": "" + } + } +``` + +>Note: +> +>- List of possible Error Codes for `STORE`: `200`, `206`, `211` **Da controllare per l'aggiunta anche di errori presenti durante il protocollo sicuro diff --git a/docs/Cortex_Protocol/STORETAGS.md b/docs/Cortex_Protocol/STORETAGS.md new file mode 100644 index 0000000..e06b26d --- /dev/null +++ b/docs/Cortex_Protocol/STORETAGS.md @@ -0,0 +1,71 @@ +#### `STORETAGS` +Store tags for a Time Series + +## **Command** + +**Arguments:** + +| Args Type| Desc | Mandatory | +| -------- | -------------------------------- | --------- | +| `key:` String | *Key* to which apply the *tags* | Yes | +| `ts:` Number | UNIX timestamp | No | +| `items:` Array | Array of *name-value* *tags* | Yes | +| - `name:` String | Name of the *tag* to apply at the *pers* | Yes | +| - `value:` String | Value of the *tag* to apply at the *pers* | Yes | + + +**Configuration:** + +| Key | Desc | Mandatory | +| :------ | :-------------------------------------- | -------------------------------- | +| `ack:` Number | Indicates whether a *response* (the ack) should be sent for the *command*. *True* by default. Allowed values: `0` is *False* and `1` is *True*| **No** | +| `sgntr:` String | Signature used for ECDSA Authentication | No: used only in Secure Protocol | + +**Example:** + +```json + { + "cmd": "STORETAGS", + "args":{ + "key": "", + "items": [ + {"tag": "", "value": ""}, + {"tag": "", "value": ""}, + {"tag": "...", "value": "..."} + ], + "ts": "" + }, + "cfg":{ + "ack": 1, + "sgntr": "" + } + } +``` + +## **Response** + +**Arguments:** None + +**Configuration:** + +| Key | Desc | Mandatory | +| ------- | ----------------------------------------- | -------------------------------- | +| `chlng` | Challenge useful to sign the next command | No: used only in Secure Protocol | + +**Examples:** + +```json + { + "rsp_code": "100", + "args":{}, + "cfg":{ + "chlng": "" + } + } +``` + +>Note: +> +>- List of possible Error Codes for `STORETAGS`: `200`, `206` **Da controllare per l'aggiunta anche di errori presenti durante il protocollo sicuro + +--- diff --git a/library.json b/library.json index 374171a..30ee46f 100644 --- a/library.json +++ b/library.json @@ -7,7 +7,7 @@ "type": "git", "url": "https://github.com/smartmeio/arancino-library.git" }, - "version": "3.0.0", + "version": "3.1.0", "authors": { "name": "smartme.IO", "url": "https://www.arancino.cc" diff --git a/library.properties b/library.properties index fef1e15..551ed99 100755 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arancino -version=3.0.0 +version=3.1.0 author=smartme.IO maintainer=smartme.IO sentence=Enables communication between microcontroller and Arancino Module running mainly in Arancino boards. From e3b6eaa0a17899dbdf7ee3b873a4f740a476d501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrea=20Cannistr=C3=A0?= Date: Fri, 11 Nov 2022 16:19:26 +0000 Subject: [PATCH 14/69] Update README.md --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e830d8f..bd815bc 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,6 @@ Arancino Library allows to export/import data to/from the Linux environment usin - [FreeRTOS](docs/FREERTOS.md) -- Insights - - [Cortex Protocol](docs/CORTEX.md) - [Debug](docs/DEBUG.md) @@ -28,9 +26,9 @@ Arancino Library allows to export/import data to/from the Linux environment usin The Arancino Library `3.1.0` officially supports the following Arancino Core versions: |Board| Core Version | |--|--| -| SAMD21 | 1.3.0 | +| SAMD21 | 1.3.1 | | nRF52 | 1.1.0 | -| RP2040 | 1.1.0 | +| RP2040 | 1.2.0 | | STM32 | 1.0.0 | @@ -40,4 +38,4 @@ Most of this documentation has been extrapolated from [Redis Command](https://re -Redis, Arduino, Atmel, Nordic, STMicroelectronics, RaspberryPi and FreeRTOS are trademarks of their respective owners. \ No newline at end of file +Redis, Arduino, Atmel, Nordic, STMicroelectronics, RaspberryPi and FreeRTOS are trademarks of their respective owners. From 37315c67de052925a68c2ef8dd94660aa658d590 Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Mon, 30 Jan 2023 17:53:02 +0100 Subject: [PATCH 15/69] Incremented stack size in examples. Fixed typos and added custom stack size for rp2040 --- examples/Arancino_FreeRTOS/01-SET/SET/SET.ino | 2 +- .../Arancino_FreeRTOS/01-SET/SET_Packet/SET_Packet.ino | 2 +- .../01-SET/SET_Persistent/SET_Persistent.ino | 2 +- examples/Arancino_FreeRTOS/02-GET/GET/GET.ino | 2 +- .../Arancino_FreeRTOS/02-GET/GET_Packet/GET_Packet.ino | 2 +- examples/Arancino_FreeRTOS/03-DEL/DEL/DEL.ino | 2 +- .../Arancino_FreeRTOS/03-DEL/DEL_Packet/DEL_Packet.ino | 2 +- examples/Arancino_FreeRTOS/05-HSET/HSET/HSET.ino | 2 +- .../05-HSET/HSET_Packet/HSET_Packet.ino | 2 +- examples/Arancino_FreeRTOS/06-HGET/HGET/HGET.ino | 2 +- .../06-HGET/HGET_Packet/HGET_Packet.ino | 2 +- examples/Arancino_FreeRTOS/07-HDEL/HDEL/HDEL.ino | 2 +- .../07-HDEL/HDEL_Packet/HDEL_Packet.ino | 2 +- examples/Arancino_FreeRTOS/08-FLUSH/FLUSH/FLUSH.ino | 2 +- .../08-FLUSH/FLUSH_Packet/FLUSH_Packet.ino | 2 +- .../Arancino_FreeRTOS/09-PUBLISH/PUBLISH/PUBLISH.ino | 2 +- .../09-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino | 2 +- examples/Arancino_FreeRTOS/10-MSET/MSET/MSET.ino | 2 +- examples/Arancino_FreeRTOS/11-MGET/MGET/MGET.ino | 2 +- .../11-MGET/MGET_Packet/MGET_Packet.ino | 2 +- examples/Arancino_FreeRTOS/12-STORE/STORE/STORE.ino | 2 +- .../12-STORE/STORE_Packet/STORE_Packet.ino | 2 +- .../13-STORETAGS/STORETAGS/STORETAGS.ino | 2 +- .../13-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino | 2 +- examples/Arancino_FreeRTOS/14-MSTORE/MSTORE/MSTORE.ino | 2 +- .../14-MSTORE/MSTORE_Packet/MSTORE_Packet.ino | 2 +- examples/Arancino_FreeRTOS/15-MQTT/MQTT/MQTT.ino | 2 +- .../16-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino | 2 +- .../CS_1-Sample_Sensor/CS_1-Sample_Sensor.ino | 2 +- .../CS_2-Smart_Light/CS_2-Smart_Light.ino | 2 +- src/Arancino.cpp | 9 +++++---- src/Arancino.h | 2 +- src/ArancinoDefinitions.h | 9 +++++++-- 33 files changed, 43 insertions(+), 37 deletions(-) diff --git a/examples/Arancino_FreeRTOS/01-SET/SET/SET.ino b/examples/Arancino_FreeRTOS/01-SET/SET/SET.ino index 62a20e0..02978ec 100644 --- a/examples/Arancino_FreeRTOS/01-SET/SET/SET.ino +++ b/examples/Arancino_FreeRTOS/01-SET/SET/SET.ino @@ -83,7 +83,7 @@ void setup() { //sets the value 123.456 into the 'baz' key Arancino.set(key3, value3); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/01-SET/SET_Packet/SET_Packet.ino b/examples/Arancino_FreeRTOS/01-SET/SET_Packet/SET_Packet.ino index fcf039e..feb4b67 100644 --- a/examples/Arancino_FreeRTOS/01-SET/SET_Packet/SET_Packet.ino +++ b/examples/Arancino_FreeRTOS/01-SET/SET_Packet/SET_Packet.ino @@ -84,7 +84,7 @@ void setup() { Arancino.free(apckt); //delete packet from memory - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/01-SET/SET_Persistent/SET_Persistent.ino b/examples/Arancino_FreeRTOS/01-SET/SET_Persistent/SET_Persistent.ino index ae68a9f..22d687a 100644 --- a/examples/Arancino_FreeRTOS/01-SET/SET_Persistent/SET_Persistent.ino +++ b/examples/Arancino_FreeRTOS/01-SET/SET_Persistent/SET_Persistent.ino @@ -67,7 +67,7 @@ void setup() { Arancino.set("EX_01_3_key_4", "bar", NULL); //volatile key Arancino.set("EX_01_3_key_5", "bar"); //volatile key - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/02-GET/GET/GET.ino b/examples/Arancino_FreeRTOS/02-GET/GET/GET.ino index 21b68b2..277bc26 100644 --- a/examples/Arancino_FreeRTOS/02-GET/GET/GET.ino +++ b/examples/Arancino_FreeRTOS/02-GET/GET/GET.ino @@ -59,7 +59,7 @@ void setup() { Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/02-GET/GET_Packet/GET_Packet.ino b/examples/Arancino_FreeRTOS/02-GET/GET_Packet/GET_Packet.ino index 2d36c3e..4be36c5 100644 --- a/examples/Arancino_FreeRTOS/02-GET/GET_Packet/GET_Packet.ino +++ b/examples/Arancino_FreeRTOS/02-GET/GET_Packet/GET_Packet.ino @@ -62,7 +62,7 @@ void setup() { Arancino.begin(amdata); //create a task for loop - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/03-DEL/DEL/DEL.ino b/examples/Arancino_FreeRTOS/03-DEL/DEL/DEL.ino index d41f883..5e26f98 100644 --- a/examples/Arancino_FreeRTOS/03-DEL/DEL/DEL.ino +++ b/examples/Arancino_FreeRTOS/03-DEL/DEL/DEL.ino @@ -61,7 +61,7 @@ void setup() { num = Arancino.del("EX_03_1_foo"); Arancino.println(num ? "Key deleted" : "Key not found"); //1 - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/03-DEL/DEL_Packet/DEL_Packet.ino b/examples/Arancino_FreeRTOS/03-DEL/DEL_Packet/DEL_Packet.ino index 3f5f492..ed126fb 100644 --- a/examples/Arancino_FreeRTOS/03-DEL/DEL_Packet/DEL_Packet.ino +++ b/examples/Arancino_FreeRTOS/03-DEL/DEL_Packet/DEL_Packet.ino @@ -92,7 +92,7 @@ void setup() { Arancino.free(apckt); //delete packet from memory - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/05-HSET/HSET/HSET.ino b/examples/Arancino_FreeRTOS/05-HSET/HSET/HSET.ino index 64e4f6f..8c83c1f 100644 --- a/examples/Arancino_FreeRTOS/05-HSET/HSET/HSET.ino +++ b/examples/Arancino_FreeRTOS/05-HSET/HSET/HSET.ino @@ -63,7 +63,7 @@ void setup() { Arancino.hset("ex05_foo","bar","yeah"); Arancino.hset("ex05_foo","bar","whoo"); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/05-HSET/HSET_Packet/HSET_Packet.ino b/examples/Arancino_FreeRTOS/05-HSET/HSET_Packet/HSET_Packet.ino index 5520ca4..e49d5f3 100644 --- a/examples/Arancino_FreeRTOS/05-HSET/HSET_Packet/HSET_Packet.ino +++ b/examples/Arancino_FreeRTOS/05-HSET/HSET_Packet/HSET_Packet.ino @@ -76,7 +76,7 @@ void setup() { Arancino.free(apckt); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/06-HGET/HGET/HGET.ino b/examples/Arancino_FreeRTOS/06-HGET/HGET/HGET.ino index 0e3b6d8..e38b1bc 100644 --- a/examples/Arancino_FreeRTOS/06-HGET/HGET/HGET.ino +++ b/examples/Arancino_FreeRTOS/06-HGET/HGET/HGET.ino @@ -60,7 +60,7 @@ void setup() { Arancino.hset("EX_06_1_foo","bar","yeah"); Arancino.hset("EX_06_1_foo","baz","whoo"); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/06-HGET/HGET_Packet/HGET_Packet.ino b/examples/Arancino_FreeRTOS/06-HGET/HGET_Packet/HGET_Packet.ino index e666194..e37376d 100644 --- a/examples/Arancino_FreeRTOS/06-HGET/HGET_Packet/HGET_Packet.ino +++ b/examples/Arancino_FreeRTOS/06-HGET/HGET_Packet/HGET_Packet.ino @@ -61,7 +61,7 @@ void setup() { Arancino.hset("EX_06_2_foo","bar","yeah"); Arancino.hset("EX_06_2_foo","baz","whoo"); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/07-HDEL/HDEL/HDEL.ino b/examples/Arancino_FreeRTOS/07-HDEL/HDEL/HDEL.ino index 82565d1..1f9b9b0 100644 --- a/examples/Arancino_FreeRTOS/07-HDEL/HDEL/HDEL.ino +++ b/examples/Arancino_FreeRTOS/07-HDEL/HDEL/HDEL.ino @@ -69,7 +69,7 @@ void setup() { Arancino.free(str); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/07-HDEL/HDEL_Packet/HDEL_Packet.ino b/examples/Arancino_FreeRTOS/07-HDEL/HDEL_Packet/HDEL_Packet.ino index 9bc34ee..9e9baa8 100644 --- a/examples/Arancino_FreeRTOS/07-HDEL/HDEL_Packet/HDEL_Packet.ino +++ b/examples/Arancino_FreeRTOS/07-HDEL/HDEL_Packet/HDEL_Packet.ino @@ -78,7 +78,7 @@ void setup() { Arancino.free(apckt); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/08-FLUSH/FLUSH/FLUSH.ino b/examples/Arancino_FreeRTOS/08-FLUSH/FLUSH/FLUSH.ino index 97ca784..91007d7 100644 --- a/examples/Arancino_FreeRTOS/08-FLUSH/FLUSH/FLUSH.ino +++ b/examples/Arancino_FreeRTOS/08-FLUSH/FLUSH/FLUSH.ino @@ -58,7 +58,7 @@ void setup() { //delete all the keys Arancino.flush(); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/08-FLUSH/FLUSH_Packet/FLUSH_Packet.ino b/examples/Arancino_FreeRTOS/08-FLUSH/FLUSH_Packet/FLUSH_Packet.ino index 507c1bb..de31c17 100644 --- a/examples/Arancino_FreeRTOS/08-FLUSH/FLUSH_Packet/FLUSH_Packet.ino +++ b/examples/Arancino_FreeRTOS/08-FLUSH/FLUSH_Packet/FLUSH_Packet.ino @@ -72,7 +72,7 @@ void setup() { Arancino.free(apckt); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/09-PUBLISH/PUBLISH/PUBLISH.ino b/examples/Arancino_FreeRTOS/09-PUBLISH/PUBLISH/PUBLISH.ino index 37254f0..bf66fe9 100644 --- a/examples/Arancino_FreeRTOS/09-PUBLISH/PUBLISH/PUBLISH.ino +++ b/examples/Arancino_FreeRTOS/09-PUBLISH/PUBLISH/PUBLISH.ino @@ -71,7 +71,7 @@ void setup() { //publish the value 123.456 into the 'EX_12_1_channel3' channel Arancino.publish(channel3, message3); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/09-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino b/examples/Arancino_FreeRTOS/09-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino index 186a996..f57a867 100644 --- a/examples/Arancino_FreeRTOS/09-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino +++ b/examples/Arancino_FreeRTOS/09-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino @@ -58,7 +58,7 @@ void setup() { Arancino.enableDebugMessages(); Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/10-MSET/MSET/MSET.ino b/examples/Arancino_FreeRTOS/10-MSET/MSET/MSET.ino index cd6b0a1..801a606 100644 --- a/examples/Arancino_FreeRTOS/10-MSET/MSET/MSET.ino +++ b/examples/Arancino_FreeRTOS/10-MSET/MSET/MSET.ino @@ -87,7 +87,7 @@ void setup(){ Arancino.free(apckt); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/11-MGET/MGET/MGET.ino b/examples/Arancino_FreeRTOS/11-MGET/MGET/MGET.ino index 5e48538..c85aab7 100644 --- a/examples/Arancino_FreeRTOS/11-MGET/MGET/MGET.ino +++ b/examples/Arancino_FreeRTOS/11-MGET/MGET/MGET.ino @@ -69,7 +69,7 @@ void setup() { Arancino.set("EX_14_1_foo1", "a"); Arancino.set("EX_14_1_foo3", "c"); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); diff --git a/examples/Arancino_FreeRTOS/11-MGET/MGET_Packet/MGET_Packet.ino b/examples/Arancino_FreeRTOS/11-MGET/MGET_Packet/MGET_Packet.ino index 5bbcb09..d522f0d 100644 --- a/examples/Arancino_FreeRTOS/11-MGET/MGET_Packet/MGET_Packet.ino +++ b/examples/Arancino_FreeRTOS/11-MGET/MGET_Packet/MGET_Packet.ino @@ -72,7 +72,7 @@ void setup() { Arancino.set("EX_14_2_foo2", "b"); Arancino.set("EX_14_2_foo3", "c"); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/12-STORE/STORE/STORE.ino b/examples/Arancino_FreeRTOS/12-STORE/STORE/STORE.ino index 29c6a25..4ceb315 100644 --- a/examples/Arancino_FreeRTOS/12-STORE/STORE/STORE.ino +++ b/examples/Arancino_FreeRTOS/12-STORE/STORE/STORE.ino @@ -59,7 +59,7 @@ void setup() { Arancino.enableDebugMessages(); Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/12-STORE/STORE_Packet/STORE_Packet.ino b/examples/Arancino_FreeRTOS/12-STORE/STORE_Packet/STORE_Packet.ino index b00c960..53fec51 100644 --- a/examples/Arancino_FreeRTOS/12-STORE/STORE_Packet/STORE_Packet.ino +++ b/examples/Arancino_FreeRTOS/12-STORE/STORE_Packet/STORE_Packet.ino @@ -61,7 +61,7 @@ void setup() { Arancino.enableDebugMessages(); Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/13-STORETAGS/STORETAGS/STORETAGS.ino b/examples/Arancino_FreeRTOS/13-STORETAGS/STORETAGS/STORETAGS.ino index 9f03b4b..3c81f1f 100644 --- a/examples/Arancino_FreeRTOS/13-STORETAGS/STORETAGS/STORETAGS.ino +++ b/examples/Arancino_FreeRTOS/13-STORETAGS/STORETAGS/STORETAGS.ino @@ -57,7 +57,7 @@ void setup() { Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/13-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino b/examples/Arancino_FreeRTOS/13-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino index 0c94d2c..1399c11 100644 --- a/examples/Arancino_FreeRTOS/13-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino +++ b/examples/Arancino_FreeRTOS/13-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino @@ -63,7 +63,7 @@ void setup() { Arancino.enableDebugMessages(); Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/14-MSTORE/MSTORE/MSTORE.ino b/examples/Arancino_FreeRTOS/14-MSTORE/MSTORE/MSTORE.ino index 24e56bc..1395e39 100644 --- a/examples/Arancino_FreeRTOS/14-MSTORE/MSTORE/MSTORE.ino +++ b/examples/Arancino_FreeRTOS/14-MSTORE/MSTORE/MSTORE.ino @@ -58,7 +58,7 @@ void setup(){ Arancino.enableDebugMessages(); Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/14-MSTORE/MSTORE_Packet/MSTORE_Packet.ino b/examples/Arancino_FreeRTOS/14-MSTORE/MSTORE_Packet/MSTORE_Packet.ino index 98e83d9..cff8f7a 100644 --- a/examples/Arancino_FreeRTOS/14-MSTORE/MSTORE_Packet/MSTORE_Packet.ino +++ b/examples/Arancino_FreeRTOS/14-MSTORE/MSTORE_Packet/MSTORE_Packet.ino @@ -62,7 +62,7 @@ void setup(){ Arancino.enableDebugMessages(); Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/15-MQTT/MQTT/MQTT.ino b/examples/Arancino_FreeRTOS/15-MQTT/MQTT/MQTT.ino index 9ef840d..85be504 100644 --- a/examples/Arancino_FreeRTOS/15-MQTT/MQTT/MQTT.ino +++ b/examples/Arancino_FreeRTOS/15-MQTT/MQTT/MQTT.ino @@ -70,7 +70,7 @@ void setup() Arancino.attachInterface(iface); Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/16-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino b/examples/Arancino_FreeRTOS/16-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino index fe84fb6..cda5df3 100644 --- a/examples/Arancino_FreeRTOS/16-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino +++ b/examples/Arancino_FreeRTOS/16-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino @@ -62,7 +62,7 @@ void setup() Arancino.attachInterface(iface); Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/CS_1-Sample_Sensor/CS_1-Sample_Sensor.ino b/examples/Arancino_FreeRTOS/CS_1-Sample_Sensor/CS_1-Sample_Sensor.ino index e3b39b6..1ff1da8 100644 --- a/examples/Arancino_FreeRTOS/CS_1-Sample_Sensor/CS_1-Sample_Sensor.ino +++ b/examples/Arancino_FreeRTOS/CS_1-Sample_Sensor/CS_1-Sample_Sensor.ino @@ -47,7 +47,7 @@ void setup() { Arancino.attachInterface(iface); Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/CS_2-Smart_Light/CS_2-Smart_Light.ino b/examples/Arancino_FreeRTOS/CS_2-Smart_Light/CS_2-Smart_Light.ino index a4dbb9f..65c64e6 100644 --- a/examples/Arancino_FreeRTOS/CS_2-Smart_Light/CS_2-Smart_Light.ino +++ b/examples/Arancino_FreeRTOS/CS_2-Smart_Light/CS_2-Smart_Light.ino @@ -53,7 +53,7 @@ void setup() { char* startingValues[] = {"255", "255", "255"}; //White Arancino.mset(keys, startingValues, 3); - xTaskCreate(loopTask, "loopTask", 256, NULL, 1, &loopTaskHandle); + xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); Arancino.startScheduler(); } diff --git a/src/Arancino.cpp b/src/Arancino.cpp index bb0d0e0..ec0a286 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -591,7 +591,7 @@ ArancinoPacket ArancinoClass::__publish(char *channel, char *msg, bool isAck) items_obj["message"] = msg; JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); - cmd_cfg["ack"] = isAck? 0 : 1; + cmd_cfg["ack"] = isAck? 1 : 0; return executeCommand(cmd_doc, isAck, CLIENTS_RESPONSE); } @@ -707,7 +707,7 @@ ArancinoPacket ArancinoClass::__store( char* key, char* value, char* timestamp, items_obj["ts"] = timestamp; JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); - cmd_cfg["ack"] = isAck? 0 : 1; + cmd_cfg["ack"] = isAck? 1 : 0; cmd_cfg["type"] = "tse"; return executeCommand(cmd_doc, isAck, ITEMS_RESPONSE); } @@ -738,7 +738,7 @@ ArancinoPacket ArancinoClass::mstore(char** keys, char** values, } JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); - cmd_cfg["ack"] = isAck? 0 : 1; + cmd_cfg["ack"] = isAck? 1 : 0; cmd_cfg["type"] = "tse"; return executeCommand(cmd_doc, isAck, ITEMS_RESPONSE); } @@ -794,7 +794,7 @@ ArancinoPacket ArancinoClass::storetags(char *key, char **tags, char **values, i cmd_args["ts"] = timestamp; JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); - cmd_cfg["ack"] = isAck? 0 : 1; + cmd_cfg["ack"] = isAck? 1 : 0; cmd_cfg["type"] = "tags"; return executeCommand(cmd_doc, isAck, VOID_RESPONSE); } @@ -1112,6 +1112,7 @@ ArancinoPacket ArancinoClass::executeCommand(char* cmd, char* key, char* field, #if defined(USEFREERTOS) while (!takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE); #endif + _iface->sendArancinoCommand(cmd_doc); StaticJsonDocument rsp_doc; diff --git a/src/Arancino.h b/src/Arancino.h index 80dc44e..947ac7a 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -144,7 +144,7 @@ class ArancinoClass { ArancinoPacket set(char* key, char* value, bool isAck = true, bool isPersistent = false, char* type = "appl"); //MSET - ArancinoPacket mset(char** keys, char** values, int len, bool isAck, bool isPersistent = false, char* type = "appl"); + ArancinoPacket mset(char** keys, char** values, int len, bool isAck=true, bool isPersistent = false, char* type = "appl"); //GET template T get(char* key, bool isPersistent = false, char* type = "appl"); diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index ef4921c..9389e95 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -154,11 +154,16 @@ under the License #define IDENTIFICATION_STACK configMINIMAL_STACK_SIZE * 4 #define INTEROCEPTION_STACK configMINIMAL_STACK_SIZE * 4 #define HEARTBEAT_STACK configMINIMAL_STACK_SIZE * 4 -#else +#elif defined(__SAMD21G18A__) #define ARANCINO_TASK_PRIORITY configMAX_PRIORITIES - 1 #define IDENTIFICATION_STACK 256 #define INTEROCEPTION_STACK 256 #define HEARTBEAT_STACK 256 +#elif defined(ARDUINO_ARCH_RP2040) +#define ARANCINO_TASK_PRIORITY configMAX_PRIORITIES - 1 +#define IDENTIFICATION_STACK 512 +#define INTEROCEPTION_STACK 512 +#define HEARTBEAT_STACK 512 #endif #define SERIAL_MAX_RETRIES 10 @@ -180,4 +185,4 @@ under the License #define FIELDS_ITEMS_RESPONSE 3 #define FIELDS_RESPONSE 4 #define ITEMS_RESPONSE 5 -#define CLIENTS_RESPONSE 6 \ No newline at end of file +#define CLIENTS_RESPONSE 6 From f5cc61071cfc667368a3f45f1329f563385948e8 Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Mon, 30 Jan 2023 18:07:01 +0100 Subject: [PATCH 16/69] Removed separate FreeRTOS tasks and merged onto a single task. WIP with timers --- src/Arancino.cpp | 315 ++++++++++++++----------- src/ArancinoTasks.cpp | 521 +++++++++++++++++++++++++++--------------- src/ArancinoTasks.h | 39 +++- 3 files changed, 554 insertions(+), 321 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index ec0a286..c2a1b2f 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -26,12 +26,18 @@ under the License ArancinoPacket reservedKeyErrorPacket = {true, RESERVED_KEY_ERROR, RESERVED_KEY_ERROR, {.string = NULL}}; // default reserved key error packet ArancinoPacket communicationErrorPacket = {true, COMMUNICATION_ERROR, COMMUNICATION_ERROR, {.string = NULL}}; // default reserved key error packet ArancinoPacket invalidCommandErrorPacket = {true, INVALID_VALUE_ERROR, INVALID_VALUE_ERROR, {.string = NULL}}; // default reserved key error packet +ArancinoPacket voidCommunicationPacket = {false, RSP_OK, VOID_ERROR_TYPE, {.string = NULL}}; // default reserved key for non-ack messages // TASK #if defined(USEFREERTOS) TaskHandle_t arancinoHandle1; -TaskHandle_t arancinoHandle2; -TaskHandle_t arancinoHandle3; +// TaskHandle_t arancinoHandle2; +// TaskHandle_t arancinoHandle3; + +TimerHandle_t timerHandle1; +TimerHandle_t timerHandle2; +TimerHandle_t timerHandle3; + SemaphoreHandle_t CommMutex; #endif @@ -131,11 +137,17 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, char* { CommMutex = xSemaphoreCreateMutex(); } + //TASK ArancinoTasks _atask; - xTaskCreate(_atask.deviceIdentification, "identification", IDENTIFICATION_STACK, NULL, ARANCINO_TASK_PRIORITY, &arancinoHandle1); - xTaskCreate(_atask.interoception, "interoception", INTEROCEPTION_STACK, NULL, ARANCINO_TASK_PRIORITY, &arancinoHandle2); - xTaskCreate(_atask.sendHeartbeat, "heartbeat", HEARTBEAT_STACK, NULL, ARANCINO_TASK_PRIORITY, &arancinoHandle3); + timerHandle1 = xTimerCreate("Heartbeat", pdMS_TO_TICKS(10000), pdTRUE, (void*)0, _atask.heartbeatCallback); + timerHandle2 = xTimerCreate("Interoception", pdMS_TO_TICKS(60000), pdTRUE, (void*)0, _atask.interoceptionCallback); + timerHandle3 = xTimerCreate("Identification", pdMS_TO_TICKS(10000), pdTRUE, (void*)0, _atask.interoceptionCallback); + + xTimerStart(timerHandle1, 0); + xTimerStart(timerHandle2, 0); + xTimerStart(timerHandle3, 0); + xTaskCreate(_atask.serviceTask, "serviceTask", 512, NULL, ARANCINO_TASK_PRIORITY, &arancinoHandle1); #endif } @@ -330,8 +342,9 @@ ArancinoPacket ArancinoClass::get(char* key, bool isPersistent, template <> char *ArancinoClass::get(char* key, bool isPersistent, char* type) { ArancinoPacket packet = get(key, isPersistent, type); - if (!packet.isError) + if (!packet.isError){ return packet.response.string; + } else return NULL; } @@ -681,8 +694,9 @@ char *ArancinoClass::store(char *key, float value, char* timestamp, bool isAck) char str[20] = ""; _floatToString(value, decimal_digits, str); ArancinoPacket packet = __store(key, str, timestamp, isAck); - if (!packet.isError) + if (!packet.isError){ return packet.response.string; + } else return NULL; } @@ -1107,124 +1121,151 @@ char *ArancinoClass::getTimestamp() ArancinoPacket ArancinoClass::executeCommand(char* cmd, char* key, char* field, char* value, bool isAck, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type){ StaticJsonDocument cmd_doc; - _buildArancinoJson(cmd_doc, cmd, key, field, value, argsHasItems, itemsHasDict, cfg); + int tx_counter = 0; + bool error = true; - #if defined(USEFREERTOS) - while (!takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE); - #endif + do { + _buildArancinoJson(cmd_doc, cmd, key, field, value, argsHasItems, itemsHasDict, cfg); + + #if defined(USEFREERTOS) + if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE){ + #endif + _iface->sendArancinoCommand(cmd_doc); - _iface->sendArancinoCommand(cmd_doc); + if(isAck){ + error = _iface->receiveArancinoResponse(cmd_doc); + } else { + #if defined(USEFREERTOS) + giveCommMutex(); + #endif + return voidCommunicationPacket; + } - StaticJsonDocument rsp_doc; - if(isAck){ - bool error = true; - int counter = 0; - while (error && counter < 5){ - counter++; - error = _iface->receiveArancinoResponse(rsp_doc); + #if defined(USEFREERTOS) + giveCommMutex(); } - if(error) - return communicationErrorPacket; - } - - #if defined(USEFREERTOS) - giveCommMutex(); - #endif + #endif - if(rsp_doc.isNull()) - return communicationErrorPacket; - - ArancinoPacket packet = createArancinoPacket(rsp_doc, response_type); - return packet; + if(!cmd_doc.isNull() && !error) { + ArancinoPacket packet = createArancinoPacket(cmd_doc, response_type); + return packet; + } else { + tx_counter++; + } + } while (tx_counter < TX_MAX_RETRIES); + + return communicationErrorPacket; } ArancinoPacket ArancinoClass::executeCommand(char* cmd, char** keys, char** fields, char** values, int len, bool isAck, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type){ StaticJsonDocument cmd_doc; - _buildArancinoJson(cmd_doc, cmd, keys, fields, values, len, argsHasItems, itemsHasDict, cfg); - - #if defined(USEFREERTOS) - while (!takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE); - #endif - _iface->sendArancinoCommand(cmd_doc); + int tx_counter = 0; + bool error = true; - StaticJsonDocument rsp_doc; - if(isAck){ - bool error = true; - int counter = 0; - while (error && counter < 5){ - counter++; - error = _iface->receiveArancinoResponse(rsp_doc); + do { + _buildArancinoJson(cmd_doc, cmd, keys, fields, values, len, argsHasItems, itemsHasDict, cfg); + + #if defined(USEFREERTOS) + if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE){ + #endif + _iface->sendArancinoCommand(cmd_doc); + + if(isAck){ + error = _iface->receiveArancinoResponse(cmd_doc); + } else { + #if defined(USEFREERTOS) + giveCommMutex(); + #endif + return voidCommunicationPacket; + } + + #if defined(USEFREERTOS) } - if(error) - return communicationErrorPacket; - } - - #if defined(USEFREERTOS) - giveCommMutex(); - #endif + giveCommMutex(); + #endif - if(rsp_doc.isNull()) - return communicationErrorPacket; - - ArancinoPacket packet = createArancinoPacket(rsp_doc, response_type); - return packet; + if(!cmd_doc.isNull() && !error){ + ArancinoPacket packet = createArancinoPacket(cmd_doc, response_type); + return packet; + } else { + tx_counter++; + } + } while (tx_counter < TX_MAX_RETRIES); + + return communicationErrorPacket; } ArancinoPacket ArancinoClass::executeCommand(JsonDocument& cmd_doc, bool isAck, int response_type){ - #if defined(USEFREERTOS) - while (!takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE); - #endif - _iface->sendArancinoCommand(cmd_doc); - + int tx_counter = 0; StaticJsonDocument rsp_doc; - if(isAck){ - bool error = true; - int counter = 0; - while (error && counter < 5){ - counter++; - error = _iface->receiveArancinoResponse(rsp_doc); + bool error = true; + + do { + #if defined(USEFREERTOS) + if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE){ + #endif + + _iface->sendArancinoCommand(cmd_doc); + + if(isAck){ + error = _iface->receiveArancinoResponse(rsp_doc); + } else { + #if defined(USEFREERTOS) + giveCommMutex(); + #endif + return voidCommunicationPacket; + } + + #if defined(USEFREERTOS) } - if(error) - return communicationErrorPacket; - } - - #if defined(USEFREERTOS) - giveCommMutex(); - #endif + giveCommMutex(); + #endif - if(rsp_doc.isNull()) - return communicationErrorPacket; - - ArancinoPacket packet = createArancinoPacket(rsp_doc, response_type); - return packet; + if(!rsp_doc.isNull() && !error){ + ArancinoPacket packet = createArancinoPacket(rsp_doc, response_type); + return packet; + } else { + tx_counter++; + } + } while (tx_counter < TX_MAX_RETRIES); + + return communicationErrorPacket; } ArancinoPacket ArancinoClass::executeCommand(JsonDocument& cmd_doc, JsonDocument& rsp_doc, bool isAck, int response_type){ - #if defined(USEFREERTOS) - while (!takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE); - #endif - _iface->sendArancinoCommand(cmd_doc); + int tx_counter = 0; + bool error = true; - if(isAck){ - bool error = true; - int counter = 0; - while (error && counter < 5){ - counter++; - error = _iface->receiveArancinoResponse(rsp_doc); + do { + #if defined(USEFREERTOS) + if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE){ + #endif + + _iface->sendArancinoCommand(cmd_doc); + + if(isAck){ + error = _iface->receiveArancinoResponse(rsp_doc); + } else { + #if defined(USEFREERTOS) + giveCommMutex(); + #endif + return voidCommunicationPacket; + } + + #if defined(USEFREERTOS) } - if(error) - return communicationErrorPacket; - } - - #if defined(USEFREERTOS) - giveCommMutex(); - #endif + giveCommMutex(); + #endif - if(rsp_doc.isNull()) - return communicationErrorPacket; - - ArancinoPacket packet = createArancinoPacket(rsp_doc, response_type); - return packet; + if(!rsp_doc.isNull() && !error){ + ArancinoPacket packet = createArancinoPacket(rsp_doc, response_type); + return packet; + } else { + tx_counter++; + } + } while (tx_counter < TX_MAX_RETRIES); + + return communicationErrorPacket; } ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, int response_type){ @@ -1257,6 +1298,9 @@ ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, ArancinoPacket temp = {false, response_dict["rsp_code"], STRING_ARRAY, {.stringArray = resp_values}}; packet = temp; } + else{ + packet = communicationErrorPacket; + } break; } case KEY_RESPONSE: { @@ -1306,40 +1350,41 @@ ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, } void ArancinoClass::_buildArancinoJson(JsonDocument& cmd_doc, char* cmd, char* key, char* field, char* value, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg){ - JsonObject cmd_args = cmd_doc.createNestedObject("args"); - cmd_doc["cmd"] = cmd; - - if (argsHasItems){ - JsonArray cmd_items = cmd_args.createNestedArray("items"); - if (itemsHasDict){ - JsonObject items_obj = cmd_items.createNestedObject(); - - if (key){ - items_obj["key"] = key; - } - - if (field){ - items_obj["field"] = field; - } - - if(value){ - items_obj["value"] = value; - } - } else { - cmd_items.add(key); - } - } - - JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); - if (cfg.pers){ - cmd_cfg["pers"] = cfg.pers == CFG_FALSE ? 0 : 1; - } - if (cfg.ack){ - cmd_cfg["ack"] = cfg.ack == CFG_FALSE ? 0 : 1; - } - if (cfg.type){ - cmd_cfg["type"] = cfg.type; - } + + JsonObject cmd_args = cmd_doc.createNestedObject("args"); + cmd_doc["cmd"] = cmd; + + if (argsHasItems){ + JsonArray cmd_items = cmd_args.createNestedArray("items"); + if (itemsHasDict){ + JsonObject items_obj = cmd_items.createNestedObject(); + + if (key){ + items_obj["key"] = key; + } + + if (field){ + items_obj["field"] = field; + } + + if(value){ + items_obj["value"] = value; + } + } else { + cmd_items.add(key); + } + } + + JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); + if (cfg.pers){ + cmd_cfg["pers"] = cfg.pers == CFG_FALSE ? 0 : 1; + } + if (cfg.ack){ + cmd_cfg["ack"] = cfg.ack == CFG_FALSE ? 0 : 1; + } + if (cfg.type){ + cmd_cfg["type"] = cfg.type; + } } void ArancinoClass::_buildArancinoJson(JsonDocument& cmd_doc, char* cmd, char** keys, char** fields, char** values, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg){ diff --git a/src/ArancinoTasks.cpp b/src/ArancinoTasks.cpp index a509ed3..3b99c21 100644 --- a/src/ArancinoTasks.cpp +++ b/src/ArancinoTasks.cpp @@ -38,38 +38,97 @@ under the License #if defined(USEFREERTOS) -DynamicJsonDocument* ArancinoTasks::cmd_doc; -DynamicJsonDocument* ArancinoTasks::rsp_doc; -SemaphoreHandle_t ArancinoTasks::jsonMutex; - +FreeRTOSDynamicJsonDocument* ArancinoTasks::cmd_doc; +FreeRTOSDynamicJsonDocument* ArancinoTasks::rsp_doc; +// SemaphoreHandle_t ArancinoTasks::jsonMutex; +bool ArancinoTasks::_identificationFlag; +bool ArancinoTasks::_interoceptionFlag; +bool ArancinoTasks::_heartbeatFlag; ArancinoTasks::ArancinoTasks(){ - cmd_doc = new DynamicJsonDocument(CMD_DOC_SIZE); - rsp_doc = new DynamicJsonDocument(RSP_DOC_SIZE); - jsonMutex = xSemaphoreCreateMutex(); + cmd_doc = new FreeRTOSDynamicJsonDocument(CMD_DOC_SIZE); + rsp_doc = new FreeRTOSDynamicJsonDocument(RSP_DOC_SIZE); + //jsonMutex = xSemaphoreCreateMutex(); + + _identificationFlag = false; + _interoceptionFlag = false; + _heartbeatFlag = false; +} + +void ArancinoTasks::identificationCallback (TimerHandle_t xTimer){ + ArancinoTasks::_identificationFlag = true; +} +void ArancinoTasks::interoceptionCallback (TimerHandle_t xTimer){ + ArancinoTasks::_interoceptionFlag = true; } -void ArancinoTasks::deviceIdentification(void *pvPramaters){ +void ArancinoTasks::heartbeatCallback (TimerHandle_t xTimer){ + _heartbeatFlag = true; +} + + +void ArancinoTasks::serviceTask(void* pvParameters){ + //Heartbeat region + uint8_t idSize = strlen(Arancino.id); + char topic[idSize + 5]; //ID_SIZE + '_HBx' + '\0' + strcpy(topic, Arancino.id); + strcat(topic, "_HB0"); + + //Identification region pinMode(LED_BUILTIN,OUTPUT); - while (1) - { - xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); - (*cmd_doc).clear(); - JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); - (*cmd_doc)["cmd"] = GET_COMMAND; - JsonArray cmd_items = cmd_args.createNestedArray("items"); - cmd_items.add(BLINK_ID_KEY); - - JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); - cmd_cfg["pers"] = 1; - cmd_cfg["type"] = "rsvd"; - - ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), true, KEY_VALUE_RESPONSE); - xSemaphoreGive(jsonMutex); + // digitalWrite(LED_BUILTIN, HIGH); + // Arancino.delay(200); + // digitalWrite(LED_BUILTIN, LOW); + // Arancino.delay(200); + + + while(1){ + + if(_heartbeatFlag){ + topic[idSize+3] = '0'; //If the topic structure isn't changed i know exactly the byte I'm supposed to change + + JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); + (*cmd_doc)["cmd"] = PUBLISH_COMMAND; + JsonArray cmd_items = cmd_args.createNestedArray("items"); + JsonObject items_obj = cmd_items.createNestedObject(); + items_obj["channel"] = topic; + items_obj["message"] = Arancino.getTimestamp(); + + JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); + cmd_cfg["ack"] = 0; + cmd_cfg["pers"] = 0; + + ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, CLIENTS_RESPONSE); + + topic[idSize+3] = '1'; //If the topic structure isn't changed i know exactly the byte I'm supposed to change - if(!strcmp(rsp.response.string, "1")){ + items_obj["channel"] = topic; + items_obj["message"] = Arancino.getTimestamp(); + + rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, CLIENTS_RESPONSE); + (*cmd_doc).clear(); + _heartbeatFlag = false; + } + +/* + + + if(_identificationFlag){ + JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); + (*cmd_doc)["cmd"] = GET_COMMAND; + JsonArray cmd_items = cmd_args.createNestedArray("items"); + cmd_items.add(BLINK_ID_KEY); + + JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); + cmd_cfg["pers"] = 1; + cmd_cfg["type"] = "rsvd"; + + ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), true, KEY_VALUE_RESPONSE); + (*cmd_doc).clear(); + + if(!strcmp(rsp.response.string, "1")){ for(int i=0;i < 20; i++){ #if defined (ARDUINO_ARANCINO_VOLANTE) digitalWrite(LED_BUILTIN,LOW); @@ -85,183 +144,289 @@ void ArancinoTasks::deviceIdentification(void *pvPramaters){ vTaskDelay(200); } - xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); - (*cmd_doc).clear(); JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); (*cmd_doc)["cmd"] = SET_COMMAND; JsonArray cmd_items = cmd_args.createNestedArray("items"); JsonObject items_obj = cmd_items.createNestedObject(); items_obj["key"] = BLINK_ID_KEY; items_obj["value"] = 0; - //cmd_items.add(BLINK_ID_KEY); JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); cmd_cfg["pers"] = 1; cmd_cfg["type"] = "rsvd"; cmd_cfg["ack"] = 0; - ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, VOID_RESPONSE); - xSemaphoreGive(jsonMutex); + ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), false, VOID_RESPONSE); + (*cmd_doc).clear(); + _identificationFlag = false; + } + if (_interoceptionFlag){ + #if !defined(ARDUINO_ARANCINO_VOLANTE) && !defined(ARDUINO_ARCH_RP2040) + int memory_free = xPortGetFreeHeapSize(); + int memory_used=configTOTAL_HEAP_SIZE-memory_free; + #endif + + #if defined(ARDUINO_ARANCINO_VOLANTE) || defined(ARDUINO_ARCH_RP2040) + char* ts = Arancino.getTimestamp(); + JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); + (*cmd_doc)["cmd"] = STORE_COMMAND; + JsonArray cmd_items = cmd_args.createNestedArray("items"); + JsonObject memfree_obj = cmd_items.createNestedObject(); + JsonObject temp_obj = cmd_items.createNestedObject(); + + memfree_obj["key"] = "MEM_TOT"; + memfree_obj["value"] = configTOTAL_HEAP_SIZE; + memfree_obj["ts"] = ts; + temp_obj["key"] = "TEMP"; + temp_obj["value"] = mcuTemp(); + temp_obj["ts"] = ts; + JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); + cmd_cfg["ack"] = 0; + cmd_cfg["type"] = "tse"; + + ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), false, ITEMS_RESPONSE); + (*cmd_doc).clear(); + #else + char* ts = Arancino.getTimestamp(); + JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); + (*cmd_doc)["cmd"] = STORE_COMMAND; + JsonArray cmd_items = cmd_args.createNestedArray("items"); + JsonObject memfree_obj = cmd_items.createNestedObject(); + JsonObject temp_obj = cmd_items.createNestedObject(); + JsonObject memtot_obj = cmd_items.createNestedObject(); + JsonObject memused_obj = cmd_items.createNestedObject(); + + memtot_obj["key"] = "MEM_TOT"; + memtot_obj["value"] = configTOTAL_HEAP_SIZE; + memtot_obj["ts"] = ts; + temp_obj["key"] = "TEMP"; + temp_obj["value"] = 0; + temp_obj["ts"] = ts; + memfree_obj["key"] = "MEM_FREE"; + memfree_obj["value"] = xPortGetFreeHeapSize(); + memfree_obj["ts"] = ts; + memused_obj["key"] = "MEM_USED"; + memused_obj["value"] = configTOTAL_HEAP_SIZE-memory_free; + memused_obj["ts"] = ts; + JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); + cmd_cfg["ack"] = 0; + cmd_cfg["type"] = "tse"; + + ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), false, ITEMS_RESPONSE); + (*cmd_doc).clear(); + } } - Arancino.free(rsp); - vTaskDelay(10000); //wait 10 seconds (non-blocking delay) - } -} -void ArancinoTasks::interoception(void *pvPramaters){ - while (1) - { - #if !defined(ARDUINO_ARANCINO_VOLANTE) && !defined(ARDUINO_ARCH_RP2040) - int memory_free = xPortGetFreeHeapSize(); - int memory_used=configTOTAL_HEAP_SIZE-memory_free; - #endif - - float temperature = mcuTemp(); - - #if defined(ARDUINO_ARANCINO_VOLANTE) || defined(ARDUINO_ARCH_RP2040) - xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); - char* ts = Arancino.getTimestamp(); - (*cmd_doc).clear(); - JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); - (*cmd_doc)["cmd"] = STORE_COMMAND; - JsonArray cmd_items = cmd_args.createNestedArray("items"); - JsonObject memfree_obj = cmd_items.createNestedObject(); - JsonObject temp_obj = cmd_items.createNestedObject(); - - memfree_obj["key"] = "MEM_TOT"; - memfree_obj["value"] = configTOTAL_HEAP_SIZE; - memfree_obj["ts"] = ts; - temp_obj["key"] = "TEMP"; - temp_obj["value"] = temperature; - temp_obj["ts"] = ts; - JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); - cmd_cfg["ack"] = 0; - cmd_cfg["type"] = "tse"; - - ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, ITEMS_RESPONSE); - xSemaphoreGive(jsonMutex); - - #else - xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); - char* ts = Arancino.getTimestamp(); - (*cmd_doc).clear(); - JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); - (*cmd_doc)["cmd"] = STORE_COMMAND; - JsonArray cmd_items = cmd_args.createNestedArray("items"); - JsonObject memfree_obj = cmd_items.createNestedObject(); - JsonObject temp_obj = cmd_items.createNestedObject(); - - memfree_obj["key"] = "MEM_TOT"; - memfree_obj["value"] = configTOTAL_HEAP_SIZE; - memfree_obj["ts"] = ts; - temp_obj["key"] = "TEMP"; - temp_obj["value"] = temperature; - temp_obj["ts"] = ts; - temp_obj["key"] = "MEM_FREE"; - temp_obj["value"] = xPortGetFreeHeapSize(); - temp_obj["ts"] = ts; - temp_obj["key"] = "MEM_USED"; - temp_obj["value"] = configTOTAL_HEAP_SIZE-memory_free; - temp_obj["ts"] = ts; - JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); - cmd_cfg["ack"] = 0; - cmd_cfg["type"] = "tse"; - - ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, ITEMS_RESPONSE); - xSemaphoreGive(jsonMutex); - #endif - Arancino.free(rsp); - vTaskDelay(60000); //wait 60 seconds (non-blocking delay) +*/ + //METTERE LO YIELD + vTaskDelay(1000); } - } -void ArancinoTasks::sendHeartbeat(void *pvPramaters){ - uint8_t idSize = strlen(Arancino.id); - char topic[idSize + 5]; //ID_SIZE + '_HBx' + '\0' - strcpy(topic, Arancino.id); - strcat(topic, "_HB0"); - while (1) { - xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); - topic[idSize+3] = '0'; //If the topic structure isn't changed i know exactly the byte I'm supposed to change +// void ArancinoTasks::deviceIdentification(void *pvPramaters){ +// pinMode(LED_BUILTIN,OUTPUT); +// while (1) +// { +// xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); +// JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); +// (*cmd_doc)["cmd"] = GET_COMMAND; +// JsonArray cmd_items = cmd_args.createNestedArray("items"); +// cmd_items.add(BLINK_ID_KEY); + +// JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); +// cmd_cfg["pers"] = 1; +// cmd_cfg["type"] = "rsvd"; - (*cmd_doc).clear(); - JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); - (*cmd_doc)["cmd"] = PUBLISH_COMMAND; - JsonArray cmd_items = cmd_args.createNestedArray("items"); - JsonObject items_obj = cmd_items.createNestedObject(); - items_obj["channel"] = topic; - items_obj["message"] = Arancino.getTimestamp(); - - JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); - cmd_cfg["ack"] = 0; +// ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), true, KEY_VALUE_RESPONSE); +// xSemaphoreGive(jsonMutex); + + +// if(!strcmp(rsp.response.string, "1")){ +// for(int i=0;i < 20; i++){ +// #if defined (ARDUINO_ARANCINO_VOLANTE) +// digitalWrite(LED_BUILTIN,LOW); +// #else +// digitalWrite(LED_BUILTIN,HIGH); +// #endif +// vTaskDelay(100); +// #if defined (ARDUINO_ARANCINO_VOLANTE) +// digitalWrite(LED_BUILTIN,HIGH); +// #else +// digitalWrite(LED_BUILTIN,LOW); +// #endif +// vTaskDelay(200); +// } + +// xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); +// JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); +// (*cmd_doc)["cmd"] = SET_COMMAND; +// JsonArray cmd_items = cmd_args.createNestedArray("items"); +// JsonObject items_obj = cmd_items.createNestedObject(); +// items_obj["key"] = BLINK_ID_KEY; +// items_obj["value"] = 0; +// //cmd_items.add(BLINK_ID_KEY); + +// JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); +// cmd_cfg["pers"] = 1; +// cmd_cfg["type"] = "rsvd"; +// cmd_cfg["ack"] = 0; + +// ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), false, VOID_RESPONSE); +// (*cmd_doc).clear(); +// xSemaphoreGive(jsonMutex); + +// } +// Arancino.free(rsp); +// vTaskDelay(10000); //wait 10 seconds (non-blocking delay) +// } +// } + +// void ArancinoTasks::interoception(void *pvPramaters){ +// while (1) +// { +// #if !defined(ARDUINO_ARANCINO_VOLANTE) && !defined(ARDUINO_ARCH_RP2040) +// int memory_free = xPortGetFreeHeapSize(); +// int memory_used=configTOTAL_HEAP_SIZE-memory_free; +// #endif + +// #if defined(ARDUINO_ARANCINO_VOLANTE) || defined(ARDUINO_ARCH_RP2040) +// xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); +// char* ts = Arancino.getTimestamp(); +// JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); +// (*cmd_doc)["cmd"] = STORE_COMMAND; +// JsonArray cmd_items = cmd_args.createNestedArray("items"); +// JsonObject memfree_obj = cmd_items.createNestedObject(); +// JsonObject temp_obj = cmd_items.createNestedObject(); - ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, CLIENTS_RESPONSE); +// memfree_obj["key"] = "MEM_TOT"; +// memfree_obj["value"] = configTOTAL_HEAP_SIZE; +// memfree_obj["ts"] = ts; +// temp_obj["key"] = "TEMP"; +// temp_obj["value"] = mcuTemp(); +// temp_obj["ts"] = ts; +// JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); +// cmd_cfg["ack"] = 0; +// cmd_cfg["type"] = "tse"; - topic[idSize+3] = '1'; //If the topic structure isn't changed i know exactly the byte I'm supposed to change +// ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), false, ITEMS_RESPONSE); +// xSemaphoreGive(jsonMutex); + +// #else +// xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); +// char* ts = Arancino.getTimestamp(); +// JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); +// (*cmd_doc)["cmd"] = STORE_COMMAND; +// JsonArray cmd_items = cmd_args.createNestedArray("items"); +// JsonObject memfree_obj = cmd_items.createNestedObject(); +// JsonObject temp_obj = cmd_items.createNestedObject(); +// JsonObject memtot_obj = cmd_items.createNestedObject(); +// JsonObject memused_obj = cmd_items.createNestedObject(); - (*cmd_doc).clear(); - cmd_args = (*cmd_doc).createNestedObject("args"); - (*cmd_doc)["cmd"] = PUBLISH_COMMAND; - cmd_items = cmd_args.createNestedArray("items"); - items_obj = cmd_items.createNestedObject(); - items_obj["channel"] = topic; - items_obj["message"] = Arancino.getTimestamp(); - - cmd_cfg = (*cmd_doc).createNestedObject("cfg"); - cmd_cfg["ack"] = 0; +// memtot_obj["key"] = "MEM_TOT"; +// memtot_obj["value"] = configTOTAL_HEAP_SIZE; +// memtot_obj["ts"] = ts; +// temp_obj["key"] = "TEMP"; +// temp_obj["value"] = 0; +// temp_obj["ts"] = ts; +// memfree_obj["key"] = "MEM_FREE"; +// memfree_obj["value"] = xPortGetFreeHeapSize(); +// memfree_obj["ts"] = ts; +// memused_obj["key"] = "MEM_USED"; +// memused_obj["value"] = configTOTAL_HEAP_SIZE-memory_free; +// memused_obj["ts"] = ts; +// JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); +// cmd_cfg["ack"] = 0; +// cmd_cfg["type"] = "tse"; - rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, CLIENTS_RESPONSE); +// ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), false, ITEMS_RESPONSE); +// (*cmd_doc).clear(); +// xSemaphoreGive(jsonMutex); +// #endif +// Arancino.free(rsp); +// vTaskDelay(60000); //wait 60 seconds (non-blocking delay) +// } + +// } + +// void ArancinoTasks::sendHeartbeat(void *pvPramaters){ +// uint8_t idSize = strlen(Arancino.id); +// char topic[idSize + 5]; //ID_SIZE + '_HBx' + '\0' +// strcpy(topic, Arancino.id); +// strcat(topic, "_HB0"); + +// while (1) { +// xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); +// topic[idSize+3] = '0'; //If the topic structure isn't changed i know exactly the byte I'm supposed to change - xSemaphoreGive(jsonMutex); - - vTaskDelay(10000); - } -} - -#if defined(__SAMD21G18A__) -float ArancinoTasks::mcuTemp(){ - TemperatureZero tempZero = TemperatureZero(); - tempZero.init(); - return tempZero.readInternalTemperature(); -} - -#elif defined(ARDUINO_ARANCINOV12_H743ZI) || defined(ARDUINO_ARANCINOV12_H743ZI2) - - -float ArancinoTasks::mcuTemp(){ - #ifdef ATEMP - int32_t VRef; - #ifdef __LL_ADC_CALC_VREFANALOG_VOLTAGE - VRef= (__LL_ADC_CALC_VREFANALOG_VOLTAGE(analogRead(AVREF), LL_ADC_RESOLUTION)); - #else - VRef= (VREFINT * ADC_RANGE / analogRead(AVREF)); // ADC sample to mV - #endif - #ifdef __LL_ADC_CALC_TEMPERATURE - return (__LL_ADC_CALC_TEMPERATURE(VRef, analogRead(ATEMP), LL_ADC_RESOLUTION)); - #elif defined(__LL_ADC_CALC_TEMPERATURE_TYP_PARAMS) - return (__LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(AVG_SLOPE, V25, CALX_TEMP, VRef, analogRead(ATEMP), LL_ADC_RESOLUTION)); - #else - return 0; - #endif - #else - return 0; - #endif - -} - -#elif defined (ARDUINO_ARANCINO_VOLANTE) - -float ArancinoTasks::mcuTemp(){ - return readCPUTemperature(); -} - -#else - -float ArancinoTasks::mcuTemp(){ - return 0; -} -#endif +// JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); +// (*cmd_doc)["cmd"] = PUBLISH_COMMAND; +// JsonArray cmd_items = cmd_args.createNestedArray("items"); +// JsonObject items_obj = cmd_items.createNestedObject(); +// items_obj["channel"] = topic; +// items_obj["message"] = Arancino.getTimestamp(); + +// JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); +// cmd_cfg["ack"] = 0; +// cmd_cfg["pers"] = 0; + +// ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, CLIENTS_RESPONSE); + +// topic[idSize+3] = '1'; //If the topic structure isn't changed i know exactly the byte I'm supposed to change + +// items_obj["channel"] = topic; +// items_obj["message"] = Arancino.getTimestamp(); + +// rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, CLIENTS_RESPONSE); +// (*cmd_doc).clear(); +// xSemaphoreGive(jsonMutex); + +// vTaskDelay(10000); +// } +// } + +// #if defined(__SAMD21G18A__) +// float ArancinoTasks::mcuTemp(){ +// TemperatureZero tempZero = TemperatureZero(); +// tempZero.init(); +// return tempZero.readInternalTemperature(); +// } + +// #elif defined(ARDUINO_ARANCINOV12_H743ZI) || defined(ARDUINO_ARANCINOV12_H743ZI2) + + +// float ArancinoTasks::mcuTemp(){ +// #ifdef ATEMP +// int32_t VRef; +// #ifdef __LL_ADC_CALC_VREFANALOG_VOLTAGE +// VRef= (__LL_ADC_CALC_VREFANALOG_VOLTAGE(analogRead(AVREF), LL_ADC_RESOLUTION)); +// #else +// VRef= (VREFINT * ADC_RANGE / analogRead(AVREF)); // ADC sample to mV +// #endif +// #ifdef __LL_ADC_CALC_TEMPERATURE +// return (__LL_ADC_CALC_TEMPERATURE(VRef, analogRead(ATEMP), LL_ADC_RESOLUTION)); +// #elif defined(__LL_ADC_CALC_TEMPERATURE_TYP_PARAMS) +// return (__LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(AVG_SLOPE, V25, CALX_TEMP, VRef, analogRead(ATEMP), LL_ADC_RESOLUTION)); +// #else +// return 0; +// #endif +// #else +// return 0; +// #endif + +// } + +// #elif defined (ARDUINO_ARANCINO_VOLANTE) + +// float ArancinoTasks::mcuTemp(){ +// return readCPUTemperature(); +// } + +// #else + +// float ArancinoTasks::mcuTemp(){ +// return 0; +// } +// #endif #endif diff --git a/src/ArancinoTasks.h b/src/ArancinoTasks.h index 49bf42c..ed010f5 100644 --- a/src/ArancinoTasks.h +++ b/src/ArancinoTasks.h @@ -23,21 +23,44 @@ under the License #include #include +#include +struct FreeRTOSAllocator { + void* allocate(size_t n) { + return pvPortMalloc(n); + } + + void deallocate(void* p) { + vPortFree(p); + } +}; + +typedef BasicJsonDocument FreeRTOSDynamicJsonDocument; class ArancinoTasks{ + #ifdef USEFREERTOS public: ArancinoTasks(); - static void deviceIdentification(void *pvPramaters); - static void interoception(void *pvPramaters); - static void sendHeartbeat(void *pvPramaters); + static void serviceTask(void *pvPramaters); + TimerHandle_t identificationTimer; + TimerHandle_t interoceptionTimer; + TimerHandle_t heartbeatTimer; + + static void identificationCallback(TimerHandle_t xTimer); + static void interoceptionCallback(TimerHandle_t xTimer); + static void heartbeatCallback(TimerHandle_t xTimer); + private: static float mcuTemp(); - static DynamicJsonDocument* cmd_doc; - static DynamicJsonDocument* rsp_doc; - #ifdef USEFREERTOS + static FreeRTOSDynamicJsonDocument* cmd_doc; + static FreeRTOSDynamicJsonDocument* rsp_doc; static SemaphoreHandle_t jsonMutex; - #endif + + static bool _identificationFlag; + static bool _interoceptionFlag; + static bool _heartbeatFlag; + + #endif }; -#endif \ No newline at end of file +#endif From 9cd7f06292fc51f7c13fc721fdc1dcf40e61f46c Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Mon, 30 Jan 2023 18:15:23 +0100 Subject: [PATCH 17/69] Restoring comm_timeout implementation --- src/ArancinoInterface.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index 6906f98..b051bd2 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -36,7 +36,15 @@ void SerialIface::ifaceBegin(){ } void SerialIface::sendArancinoCommand(JsonDocument& command){ + if (this->comm_timeout){ + while(this->_serialPort->available() > 0){ + this->_serialPort->read(); + } + comm_timeout=false; + + } serializeMsgPack(command, *_serialPort); + #if defined(USEFREERTOS) && defined(USE_TINYUSB) if (xTaskGetSchedulerState() != taskSCHEDULER_RUNNING) @@ -49,6 +57,9 @@ void SerialIface::sendArancinoCommand(JsonDocument& command){ bool SerialIface::receiveArancinoResponse(JsonDocument& response){ DeserializationError error = deserializeMsgPack(response, *_serialPort); + if (error){ + this->comm_timeout = true; + } return error; } @@ -60,7 +71,7 @@ void SerialIface::setSerialPort(Stream& serialPort){ void SerialIface::setSerialPort(){ //default implementation for Arancino boards #if defined (SERIAL_PORT) && defined(BAUDRATE) && defined (TIMEOUT) - //SERIAL_PORT.begin(BAUDRATE); + SERIAL_PORT.begin(BAUDRATE); SERIAL_PORT.setTimeout(TIMEOUT); this->_serialPort = &SERIAL_PORT; #endif From 72a7073645423534ec76f055ef0d57e465e094ec Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Thu, 19 Jan 2023 11:01:30 +0100 Subject: [PATCH 18/69] First attempt to fix sendArancinoCommand --- src/ArancinoInterface.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index b051bd2..b599b27 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -35,6 +35,9 @@ void SerialIface::ifaceBegin(){ //Nothing to initialize here. } +size_t docSize; +char* docStr; + void SerialIface::sendArancinoCommand(JsonDocument& command){ if (this->comm_timeout){ while(this->_serialPort->available() > 0){ @@ -43,8 +46,12 @@ void SerialIface::sendArancinoCommand(JsonDocument& command){ comm_timeout=false; } - serializeMsgPack(command, *_serialPort); - + docSize = measureMsgPack(command); + docStr = (char*)malloc(docSize * sizeof(char)); + serializeMsgPack(command, docStr, docSize); + (*_serialPort).write(docStr, docSize); + //serializeMsgPack(command, *_serialPort); + free(docStr); #if defined(USEFREERTOS) && defined(USE_TINYUSB) if (xTaskGetSchedulerState() != taskSCHEDULER_RUNNING) From b0fe2a5fdc78d8ce5887be5f60ad487356de5db6 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Thu, 19 Jan 2023 11:03:22 +0100 Subject: [PATCH 19/69] Included timers.h for RP2040 when using FreeRTOS --- src/Arancino.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Arancino.h b/src/Arancino.h index 947ac7a..f6192f4 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -60,6 +60,7 @@ extern "C" { #include #elif defined (ARDUINO_ARCH_RP2040) #include +#include #include #include #if defined(USE_TINYUSB) From 4a244d0e4b578bd7ccaa2efc84c24be7d6ec552b Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Thu, 19 Jan 2023 11:04:42 +0100 Subject: [PATCH 20/69] fix identificationCallback --- src/Arancino.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index c2a1b2f..fb2609e 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -142,7 +142,7 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, char* ArancinoTasks _atask; timerHandle1 = xTimerCreate("Heartbeat", pdMS_TO_TICKS(10000), pdTRUE, (void*)0, _atask.heartbeatCallback); timerHandle2 = xTimerCreate("Interoception", pdMS_TO_TICKS(60000), pdTRUE, (void*)0, _atask.interoceptionCallback); - timerHandle3 = xTimerCreate("Identification", pdMS_TO_TICKS(10000), pdTRUE, (void*)0, _atask.interoceptionCallback); + timerHandle3 = xTimerCreate("Identification", pdMS_TO_TICKS(10000), pdTRUE, (void*)0, _atask.identificationCallback); xTimerStart(timerHandle1, 0); xTimerStart(timerHandle2, 0); From f57c036224f2fb3ec9a1c1a0bf1f674b3310a2d4 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Fri, 20 Jan 2023 10:43:11 +0100 Subject: [PATCH 21/69] Implem. a better way to send chars via SerialUSB --- src/ArancinoInterface.cpp | 62 +++++++++++++++++++++++++++++++++++++-- src/ArancinoInterface.h | 1 + 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index b599b27..ef8d29f 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -35,10 +35,56 @@ void SerialIface::ifaceBegin(){ //Nothing to initialize here. } -size_t docSize; -char* docStr; +int SerialIface::serialWrite(const char* str, uint32_t len, long timeout){ + int sent = 0; //successfully sent chars count + int written = -1; + int i; //sending command index + long send_ts; + for (i = 0; i < len; i++) { + written = -1; + send_ts = millis(); + do + { + written = (*_serialPort).write(str[i]); + if (written > 0) + { + // SERIAL_DEBUG.print("Sent: "); + // SERIAL_DEBUG.print(" 0x"); + // SERIAL_DEBUG.print(str[i], HEX); + // SERIAL_DEBUG.print(" = "); + // SERIAL_DEBUG.println(str[i]); + } + else + { + SERIAL_DEBUG.print("Retry: "); + SERIAL_DEBUG.print(" 0x"); + SERIAL_DEBUG.print(str[i], HEX); + SERIAL_DEBUG.print(" = "); + SERIAL_DEBUG.println(str[i]); + } + } while (written < 1 && millis() < (send_ts + timeout)); + + if (written < 1) + { + SERIAL_DEBUG.print("Error sending: "); + SERIAL_DEBUG.print(" 0x"); + SERIAL_DEBUG.print(str[i], HEX); + SERIAL_DEBUG.print(" = "); + SERIAL_DEBUG.println(str[i]); + break; + } + else + { + ++sent; //increasing successfully sent chars + } + } + return sent; //if sent < len then error! +} void SerialIface::sendArancinoCommand(JsonDocument& command){ + size_t docSize; + char* docStr; + if (this->comm_timeout){ while(this->_serialPort->available() > 0){ this->_serialPort->read(); @@ -46,10 +92,20 @@ void SerialIface::sendArancinoCommand(JsonDocument& command){ comm_timeout=false; } + docSize = measureMsgPack(command); docStr = (char*)malloc(docSize * sizeof(char)); serializeMsgPack(command, docStr, docSize); - (*_serialPort).write(docStr, docSize); + + int sent = serialWrite(docStr, docSize, 500); //TODO: set correct timeout + if (sent < docSize) + { + SERIAL_DEBUG.print("Error: sent "); + SERIAL_DEBUG.print(sent); + SERIAL_DEBUG.print(" of "); + SERIAL_DEBUG.println(docSize); + __NOP(); + } //serializeMsgPack(command, *_serialPort); free(docStr); diff --git a/src/ArancinoInterface.h b/src/ArancinoInterface.h index 941c47c..629a8a9 100644 --- a/src/ArancinoInterface.h +++ b/src/ArancinoInterface.h @@ -46,6 +46,7 @@ class SerialIface : public ArancinoIface { private: void ifaceBegin(); + int serialWrite(const char* str, uint32_t len, long timeout); void sendArancinoCommand(JsonDocument& command); bool receiveArancinoResponse(JsonDocument& response); From 61885ef7eef4e1cf56848dfbb3a19e263ff1503e Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Mon, 30 Jan 2023 18:19:52 +0100 Subject: [PATCH 22/69] Improved executeCommand functions --- src/Arancino.cpp | 196 +++++++++++++++++++++-------------------------- src/Arancino.h | 1 - 2 files changed, 88 insertions(+), 109 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index fb2609e..e214541 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -21,8 +21,6 @@ under the License #include "Arancino.h" #include "ArancinoTasks.h" -#define DEBUG 0 - ArancinoPacket reservedKeyErrorPacket = {true, RESERVED_KEY_ERROR, RESERVED_KEY_ERROR, {.string = NULL}}; // default reserved key error packet ArancinoPacket communicationErrorPacket = {true, COMMUNICATION_ERROR, COMMUNICATION_ERROR, {.string = NULL}}; // default reserved key error packet ArancinoPacket invalidCommandErrorPacket = {true, INVALID_VALUE_ERROR, INVALID_VALUE_ERROR, {.string = NULL}}; // default reserved key error packet @@ -147,7 +145,7 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, char* xTimerStart(timerHandle1, 0); xTimerStart(timerHandle2, 0); xTimerStart(timerHandle3, 0); - xTaskCreate(_atask.serviceTask, "serviceTask", 512, NULL, ARANCINO_TASK_PRIORITY, &arancinoHandle1); + xTaskCreate(_atask.serviceTask, "serviceTask", SERVICETASK_STACK, NULL, ARANCINO_TASK_PRIORITY, &arancinoHandle1); #endif } @@ -1121,151 +1119,133 @@ char *ArancinoClass::getTimestamp() ArancinoPacket ArancinoClass::executeCommand(char* cmd, char* key, char* field, char* value, bool isAck, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type){ StaticJsonDocument cmd_doc; - int tx_counter = 0; bool error = true; - do { - _buildArancinoJson(cmd_doc, cmd, key, field, value, argsHasItems, itemsHasDict, cfg); - - #if defined(USEFREERTOS) - if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE){ - #endif - _iface->sendArancinoCommand(cmd_doc); - - if(isAck){ - error = _iface->receiveArancinoResponse(cmd_doc); - } else { - #if defined(USEFREERTOS) - giveCommMutex(); - #endif - return voidCommunicationPacket; - } + _buildArancinoJson(cmd_doc, cmd, key, field, value, argsHasItems, itemsHasDict, cfg); - #if defined(USEFREERTOS) - giveCommMutex(); - } - #endif + #if defined(USEFREERTOS) + if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE){ + #endif + _iface->sendArancinoCommand(cmd_doc); - if(!cmd_doc.isNull() && !error) { - ArancinoPacket packet = createArancinoPacket(cmd_doc, response_type); - return packet; + if(isAck){ + error = _iface->receiveArancinoResponse(cmd_doc); } else { - tx_counter++; + #if defined(USEFREERTOS) + giveCommMutex(); + #endif + return voidCommunicationPacket; } - } while (tx_counter < TX_MAX_RETRIES); - return communicationErrorPacket; + #if defined(USEFREERTOS) + giveCommMutex(); + } + #endif + + if(!cmd_doc.isNull() && !error) { + ArancinoPacket packet = createArancinoPacket(cmd_doc, response_type); + return packet; + } else { + return communicationErrorPacket; + } } ArancinoPacket ArancinoClass::executeCommand(char* cmd, char** keys, char** fields, char** values, int len, bool isAck, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type){ StaticJsonDocument cmd_doc; - int tx_counter = 0; bool error = true; - do { - _buildArancinoJson(cmd_doc, cmd, keys, fields, values, len, argsHasItems, itemsHasDict, cfg); + _buildArancinoJson(cmd_doc, cmd, keys, fields, values, len, argsHasItems, itemsHasDict, cfg); - #if defined(USEFREERTOS) - if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE){ - #endif - _iface->sendArancinoCommand(cmd_doc); - - if(isAck){ - error = _iface->receiveArancinoResponse(cmd_doc); - } else { - #if defined(USEFREERTOS) - giveCommMutex(); - #endif - return voidCommunicationPacket; - } - - #if defined(USEFREERTOS) - } - giveCommMutex(); - #endif + #if defined(USEFREERTOS) + if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE){ + #endif + _iface->sendArancinoCommand(cmd_doc); - if(!cmd_doc.isNull() && !error){ - ArancinoPacket packet = createArancinoPacket(cmd_doc, response_type); - return packet; + if(isAck){ + error = _iface->receiveArancinoResponse(cmd_doc); } else { - tx_counter++; + #if defined(USEFREERTOS) + giveCommMutex(); + #endif + return voidCommunicationPacket; } - } while (tx_counter < TX_MAX_RETRIES); + + #if defined(USEFREERTOS) + giveCommMutex(); + } + #endif + + if(!cmd_doc.isNull() && !error){ + ArancinoPacket packet = createArancinoPacket(cmd_doc, response_type); + return packet; + } else { + return communicationErrorPacket; + } - return communicationErrorPacket; + } ArancinoPacket ArancinoClass::executeCommand(JsonDocument& cmd_doc, bool isAck, int response_type){ - int tx_counter = 0; StaticJsonDocument rsp_doc; bool error = true; - do { - #if defined(USEFREERTOS) - if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE){ - #endif + #if defined(USEFREERTOS) + if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE){ + #endif - _iface->sendArancinoCommand(cmd_doc); + _iface->sendArancinoCommand(cmd_doc); - if(isAck){ - error = _iface->receiveArancinoResponse(rsp_doc); - } else { - #if defined(USEFREERTOS) - giveCommMutex(); - #endif - return voidCommunicationPacket; - } - + if(isAck){ + error = _iface->receiveArancinoResponse(rsp_doc); + } else { #if defined(USEFREERTOS) - } giveCommMutex(); #endif + return voidCommunicationPacket; + } + + #if defined(USEFREERTOS) + giveCommMutex(); + } + #endif - if(!rsp_doc.isNull() && !error){ - ArancinoPacket packet = createArancinoPacket(rsp_doc, response_type); - return packet; - } else { - tx_counter++; - } - } while (tx_counter < TX_MAX_RETRIES); - - return communicationErrorPacket; + if(!rsp_doc.isNull() && !error){ + ArancinoPacket packet = createArancinoPacket(rsp_doc, response_type); + return packet; + } else { + return communicationErrorPacket; + } } ArancinoPacket ArancinoClass::executeCommand(JsonDocument& cmd_doc, JsonDocument& rsp_doc, bool isAck, int response_type){ - int tx_counter = 0; bool error = true; - do { - #if defined(USEFREERTOS) - if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE){ - #endif - - _iface->sendArancinoCommand(cmd_doc); + #if defined(USEFREERTOS) + if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE){ + #endif - if(isAck){ - error = _iface->receiveArancinoResponse(rsp_doc); - } else { - #if defined(USEFREERTOS) - giveCommMutex(); - #endif - return voidCommunicationPacket; - } - - #if defined(USEFREERTOS) - } - giveCommMutex(); - #endif + _iface->sendArancinoCommand(cmd_doc); - if(!rsp_doc.isNull() && !error){ - ArancinoPacket packet = createArancinoPacket(rsp_doc, response_type); - return packet; + if(isAck){ + error = _iface->receiveArancinoResponse(rsp_doc); } else { - tx_counter++; + #if defined(USEFREERTOS) + giveCommMutex(); + #endif + return voidCommunicationPacket; } - } while (tx_counter < TX_MAX_RETRIES); + + #if defined(USEFREERTOS) + giveCommMutex(); + } + #endif - return communicationErrorPacket; + if(!rsp_doc.isNull() && !error){ + ArancinoPacket packet = createArancinoPacket(rsp_doc, response_type); + return packet; + } else { + return communicationErrorPacket; + } } ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, int response_type){ diff --git a/src/Arancino.h b/src/Arancino.h index f6192f4..2abafc0 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -294,7 +294,6 @@ class ArancinoClass { void _buildArancinoJson(JsonDocument& doc, char* cmd, char* key, char* field, char* value, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg); void _buildArancinoJson(JsonDocument& doc, char* cmd, char** keys, char** fields, char** values, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg); - //Protocol interface ArancinoIface* _iface; From a1f3cb68cc20d6a4b9b45e659e1fab024916cef6 Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Mon, 30 Jan 2023 18:22:49 +0100 Subject: [PATCH 23/69] Removed unneeded gimmicks in service tasks implementation. General cleanup and improvements --- src/ArancinoDefinitions.h | 21 +- src/ArancinoInterface.cpp | 19 +- src/ArancinoTasks.cpp | 569 +++++++++++++------------------------- src/ArancinoTasks.h | 22 +- 4 files changed, 222 insertions(+), 409 deletions(-) diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index 9389e95..2dadd9d 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -24,7 +24,7 @@ under the License #if defined(__SAMD21G18A__) #define BAUDRATE 4000000 -#define TIMEOUT 100 +#define TIMEOUT 1000 #define SERIAL_PORT SerialUSB #define SERIAL_DEBUG Serial #elif defined(ARDUINO_ARCH_RP2040) && defined(USEFREERTOS) @@ -115,7 +115,9 @@ under the License #define ERR_REDIS_KEY_EXISTS_IN_STD 207 //Key exists in the Standard Data Store #define ERR_REDIS_KEY_EXISTS_IN_PERS 208 //Key exists in the Persistent Data Store #define ERR_NON_COMPATIBILITY 209 //Non compatibility between Arancino Module and Library -#define ERR_STORE_CONVERSION 211 //Non compatibility between Arancino Module and Library +#define ERR_INVALID_ARGUMENTS 210 //Generic Invalid Arguments +#define ERR_VALUE 211 //Invalid value +#define ERR_CMD_TYPE 212 //Error during packet transmission #define DBG_PIN 26 //pin used to Debug Message //#define PWR_PIN ?? //pin used for Power Management @@ -134,6 +136,7 @@ under the License #define RESERVED_KEY_ERROR -3 #define COMMUNICATION_ERROR -2 #define GENERIC_ERROR -1 +#define VOID_ERROR_TYPE 0 //RESPONSE TYPE #define VOID (int)0 @@ -151,19 +154,13 @@ under the License #if defined(ARDUINO_ARCH_ESP32) //ESP32 configMAX_PRIORITIES is 25 #define ARANCINO_TASK_PRIORITY 20 -#define IDENTIFICATION_STACK configMINIMAL_STACK_SIZE * 4 -#define INTEROCEPTION_STACK configMINIMAL_STACK_SIZE * 4 -#define HEARTBEAT_STACK configMINIMAL_STACK_SIZE * 4 +#define SERVICETASK_STACK (1024 * 4) #elif defined(__SAMD21G18A__) #define ARANCINO_TASK_PRIORITY configMAX_PRIORITIES - 1 -#define IDENTIFICATION_STACK 256 -#define INTEROCEPTION_STACK 256 -#define HEARTBEAT_STACK 256 +#define SERVICETASK_STACK 768 #elif defined(ARDUINO_ARCH_RP2040) #define ARANCINO_TASK_PRIORITY configMAX_PRIORITIES - 1 -#define IDENTIFICATION_STACK 512 -#define INTEROCEPTION_STACK 512 -#define HEARTBEAT_STACK 512 +#define SERVICETASK_STACK 1024 #endif #define SERIAL_MAX_RETRIES 10 @@ -185,4 +182,4 @@ under the License #define FIELDS_ITEMS_RESPONSE 3 #define FIELDS_RESPONSE 4 #define ITEMS_RESPONSE 5 -#define CLIENTS_RESPONSE 6 +#define CLIENTS_RESPONSE 6 \ No newline at end of file diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index ef8d29f..438aa28 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -36,6 +36,9 @@ void SerialIface::ifaceBegin(){ } int SerialIface::serialWrite(const char* str, uint32_t len, long timeout){ + if (!str || !len) + return 0; + int sent = 0; //successfully sent chars count int written = -1; int i; //sending command index @@ -46,21 +49,15 @@ int SerialIface::serialWrite(const char* str, uint32_t len, long timeout){ do { written = (*_serialPort).write(str[i]); - if (written > 0) - { - // SERIAL_DEBUG.print("Sent: "); - // SERIAL_DEBUG.print(" 0x"); - // SERIAL_DEBUG.print(str[i], HEX); - // SERIAL_DEBUG.print(" = "); - // SERIAL_DEBUG.println(str[i]); - } - else + if (written <= 0) { + #if DEBUG SERIAL_DEBUG.print("Retry: "); SERIAL_DEBUG.print(" 0x"); SERIAL_DEBUG.print(str[i], HEX); SERIAL_DEBUG.print(" = "); SERIAL_DEBUG.println(str[i]); + #endif } } while (written < 1 && millis() < (send_ts + timeout)); @@ -100,13 +97,15 @@ void SerialIface::sendArancinoCommand(JsonDocument& command){ int sent = serialWrite(docStr, docSize, 500); //TODO: set correct timeout if (sent < docSize) { + #if DEBUG SERIAL_DEBUG.print("Error: sent "); SERIAL_DEBUG.print(sent); SERIAL_DEBUG.print(" of "); SERIAL_DEBUG.println(docSize); __NOP(); + #endif } - //serializeMsgPack(command, *_serialPort); + free(docStr); #if defined(USEFREERTOS) && defined(USE_TINYUSB) diff --git a/src/ArancinoTasks.cpp b/src/ArancinoTasks.cpp index 3b99c21..1e6ced7 100644 --- a/src/ArancinoTasks.cpp +++ b/src/ArancinoTasks.cpp @@ -19,414 +19,239 @@ under the License */ #include -#if defined(__SAMD21G18A__) -#include -#endif -#if defined(ARDUINO_ARCH_ESP32) -#include -#else -#include -#endif -#if defined(ARDUINO_ARANCINOV12_H743ZI) || defined(ARDUINO_ARANCINOV12_H743ZI2) -#include "stm32yyxx_ll_adc.h" -#define CALX_TEMP 25 -#define LL_ADC_RESOLUTION LL_ADC_RESOLUTION_12B -#define ADC_RANGE 4096 -#endif - -/******** TASK DEVICE IDENTIFICATION *********/ #if defined(USEFREERTOS) -FreeRTOSDynamicJsonDocument* ArancinoTasks::cmd_doc; -FreeRTOSDynamicJsonDocument* ArancinoTasks::rsp_doc; -// SemaphoreHandle_t ArancinoTasks::jsonMutex; -bool ArancinoTasks::_identificationFlag; -bool ArancinoTasks::_interoceptionFlag; -bool ArancinoTasks::_heartbeatFlag; + #if defined(__SAMD21G18A__) + #include + #endif -ArancinoTasks::ArancinoTasks(){ - cmd_doc = new FreeRTOSDynamicJsonDocument(CMD_DOC_SIZE); - rsp_doc = new FreeRTOSDynamicJsonDocument(RSP_DOC_SIZE); - //jsonMutex = xSemaphoreCreateMutex(); + #if defined(ARDUINO_ARCH_ESP32) + #include + #else + #include + #endif + + #if defined(ARDUINO_ARANCINOV12_H743ZI) || defined(ARDUINO_ARANCINOV12_H743ZI2) + #include "stm32yyxx_ll_adc.h" + #define CALX_TEMP 25 + #define LL_ADC_RESOLUTION LL_ADC_RESOLUTION_12B + #define ADC_RANGE 4096 + #endif + + /******** TASK DEVICE IDENTIFICATION *********/ + + DynamicJsonDocument* ArancinoTasks::cmd_doc; + DynamicJsonDocument* ArancinoTasks::rsp_doc; + + bool ArancinoTasks::_identificationFlag; + bool ArancinoTasks::_interoceptionFlag; + bool ArancinoTasks::_heartbeatFlag; + + ArancinoTasks::ArancinoTasks(){ + cmd_doc = new DynamicJsonDocument(CMD_DOC_SIZE); + rsp_doc = new DynamicJsonDocument(RSP_DOC_SIZE); _identificationFlag = false; _interoceptionFlag = false; _heartbeatFlag = false; -} + } -void ArancinoTasks::identificationCallback (TimerHandle_t xTimer){ + void ArancinoTasks::identificationCallback (TimerHandle_t xTimer){ ArancinoTasks::_identificationFlag = true; -} + } -void ArancinoTasks::interoceptionCallback (TimerHandle_t xTimer){ + void ArancinoTasks::interoceptionCallback (TimerHandle_t xTimer){ ArancinoTasks::_interoceptionFlag = true; -} + } -void ArancinoTasks::heartbeatCallback (TimerHandle_t xTimer){ + void ArancinoTasks::heartbeatCallback (TimerHandle_t xTimer){ _heartbeatFlag = true; -} + } + + void ArancinoTasks::heartbeatTask(){ + uint8_t idSize = strlen(Arancino.id); + char topic[idSize + 5]; //ID_SIZE + '_HBx' + '\0' + strcpy(topic, Arancino.id); + strcat(topic, "_HB0"); + topic[idSize+3] = '0'; //If the topic structure isn't changed i know exactly the byte I'm supposed to change -void ArancinoTasks::serviceTask(void* pvParameters){ - //Heartbeat region - uint8_t idSize = strlen(Arancino.id); - char topic[idSize + 5]; //ID_SIZE + '_HBx' + '\0' - strcpy(topic, Arancino.id); - strcat(topic, "_HB0"); + JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); + (*cmd_doc)["cmd"] = PUBLISH_COMMAND; + JsonArray cmd_items = cmd_args.createNestedArray("items"); + JsonObject items_obj = cmd_items.createNestedObject(); + items_obj["channel"] = topic; + items_obj["message"] = Arancino.getTimestamp(); - //Identification region - pinMode(LED_BUILTIN,OUTPUT); + JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); + cmd_cfg["ack"] = 0; + cmd_cfg["pers"] = 0; - // digitalWrite(LED_BUILTIN, HIGH); - // Arancino.delay(200); - // digitalWrite(LED_BUILTIN, LOW); - // Arancino.delay(200); - + ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, CLIENTS_RESPONSE); + + topic[idSize+3] = '1'; //If the topic structure isn't changed i know exactly the byte I'm supposed to change + + items_obj["channel"] = topic; + items_obj["message"] = Arancino.getTimestamp(); - while(1){ + rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, CLIENTS_RESPONSE); + (*cmd_doc).clear(); + Arancino.free(rsp); + } - if(_heartbeatFlag){ - topic[idSize+3] = '0'; //If the topic structure isn't changed i know exactly the byte I'm supposed to change + void ArancinoTasks::identificationTask(){ + JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); + (*cmd_doc)["cmd"] = GET_COMMAND; + JsonArray cmd_items = cmd_args.createNestedArray("items"); + uint8_t idSize = strlen(Arancino.id); + char blink_key[idSize + 1 + strlen(BLINK_ID_KEY)]; + strcpy(blink_key, Arancino.id); + char separator = '_'; + strncat(blink_key, &separator, 1); + strcat(blink_key, BLINK_ID_KEY); + + cmd_items.add(blink_key); + JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); + cmd_cfg["pers"] = 1; + cmd_cfg["type"] = "rsvd"; + + ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), true, KEY_VALUE_RESPONSE); + (*cmd_doc).clear(); + + if(!strcmp(rsp.response.string, "1")){ + for(int i=0;i < 20; i++){ + #if defined (ARDUINO_ARANCINO_VOLANTE) + digitalWrite(LED_BUILTIN,LOW); + #else + digitalWrite(LED_BUILTIN,HIGH); + #endif + vTaskDelay(100); + #if defined (ARDUINO_ARANCINO_VOLANTE) + digitalWrite(LED_BUILTIN,HIGH); + #else + digitalWrite(LED_BUILTIN,LOW); + #endif + vTaskDelay(200); + } - JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); - (*cmd_doc)["cmd"] = PUBLISH_COMMAND; - JsonArray cmd_items = cmd_args.createNestedArray("items"); + cmd_args = (*cmd_doc).createNestedObject("args"); + (*cmd_doc)["cmd"] = SET_COMMAND; + cmd_items = cmd_args.createNestedArray("items"); JsonObject items_obj = cmd_items.createNestedObject(); - items_obj["channel"] = topic; - items_obj["message"] = Arancino.getTimestamp(); + items_obj["key"] = blink_key; + items_obj["value"] = 0; - JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); + cmd_cfg = (*cmd_doc).createNestedObject("cfg"); + cmd_cfg["pers"] = 1; + cmd_cfg["type"] = "rsvd"; cmd_cfg["ack"] = 0; - cmd_cfg["pers"] = 0; - - ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, CLIENTS_RESPONSE); - topic[idSize+3] = '1'; //If the topic structure isn't changed i know exactly the byte I'm supposed to change - - items_obj["channel"] = topic; - items_obj["message"] = Arancino.getTimestamp(); - - rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, CLIENTS_RESPONSE); + ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), false, VOID_RESPONSE); (*cmd_doc).clear(); - _heartbeatFlag = false; } + Arancino.free(rsp); + } -/* - + void ArancinoTasks::interoceptionTask(){ + char* ts = Arancino.getTimestamp(); + JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); + JsonArray cmd_items = cmd_args.createNestedArray("items"); + JsonObject temp_obj = cmd_items.createNestedObject(); + JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); + + (*cmd_doc)["cmd"] = STORE_COMMAND; + temp_obj["key"] = "TEMP"; + temp_obj["value"] = mcuTemp(); + temp_obj["ts"] = ts; + cmd_cfg["ack"] = 0; + cmd_cfg["type"] = "tse"; + + #if defined(__SAMD21G18A__) + JsonObject memtot_obj = cmd_items.createNestedObject(); + JsonObject memused_obj = cmd_items.createNestedObject(); + memtot_obj["key"] = "MEM_TOT"; + memtot_obj["value"] = configTOTAL_HEAP_SIZE; + memtot_obj["ts"] = ts; + memused_obj["key"] = "MEM_USED"; + memused_obj["value"] = configTOTAL_HEAP_SIZE - xPortGetFreeHeapSize(); + memused_obj["ts"] = ts; + #elif defined(ARDUINO_ARCH_RP2040) + JsonObject memtot_obj = cmd_items.createNestedObject(); + JsonObject memused_obj = cmd_items.createNestedObject(); + memtot_obj["key"] = "MEM_TOT"; + memtot_obj["value"] = rp2040.getTotalHeap(); + memtot_obj["ts"] = ts; + memused_obj["key"] = "MEM_USED"; + memused_obj["value"] = rp2040.getUsedHeap(); + memused_obj["ts"] = ts; + #endif + + Arancino.executeCommand((*cmd_doc), false, ITEMS_RESPONSE); + (*cmd_doc).clear(); + } - if(_identificationFlag){ - JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); - (*cmd_doc)["cmd"] = GET_COMMAND; - JsonArray cmd_items = cmd_args.createNestedArray("items"); - cmd_items.add(BLINK_ID_KEY); + void ArancinoTasks::serviceTask(void* pvParameters){ + pinMode(LED_BUILTIN,OUTPUT); - JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); - cmd_cfg["pers"] = 1; - cmd_cfg["type"] = "rsvd"; - - ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), true, KEY_VALUE_RESPONSE); - (*cmd_doc).clear(); + while(1){ + //Heartbeat + if(_heartbeatFlag){ + heartbeatTask(); + _heartbeatFlag = false; + } - if(!strcmp(rsp.response.string, "1")){ - for(int i=0;i < 20; i++){ - #if defined (ARDUINO_ARANCINO_VOLANTE) - digitalWrite(LED_BUILTIN,LOW); - #else - digitalWrite(LED_BUILTIN,HIGH); - #endif - vTaskDelay(100); - #if defined (ARDUINO_ARANCINO_VOLANTE) - digitalWrite(LED_BUILTIN,HIGH); - #else - digitalWrite(LED_BUILTIN,LOW); - #endif - vTaskDelay(200); - } - - JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); - (*cmd_doc)["cmd"] = SET_COMMAND; - JsonArray cmd_items = cmd_args.createNestedArray("items"); - JsonObject items_obj = cmd_items.createNestedObject(); - items_obj["key"] = BLINK_ID_KEY; - items_obj["value"] = 0; - - JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); - cmd_cfg["pers"] = 1; - cmd_cfg["type"] = "rsvd"; - cmd_cfg["ack"] = 0; - - ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), false, VOID_RESPONSE); - (*cmd_doc).clear(); + //Blink id + if(_identificationFlag){ + identificationTask(); _identificationFlag = false; } + // Interoception if (_interoceptionFlag){ - #if !defined(ARDUINO_ARANCINO_VOLANTE) && !defined(ARDUINO_ARCH_RP2040) - int memory_free = xPortGetFreeHeapSize(); - int memory_used=configTOTAL_HEAP_SIZE-memory_free; - #endif - - #if defined(ARDUINO_ARANCINO_VOLANTE) || defined(ARDUINO_ARCH_RP2040) - char* ts = Arancino.getTimestamp(); - JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); - (*cmd_doc)["cmd"] = STORE_COMMAND; - JsonArray cmd_items = cmd_args.createNestedArray("items"); - JsonObject memfree_obj = cmd_items.createNestedObject(); - JsonObject temp_obj = cmd_items.createNestedObject(); - - memfree_obj["key"] = "MEM_TOT"; - memfree_obj["value"] = configTOTAL_HEAP_SIZE; - memfree_obj["ts"] = ts; - temp_obj["key"] = "TEMP"; - temp_obj["value"] = mcuTemp(); - temp_obj["ts"] = ts; - JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); - cmd_cfg["ack"] = 0; - cmd_cfg["type"] = "tse"; - - ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), false, ITEMS_RESPONSE); - (*cmd_doc).clear(); - #else - char* ts = Arancino.getTimestamp(); - JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); - (*cmd_doc)["cmd"] = STORE_COMMAND; - JsonArray cmd_items = cmd_args.createNestedArray("items"); - JsonObject memfree_obj = cmd_items.createNestedObject(); - JsonObject temp_obj = cmd_items.createNestedObject(); - JsonObject memtot_obj = cmd_items.createNestedObject(); - JsonObject memused_obj = cmd_items.createNestedObject(); - - memtot_obj["key"] = "MEM_TOT"; - memtot_obj["value"] = configTOTAL_HEAP_SIZE; - memtot_obj["ts"] = ts; - temp_obj["key"] = "TEMP"; - temp_obj["value"] = 0; - temp_obj["ts"] = ts; - memfree_obj["key"] = "MEM_FREE"; - memfree_obj["value"] = xPortGetFreeHeapSize(); - memfree_obj["ts"] = ts; - memused_obj["key"] = "MEM_USED"; - memused_obj["value"] = configTOTAL_HEAP_SIZE-memory_free; - memused_obj["ts"] = ts; - JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); - cmd_cfg["ack"] = 0; - cmd_cfg["type"] = "tse"; - - ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), false, ITEMS_RESPONSE); - (*cmd_doc).clear(); + interoceptionTask(); + _interoceptionFlag = false; } + + vTaskDelay(1000); } + } -*/ - //METTERE LO YIELD - vTaskDelay(1000); + + #if defined(__SAMD21G18A__) + float ArancinoTasks::mcuTemp(){ + TemperatureZero tempZero = TemperatureZero(); + tempZero.init(); + return tempZero.readInternalTemperature(); + } + #elif defined(ARDUINO_ARANCINOV12_H743ZI) || defined(ARDUINO_ARANCINOV12_H743ZI2) + float ArancinoTasks::mcuTemp(){ + #ifdef ATEMP + int32_t VRef; + #ifdef __LL_ADC_CALC_VREFANALOG_VOLTAGE + VRef= (__LL_ADC_CALC_VREFANALOG_VOLTAGE(analogRead(AVREF), LL_ADC_RESOLUTION)); + #else + VRef= (VREFINT * ADC_RANGE / analogRead(AVREF)); // ADC sample to mV + #endif + #ifdef __LL_ADC_CALC_TEMPERATURE + return (__LL_ADC_CALC_TEMPERATURE(VRef, analogRead(ATEMP), LL_ADC_RESOLUTION)); + #elif defined(__LL_ADC_CALC_TEMPERATURE_TYP_PARAMS) + return (__LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(AVG_SLOPE, V25, CALX_TEMP, VRef, analogRead(ATEMP), LL_ADC_RESOLUTION)); + #else + return 0; + #endif + #else + return 0; + #endif } -} - - -// void ArancinoTasks::deviceIdentification(void *pvPramaters){ -// pinMode(LED_BUILTIN,OUTPUT); -// while (1) -// { -// xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); -// JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); -// (*cmd_doc)["cmd"] = GET_COMMAND; -// JsonArray cmd_items = cmd_args.createNestedArray("items"); -// cmd_items.add(BLINK_ID_KEY); - -// JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); -// cmd_cfg["pers"] = 1; -// cmd_cfg["type"] = "rsvd"; - -// ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), true, KEY_VALUE_RESPONSE); -// xSemaphoreGive(jsonMutex); - - -// if(!strcmp(rsp.response.string, "1")){ -// for(int i=0;i < 20; i++){ -// #if defined (ARDUINO_ARANCINO_VOLANTE) -// digitalWrite(LED_BUILTIN,LOW); -// #else -// digitalWrite(LED_BUILTIN,HIGH); -// #endif -// vTaskDelay(100); -// #if defined (ARDUINO_ARANCINO_VOLANTE) -// digitalWrite(LED_BUILTIN,HIGH); -// #else -// digitalWrite(LED_BUILTIN,LOW); -// #endif -// vTaskDelay(200); -// } - -// xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); -// JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); -// (*cmd_doc)["cmd"] = SET_COMMAND; -// JsonArray cmd_items = cmd_args.createNestedArray("items"); -// JsonObject items_obj = cmd_items.createNestedObject(); -// items_obj["key"] = BLINK_ID_KEY; -// items_obj["value"] = 0; -// //cmd_items.add(BLINK_ID_KEY); - -// JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); -// cmd_cfg["pers"] = 1; -// cmd_cfg["type"] = "rsvd"; -// cmd_cfg["ack"] = 0; - -// ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), false, VOID_RESPONSE); -// (*cmd_doc).clear(); -// xSemaphoreGive(jsonMutex); - -// } -// Arancino.free(rsp); -// vTaskDelay(10000); //wait 10 seconds (non-blocking delay) -// } -// } - -// void ArancinoTasks::interoception(void *pvPramaters){ -// while (1) -// { -// #if !defined(ARDUINO_ARANCINO_VOLANTE) && !defined(ARDUINO_ARCH_RP2040) -// int memory_free = xPortGetFreeHeapSize(); -// int memory_used=configTOTAL_HEAP_SIZE-memory_free; -// #endif - -// #if defined(ARDUINO_ARANCINO_VOLANTE) || defined(ARDUINO_ARCH_RP2040) -// xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); -// char* ts = Arancino.getTimestamp(); -// JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); -// (*cmd_doc)["cmd"] = STORE_COMMAND; -// JsonArray cmd_items = cmd_args.createNestedArray("items"); -// JsonObject memfree_obj = cmd_items.createNestedObject(); -// JsonObject temp_obj = cmd_items.createNestedObject(); - -// memfree_obj["key"] = "MEM_TOT"; -// memfree_obj["value"] = configTOTAL_HEAP_SIZE; -// memfree_obj["ts"] = ts; -// temp_obj["key"] = "TEMP"; -// temp_obj["value"] = mcuTemp(); -// temp_obj["ts"] = ts; -// JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); -// cmd_cfg["ack"] = 0; -// cmd_cfg["type"] = "tse"; - -// ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), false, ITEMS_RESPONSE); -// xSemaphoreGive(jsonMutex); - -// #else -// xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); -// char* ts = Arancino.getTimestamp(); -// JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); -// (*cmd_doc)["cmd"] = STORE_COMMAND; -// JsonArray cmd_items = cmd_args.createNestedArray("items"); -// JsonObject memfree_obj = cmd_items.createNestedObject(); -// JsonObject temp_obj = cmd_items.createNestedObject(); -// JsonObject memtot_obj = cmd_items.createNestedObject(); -// JsonObject memused_obj = cmd_items.createNestedObject(); - -// memtot_obj["key"] = "MEM_TOT"; -// memtot_obj["value"] = configTOTAL_HEAP_SIZE; -// memtot_obj["ts"] = ts; -// temp_obj["key"] = "TEMP"; -// temp_obj["value"] = 0; -// temp_obj["ts"] = ts; -// memfree_obj["key"] = "MEM_FREE"; -// memfree_obj["value"] = xPortGetFreeHeapSize(); -// memfree_obj["ts"] = ts; -// memused_obj["key"] = "MEM_USED"; -// memused_obj["value"] = configTOTAL_HEAP_SIZE-memory_free; -// memused_obj["ts"] = ts; -// JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); -// cmd_cfg["ack"] = 0; -// cmd_cfg["type"] = "tse"; - -// ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), false, ITEMS_RESPONSE); -// (*cmd_doc).clear(); -// xSemaphoreGive(jsonMutex); -// #endif -// Arancino.free(rsp); -// vTaskDelay(60000); //wait 60 seconds (non-blocking delay) -// } - -// } - -// void ArancinoTasks::sendHeartbeat(void *pvPramaters){ -// uint8_t idSize = strlen(Arancino.id); -// char topic[idSize + 5]; //ID_SIZE + '_HBx' + '\0' -// strcpy(topic, Arancino.id); -// strcat(topic, "_HB0"); - -// while (1) { -// xSemaphoreTake(jsonMutex, (TickType_t)portMAX_DELAY); -// topic[idSize+3] = '0'; //If the topic structure isn't changed i know exactly the byte I'm supposed to change - -// JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); -// (*cmd_doc)["cmd"] = PUBLISH_COMMAND; -// JsonArray cmd_items = cmd_args.createNestedArray("items"); -// JsonObject items_obj = cmd_items.createNestedObject(); -// items_obj["channel"] = topic; -// items_obj["message"] = Arancino.getTimestamp(); - -// JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); -// cmd_cfg["ack"] = 0; -// cmd_cfg["pers"] = 0; - -// ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, CLIENTS_RESPONSE); - -// topic[idSize+3] = '1'; //If the topic structure isn't changed i know exactly the byte I'm supposed to change - -// items_obj["channel"] = topic; -// items_obj["message"] = Arancino.getTimestamp(); - -// rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, CLIENTS_RESPONSE); -// (*cmd_doc).clear(); -// xSemaphoreGive(jsonMutex); - -// vTaskDelay(10000); -// } -// } - -// #if defined(__SAMD21G18A__) -// float ArancinoTasks::mcuTemp(){ -// TemperatureZero tempZero = TemperatureZero(); -// tempZero.init(); -// return tempZero.readInternalTemperature(); -// } - -// #elif defined(ARDUINO_ARANCINOV12_H743ZI) || defined(ARDUINO_ARANCINOV12_H743ZI2) - - -// float ArancinoTasks::mcuTemp(){ -// #ifdef ATEMP -// int32_t VRef; -// #ifdef __LL_ADC_CALC_VREFANALOG_VOLTAGE -// VRef= (__LL_ADC_CALC_VREFANALOG_VOLTAGE(analogRead(AVREF), LL_ADC_RESOLUTION)); -// #else -// VRef= (VREFINT * ADC_RANGE / analogRead(AVREF)); // ADC sample to mV -// #endif -// #ifdef __LL_ADC_CALC_TEMPERATURE -// return (__LL_ADC_CALC_TEMPERATURE(VRef, analogRead(ATEMP), LL_ADC_RESOLUTION)); -// #elif defined(__LL_ADC_CALC_TEMPERATURE_TYP_PARAMS) -// return (__LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(AVG_SLOPE, V25, CALX_TEMP, VRef, analogRead(ATEMP), LL_ADC_RESOLUTION)); -// #else -// return 0; -// #endif -// #else -// return 0; -// #endif - -// } - -// #elif defined (ARDUINO_ARANCINO_VOLANTE) - -// float ArancinoTasks::mcuTemp(){ -// return readCPUTemperature(); -// } - -// #else - -// float ArancinoTasks::mcuTemp(){ -// return 0; -// } -// #endif -#endif + + #elif defined (ARDUINO_ARANCINO_VOLANTE) + float ArancinoTasks::mcuTemp(){ + return readCPUTemperature(); + } + #else + float ArancinoTasks::mcuTemp(){ + return 0; + } + #endif +#endif \ No newline at end of file diff --git a/src/ArancinoTasks.h b/src/ArancinoTasks.h index ed010f5..5b1fdfd 100644 --- a/src/ArancinoTasks.h +++ b/src/ArancinoTasks.h @@ -25,18 +25,6 @@ under the License #include #include -struct FreeRTOSAllocator { - void* allocate(size_t n) { - return pvPortMalloc(n); - } - - void deallocate(void* p) { - vPortFree(p); - } -}; - -typedef BasicJsonDocument FreeRTOSDynamicJsonDocument; - class ArancinoTasks{ #ifdef USEFREERTOS public: @@ -52,10 +40,14 @@ class ArancinoTasks{ private: static float mcuTemp(); - static FreeRTOSDynamicJsonDocument* cmd_doc; - static FreeRTOSDynamicJsonDocument* rsp_doc; + static DynamicJsonDocument* cmd_doc; + static DynamicJsonDocument* rsp_doc; static SemaphoreHandle_t jsonMutex; + static void identificationTask(); + static void interoceptionTask(); + static void heartbeatTask(); + static bool _identificationFlag; static bool _interoceptionFlag; static bool _heartbeatFlag; @@ -63,4 +55,4 @@ class ArancinoTasks{ #endif }; -#endif +#endif \ No newline at end of file From c7b10bc0016ac61b3dd66f68e47a80430a598fcd Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Wed, 1 Feb 2023 10:34:08 +0100 Subject: [PATCH 24/69] serialWrite timeout equal to _serialPort timeout --- src/ArancinoInterface.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index 438aa28..7a4c3fe 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -42,10 +42,13 @@ int SerialIface::serialWrite(const char* str, uint32_t len, long timeout){ int sent = 0; //successfully sent chars count int written = -1; int i; //sending command index - long send_ts; + long str_send_ts = millis(); //start timestamp of string sending + long char_send_ts; //start timestamp of single char sending + const long char_timeout = 100; + for (i = 0; i < len; i++) { written = -1; - send_ts = millis(); + char_send_ts = millis(); do { written = (*_serialPort).write(str[i]); @@ -59,21 +62,32 @@ int SerialIface::serialWrite(const char* str, uint32_t len, long timeout){ SERIAL_DEBUG.println(str[i]); #endif } - } while (written < 1 && millis() < (send_ts + timeout)); + } while (written < 1 && millis() < (char_send_ts + char_timeout)); if (written < 1) { + #if DEBUG SERIAL_DEBUG.print("Error sending: "); SERIAL_DEBUG.print(" 0x"); SERIAL_DEBUG.print(str[i], HEX); SERIAL_DEBUG.print(" = "); SERIAL_DEBUG.println(str[i]); + #endif break; } else { ++sent; //increasing successfully sent chars } + + if (millis() > (str_send_ts + timeout)) + { + //Command sending timeout, exit from for-cycle + #if DEBUG + SERIAL_DEBUG.println("serialWrite timeout"); + #endif + break; + } } return sent; //if sent < len then error! } @@ -94,15 +108,14 @@ void SerialIface::sendArancinoCommand(JsonDocument& command){ docStr = (char*)malloc(docSize * sizeof(char)); serializeMsgPack(command, docStr, docSize); - int sent = serialWrite(docStr, docSize, 500); //TODO: set correct timeout + int sent = serialWrite(docStr, docSize, this->_serialPort->getTimeout()); if (sent < docSize) { #if DEBUG SERIAL_DEBUG.print("Error: sent "); SERIAL_DEBUG.print(sent); SERIAL_DEBUG.print(" of "); - SERIAL_DEBUG.println(docSize); - __NOP(); + SERIAL_DEBUG.println(docSize); #endif } From 32695fd15368e927d98a8f249cc0e35b8d180df7 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Fri, 3 Feb 2023 10:16:55 +0100 Subject: [PATCH 25/69] Fixed wrong persistence in HGET --- src/Arancino.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arancino.h b/src/Arancino.h index 2abafc0..bacba2e 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -165,7 +165,7 @@ class ArancinoClass { ArancinoPacket hset(char* key, char* field, long value, bool isAck = true, bool isPersistent = false, char* type = "appl"); //HGET - template T hget(char* key, char* field, bool isPersistent = true, char* type = "appl"); + template T hget(char* key, char* field, bool isPersistent = false, char* type = "appl"); //HDEL template T hdel(char* key, char* field, bool isAck = true, bool isPersistent = false); From 828cca182a5e9745ed461e61f7245485bc612295 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Fri, 3 Feb 2023 12:32:21 +0100 Subject: [PATCH 26/69] Fixed typos and wrong reponse type in HDEL --- src/Arancino.cpp | 14 ++++---------- src/ArancinoDefinitions.h | 7 +++---- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index e214541..d9ae85a 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -380,7 +380,7 @@ ArancinoPacket ArancinoClass::del(char* key, bool isAck, bool is cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; cfg.type = type; - return executeCommand(DEL_COMMAND, key, NULL, NULL, isAck, true, false, cfg, KEY_RESPONSE); + return executeCommand(DEL_COMMAND, key, NULL, NULL, isAck, true, false, cfg, KEYS_RESPONSE); } template <> @@ -477,7 +477,7 @@ ArancinoPacket ArancinoClass::hdel(char *key, char *field, bool ArancinoCFG cfg; cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; - return executeCommand(HDEL_COMMAND, key, field, NULL, isAck, true, true, cfg, FIELDS_RESPONSE); + return executeCommand(HDEL_COMMAND, key, field, NULL, isAck, true, true, cfg, KEYS_RESPONSE); } template <> @@ -1283,18 +1283,12 @@ ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, } break; } - case KEY_RESPONSE: { - // DEL + case KEYS_RESPONSE: { + // DEL - HDEL ArancinoPacket temp = {false, response_dict["rsp_code"], INT, {.integer = response_dict["args"]["keys"]}}; packet = temp; break; } - case FIELDS_RESPONSE: { - // HDEL - ArancinoPacket temp = {false, response_dict["rsp_code"], INT, {.integer = response_dict["args"]["fields"]}}; - packet = temp; - break; - } case ITEMS_RESPONSE: { // STORE - MSTORE JsonArray resp_items = response_dict["args"]["items"]; diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index 2dadd9d..077c581 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -178,8 +178,7 @@ under the License #define VOID_RESPONSE 0 #define KEY_VALUE_RESPONSE 1 -#define KEY_RESPONSE 2 +#define KEYS_RESPONSE 2 #define FIELDS_ITEMS_RESPONSE 3 -#define FIELDS_RESPONSE 4 -#define ITEMS_RESPONSE 5 -#define CLIENTS_RESPONSE 6 \ No newline at end of file +#define ITEMS_RESPONSE 4 +#define CLIENTS_RESPONSE 5 \ No newline at end of file From 7b211afb8b4c69068be48b9309129ffb7e8fe707 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Fri, 3 Feb 2023 12:56:43 +0100 Subject: [PATCH 27/69] Improved error handling in createArancinoPacket --- src/Arancino.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index d9ae85a..3345cce 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -1262,13 +1262,20 @@ ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, // GET - MGET - HGET JsonArray resp_items = response_dict["args"]["items"]; int resp_size = resp_items.size(); - if (resp_size > 0 && resp_size < 2) { + if (resp_size == 0) + { + packet = communicationErrorPacket; + } + else if (resp_size == 1) + { const char* value = resp_items[0]["value"]; char* ret_value = (char*) calloc(strlen(value), sizeof(char)); strcpy(ret_value, value); ArancinoPacket temp = {false, response_dict["rsp_code"], STRING, {.string = ret_value}}; packet = temp; - } else if (resp_size > 1) { + } + else if (resp_size > 1) + { char* resp_values[resp_size]; for (int i=0; i 0 && resp_size < 2) { + if (resp_size == 0) + { + packet = communicationErrorPacket; + } + else if (resp_size == 1) + { const char* value = resp_items[0]; char* ret_value = (char*) calloc(strlen(value), sizeof(char)); strcpy(ret_value, value); ArancinoPacket temp = {false, response_dict["rsp_code"], STRING, {.string = ret_value}}; packet = temp; - } else if (resp_size > 1) { + } + else if (resp_size > 1) + { char* resp_values[resp_size]; for (int i=0; i Date: Tue, 7 Feb 2023 13:08:18 +0100 Subject: [PATCH 28/69] Fixed wrong allocation on STRING_ARRAY responses --- src/Arancino.cpp | 83 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 67 insertions(+), 16 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index 3345cce..406b3b6 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -895,9 +895,9 @@ void ArancinoClass::free(char *str) void ArancinoClass::free(char **_array) { - char **dummy = (_array != NULL) ? _array - sizeof(char) : NULL; + char **dummy = (_array != NULL) ? _array - 1 : NULL; - if (_array != NULL) + if (*_array != NULL) { #if defined(USEFREERTOS) vPortFree(*_array); @@ -1079,7 +1079,7 @@ void ArancinoClass::println(double value) int ArancinoClass::getArraySize(char **_array) { - char **dummy = (_array != NULL) ? _array - sizeof(char) : NULL; + char **dummy = (_array != NULL) ? _array - 1 : NULL; return dummy != NULL ? (int)(*dummy) : 0; } @@ -1276,16 +1276,40 @@ ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, } else if (resp_size > 1) { - char* resp_values[resp_size]; - for (int i=0; i 1) { - char* resp_values[resp_size]; - for (int i=0; i Date: Tue, 14 Feb 2023 13:36:40 +0100 Subject: [PATCH 29/69] Added checks on null strings and fixed calloc size --- src/Arancino.cpp | 82 ++++++++++++++++++++++++++++++++----------- src/ArancinoTasks.cpp | 2 +- 2 files changed, 63 insertions(+), 21 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index 406b3b6..b348838 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -1269,10 +1269,17 @@ ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, else if (resp_size == 1) { const char* value = resp_items[0]["value"]; - char* ret_value = (char*) calloc(strlen(value), sizeof(char)); - strcpy(ret_value, value); - ArancinoPacket temp = {false, response_dict["rsp_code"], STRING, {.string = ret_value}}; - packet = temp; + if (value != NULL) + { + char* ret_value = (char*) calloc(strlen(value) + 1, sizeof(char)); + strcpy(ret_value, value); + ArancinoPacket temp = {false, response_dict["rsp_code"], STRING, {.string = ret_value}}; + packet = temp; + } + else + { + packet = voidCommunicationPacket; + } } else if (resp_size > 1) { @@ -1292,18 +1299,33 @@ ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, size_t stringsLen = 0; //sum of lengths of all the returned strings for (size_t i = 0; i < resp_size; i++) { - stringsLen += strlen(resp_items[i]["value"]) + 1; //adding an element for \0 + if (resp_items[i]["value"] != NULL) + { + stringsLen += strlen(resp_items[i]["value"]); + } + stringsLen += 1; //adding an element for \0 } response_strings = (char*)malloc(stringsLen * sizeof(char)); + uint32_t start_index = 0; //Index at which the next string must be written for (int i = 0; i < resp_size; i++){ - size_t current_str_len = strlen(resp_items[i]["value"]); - strncpy(&response_strings[start_index], resp_items[i]["value"], current_str_len); - response_strings[start_index + current_str_len] = '\0'; - strings_array[i] = &response_strings[start_index]; - start_index += (current_str_len + 1); + if (resp_items[i]["value"] != NULL) + { + size_t current_str_len = strlen(resp_items[i]["value"]); + strncpy(&response_strings[start_index], resp_items[i]["value"], current_str_len); + response_strings[start_index + current_str_len] = '\0'; + strings_array[i] = &response_strings[start_index]; + start_index += (current_str_len + 1); + } + else + { + //in case of missing value (value = None) + response_strings[start_index] = '\0'; + start_index += 1; + } + } ArancinoPacket temp = {false, response_dict["rsp_code"], STRING_ARRAY, {.stringArray = strings_array}}; packet = temp; @@ -1331,10 +1353,17 @@ ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, else if (resp_size == 1) { const char* value = resp_items[0]; - char* ret_value = (char*) calloc(strlen(value), sizeof(char)); - strcpy(ret_value, value); - ArancinoPacket temp = {false, response_dict["rsp_code"], STRING, {.string = ret_value}}; - packet = temp; + if (value != NULL) + { + char* ret_value = (char*) calloc(strlen(value) + 1, sizeof(char)); + strcpy(ret_value, value); + ArancinoPacket temp = {false, response_dict["rsp_code"], STRING, {.string = ret_value}}; + packet = temp; + } + else + { + packet = voidCommunicationPacket; + } } else if (resp_size > 1) { @@ -1354,18 +1383,31 @@ ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, size_t stringsLen = 0; //sum of lengths of all the returned strings for (size_t i = 0; i < resp_size; i++) { - stringsLen += strlen(resp_items[i]) + 1; //adding an element for \0 + if (resp_items[i] != NULL) + { + stringsLen += strlen(resp_items[i]); + } + stringsLen += 1; //adding an element for \0 } response_strings = (char*)malloc(stringsLen * sizeof(char)); uint32_t start_index = 0; //Index at which the next string must be written for (int i = 0; i < resp_size; i++){ - size_t current_str_len = strlen(resp_items[i]); - strncpy(&response_strings[start_index], resp_items[i], current_str_len); - response_strings[start_index + current_str_len] = '\0'; - strings_array[i] = &response_strings[start_index]; - start_index += (current_str_len + 1); + if (resp_items[i] != NULL) + { + size_t current_str_len = strlen(resp_items[i]); + strncpy(&response_strings[start_index], resp_items[i], current_str_len); + response_strings[start_index + current_str_len] = '\0'; + strings_array[i] = &response_strings[start_index]; + start_index += (current_str_len + 1); + } + else + { + //in case of missing value (value = None) + response_strings[start_index] = '\0'; + start_index += 1; + } } ArancinoPacket temp = {false, response_dict["rsp_code"], STRING_ARRAY, {.stringArray = strings_array}}; packet = temp; diff --git a/src/ArancinoTasks.cpp b/src/ArancinoTasks.cpp index 1e6ced7..3b7ddad 100644 --- a/src/ArancinoTasks.cpp +++ b/src/ArancinoTasks.cpp @@ -119,7 +119,7 @@ under the License ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), true, KEY_VALUE_RESPONSE); (*cmd_doc).clear(); - if(!strcmp(rsp.response.string, "1")){ + if(rsp.response.string != NULL && !strcmp(rsp.response.string, "1")){ for(int i=0;i < 20; i++){ #if defined (ARDUINO_ARANCINO_VOLANTE) digitalWrite(LED_BUILTIN,LOW); From a4c3c80f1bdfacdf7d520bcf3d3f18cb3c9c660f Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Tue, 14 Feb 2023 13:38:46 +0100 Subject: [PATCH 30/69] Improved ESP32 compatibility --- src/Arancino.cpp | 3 +++ src/Arancino.h | 7 +++++++ src/ArancinoInterface.cpp | 8 +++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index b348838..26307fe 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -75,6 +75,9 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, char* custom_v1, char* custo } void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, char* custom_v1, char* custom_v2) { +#if defined(ARDUINO_ARCH_ESP32) + esp_task_wdt_init(120, true); +#endif MicroID.getUniqueIDString(id, ID_SIZE/2); _iface->ifaceBegin(); diff --git a/src/Arancino.h b/src/Arancino.h index bacba2e..bc5b3ee 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -77,6 +77,13 @@ extern "C" { #include #endif +#if defined(ARDUINO_ARCH_ESP32) +#include +#include +#define pvPortMalloc std::malloc +#define vPortFree std::free +#endif + #include "ArancinoTasks.h" //Power Mode diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index 7a4c3fe..03f6045 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -108,7 +108,7 @@ void SerialIface::sendArancinoCommand(JsonDocument& command){ docStr = (char*)malloc(docSize * sizeof(char)); serializeMsgPack(command, docStr, docSize); - int sent = serialWrite(docStr, docSize, this->_serialPort->getTimeout()); + int sent = serialWrite(docStr, docSize, TIMEOUT); if (sent < docSize) { #if DEBUG @@ -146,7 +146,13 @@ void SerialIface::setSerialPort(Stream& serialPort){ void SerialIface::setSerialPort(){ //default implementation for Arancino boards #if defined (SERIAL_PORT) && defined(BAUDRATE) && defined (TIMEOUT) + + #if defined(ARDUINO_ARCH_ESP32) && defined(UART_RX) && defined(UART_TX) + SERIAL_PORT.begin(BAUDRATE, SERIAL_8N1, UART_RX, UART_TX); + #else SERIAL_PORT.begin(BAUDRATE); + #endif + SERIAL_PORT.setTimeout(TIMEOUT); this->_serialPort = &SERIAL_PORT; #endif From fab41b8ecc23634360b791c8cd0b4a4747904d2c Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Wed, 15 Feb 2023 13:08:33 +0100 Subject: [PATCH 31/69] Improved strings array alloc/dealloc technique --- src/Arancino.cpp | 72 +++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 47 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index 26307fe..272ad53 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -898,16 +898,25 @@ void ArancinoClass::free(char *str) void ArancinoClass::free(char **_array) { + if (_array == NULL) + return; + char **dummy = (_array != NULL) ? _array - 1 : NULL; - if (*_array != NULL) + size_t str_count = (int)dummy[0]; + for (size_t i = 0; i < str_count; i++) { + char* str = _array[i]; + if (str != NULL) + { #if defined(USEFREERTOS) - vPortFree(*_array); + vPortFree(str); #else - std::free(*_array); + std::free(str); #endif + } } + if (dummy != NULL) { #if defined(USEFREERTOS) @@ -1299,37 +1308,21 @@ ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, will contain the items count */ ++strings_array; - size_t stringsLen = 0; //sum of lengths of all the returned strings for (size_t i = 0; i < resp_size; i++) { - if (resp_items[i]["value"] != NULL) - { - stringsLen += strlen(resp_items[i]["value"]); - } - stringsLen += 1; //adding an element for \0 - } - - response_strings = (char*)malloc(stringsLen * sizeof(char)); - - uint32_t start_index = 0; //Index at which the next string must be written - - for (int i = 0; i < resp_size; i++){ - if (resp_items[i]["value"] != NULL) + const char* value = resp_items[i]["value"]; + if (value != NULL) { - size_t current_str_len = strlen(resp_items[i]["value"]); - strncpy(&response_strings[start_index], resp_items[i]["value"], current_str_len); - response_strings[start_index + current_str_len] = '\0'; - strings_array[i] = &response_strings[start_index]; - start_index += (current_str_len + 1); + size_t stringsLen = strlen(value) + 1; //adding an element for \0 + strings_array[i] = (char*)malloc(stringsLen * sizeof(char)); + strcpy(strings_array[i], value); } else { - //in case of missing value (value = None) - response_strings[start_index] = '\0'; - start_index += 1; + strings_array[i] = NULL; } - } + ArancinoPacket temp = {false, response_dict["rsp_code"], STRING_ARRAY, {.stringArray = strings_array}}; packet = temp; } @@ -1383,33 +1376,18 @@ ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, will contain the items count */ ++strings_array; - size_t stringsLen = 0; //sum of lengths of all the returned strings for (size_t i = 0; i < resp_size; i++) { - if (resp_items[i] != NULL) - { - stringsLen += strlen(resp_items[i]); - } - stringsLen += 1; //adding an element for \0 - } - - response_strings = (char*)malloc(stringsLen * sizeof(char)); - uint32_t start_index = 0; //Index at which the next string must be written - - for (int i = 0; i < resp_size; i++){ - if (resp_items[i] != NULL) + const char* value = resp_items[i]; + if (value != NULL) { - size_t current_str_len = strlen(resp_items[i]); - strncpy(&response_strings[start_index], resp_items[i], current_str_len); - response_strings[start_index + current_str_len] = '\0'; - strings_array[i] = &response_strings[start_index]; - start_index += (current_str_len + 1); + size_t stringsLen = strlen(value) + 1; //adding an element for \0 + strings_array[i] = (char*)malloc(stringsLen * sizeof(char)); + strcpy(strings_array[i], value); } else { - //in case of missing value (value = None) - response_strings[start_index] = '\0'; - start_index += 1; + strings_array[i] = NULL; } } ArancinoPacket temp = {false, response_dict["rsp_code"], STRING_ARRAY, {.stringArray = strings_array}}; From 1d336594e77d5b4901ba5d4bbbbbeefff8bcd504 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Thu, 16 Feb 2023 13:22:28 +0100 Subject: [PATCH 32/69] Added NRF52 support --- src/Arancino.cpp | 2 +- src/ArancinoDefinitions.h | 46 ++++++++++++++++++++++++++++++--------- src/ArancinoInterface.cpp | 2 +- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index 272ad53..e309bca 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -238,7 +238,7 @@ void ArancinoClass::enableDebugMessages(bool sendViaCommMode){ _commMode = true; } else { //Default config for Arancino Boards - #if defined(SERIAL_DEBUG) && defined(BAUDRATE_DEBUG) + #if defined(SERIAL_DEBUG) SERIAL_DEBUG.begin(BAUDRATE_DEBUG); _isDebug = true; _dbgSerial = &SERIAL_DEBUG; diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index 077c581..7a79c3c 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -18,18 +18,30 @@ License for the specific language governing permissions and limitations under the License */ +#ifndef __ARANCINODEFINITIONS_H__ +#define __ARANCINODEFINITIONS_H__ +#include + #ifndef MCU_FAMILY #define MCU_FAMILY (char*)"undefined" #endif +#ifdef BAUDRATE +#undef BAUDRATE +#endif + +#ifdef TIMEOUT +#undef TIMEOUT +#endif + #if defined(__SAMD21G18A__) -#define BAUDRATE 4000000 -#define TIMEOUT 1000 +const uint32_t BAUDRATE = 4000000; +const uint32_t TIMEOUT = 1000; #define SERIAL_PORT SerialUSB #define SERIAL_DEBUG Serial #elif defined(ARDUINO_ARCH_RP2040) && defined(USEFREERTOS) -#define BAUDRATE 256000 -#define TIMEOUT 10000 +const uint32_t BAUDRATE = 256000; +const uint32_t TIMEOUT = 10000; #if defined(USE_TINYUSB) #define SERIAL_PORT SerialTinyUSB #else @@ -43,8 +55,8 @@ under the License */ #define CUSTOM_SERIAL -#define BAUDRATE 115200 -#define TIMEOUT 10000 +const uint32_t BAUDRATE = 115200; +const uint32_t TIMEOUT = 10000; #if defined(CUSTOM_SERIAL) #define SERIAL_PORT SerialPort @@ -59,15 +71,20 @@ under the License #define SERIAL_PORT Serial1 #endif #define SERIAL_DEBUG Serial +#elif defined(ARDUINO_ARCH_NRF52) +const uint32_t BAUDRATE = 256000; +const uint32_t TIMEOUT = 10000; +#define SERIAL_PORT Serial +#define SERIAL_DEBUG Serial1 #else -//#define BAUDRATE 256000 -#define TIMEOUT 10000 +const uint32_t BAUDRATE = 256000; +const uint32_t TIMEOUT = 10000; #define SERIAL_PORT Serial #define SERIAL_DEBUG Serial1 #endif #define SERIAL_TRANSPORT typeof(SERIAL_PORT) -#define BAUDRATE_DEBUG 115200 +const uint32_t BAUDRATE_DEBUG = 115200; #define START_COMMAND (char*)"START" #define MSET_COMMAND (char*)"MSET" @@ -161,6 +178,13 @@ under the License #elif defined(ARDUINO_ARCH_RP2040) #define ARANCINO_TASK_PRIORITY configMAX_PRIORITIES - 1 #define SERVICETASK_STACK 1024 +#elif defined(ARDUINO_ARCH_NRF52) +#define ARANCINO_TASK_PRIORITY configMAX_PRIORITIES - 1 +#define SERVICETASK_STACK 2048 +#else +#warning "This platform has not been tested!" +#define ARANCINO_TASK_PRIORITY configMAX_PRIORITIES - 1 +#define SERVICETASK_STACK 1024 #endif #define SERIAL_MAX_RETRIES 10 @@ -181,4 +205,6 @@ under the License #define KEYS_RESPONSE 2 #define FIELDS_ITEMS_RESPONSE 3 #define ITEMS_RESPONSE 4 -#define CLIENTS_RESPONSE 5 \ No newline at end of file +#define CLIENTS_RESPONSE 5 + +#endif \ No newline at end of file diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index 03f6045..3e920a0 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -145,7 +145,7 @@ void SerialIface::setSerialPort(Stream& serialPort){ void SerialIface::setSerialPort(){ //default implementation for Arancino boards - #if defined (SERIAL_PORT) && defined(BAUDRATE) && defined (TIMEOUT) + #if defined(SERIAL_PORT) #if defined(ARDUINO_ARCH_ESP32) && defined(UART_RX) && defined(UART_TX) SERIAL_PORT.begin(BAUDRATE, SERIAL_8N1, UART_RX, UART_TX); From cbd485df3db7bf8f95e50f102b2d85e7b33b988c Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Fri, 17 Feb 2023 12:53:15 +0100 Subject: [PATCH 33/69] Decreased ARANCINO_TASK_PRIORITY priority for NRF --- src/ArancinoDefinitions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index 7a79c3c..ee988d2 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -179,7 +179,7 @@ const uint32_t BAUDRATE_DEBUG = 115200; #define ARANCINO_TASK_PRIORITY configMAX_PRIORITIES - 1 #define SERVICETASK_STACK 1024 #elif defined(ARDUINO_ARCH_NRF52) -#define ARANCINO_TASK_PRIORITY configMAX_PRIORITIES - 1 +#define ARANCINO_TASK_PRIORITY TASK_PRIO_HIGH #define SERVICETASK_STACK 2048 #else #warning "This platform has not been tested!" From 7b31f3b4cd20a88f7740c8e055bb076c6fe7f38c Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Mon, 20 Feb 2023 13:21:32 +0100 Subject: [PATCH 34/69] Fixed warning conversion const char* to char* --- src/Arancino.cpp | 128 ++++++++++++++++++-------------------- src/Arancino.h | 126 ++++++++++++++----------------------- src/ArancinoDefinitions.h | 72 ++++++++++----------- 3 files changed, 143 insertions(+), 183 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index e309bca..b356a2e 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -67,14 +67,14 @@ void ArancinoClass::delay(long milli){ /******** API BASIC :: BEGIN *********/ -void ArancinoClass::begin(ArancinoMetadata _amdata, char* custom_v1, char* custom_v2) +void ArancinoClass::begin(ArancinoMetadata _amdata, const char* custom_v1, const char* custom_v2) { ArancinoConfig _acfg; // setting default configuration value begin(_amdata, _acfg); } -void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, char* custom_v1, char* custom_v2) { +void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, const char* custom_v1, const char* custom_v2) { #if defined(ARDUINO_ARCH_ESP32) esp_task_wdt_init(120, true); #endif @@ -264,42 +264,42 @@ void ArancinoClass::disableDebugMessages(){ /******** API BASIC :: SET *********/ -ArancinoPacket ArancinoClass::set(char *key, int value, bool isAck, bool isPersistent, char* type) +ArancinoPacket ArancinoClass::set(const char* key, int value, bool isAck, bool isPersistent, const char* type) { char str[20] = ""; itoa(value, str, 10); return set(key, str, isAck, isPersistent); } -ArancinoPacket ArancinoClass::set(char *key, uint32_t value, bool isAck, bool isPersistent, char* type) +ArancinoPacket ArancinoClass::set(const char* key, uint32_t value, bool isAck, bool isPersistent, const char* type) { char str[20] = ""; itoa(value, str, 10); return set(key, str, isAck, isPersistent); } -ArancinoPacket ArancinoClass::set(char *key, long value, bool isAck, bool isPersistent, char* type) +ArancinoPacket ArancinoClass::set(const char* key, long value, bool isAck, bool isPersistent, const char* type) { char str[20] = ""; itoa(value, str, 10); return set(key, str, isAck, isPersistent); } -ArancinoPacket ArancinoClass::set(char *key, float value, bool isAck, bool isPersistent, char* type) +ArancinoPacket ArancinoClass::set(const char* key, float value, bool isAck, bool isPersistent, const char* type) { char str[20] = ""; _floatToString(value, decimal_digits, str); return set(key, str, isAck, isPersistent); } -ArancinoPacket ArancinoClass::set(char *key, double value, bool isAck, bool isPersistent, char* type) +ArancinoPacket ArancinoClass::set(const char* key, double value, bool isAck, bool isPersistent, const char* type) { char str[20] = ""; _doubleToString(value, decimal_digits, str); return set(key, str, isAck, isPersistent); } -ArancinoPacket ArancinoClass::set(char *key, char *value, bool isAck, bool isPersistent, char* type) +ArancinoPacket ArancinoClass::set(const char* key, const char* value, bool isAck, bool isPersistent, const char* type) { if (key == NULL || value == NULL || strcmp(key, "") == 0) return invalidCommandErrorPacket; @@ -314,7 +314,7 @@ ArancinoPacket ArancinoClass::set(char *key, char *value, bool isAck, bool isPer /******** API BASIC :: MSET *********/ -ArancinoPacket ArancinoClass::mset(char **keys, char **values, int len, bool isAck, bool isPersistent, char* type ) +ArancinoPacket ArancinoClass::mset(char **keys, char **values, int len, bool isAck, bool isPersistent, const char* type ) { if ((keys == NULL) || (values == NULL) || (len <= 0)) return invalidCommandErrorPacket; @@ -329,7 +329,7 @@ ArancinoPacket ArancinoClass::mset(char **keys, char **values, int len, bool isA /******** API BASIC :: GET *********/ template <> -ArancinoPacket ArancinoClass::get(char* key, bool isPersistent, char* type) +ArancinoPacket ArancinoClass::get(const char* key, bool isPersistent, const char* type) { if (key == NULL && strcmp(key, "") == 0) return invalidCommandErrorPacket; @@ -340,7 +340,7 @@ ArancinoPacket ArancinoClass::get(char* key, bool isPersistent, return executeCommand(GET_COMMAND, key, NULL, NULL, true, true, false, cfg, KEY_VALUE_RESPONSE); } -template <> char *ArancinoClass::get(char* key, bool isPersistent, char* type) +template <> char *ArancinoClass::get(const char* key, bool isPersistent, const char* type) { ArancinoPacket packet = get(key, isPersistent, type); if (!packet.isError){ @@ -352,7 +352,7 @@ template <> char *ArancinoClass::get(char* key, bool isPersistent, char* type) /******** API BASIC :: MGET *********/ -template <> ArancinoPacket ArancinoClass::mget(char **keys, int len, bool isPersistent, char* type) +template <> ArancinoPacket ArancinoClass::mget(char **keys, int len, bool isPersistent, const char* type) { if ((keys == NULL) || (len <= 0)) return invalidCommandErrorPacket; @@ -363,7 +363,7 @@ template <> ArancinoPacket ArancinoClass::mget(char **keys, int return executeCommand(GET_COMMAND, keys, NULL, NULL, len, true, true, false, cfg, KEY_VALUE_RESPONSE); } -template <> char **ArancinoClass::mget(char** keys, int len, bool isPersistent, char* type) +template <> char **ArancinoClass::mget(char** keys, int len, bool isPersistent, const char* type) { ArancinoPacket packet = mget(keys, len, isPersistent, type); if (packet.isError) @@ -374,7 +374,7 @@ template <> char **ArancinoClass::mget(char** keys, int len, bool isPersistent, /******** API BASIC :: DEL *********/ template <> -ArancinoPacket ArancinoClass::del(char* key, bool isAck, bool isPersistent, char* type) +ArancinoPacket ArancinoClass::del(const char* key, bool isAck, bool isPersistent, const char* type) { if (key == NULL && strcmp(key, "") == 0) return invalidCommandErrorPacket; @@ -387,7 +387,7 @@ ArancinoPacket ArancinoClass::del(char* key, bool isAck, bool is } template <> -int ArancinoClass::del(char* key, bool isAck, bool isPersistent, char* type) +int ArancinoClass::del(const char* key, bool isAck, bool isPersistent, const char* type) { ArancinoPacket packet = del(key, isAck, isPersistent, type); if (!packet.isError) @@ -398,44 +398,44 @@ int ArancinoClass::del(char* key, bool isAck, bool isPersistent, char* type) /******** API BASIC :: HSET *********/ -ArancinoPacket ArancinoClass::hset(char *key, char *field, int value, bool isAck, bool isPersistent, char* type) +ArancinoPacket ArancinoClass::hset(const char* key, const char* field, int value, bool isAck, bool isPersistent, const char* type) { char str[20]; itoa(value, str, 10); return hset(key, field, str, isAck, isPersistent, type); } -ArancinoPacket ArancinoClass::hset(char *key, char *field, float value, bool isAck, bool isPersistent, char* type) +ArancinoPacket ArancinoClass::hset(const char* key, const char* field, float value, bool isAck, bool isPersistent, const char* type) { char str[20] = ""; _floatToString(value, decimal_digits, str); return hset(key, field, str); } -ArancinoPacket ArancinoClass::hset(char *key, char *field, double value, bool isAck, bool isPersistent, char* type) +ArancinoPacket ArancinoClass::hset(const char* key, const char* field, double value, bool isAck, bool isPersistent, const char* type) { char str[20] = ""; _doubleToString(value, decimal_digits, str); return hset(key, field, str, isAck, isPersistent, type); } -ArancinoPacket ArancinoClass::hset(char *key, char *field, uint32_t value, bool isAck, bool isPersistent, char* type) +ArancinoPacket ArancinoClass::hset(const char* key, const char* field, uint32_t value, bool isAck, bool isPersistent, const char* type) { char str[20]; itoa(value, str, 10); return hset(key, field, str, isAck, isPersistent, type); } -ArancinoPacket ArancinoClass::hset(char *key, char *field, long value, bool isAck, bool isPersistent, char* type) +ArancinoPacket ArancinoClass::hset(const char* key, const char* field, long value, bool isAck, bool isPersistent, const char* type) { char str[20]; itoa(value, str, 10); return hset(key, field, str, isAck, isPersistent, type); } -ArancinoPacket ArancinoClass::hset(char *key, char *field, char *value, bool isAck, bool isPersistent, char* type) +ArancinoPacket ArancinoClass::hset(const char* key, const char* field, const char* value, bool isAck, bool isPersistent, const char* type) { - if (key == NULL && field == NULL || value == NULL || strcmp(key, "") == 0 || strcmp(field, "") == 0) + if ((key == NULL && field == NULL) || (value == NULL || strcmp(key, "") == 0) || (strcmp(field, "") == 0)) return invalidCommandErrorPacket; ArancinoCFG cfg; @@ -448,7 +448,7 @@ ArancinoPacket ArancinoClass::hset(char *key, char *field, char *value, bool isA /******** API BASIC :: HGET *********/ template <> -ArancinoPacket ArancinoClass::hget(char *key, char *field, bool isPersistent, char* type) +ArancinoPacket ArancinoClass::hget(const char* key, const char* field, bool isPersistent, const char* type) { if (key == NULL || field == NULL || strcmp(key, "") == 0 || strcmp(field, "") == 0) return invalidCommandErrorPacket; @@ -460,7 +460,7 @@ ArancinoPacket ArancinoClass::hget(char *key, char *field, bool } template <> -char *ArancinoClass::hget(char *key, char *field, bool isPersistent, char* type) +char *ArancinoClass::hget(const char* key, const char* field, bool isPersistent, const char* type) { ArancinoPacket packet = hget(key, field, isPersistent, type); if (!packet.isError) @@ -472,7 +472,7 @@ char *ArancinoClass::hget(char *key, char *field, bool isPersistent, char* type) /******** API BASIC :: HDEL *********/ template <> -ArancinoPacket ArancinoClass::hdel(char *key, char *field, bool isAck, bool isPersistent) +ArancinoPacket ArancinoClass::hdel(const char* key, const char* field, bool isAck, bool isPersistent) { if (key == NULL && field == NULL && strcmp(key, "") == 0 && strcmp(field, "") == 0) return invalidCommandErrorPacket; @@ -484,7 +484,7 @@ ArancinoPacket ArancinoClass::hdel(char *key, char *field, bool } template <> -int ArancinoClass::hdel(char *key, char *field, bool isAck, bool isPersistent) +int ArancinoClass::hdel(const char* key, const char* field, bool isAck, bool isPersistent) { ArancinoPacket packet = hdel(key, field, isAck, isPersistent); int retValue = 0; @@ -496,13 +496,13 @@ int ArancinoClass::hdel(char *key, char *field, bool isAck, bool isPersistent) /******** API BASIC :: PUBLISH *********/ template <> -ArancinoPacket ArancinoClass::publish(char *channel, char *msg, bool isAck) +ArancinoPacket ArancinoClass::publish(const char* channel, const char* msg, bool isAck) { return __publish(channel, msg, isAck); } template <> -int ArancinoClass::publish(char *channel, char *msg, bool isAck) +int ArancinoClass::publish(const char* channel, const char* msg, bool isAck) { ArancinoPacket packet = __publish(channel, msg, isAck); if (!packet.isError) @@ -512,7 +512,7 @@ int ArancinoClass::publish(char *channel, char *msg, bool isAck) } template <> -ArancinoPacket ArancinoClass::publish(char *channel, double msg, bool isAck) +ArancinoPacket ArancinoClass::publish(const char* channel, double msg, bool isAck) { char str[20] = ""; _doubleToString(msg, decimal_digits, str); @@ -520,7 +520,7 @@ ArancinoPacket ArancinoClass::publish(char *channel, double msg, } template <> -int ArancinoClass::publish(char *channel, double msg, bool isAck) +int ArancinoClass::publish(const char* channel, double msg, bool isAck) { char str[20] = ""; _doubleToString(msg, decimal_digits, str); @@ -532,7 +532,7 @@ int ArancinoClass::publish(char *channel, double msg, bool isAck) } template <> -ArancinoPacket ArancinoClass::publish(char *channel, int msg, bool isAck) +ArancinoPacket ArancinoClass::publish(const char* channel, int msg, bool isAck) { char str[20] = ""; itoa(msg, str, 10); @@ -540,7 +540,7 @@ ArancinoPacket ArancinoClass::publish(char *channel, int msg, bo } template <> -int ArancinoClass::publish(char *channel, int msg, bool isAck) +int ArancinoClass::publish(const char* channel, int msg, bool isAck) { char str[20] = ""; itoa(msg, str, 10); @@ -552,7 +552,7 @@ int ArancinoClass::publish(char *channel, int msg, bool isAck) } template <> -ArancinoPacket ArancinoClass::publish(char *channel, uint32_t msg, bool isAck) +ArancinoPacket ArancinoClass::publish(const char* channel, uint32_t msg, bool isAck) { char str[20] = ""; itoa(msg, str, 10); @@ -560,7 +560,7 @@ ArancinoPacket ArancinoClass::publish(char *channel, uint32_t ms } template <> -int ArancinoClass::publish(char *channel, uint32_t msg, bool isAck) +int ArancinoClass::publish(const char* channel, uint32_t msg, bool isAck) { char str[20] = ""; itoa(msg, str, 10); @@ -572,7 +572,7 @@ int ArancinoClass::publish(char *channel, uint32_t msg, bool isAck) } template <> -ArancinoPacket ArancinoClass::publish(char *channel, long msg, bool isAck) +ArancinoPacket ArancinoClass::publish(const char* channel, long msg, bool isAck) { char str[20] = ""; itoa(msg, str, 10); @@ -580,7 +580,7 @@ ArancinoPacket ArancinoClass::publish(char *channel, long msg, b } template <> -int ArancinoClass::publish(char *channel, long msg, bool isAck) +int ArancinoClass::publish(const char* channel, long msg, bool isAck) { char str[20] = ""; itoa(msg, str, 10); @@ -591,7 +591,7 @@ int ArancinoClass::publish(char *channel, long msg, bool isAck) return 0; } -ArancinoPacket ArancinoClass::__publish(char *channel, char *msg, bool isAck) +ArancinoPacket ArancinoClass::__publish(const char* channel, const char* msg, bool isAck) { if (channel == NULL || msg == NULL || strcmp(channel, "") == 0) return invalidCommandErrorPacket; @@ -622,7 +622,7 @@ ArancinoPacket ArancinoClass::flush(bool isAck, bool isPersistent) /******** API BASIC :: STORE *********/ template <> -ArancinoPacket ArancinoClass::store(char *key, int value, char* timestamp, bool isAck) +ArancinoPacket ArancinoClass::store(const char* key, int value, const char* timestamp, bool isAck) { char str[20] = ""; itoa(value, str, 10); @@ -630,7 +630,7 @@ ArancinoPacket ArancinoClass::store(char *key, int value, char* } template <> -char *ArancinoClass::store(char *key, int value, char* timestamp, bool isAck) +char *ArancinoClass::store(const char* key, int value, const char* timestamp, bool isAck) { char str[20] = ""; itoa(value, str, 10); @@ -642,7 +642,7 @@ char *ArancinoClass::store(char *key, int value, char* timestamp, bool isAck) } template <> -ArancinoPacket ArancinoClass::store(char *key, uint32_t value, char* timestamp, bool isAck) +ArancinoPacket ArancinoClass::store(const char* key, uint32_t value, const char* timestamp, bool isAck) { char str[20] = ""; itoa(value, str, 10); @@ -650,7 +650,7 @@ ArancinoPacket ArancinoClass::store(char *key, uint32_t value, c } template <> -char *ArancinoClass::store(char *key, uint32_t value, char* timestamp, bool isAck) +char *ArancinoClass::store(const char* key, uint32_t value, const char* timestamp, bool isAck) { char str[20] = ""; itoa(value, str, 10); @@ -662,7 +662,7 @@ char *ArancinoClass::store(char *key, uint32_t value, char* timestamp, bool isAc } template <> -ArancinoPacket ArancinoClass::store(char *key, long value, char* timestamp, bool isAck) +ArancinoPacket ArancinoClass::store(const char* key, long value, const char* timestamp, bool isAck) { char str[20] = ""; itoa(value, str, 10); @@ -670,7 +670,7 @@ ArancinoPacket ArancinoClass::store(char *key, long value, char* } template <> -char *ArancinoClass::store(char *key, long value, char* timestamp, bool isAck) +char *ArancinoClass::store(const char* key, long value, const char* timestamp, bool isAck) { char str[20] = ""; itoa(value, str, 10); @@ -682,7 +682,7 @@ char *ArancinoClass::store(char *key, long value, char* timestamp, bool isAck) } template <> -ArancinoPacket ArancinoClass::store(char *key, float value, char* timestamp, bool isAck) +ArancinoPacket ArancinoClass::store(const char* key, float value, const char* timestamp, bool isAck) { char str[20] = ""; _floatToString(value, decimal_digits, str); @@ -690,7 +690,7 @@ ArancinoPacket ArancinoClass::store(char *key, float value, char } template <> -char *ArancinoClass::store(char *key, float value, char* timestamp, bool isAck) +char *ArancinoClass::store(const char* key, float value, const char* timestamp, bool isAck) { char str[20] = ""; _floatToString(value, decimal_digits, str); @@ -702,7 +702,7 @@ char *ArancinoClass::store(char *key, float value, char* timestamp, bool isAck) return NULL; } -ArancinoPacket ArancinoClass::__store( char* key, char* value, char* timestamp, bool isAck) { +ArancinoPacket ArancinoClass::__store(const char* key, const char* value, const char* timestamp, bool isAck) { if(timestamp==NULL){ timestamp = getTimestamp(); @@ -730,7 +730,7 @@ ArancinoPacket ArancinoClass::__store( char* key, char* value, char* timestamp, /******** API BASIC :: MSTORE *********/ template <> -ArancinoPacket ArancinoClass::mstore(char** keys, char** values, int len, char* timestamp, bool isAck) +ArancinoPacket ArancinoClass::mstore(char** keys, char** values, int len, const char* timestamp, bool isAck) { if(timestamp==NULL){ timestamp = getTimestamp(); @@ -759,7 +759,7 @@ ArancinoPacket ArancinoClass::mstore(char** keys, char** values, } template<> -void ArancinoClass::mstore(char** keys, char** values, int len, char* timestamp, bool isAck) { +void ArancinoClass::mstore(char** keys, char** values, int len, const char* timestamp, bool isAck) { if(timestamp==NULL){ timestamp = getTimestamp(); } @@ -771,7 +771,7 @@ void ArancinoClass::mstore(char** keys, char** values, int len, char* timestamp, } template <> -char **ArancinoClass::mstore(char** keys, char** values, int len, char* timestamp, bool isAck) +char **ArancinoClass::mstore(char** keys, char** values, int len, const char* timestamp, bool isAck) { if(timestamp==NULL){ timestamp = getTimestamp(); @@ -788,7 +788,7 @@ char **ArancinoClass::mstore(char** keys, char** values, int len, char* timestam /******** API BASIC :: STORETAGS *********/ -ArancinoPacket ArancinoClass::storetags(char *key, char **tags, char **values, int len, char* timestamp, bool isAck) +ArancinoPacket ArancinoClass::storetags(const char* key, char **tags, char **values, int len, const char* timestamp, bool isAck) { if(timestamp==NULL){ timestamp = getTimestamp(); @@ -816,7 +816,7 @@ ArancinoPacket ArancinoClass::storetags(char *key, char **tags, char **values, i /******** API BASIC :: SETRESERVED *********/ -ArancinoPacket ArancinoClass::setReserved(char *key, char *value) +ArancinoPacket ArancinoClass::setReserved(const char* key, const char* value) { if (key == NULL && value == NULL && strcmp(key, "") == 0) return invalidCommandErrorPacket; @@ -826,7 +826,7 @@ ArancinoPacket ArancinoClass::setReserved(char *key, char *value) /******** API BASIC :: GETRESERVED *********/ template <> -ArancinoPacket ArancinoClass::getReserved(char *key) +ArancinoPacket ArancinoClass::getReserved(const char* key) { if (key == NULL && strcmp(key, "") == 0) return invalidCommandErrorPacket; @@ -835,7 +835,7 @@ ArancinoPacket ArancinoClass::getReserved(char *key) } template <> -char *ArancinoClass::getReserved(char *key) +char *ArancinoClass::getReserved(const char* key) { ArancinoPacket packet = getReserved(key); if (!packet.isError) @@ -1034,7 +1034,7 @@ bool ArancinoClass::isValidUTF8(const char *string) // From: https://stackoverfl /******** API ADVANCED :: PRINT *********/ -void ArancinoClass::print(char* value){ +void ArancinoClass::print(const char* value){ _printDebugMessage(value); } @@ -1129,7 +1129,7 @@ char *ArancinoClass::getTimestamp() /******** INTERNAL UTILS :: FREE *********/ -ArancinoPacket ArancinoClass::executeCommand(char* cmd, char* key, char* field, char* value, bool isAck, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type){ +ArancinoPacket ArancinoClass::executeCommand(const char* cmd, const char* key, const char* field, const char* value, bool isAck, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type){ StaticJsonDocument cmd_doc; bool error = true; @@ -1162,7 +1162,7 @@ ArancinoPacket ArancinoClass::executeCommand(char* cmd, char* key, char* field, } } -ArancinoPacket ArancinoClass::executeCommand(char* cmd, char** keys, char** fields, char** values, int len, bool isAck, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type){ +ArancinoPacket ArancinoClass::executeCommand(const char* cmd, char** keys, char** fields, char** values, int len, bool isAck, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type){ StaticJsonDocument cmd_doc; bool error = true; @@ -1297,11 +1297,6 @@ ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, { char** strings_array = (char**)malloc((resp_size + 1) * sizeof(char*)); - /* will contain the union of the response strings terminated with \0 - E.G.: "rsp1\0rsp2\0rsp3\0 - */ - char* response_strings = NULL; - strings_array[0] = (char*)resp_size; //save the items count into the first element of the array /* Move pointer to next position, since the first one @@ -1364,11 +1359,6 @@ ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, else if (resp_size > 1) { char** strings_array = (char**)malloc((resp_size + 1) * sizeof(char*)); - - /* will contain the union of the response strings terminated with \0 - E.G.: "rsp1\0rsp2\0rsp3\0 - */ - char* response_strings = NULL; strings_array[0] = (char*)resp_size; //save the items count into the first element of the array @@ -1411,7 +1401,7 @@ ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, return packet; } -void ArancinoClass::_buildArancinoJson(JsonDocument& cmd_doc, char* cmd, char* key, char* field, char* value, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg){ +void ArancinoClass::_buildArancinoJson(JsonDocument& cmd_doc, const char* cmd, const char* key, const char* field, const char* value, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg){ JsonObject cmd_args = cmd_doc.createNestedObject("args"); cmd_doc["cmd"] = cmd; @@ -1449,7 +1439,7 @@ void ArancinoClass::_buildArancinoJson(JsonDocument& cmd_doc, char* cmd, char* k } } -void ArancinoClass::_buildArancinoJson(JsonDocument& cmd_doc, char* cmd, char** keys, char** fields, char** values, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg){ +void ArancinoClass::_buildArancinoJson(JsonDocument& cmd_doc, const char* cmd, char** keys, char** fields, char** values, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg){ JsonObject cmd_args = cmd_doc.createNestedObject("args"); cmd_doc["cmd"] = cmd; @@ -1535,7 +1525,7 @@ void ArancinoClass::_floatToString(float value, unsigned int _nDecimal, char *st interrupts(); } -void ArancinoClass::_printDebugMessage(char* value) { +void ArancinoClass::_printDebugMessage(const char* value) { if (_isDebug && _commMode){ __publish(MONITOR_KEY, value); set(MONITOR_KEY, value, false); diff --git a/src/Arancino.h b/src/Arancino.h index bc5b3ee..c0fa7ed 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -106,15 +106,15 @@ typedef struct { } ArancinoPacket; typedef struct { - char* fwname; - char* fwversion; - char* tzoffset; + const char* fwname; + const char* fwversion; + const char* tzoffset; } ArancinoMetadata; typedef struct { uint8_t pers = CFG_UNSET; uint8_t ack = CFG_UNSET; - char* type = CFG_UNSET; + const char* type = CFG_UNSET; //const char* signature } ArancinoCFG; @@ -141,64 +141,64 @@ class ArancinoClass { void attachInterface(ArancinoIface& iface); //BEGIN - void begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, char* custom_v1 = NULL, char* custom_v2 = NULL); - void begin(ArancinoMetadata _amdata, char* custom_v1 = NULL, char* custom_v2 = NULL); + void begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, const char* custom_v1 = NULL, const char* custom_v2 = NULL); + void begin(ArancinoMetadata _amdata, const char* custom_v1 = NULL, const char* custom_v2 = NULL); - ArancinoPacket set(char* key, int value, bool isAck = true, bool isPersistent = false, char* type = "appl"); - ArancinoPacket set(char* key, double value, bool isAck = true, bool isPersistent = false, char* type = "appl"); - ArancinoPacket set(char* key, float value, bool isAck = true, bool isPersistent = false, char* type = "appl"); - ArancinoPacket set(char* key, long value, bool isAck = true, bool isPersistent = false, char* type = "appl"); - ArancinoPacket set(char* key, uint32_t value, bool isAck = true, bool isPersistent = false, char* type = "appl"); - ArancinoPacket set(char* key, char* value, bool isAck = true, bool isPersistent = false, char* type = "appl"); + ArancinoPacket set(const char* key, int value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket set(const char* key, double value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket set(const char* key, float value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket set(const char* key, long value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket set(const char* key, uint32_t value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket set(const char* key, const char* value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); //MSET - ArancinoPacket mset(char** keys, char** values, int len, bool isAck=true, bool isPersistent = false, char* type = "appl"); + ArancinoPacket mset(char** keys, char** values, int len, bool isAck=true, bool isPersistent = false, const char* type = "appl"); //GET - template T get(char* key, bool isPersistent = false, char* type = "appl"); + template T get(const char* key, bool isPersistent = false, const char* type = "appl"); //MGET - template T mget(char** keys, int len, bool isPersistent = false, char* type = "appl"); + template T mget(char** keys, int len, bool isPersistent = false, const char* type = "appl"); //DEL - template T del(char* key, bool isAck = true, bool isPersistent = false, char* type = "appl"); + template T del(const char* key, bool isAck = true, bool isPersistent = false, const char* type = "appl"); //HSET - ArancinoPacket hset(char* key, char* field, char* value, bool isAck = true, bool isPersistent = false, char* type = "appl"); - ArancinoPacket hset(char* key, char* field, int value, bool isAck = true, bool isPersistent = false, char* type = "appl"); - ArancinoPacket hset(char* key, char* field, float value, bool isAck = true, bool isPersistent = false, char* type = "appl"); - ArancinoPacket hset(char* key, char* field, double value, bool isAck = true, bool isPersistent = false, char* type = "appl"); - ArancinoPacket hset(char* key, char* field, uint32_t value, bool isAck = true, bool isPersistent = false, char* type = "appl"); - ArancinoPacket hset(char* key, char* field, long value, bool isAck = true, bool isPersistent = false, char* type = "appl"); + ArancinoPacket hset(const char* key, const char* field, const char* value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket hset(const char* key, const char* field, int value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket hset(const char* key, const char* field, float value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket hset(const char* key, const char* field, double value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket hset(const char* key, const char* field, uint32_t value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); + ArancinoPacket hset(const char* key, const char* field, long value, bool isAck = true, bool isPersistent = false, const char* type = "appl"); //HGET - template T hget(char* key, char* field, bool isPersistent = false, char* type = "appl"); + template T hget(const char* key, const char* field, bool isPersistent = false, const char* type = "appl"); //HDEL - template T hdel(char* key, char* field, bool isAck = true, bool isPersistent = false); + template T hdel(const char* key, const char* field, bool isAck = true, bool isPersistent = false); //PUBLISH - template T publish(char* channel, char* msg, bool isAck = true); - template T publish(char* channel, double msg, bool isAck = true); - template T publish(char* channel, int msg, bool isAck = true); - template T publish(char* channel, uint32_t msg, bool isAck = true); - template T publish(char* channel, long msg, bool isAck = true); + template T publish(const char* channel, const char* msg, bool isAck = true); + template T publish(const char* channel, double msg, bool isAck = true); + template T publish(const char* channel, int msg, bool isAck = true); + template T publish(const char* channel, uint32_t msg, bool isAck = true); + template T publish(const char* channel, long msg, bool isAck = true); //FLUSH ArancinoPacket flush(bool isAck = true, bool isPersistent = false); //STORE - template T store(char* key, int value, char* timestamp = NULL, bool isAck = true); - template T store(char* key, uint32_t value, char* timestamp = NULL, bool isAck = true); - template T store(char* key, double value, char* timestamp = NULL, bool isAck = true); - template T store(char* key, float value, char* timestamp = NULL, bool isAck = true); - template T store(char* key, long value, char* timestamp = NULL, bool isAck = true); + template T store(const char* key, int value, const char* timestamp = NULL, bool isAck = true); + template T store(const char* key, uint32_t value, const char* timestamp = NULL, bool isAck = true); + template T store(const char* key, double value, const char* timestamp = NULL, bool isAck = true); + template T store(const char* key, float value, const char* timestamp = NULL, bool isAck = true); + template T store(const char* key, long value, const char* timestamp = NULL, bool isAck = true); //MSTORE - template T mstore(char** keys, char** values, int len, char* timestamp = NULL, bool isAck = true); + template T mstore(char** keys, char** values, int len, const char* timestamp = NULL, bool isAck = true); //STORE TAGS - ArancinoPacket storetags(char* key, char** tags, char** values, int len, char* timestamp = NULL, bool isAck = true); + ArancinoPacket storetags(const char* key, char** tags, char** values, int len, const char* timestamp = NULL, bool isAck = true); //GETRESERVED char* getModuleVersion(); @@ -225,7 +225,7 @@ class ArancinoClass { //PRINT void print(String value); - void print(char* value); + void print(const char* value); void print(int value); void print(float value); void print(double value); @@ -241,7 +241,7 @@ class ArancinoClass { char* getTimestamp(); //CHECK UTF-8 - bool isValidUTF8(const char * string); + bool isValidUTF8(const char* string); //HW CONTROL void systemReset(); @@ -268,18 +268,18 @@ class ArancinoClass { void _freeArray(char** _array); void _freePacket(ArancinoPacket packet); - ArancinoPacket __publish(char* channel, char* msg, bool isAck = true); - ArancinoPacket __store(char* key, char* value, char* timestamp=NULL, bool isAck = true); + ArancinoPacket __publish(const char* channel, const char* msg, bool isAck = true); + ArancinoPacket __store(const char* key, const char* value, const char* timestamp=NULL, bool isAck = true); - template T getReserved(char* key); - ArancinoPacket setReserved( char* key, char* value); + template T getReserved(const char* key); + ArancinoPacket setReserved( const char* key, const char* value); //INTERNAL UTILS void _doubleToString(double value, unsigned int _nDecimal, char* str); //truncation! void _floatToString(float value, unsigned int _nDecimal, char* str); - void _printDebugMessage(char* value); + void _printDebugMessage(const char* value); #if defined(USEFREERTOS) //The entire prototype would be ill-formed if freertos is not defined BaseType_t takeCommMutex(TickType_t timeout); @@ -290,16 +290,16 @@ class ArancinoClass { //execute command - ArancinoPacket createArancinoPacket(char* response_raw, int response_type); + ArancinoPacket createArancinoPacket(const char* response_raw, int response_type); - ArancinoPacket executeCommand(char* cmd, char* key, char* field, char* value, bool isAck, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type); - ArancinoPacket executeCommand(char* cmd, char** keys, char** fields, char** values, int len, bool isAck, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type); + ArancinoPacket executeCommand(const char* cmd, const char* key, const char* field, const char* value, bool isAck, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type); + ArancinoPacket executeCommand(const char* cmd, char** keys, char** fields, char** values, int len, bool isAck, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg, int response_type); ArancinoPacket executeCommand(JsonDocument& cmd_doc, bool isAck, int response_type); ArancinoPacket executeCommand(JsonDocument& cmd_doc, JsonDocument& rsp_doc, bool isAck, int response_type); ArancinoPacket createArancinoPacket(JsonDocument& response_dict, int response_type); - void _buildArancinoJson(JsonDocument& doc, char* cmd, char* key, char* field, char* value, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg); - void _buildArancinoJson(JsonDocument& doc, char* cmd, char** keys, char** fields, char** values, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg); + void _buildArancinoJson(JsonDocument& doc, const char* cmd, const char* key, const char* field, const char* value, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg); + void _buildArancinoJson(JsonDocument& doc, const char* cmd, char** keys, char** fields, char** values, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg); //Protocol interface ArancinoIface* _iface; @@ -309,36 +309,6 @@ class ArancinoClass { bool _isDebug = false; bool _commMode = false; - //TEMPLATE WRAPPED - // ArancinoPacket _getPacket(char* key); - // char* _get(char* key); - - // ArancinoPacket _delPacket(char* key); - // int _del(char* key); - - // ArancinoPacket _hgetPacket(char* key, char* field); - // char* _hget(char* key, char* field); - - // ArancinoPacket _hgetallPacket(char* key); - // char** _hgetall(char* key); - - // ArancinoPacket _hkeysPacket(char* key); - // char** _hkeys(char* key); - - // ArancinoPacket _hvalsPacket(char* key); - // char** _hvals(char* key); - - // ArancinoPacket _hdelPacket(char* key, char* field); - // int _hdel(char* key, char* field); - - // ArancinoPacket _keysPacket(char* pattern=""); - // char** _keys(char* pattern=""); - - // ArancinoPacket _publishPacket(int channel, char* msg); - // ArancinoPacket _publishPacket(char* channel, char* msg); - // int _publish(int channel, char* msg); - // int _publish(char* channel, char* msg); - friend class ArancinoTasks; }; diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index ee988d2..06d61fc 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -23,7 +23,7 @@ under the License #include #ifndef MCU_FAMILY -#define MCU_FAMILY (char*)"undefined" +#define MCU_FAMILY (const char*)"undefined" #endif #ifdef BAUDRATE @@ -86,37 +86,37 @@ const uint32_t TIMEOUT = 10000; #define SERIAL_TRANSPORT typeof(SERIAL_PORT) const uint32_t BAUDRATE_DEBUG = 115200; -#define START_COMMAND (char*)"START" -#define MSET_COMMAND (char*)"MSET" -#define MSET_PERS_COMMAND (char*)"MSETPERS" -#define SET_COMMAND (char*)"SET" -#define SET_PERS_COMMAND (char*)"SETPERS" -#define MGET_COMMAND (char*)"MGET" -#define GET_COMMAND (char*)"GET" -#define DEL_COMMAND (char*)"DEL" -#define KEYS_COMMAND (char*)"KEYS" -#define HGET_COMMAND (char*)"HGET" -#define HGETALL_COMMAND (char*)"HGETALL" -#define HKEYS_COMMAND (char*)"HKEYS" -#define HDEL_COMMAND (char*)"HDEL" -#define HSET_COMMAND (char*)"HSET" -#define HSET_PERS_COMMAND (char*)"HSETPERS" -#define HVALS_COMMAND (char*)"HVALS" -#define PUBLISH_COMMAND (char*)"PUB" -#define FLUSH_COMMAND (char*)"FLUSH" -#define STORE_COMMAND (char*)"STORE" -#define MSTORE_COMMAND (char*)"MSTORE" -#define STORETAGS_COMMAND (char*)"STORETAGS" -#define GETRESERVED_COMMAND (char*)"GETRSVD" -#define SETRESERVED_COMMAND (char*)"SETRSVD" +#define START_COMMAND (const char*)"START" +#define MSET_COMMAND (const char*)"MSET" +#define MSET_PERS_COMMAND (const char*)"MSETPERS" +#define SET_COMMAND (const char*)"SET" +#define SET_PERS_COMMAND (const char*)"SETPERS" +#define MGET_COMMAND (const char*)"MGET" +#define GET_COMMAND (const char*)"GET" +#define DEL_COMMAND (const char*)"DEL" +#define KEYS_COMMAND (const char*)"KEYS" +#define HGET_COMMAND (const char*)"HGET" +#define HGETALL_COMMAND (const char*)"HGETALL" +#define HKEYS_COMMAND (const char*)"HKEYS" +#define HDEL_COMMAND (const char*)"HDEL" +#define HSET_COMMAND (const char*)"HSET" +#define HSET_PERS_COMMAND (const char*)"HSETPERS" +#define HVALS_COMMAND (const char*)"HVALS" +#define PUBLISH_COMMAND (const char*)"PUB" +#define FLUSH_COMMAND (const char*)"FLUSH" +#define STORE_COMMAND (const char*)"STORE" +#define MSTORE_COMMAND (const char*)"MSTORE" +#define STORETAGS_COMMAND (const char*)"STORETAGS" +#define GETRESERVED_COMMAND (const char*)"GETRSVD" +#define SETRESERVED_COMMAND (const char*)"SETRSVD" #define SENT_STRING "Sent Command: " #define RCV_STRING "Received Response: " -#define END_TX_CHAR (char)4 //'@' // -#define DATA_SPLIT_CHAR (char)30 //'#' // -#define ARRAY_SPLIT_CHAR (char)16 //'%' // -#define NULL_CHAR (char)25 +#define END_TX_CHAR (const char)4 //'@' // +#define DATA_SPLIT_CHAR (const char)30 //'#' // +#define ARRAY_SPLIT_CHAR (const char)16 //'%' // +#define NULL_CHAR (const char)25 #define ID_SEPARATOR "_" #define RSP_OK 100 @@ -139,14 +139,14 @@ const uint32_t BAUDRATE_DEBUG = 115200; #define DBG_PIN 26 //pin used to Debug Message //#define PWR_PIN ?? //pin used for Power Management -#define MONITOR_KEY (char*)"___MONITOR___" -#define POWER_KEY (char*)"___POWER___" -#define MODVERS_KEY (char*)"___MODVERS___" -#define MODLOGLVL_KEY (char*)"___MODLOGLVL___" -#define MODENV_KEY (char*)"___MODENV___" -#define BLINK_ID_KEY (char*)"___BLINK_ID___" -#define LIB_VERSION (char*)"2.0.0" //library version -#define CRTX_VERSION (char*)"1.0.0" //cortex version +#define MONITOR_KEY (const char*)"___MONITOR___" +#define POWER_KEY (const char*)"___POWER___" +#define MODVERS_KEY (const char*)"___MODVERS___" +#define MODLOGLVL_KEY (const char*)"___MODLOGLVL___" +#define MODENV_KEY (const char*)"___MODENV___" +#define BLINK_ID_KEY (const char*)"___BLINK_ID___" +#define LIB_VERSION (const char*)"2.0.0" //library version +#define CRTX_VERSION (const char*)"1.0.0" //cortex version //RESPONSE CODE #define INVALID_VALUE_ERROR -4 From e7a988f51ee530267d3456ef32bfdf0c60a1260e Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Tue, 21 Feb 2023 10:59:58 +0100 Subject: [PATCH 35/69] Fixed several warnings --- src/Arancino.cpp | 8 ++++---- src/Arancino.h | 2 +- src/ArancinoInterface.cpp | 12 ++++++------ src/ArancinoInterface.h | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index b356a2e..5feb355 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -50,11 +50,11 @@ void ArancinoClass::attachInterface(ArancinoIface& iface){ } /******** API BASIC :: DELAY *********/ -void ArancinoClass::delay(long milli){ +void ArancinoClass::delay(unsigned long milli){ //Check if scheduler was started or not #if defined(USEFREERTOS) if(xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED){ - long startmillis = millis(); + unsigned long startmillis = millis(); while(millis() - startmillis < milli); } else { vTaskDelay(milli); @@ -1273,7 +1273,7 @@ ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, case KEY_VALUE_RESPONSE: { // GET - MGET - HGET JsonArray resp_items = response_dict["args"]["items"]; - int resp_size = resp_items.size(); + size_t resp_size = resp_items.size(); if (resp_size == 0) { packet = communicationErrorPacket; @@ -1336,7 +1336,7 @@ ArancinoPacket ArancinoClass::createArancinoPacket(JsonDocument& response_dict, case ITEMS_RESPONSE: { // STORE - MSTORE JsonArray resp_items = response_dict["args"]["items"]; - int resp_size = resp_items.size(); + size_t resp_size = resp_items.size(); if (resp_size == 0) { packet = communicationErrorPacket; diff --git a/src/Arancino.h b/src/Arancino.h index c0fa7ed..af7f0bd 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -133,7 +133,7 @@ class ArancinoClass { void startScheduler(); //SLEEP - void delay(long milli); + void delay(unsigned long milli); /***** API BASIC *****/ diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index 3e920a0..7a894a0 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -35,16 +35,16 @@ void SerialIface::ifaceBegin(){ //Nothing to initialize here. } -int SerialIface::serialWrite(const char* str, uint32_t len, long timeout){ +int SerialIface::serialWrite(const char* str, uint32_t len, unsigned long timeout){ if (!str || !len) return 0; int sent = 0; //successfully sent chars count int written = -1; - int i; //sending command index - long str_send_ts = millis(); //start timestamp of string sending - long char_send_ts; //start timestamp of single char sending - const long char_timeout = 100; + uint32_t i; //sending command index + unsigned long str_send_ts = millis(); //start timestamp of string sending + unsigned long char_send_ts; //start timestamp of single char sending + const unsigned long char_timeout = 100; for (i = 0; i < len; i++) { written = -1; @@ -108,7 +108,7 @@ void SerialIface::sendArancinoCommand(JsonDocument& command){ docStr = (char*)malloc(docSize * sizeof(char)); serializeMsgPack(command, docStr, docSize); - int sent = serialWrite(docStr, docSize, TIMEOUT); + uint32_t sent = serialWrite(docStr, docSize, TIMEOUT); if (sent < docSize) { #if DEBUG diff --git a/src/ArancinoInterface.h b/src/ArancinoInterface.h index 629a8a9..66b49cd 100644 --- a/src/ArancinoInterface.h +++ b/src/ArancinoInterface.h @@ -46,7 +46,7 @@ class SerialIface : public ArancinoIface { private: void ifaceBegin(); - int serialWrite(const char* str, uint32_t len, long timeout); + int serialWrite(const char* str, uint32_t len, unsigned long timeout); void sendArancinoCommand(JsonDocument& command); bool receiveArancinoResponse(JsonDocument& response); From db8227f6249a038428cebc2f96005b457a9f25c0 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Tue, 21 Feb 2023 13:27:38 +0100 Subject: [PATCH 36/69] Moved services flags control from timers to task --- src/Arancino.cpp | 11 ----------- src/ArancinoDefinitions.h | 5 +++++ src/ArancinoTasks.cpp | 39 ++++++++++++--------------------------- 3 files changed, 17 insertions(+), 38 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index 5feb355..da46cdc 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -32,10 +32,6 @@ TaskHandle_t arancinoHandle1; // TaskHandle_t arancinoHandle2; // TaskHandle_t arancinoHandle3; -TimerHandle_t timerHandle1; -TimerHandle_t timerHandle2; -TimerHandle_t timerHandle3; - SemaphoreHandle_t CommMutex; #endif @@ -141,13 +137,6 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, const //TASK ArancinoTasks _atask; - timerHandle1 = xTimerCreate("Heartbeat", pdMS_TO_TICKS(10000), pdTRUE, (void*)0, _atask.heartbeatCallback); - timerHandle2 = xTimerCreate("Interoception", pdMS_TO_TICKS(60000), pdTRUE, (void*)0, _atask.interoceptionCallback); - timerHandle3 = xTimerCreate("Identification", pdMS_TO_TICKS(10000), pdTRUE, (void*)0, _atask.identificationCallback); - - xTimerStart(timerHandle1, 0); - xTimerStart(timerHandle2, 0); - xTimerStart(timerHandle3, 0); xTaskCreate(_atask.serviceTask, "serviceTask", SERVICETASK_STACK, NULL, ARANCINO_TASK_PRIORITY, &arancinoHandle1); #endif } diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index 06d61fc..be22ab3 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -187,6 +187,11 @@ const uint32_t BAUDRATE_DEBUG = 115200; #define SERVICETASK_STACK 1024 #endif +#define HEARTBEAT_PERIOD (pdMS_TO_TICKS(10000)) +#define IDENTIFICATION_PERIOD (pdMS_TO_TICKS(60000)) +#define INTEROCEPTION_PERIOD (pdMS_TO_TICKS(10000)) +#define SERVICE_TASK_PERIOD (pdMS_TO_TICKS(5000)) + #define SERIAL_MAX_RETRIES 10 #define MQTT_MAX_RETRIES 100 #define BLUETOOTH_MAX_RETRIES 100 diff --git a/src/ArancinoTasks.cpp b/src/ArancinoTasks.cpp index 3b7ddad..6d19418 100644 --- a/src/ArancinoTasks.cpp +++ b/src/ArancinoTasks.cpp @@ -44,29 +44,9 @@ under the License DynamicJsonDocument* ArancinoTasks::cmd_doc; DynamicJsonDocument* ArancinoTasks::rsp_doc; - bool ArancinoTasks::_identificationFlag; - bool ArancinoTasks::_interoceptionFlag; - bool ArancinoTasks::_heartbeatFlag; - ArancinoTasks::ArancinoTasks(){ cmd_doc = new DynamicJsonDocument(CMD_DOC_SIZE); rsp_doc = new DynamicJsonDocument(RSP_DOC_SIZE); - - _identificationFlag = false; - _interoceptionFlag = false; - _heartbeatFlag = false; - } - - void ArancinoTasks::identificationCallback (TimerHandle_t xTimer){ - ArancinoTasks::_identificationFlag = true; - } - - void ArancinoTasks::interoceptionCallback (TimerHandle_t xTimer){ - ArancinoTasks::_interoceptionFlag = true; - } - - void ArancinoTasks::heartbeatCallback (TimerHandle_t xTimer){ - _heartbeatFlag = true; } void ArancinoTasks::heartbeatTask(){ @@ -148,6 +128,7 @@ under the License cmd_cfg["ack"] = 0; ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), false, VOID_RESPONSE); + (void)rsp; //to silence the warning (*cmd_doc).clear(); } Arancino.free(rsp); @@ -194,26 +175,30 @@ under the License void ArancinoTasks::serviceTask(void* pvParameters){ pinMode(LED_BUILTIN,OUTPUT); + TickType_t HB_LastWakeTime = xTaskGetTickCount(); + TickType_t ID_LastWakeTime = xTaskGetTickCount(); + TickType_t INT_LastWakeTime = xTaskGetTickCount(); + while(1){ //Heartbeat - if(_heartbeatFlag){ + if(xTaskGetTickCount() >= HB_LastWakeTime + HEARTBEAT_PERIOD){ heartbeatTask(); - _heartbeatFlag = false; + HB_LastWakeTime = xTaskGetTickCount(); } //Blink id - if(_identificationFlag){ + if(xTaskGetTickCount() >= ID_LastWakeTime + IDENTIFICATION_PERIOD){ identificationTask(); - _identificationFlag = false; + ID_LastWakeTime = xTaskGetTickCount(); } // Interoception - if (_interoceptionFlag){ + if (xTaskGetTickCount() >= INT_LastWakeTime + INTEROCEPTION_PERIOD){ interoceptionTask(); - _interoceptionFlag = false; + INT_LastWakeTime = xTaskGetTickCount(); } - vTaskDelay(1000); + vTaskDelay(SERVICE_TASK_PERIOD); } } From 6dc5170c73575049b180acc3db00d0f50884e26d Mon Sep 17 00:00:00 2001 From: andrea-83 Date: Fri, 24 Feb 2023 16:07:57 +0100 Subject: [PATCH 37/69] add stream to mqtt publish --- src/ArancinoInterface.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index 7a894a0..833bae5 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -20,6 +20,7 @@ under the License #include "ArancinoInterface.h" #include +#include #if defined(ARDUINO_ARCH_ESP32) && defined(CUSTOM_SERIAL) HardwareSerial SERIAL_PORT(UARTx); @@ -206,17 +207,17 @@ void MqttIface::ifaceBegin(){ void MqttIface::sendArancinoCommand(JsonDocument& command){ int counter = 0; - char buff[CMD_DOC_SIZE]; - serializeMsgPack(command, buff); while (counter < MQTT_MAX_RETRIES){ - if (this->publish(_outputTopic, buff)){ + if(this->beginPublish(_outputTopic, measureMsgPack(command),false)){ + BufferingPrint bufferedClient(*this->_client, 64); + serializeMsgPack(command, bufferedClient); + bufferedClient.flush(); + this-> endPublish(); return; } Arancino.println("Failed to send message, retrying."); - counter++; + counter++; } - Arancino.println("Failed to send message. Attempting to reconnect"); - //This should not happen. Check if still connected this->_reconnect(); } @@ -235,7 +236,7 @@ bool MqttIface::receiveArancinoResponse(JsonDocument& response){ } _newIncomingMessage = false; - bool error = deserializeMsgPack(response, _inputBuffer, sizeof(_inputBuffer)); + bool error = deserializeMsgPack(response, _inputBuffer); Arancino.free(_inputBuffer); return error; } From 81c09a3f6051eb39847cd87538727d484900c3e0 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Wed, 1 Mar 2023 12:35:19 +0100 Subject: [PATCH 38/69] Updated FREERTOS.md --- docs/FREERTOS.md | 55 ++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/docs/FREERTOS.md b/docs/FREERTOS.md index f4eea05..6834f01 100644 --- a/docs/FREERTOS.md +++ b/docs/FREERTOS.md @@ -2,7 +2,7 @@ The following section concern the use of FreeRTOS, already implemented in the Arancino Library; will be illustrated the Arancino-related FreeRTOS APIs and some basic FreeRTOS functions. For more advanced features, please see the official [FreeRTOS Documentation](https://www.freertos.org/Documentation/RTOS_book.html). ### FreeRTOS library -The Arancino library can take advantage of FreeRTOS library in order to achieve multiple tasks on a single MCU core; this includes several support tasks that act as support routines for Arancino protocol. __Users that desire to use FreeRTOS without using an Arancino board must install the correct FreeRTOS library__; the correct functioning of the library is not guaranteed with other FreeRTOS versions. Still users don't have to include the FreeRTOS library because it is already included in Arancino library if the flag USEFREERTOS is defined. +The Arancino library can take advantage of FreeRTOS library in order to run multiple tasks both in single-core and multi-core MCUs; this includes support task that executes support routines for Arancino protocol. __Users that desire to use FreeRTOS without using an Arancino board must install the correct FreeRTOS library__; the correct functioning of the library is not guaranteed with other FreeRTOS versions. Still users don't have to include the FreeRTOS library because it is already included in Arancino library. ### Notes about using FreeRTOS on other Arancino architectures The Arancino library currently supports 4 architectures. @@ -13,29 +13,27 @@ The Arancino library currently supports 4 architectures. | Arancino Pico | RP2040| yes | | Arancino V | STM32| yes | +Depending on the board used and therefore on the core, it will be possible to enable or disable the use of FreeRTOS: -When FreeRTOS is supported it's also enabled by default. You can enable or disable it: - -#### Arduino IDE: -Go into the directory of the desidered core (depends by your system) and open the `boards.txt` file. In the `build.extra_flags` property of the desired board, append this flag `-DUSEFREERTOS` to enable or remove it to disable FreeRTOS +#### Arduino IDE +Through the menu `Tools` -> `Using FreeRTOS` -> `Yes`. #### Platform.IO: -Go into the directory of the desidered platform (depends by your system) and open the json file of the desider board. In the `extra_flags` attribute append this flag `-DUSEFREERTOS` to enable or remove it to disable FreeRTOS. - +Add an extra flag to the `platformio.ini` configuration file. Each core can have different flags to activate, for this reason it is recommended to get this information from the README of the used core. >Note: -When you disable FreeRTOS, most of the adavanced features of Arancino Library are disabled (Device Identification, Interoception and others in the futures). +When you disable FreeRTOS, most of the adavanced features of Arancino Library are disabled (Heartbeat, Device Identification, Interoception and others in the future). ___ ### startScheduler ##### *void startScheduler* -Configure the `LED_BUILTIN` for debug and start the FreeRTOS scheduler. When a fatal FreeRTOS error occur, the `LED_BUILTIN` will blink following this codes: - -- 3 blinks - Fatal Rtos Error, something bad happened. Think really hard about what you just changed. -- 2 blinks - Stack overflow, task needs more bytes defined for its stack. -- 1 blink - Malloc failed, probably ran out of heap. +Configure the `LED_BUILTIN` for debug and start the FreeRTOS scheduler. When a FreeRTOS error occur, the `LED_BUILTIN` will blink in various ways. The blink sequences vary according to the mcu, for this reason it is advisable to refer to the core documentation for more information. +The errors we can get are as follows: +- Fatal FreeRTOS Error, something bad happened. Think really hard about what you just changed. +- Stack overflow, task needs more bytes defined for its stack. +- Malloc failed, probably ran out of heap. -> **IMPORTANT**: `Arancino.startScheduler()` never returns, so it **MUST be** the last instruction of Arduino setup() function. +> **IMPORTANT**: depending on the mcu used the `Arancino.startScheduler()` function may never return. For this reason it is **strongly recommended** to insert it as the last instruction of the `setup()` function. ##### Example: ```c++ @@ -71,7 +69,7 @@ Tasks are normally implemented as an infinite loop, and must never attempt to re * **`pcName`**: A descriptive name for the task. This is mainly used to facilitate debugging, but can also be used to [obtain a task handle](https://www.freertos.org/a00021.html#xTaskGetHandle). The maximum length of a task’s name is set using the config `MAX_TASK_NAME_LEN` parameter in `FreeRTOSConfig.h`. -* **`usStackDepth`**: The number of words (not bytes!) to allocate for use as the task’s stack. For example, if the stack is 16-bits wide and _usStackDepth_ is 100, then 200 bytes will be allocated for use as the task’s stack. As another example, if the stack is 32-bits wide and _usStackDepth_ is 400 then 1600 bytes will be allocated for use as the task’s stack. +* **`usStackDepth`**: The number of words (bytes for ESP32 architecture) to allocate for use as the task’s stack. For example, if the stack is 16-bits wide and _usStackDepth_ is 100, then 200 bytes will be allocated for use as the task’s stack. As another example, if the stack is 32-bits wide and _usStackDepth_ is 400 then 1600 bytes will be allocated for use as the task’s stack. The stack depth multiplied by the stack width must not exceed the maximum value that can be contained in a variable of type `size_t`. See the FAQ [How big should the stack be?](https://www.freertos.org/FAQMem.html#StackSize). * **`pvParameters`**: A value that will be passed into the created task as the task’s parameter. @@ -131,6 +129,11 @@ void loop2(void *pvPramaters) while (1) { vTaskDelay(1000); //wait 1 second (non-blocking delay) + // OR + /* + wait 1 second (non-blocking delay, tick-independent way) + */ + vTaskDelay(1000 / portTICK_PERIOD_MS); } } @@ -223,18 +226,20 @@ void loop() { } ``` ___ -### Arancino Tasks -Since the introduction of FreeRTOS in the Arancino Library, we developed a set of support tasks that improve the Arancino protocol with useful features such as: -- `void deviceIdentification(void *pvPramaters)` -- `static void interoception(void *pvPramaters)` +### Arancino background services +Since the introduction of FreeRTOS in the Arancino Library, we developed a set of support services that improve the Arancino protocol with useful features. + +If FreeRTOS is enabled, a special service task will call these methods in the background at regular intervals. + +>**IMPORTANT NOTE:** It is essential that the tasks instantiated by the user never occupy all the cpu time, as there would be the risk of starving the service task; this occurrence would cause the MCU to be reset by the daemon. -This methods run in the background if `USEFREERTOS` flag is defined. +#### **Heartbeat** +This service is used to signal to the daemon that the MCU is alive. If the daemon does not receive the heartbeat it will reset the MCU. -### DeviceIdentification -The task implements a function for visual identification (a blink of the built-in led) of the microcontroller connected to the Arancino Deamon (by using the reserved key `BLINK_ID_KEY`). +#### **DeviceIdentification** +The service implements a function for visual identification (a blink of the built-in led) of the microcontroller connected to the Arancino Deamon (by using the reserved key `BLINK_ID_KEY`). This is very helpful when several devices are connected in the same instance of an Arancino Deamon. -### Interoception +#### **Interoception** This task periodically sends to Arancino Deamon microcontroller current health parameters such as internal temperature, free heap and total memory every 60 seconds. -The keys used by this task are `mem_free_key,mem_used_key,mem_tot_key,temp_key` -and are transmitted by a single MSTORE command. +The keys used by this task are `mem_free_key`, `mem_used_key`, `mem_tot_key`, `temp_key` and are transmitted by a single MSTORE command. From 7f179436ee5dfabecd632e2fa754315e98ca453e Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Mon, 6 Mar 2023 12:45:12 +0100 Subject: [PATCH 39/69] Improved MQTT implementation, general cleanup and callback fix --- src/Arancino.cpp | 12 ++++++------ src/ArancinoDefinitions.h | 4 ++++ src/ArancinoInterface.cpp | 10 +++++----- src/ArancinoInterface.h | 3 ++- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index da46cdc..51fef3d 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -21,10 +21,10 @@ under the License #include "Arancino.h" #include "ArancinoTasks.h" -ArancinoPacket reservedKeyErrorPacket = {true, RESERVED_KEY_ERROR, RESERVED_KEY_ERROR, {.string = NULL}}; // default reserved key error packet -ArancinoPacket communicationErrorPacket = {true, COMMUNICATION_ERROR, COMMUNICATION_ERROR, {.string = NULL}}; // default reserved key error packet -ArancinoPacket invalidCommandErrorPacket = {true, INVALID_VALUE_ERROR, INVALID_VALUE_ERROR, {.string = NULL}}; // default reserved key error packet -ArancinoPacket voidCommunicationPacket = {false, RSP_OK, VOID_ERROR_TYPE, {.string = NULL}}; // default reserved key for non-ack messages +ArancinoPacket reservedKeyErrorPacket = {true, RESERVED_KEY_ERROR, RESERVED_KEY_ERROR, {.string = NULL}}; // default reserved key error packet +ArancinoPacket communicationErrorPacket = {true, COMMUNICATION_ERROR, COMMUNICATION_ERROR, {.string = NULL}}; // default reserved key error packet +ArancinoPacket invalidCommandErrorPacket = {true, INVALID_VALUE_ERROR, INVALID_VALUE_ERROR, {.string = NULL}}; // default reserved key error packet +ArancinoPacket voidCommunicationPacket = {false, RSP_OK, VOID_ERROR_TYPE, {.string = NULL}}; // default reserved key for non-ack messages // TASK #if defined(USEFREERTOS) @@ -103,12 +103,12 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, const cmd_doc["cmd"] = START_COMMAND; JsonObject cmd_args = cmd_doc.createNestedObject("args"); cmd_args["port_id"] = id; - cmd_args["fw_mcu_family"] = (char*)MCU_FAMILY; + cmd_args["fw_mcu_family"] = MCU_FAMILY; cmd_args["fw_lib_ver"] = LIB_VERSION; cmd_args["fw_name"] = _amdata.fwname; cmd_args["fw_ver"] = _amdata.fwversion; cmd_args["fw_build_time"] = str_build_time; - cmd_args["fw_core_ver"] = (char*)ARANCINO_CORE_VERSION; + cmd_args["fw_core_ver"] = ARANCINO_CORE_VERSION; cmd_args["fw_crtx_ver"] = CRTX_VERSION; cmd_args["use_freertos"] = useFreeRtos ? 1 : 0; if(custom_v1) diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index be22ab3..2405e46 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -34,6 +34,10 @@ under the License #undef TIMEOUT #endif +#ifndef ARANCINO_CORE_VERSION +#define ARANCINO_CORE_VERSION "0.0.0" +#endif + #if defined(__SAMD21G18A__) const uint32_t BAUDRATE = 4000000; const uint32_t TIMEOUT = 1000; diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index 833bae5..c7df191 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -163,11 +163,12 @@ void SerialIface::setSerialPort(){ /******** MQTT interface *********/ //Static variables definition -char* MqttIface::_inputBuffer; bool MqttIface::_newIncomingMessage = false; char* MqttIface::_inputTopic; char* MqttIface::_outputTopic; char* MqttIface::_serviceTopic; +unsigned int MqttIface::_length; +byte* MqttIface::_payload; void MqttIface::ifaceBegin(){ setClient(*_client); @@ -236,8 +237,7 @@ bool MqttIface::receiveArancinoResponse(JsonDocument& response){ } _newIncomingMessage = false; - bool error = deserializeMsgPack(response, _inputBuffer); - Arancino.free(_inputBuffer); + bool error = deserializeMsgPack(response, this->_payload, this->_length); return error; } @@ -247,8 +247,8 @@ void MqttIface::_arancinoCallback(char* topic, byte* payload, unsigned int lengt //should check whether the message is "reset" or no other messages will be sent here? Arancino.systemReset(); } else if (!strcmp(topic, _inputTopic)){ - _inputBuffer = (char*)Arancino.calloc(length, sizeof(char)); - memcpy(_inputBuffer, payload, length); + _length = length; + _payload = payload; _newIncomingMessage = true; } } diff --git a/src/ArancinoInterface.h b/src/ArancinoInterface.h index 66b49cd..1645034 100644 --- a/src/ArancinoInterface.h +++ b/src/ArancinoInterface.h @@ -84,7 +84,8 @@ class MqttIface : public ArancinoIface, public PubSubClient { static char* _outputTopic; static char* _serviceTopic; static bool _newIncomingMessage; - static char* _inputBuffer; + static unsigned int _length; + static byte* _payload; static void _arancinoCallback(char* topic, byte* payload, unsigned int lenght); }; From 17bc2e2d5a63aa742d11a2f3972247d18c2f1caf Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Tue, 7 Mar 2023 12:01:26 +0100 Subject: [PATCH 40/69] Forced deserializeMsgPack to make a copy of MQTT payload --- src/ArancinoInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index c7df191..ba8c36d 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -237,7 +237,7 @@ bool MqttIface::receiveArancinoResponse(JsonDocument& response){ } _newIncomingMessage = false; - bool error = deserializeMsgPack(response, this->_payload, this->_length); + bool error = deserializeMsgPack(response, (const char*)this->_payload, this->_length); return error; } From 760d7c2be6a38312155f53bd9e6e14fc0a3e8544 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Tue, 7 Mar 2023 12:03:29 +0100 Subject: [PATCH 41/69] Increased MQTT MAX RETRIES --- src/ArancinoDefinitions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index 2405e46..1cbfb9e 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -197,7 +197,7 @@ const uint32_t BAUDRATE_DEBUG = 115200; #define SERVICE_TASK_PERIOD (pdMS_TO_TICKS(5000)) #define SERIAL_MAX_RETRIES 10 -#define MQTT_MAX_RETRIES 100 +#define MQTT_MAX_RETRIES 500 #define BLUETOOTH_MAX_RETRIES 100 #define ID_SIZE IDSIZE*2 //IDSIZE will be provided by microcontroller-id library From 0b81d02ca3830eac27314714fb0b9e476d635c74 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Tue, 7 Mar 2023 12:06:20 +0100 Subject: [PATCH 42/69] Adequated ESP32 serviceTask priority wrt TCPIP task priority --- src/Arancino.h | 1 + src/ArancinoDefinitions.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Arancino.h b/src/Arancino.h index af7f0bd..2ca528e 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -80,6 +80,7 @@ extern "C" { #if defined(ARDUINO_ARCH_ESP32) #include #include +#include #define pvPortMalloc std::malloc #define vPortFree std::free #endif diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index 1cbfb9e..5e45bab 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -174,7 +174,7 @@ const uint32_t BAUDRATE_DEBUG = 115200; #if defined(ARDUINO_ARCH_ESP32) //ESP32 configMAX_PRIORITIES is 25 -#define ARANCINO_TASK_PRIORITY 20 +#define ARANCINO_TASK_PRIORITY (ESP_TASK_TCPIP_PRIO - 1) #define SERVICETASK_STACK (1024 * 4) #elif defined(__SAMD21G18A__) #define ARANCINO_TASK_PRIORITY configMAX_PRIORITIES - 1 From 75d81f122ec2bb6b465d829d4009bde0f099f74b Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Tue, 7 Mar 2023 12:07:32 +0100 Subject: [PATCH 43/69] Fixed missing parameters passing on hset-float --- src/Arancino.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index 51fef3d..8027bd6 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -398,7 +398,7 @@ ArancinoPacket ArancinoClass::hset(const char* key, const char* field, float val { char str[20] = ""; _floatToString(value, decimal_digits, str); - return hset(key, field, str); + return hset(key, field, str, isAck, isPersistent, type); } ArancinoPacket ArancinoClass::hset(const char* key, const char* field, double value, bool isAck, bool isPersistent, const char* type) @@ -1471,6 +1471,8 @@ void ArancinoClass::_buildArancinoJson(JsonDocument& cmd_doc, const char* cmd, c void ArancinoClass::systemReset(){ #if defined(ARDUINO_ARCH_RP2040) watchdog_reboot(0,0,0); + #elif defined(ARDUINO_ARCH_ESP32) + esp_restart(); #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_NRF52) NVIC_SystemReset(); #else From 8499a64ce239a3c8916b3b92ce4848eaea57f472 Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Wed, 8 Mar 2023 12:46:09 +0100 Subject: [PATCH 44/69] Quality of life improvements for debug messages --- src/Arancino.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index 8027bd6..0c820bb 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -76,8 +76,13 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, const #endif MicroID.getUniqueIDString(id, ID_SIZE/2); - _iface->ifaceBegin(); - + if (_iface != NULL){ + _iface->ifaceBegin(); + } else { + Arancino.println("Interface not set!"); + while(1); + } + // firmware build time char str_build_time[strlen(__DATE__) + 1 + strlen(__TIME__) + 1 + strlen(_amdata.tzoffset)] = ""; strcpy(str_build_time, __DATE__); @@ -227,7 +232,7 @@ void ArancinoClass::enableDebugMessages(bool sendViaCommMode){ _commMode = true; } else { //Default config for Arancino Boards - #if defined(SERIAL_DEBUG) + #if defined(SERIAL_DEBUG) && defined(BAUDRATE_DEBUG) SERIAL_DEBUG.begin(BAUDRATE_DEBUG); _isDebug = true; _dbgSerial = &SERIAL_DEBUG; @@ -1517,7 +1522,7 @@ void ArancinoClass::_floatToString(float value, unsigned int _nDecimal, char *st } void ArancinoClass::_printDebugMessage(const char* value) { - if (_isDebug && _commMode){ + if (_isDebug && _commMode && started){ __publish(MONITOR_KEY, value); set(MONITOR_KEY, value, false); } else if(_isDebug && _dbgSerial != NULL){ From 95dd46dfd5a17995105fb1c1975649f40ffce57f Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Wed, 8 Mar 2023 13:28:37 +0100 Subject: [PATCH 45/69] Introduced buffering stream to BLE interface --- src/ArancinoInterface.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index ba8c36d..f2f4f61 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -306,7 +306,9 @@ void BluetoothIface::ifaceBegin(){ } void BluetoothIface::sendArancinoCommand(JsonDocument& command){ - serializeMsgPack(command, *_bleSerial); + WriteBufferingStream bufferedStream(*_bleSerial, 64); + serializeMsgPack(command, bufferedStream); + bufferedStream.flush(); } bool BluetoothIface::receiveArancinoResponse(JsonDocument& response){ From 5fa434cb11ba1a418112b835cc4aafa815c4bd3b Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Fri, 10 Mar 2023 16:32:52 +0100 Subject: [PATCH 46/69] Implemented timeout in BluetoothIface and fixed serviceTask priority --- src/ArancinoDefinitions.h | 2 +- src/ArancinoInterface.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index 5e45bab..a587595 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -183,7 +183,7 @@ const uint32_t BAUDRATE_DEBUG = 115200; #define ARANCINO_TASK_PRIORITY configMAX_PRIORITIES - 1 #define SERVICETASK_STACK 1024 #elif defined(ARDUINO_ARCH_NRF52) -#define ARANCINO_TASK_PRIORITY TASK_PRIO_HIGH +#define ARANCINO_TASK_PRIORITY TASK_PRIO_HIGH - 1 #define SERVICETASK_STACK 2048 #else #warning "This platform has not been tested!" diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index f2f4f61..bc9e594 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -306,13 +306,19 @@ void BluetoothIface::ifaceBegin(){ } void BluetoothIface::sendArancinoCommand(JsonDocument& command){ - WriteBufferingStream bufferedStream(*_bleSerial, 64); + WriteBufferingStream bufferedStream(*_bleSerial, 128); serializeMsgPack(command, bufferedStream); bufferedStream.flush(); } bool BluetoothIface::receiveArancinoResponse(JsonDocument& response){ - DeserializationError error = deserializeMsgPack(response, *_bleSerial); + unsigned long startMillis = millis(); + DeserializationError error; + do + { + error = deserializeMsgPack(response, *_bleSerial); + } + while (error != 0 && millis() < startMillis + TIMEOUT); if(error){ if (++_timeoutCounter == BLUETOOTH_MAX_RETRIES){ From 209b99b9ba3a6429aaed1c00f0527dbb153233a0 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Fri, 17 Mar 2023 10:47:25 +0100 Subject: [PATCH 47/69] Improved MQTT timeout mechanism and increased SAMD timeout --- src/ArancinoDefinitions.h | 2 +- src/ArancinoInterface.cpp | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index a587595..cef616b 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -40,7 +40,7 @@ under the License #if defined(__SAMD21G18A__) const uint32_t BAUDRATE = 4000000; -const uint32_t TIMEOUT = 1000; +const uint32_t TIMEOUT = 10000; #define SERIAL_PORT SerialUSB #define SERIAL_DEBUG Serial #elif defined(ARDUINO_ARCH_RP2040) && defined(USEFREERTOS) diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index bc9e594..7792118 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -224,20 +224,20 @@ void MqttIface::sendArancinoCommand(JsonDocument& command){ } bool MqttIface::receiveArancinoResponse(JsonDocument& response){ - int counter = 0; - while(!_newIncomingMessage){ - if (counter < MQTT_MAX_RETRIES){ - this->loop(); - counter++; - delay(10); - } else { - //No need for cleanup: no message was received nor memory allocated for it - return true; - } + unsigned long startMillis = millis(); + bool error = true; + do { + this->loop(); + delay(10); + } while(!_newIncomingMessage && (millis() < startMillis + TIMEOUT)); + + + if (_newIncomingMessage) + { + error = deserializeMsgPack(response, (const char*)this->_payload, this->_length); + _newIncomingMessage = false; } - _newIncomingMessage = false; - bool error = deserializeMsgPack(response, (const char*)this->_payload, this->_length); return error; } From dd71ac26f7d7871c3faa7db2283336a331c522a0 Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Fri, 17 Mar 2023 10:48:23 +0100 Subject: [PATCH 48/69] Updated lib version in ArancinoDefinitions.h --- src/ArancinoDefinitions.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index cef616b..6ed4fd1 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -149,7 +149,7 @@ const uint32_t BAUDRATE_DEBUG = 115200; #define MODLOGLVL_KEY (const char*)"___MODLOGLVL___" #define MODENV_KEY (const char*)"___MODENV___" #define BLINK_ID_KEY (const char*)"___BLINK_ID___" -#define LIB_VERSION (const char*)"2.0.0" //library version +#define LIB_VERSION (const char*)"3.1.0" //library version #define CRTX_VERSION (const char*)"1.0.0" //cortex version //RESPONSE CODE @@ -183,7 +183,7 @@ const uint32_t BAUDRATE_DEBUG = 115200; #define ARANCINO_TASK_PRIORITY configMAX_PRIORITIES - 1 #define SERVICETASK_STACK 1024 #elif defined(ARDUINO_ARCH_NRF52) -#define ARANCINO_TASK_PRIORITY TASK_PRIO_HIGH - 1 +#define ARANCINO_TASK_PRIORITY TASK_PRIO_HIGH #define SERVICETASK_STACK 2048 #else #warning "This platform has not been tested!" From f029d097759c3a2d065e2dff351e7b41bf64fc61 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Wed, 22 Mar 2023 11:19:10 +0100 Subject: [PATCH 49/69] Removed unused ArancinoConfig members (FreeRTOS) --- docs/VARS_DATA_STRUCT.md | 3 --- src/Arancino.cpp | 28 ++++++++++++++-------------- src/ArancinoConfig.h | 21 --------------------- 3 files changed, 14 insertions(+), 38 deletions(-) diff --git a/docs/VARS_DATA_STRUCT.md b/docs/VARS_DATA_STRUCT.md index bd3251c..d70d84a 100644 --- a/docs/VARS_DATA_STRUCT.md +++ b/docs/VARS_DATA_STRUCT.md @@ -20,9 +20,6 @@ - **`DECIMAL_DIGITS`**: Default `4`. Represents the number to the right of the decimal point for the float and double data types. Float data type has 7 digits, while double data type has up to 15 digits, including decimal digits. If the digits exceed the maximum allowed for the type(float or double), the decimal part will be truncated and rounded up or rounded down. -- **`FREERTOS_LOOP_TASK_ENABLE`**: Default `false`. If `true` the Arduino Loop function will be automatically implemented as FreeRTOS Task. -- **`FREERTOS_LOOP_TASK_STACK_SIZE`**: Default `256`. Sets the default stack size for the Arduino Loop function when it's managed as FreeRTOS Task. This length is provided in *words*, not bytes, and should be proportional to the used stack memory. -- **`FREERTOS_LOOP_TASK_PRIORITY`**: Default `0`. Assignes a priority to the Arduino Loop Task in which 0 stands for highest priority while 9 stands for lowest priority. ### ArancinoMetadata `ArancinoMetadata` is a data structure used to encapsulate firmware metadata; it is later read and exposed by Arancino Daemon via Rest API. #### Content diff --git a/src/Arancino.cpp b/src/Arancino.cpp index 0c820bb..07230f9 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -197,31 +197,31 @@ void ArancinoClass::start(JsonDocument& cmd_doc) { void ArancinoClass::startScheduler() { started = true; -#if defined(__SAMD21G18A__) - vSetErrorLed(LED_BUILTIN, HIGH); -#endif - /* - * Uncomment this if you want run loop() as a dedicated task. - * If loop() doesn't run as dedicated task, should not contain blocking code. - */ - // task started in main.c (core) #if defined(ARDUINO_ARANCINO_VOLANTE) - // initYieldTask(100); + /* + FreeRTOS scheduler has been already started + from NRF52 core + */ #elif defined(ARDUINO_ARCH_RP2040) - // initYieldTask(100); - // runLoopAsTask(128, tskIDLE_PRIORITY); - // initFreeRTOS(); //128 = stack depth for loop, tskIDLE_PRIORITY = priority + /* + FreeRTOS scheduler has been already started + from RP2040 core + */ #elif defined(__SAMD21G18A__) - //runLoopAsTask(128, tskIDLE_PRIORITY); + vSetErrorLed(LED_BUILTIN, HIGH); vTaskStartScheduler(); #elif defined(ARDUINO_ARANCINOV12_H743ZI) || defined(ARDUINO_ARANCINOV12_H743ZI2) vTaskStartScheduler(); #elif defined(ARDUINO_ARCH_ESP32) - + /* + FreeRTOS scheduler has been already started + from ESP32 core + */ #else #error "FreeRTOS not supported on the selected board!" #endif } + #endif /******** API BASIC :: DEBUG OPTIONS *********/ diff --git a/src/ArancinoConfig.h b/src/ArancinoConfig.h index 4671402..035f630 100644 --- a/src/ArancinoConfig.h +++ b/src/ArancinoConfig.h @@ -38,25 +38,4 @@ class ArancinoConfig{ */ bool USE_PORT_ID_PREFIX_KEY = false; - - /* - Enables by default the Arduino Loop function as a FreeRTOS Task. - */ - bool FREERTOS_LOOP_TASK_ENABLE = false; - - - /* - Sets the default stack size available for the Arduino Loop function when it's managed - as a FreeRTOS Task. 256 Bytes by default. - */ - int FREERTOS_LOOP_TASK_STACK_SIZE = 256; - - - /* - Assignes a priority of the Arduino Loop function when it's managed as a FreeRTOS Task. - 0 -> Lowest Priority. - 9 -> Highest Priority. - */ - int FREERTOS_LOOP_TASK_PRIORITY = 0; - }; \ No newline at end of file From ce6225fa41da5e9cc401d3bbab0727d760df8453 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Wed, 22 Mar 2023 12:16:47 +0100 Subject: [PATCH 50/69] Introduced arancino_id_prefix into msgpack --- src/Arancino.cpp | 40 +++++++++++++++++++++++++++++---------- src/Arancino.h | 7 ++++--- src/ArancinoDefinitions.h | 6 +++--- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index 07230f9..73d7b6c 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -74,6 +74,8 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, const #if defined(ARDUINO_ARCH_ESP32) esp_task_wdt_init(120, true); #endif + arancino_id_prefix = _acfg.USE_PORT_ID_PREFIX_KEY; + decimal_digits = _acfg.DECIMAL_DIGITS; MicroID.getUniqueIDString(id, ID_SIZE/2); if (_iface != NULL){ @@ -302,6 +304,7 @@ ArancinoPacket ArancinoClass::set(const char* key, const char* value, bool isAck cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; cfg.type = type; + cfg.isPrefix = arancino_id_prefix ? CFG_TRUE : CFG_FALSE; return executeCommand(SET_COMMAND, key, NULL, value, isAck, true, true, cfg, VOID_RESPONSE); } @@ -317,6 +320,7 @@ ArancinoPacket ArancinoClass::mset(char **keys, char **values, int len, bool isA cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; cfg.type = type; + cfg.isPrefix = arancino_id_prefix ? CFG_TRUE : CFG_FALSE; return executeCommand(SET_COMMAND, keys, NULL, values, len, isAck, true, true, cfg, VOID_RESPONSE); } @@ -331,6 +335,7 @@ ArancinoPacket ArancinoClass::get(const char* key, bool isPersis ArancinoCFG cfg; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; cfg.type = type; + cfg.isPrefix = arancino_id_prefix ? CFG_TRUE : CFG_FALSE; return executeCommand(GET_COMMAND, key, NULL, NULL, true, true, false, cfg, KEY_VALUE_RESPONSE); } @@ -354,6 +359,7 @@ template <> ArancinoPacket ArancinoClass::mget(char **keys, int ArancinoCFG cfg; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; cfg.type = type; + cfg.isPrefix = arancino_id_prefix ? CFG_TRUE : CFG_FALSE; return executeCommand(GET_COMMAND, keys, NULL, NULL, len, true, true, false, cfg, KEY_VALUE_RESPONSE); } @@ -377,6 +383,7 @@ ArancinoPacket ArancinoClass::del(const char* key, bool isAck, b cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; cfg.type = type; + cfg.isPrefix = arancino_id_prefix ? CFG_TRUE : CFG_FALSE; return executeCommand(DEL_COMMAND, key, NULL, NULL, isAck, true, false, cfg, KEYS_RESPONSE); } @@ -436,6 +443,7 @@ ArancinoPacket ArancinoClass::hset(const char* key, const char* field, const cha cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; cfg.type = type; + cfg.isPrefix = arancino_id_prefix ? CFG_TRUE : CFG_FALSE; return executeCommand(HSET_COMMAND, key, field, value, isAck, true, true, cfg, VOID_RESPONSE); } @@ -450,6 +458,7 @@ ArancinoPacket ArancinoClass::hget(const char* key, const char* ArancinoCFG cfg; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; cfg.type = type; + cfg.isPrefix = arancino_id_prefix ? CFG_TRUE : CFG_FALSE; return executeCommand(HGET_COMMAND, key, field, NULL, true, true, true, cfg, KEY_VALUE_RESPONSE); } @@ -474,6 +483,7 @@ ArancinoPacket ArancinoClass::hdel(const char* key, const char* ArancinoCFG cfg; cfg.ack = isAck ? CFG_TRUE : CFG_FALSE; cfg.pers = isPersistent ? CFG_TRUE : CFG_FALSE; + cfg.isPrefix = arancino_id_prefix ? CFG_TRUE : CFG_FALSE; return executeCommand(HDEL_COMMAND, key, field, NULL, isAck, true, true, cfg, KEYS_RESPONSE); } @@ -599,7 +609,8 @@ ArancinoPacket ArancinoClass::__publish(const char* channel, const char* msg, bo items_obj["message"] = msg; JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); - cmd_cfg["ack"] = isAck? 1 : 0; + cmd_cfg["ack"] = isAck ? CFG_TRUE : CFG_FALSE; + cmd_cfg["prfx"] = arancino_id_prefix ? CFG_TRUE : CFG_FALSE; return executeCommand(cmd_doc, isAck, CLIENTS_RESPONSE); } @@ -716,8 +727,9 @@ ArancinoPacket ArancinoClass::__store(const char* key, const char* value, const items_obj["ts"] = timestamp; JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); - cmd_cfg["ack"] = isAck? 1 : 0; + cmd_cfg["ack"] = isAck ? CFG_TRUE : CFG_FALSE; cmd_cfg["type"] = "tse"; + cmd_cfg["prfx"] = arancino_id_prefix ? CFG_TRUE : CFG_FALSE; return executeCommand(cmd_doc, isAck, ITEMS_RESPONSE); } @@ -747,8 +759,9 @@ ArancinoPacket ArancinoClass::mstore(char** keys, char** values, } JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); - cmd_cfg["ack"] = isAck? 1 : 0; + cmd_cfg["ack"] = isAck ? CFG_TRUE : CFG_FALSE; cmd_cfg["type"] = "tse"; + cmd_cfg["prfx"] = arancino_id_prefix ? CFG_TRUE : CFG_FALSE; return executeCommand(cmd_doc, isAck, ITEMS_RESPONSE); } @@ -803,8 +816,9 @@ ArancinoPacket ArancinoClass::storetags(const char* key, char **tags, char **val cmd_args["ts"] = timestamp; JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); - cmd_cfg["ack"] = isAck? 1 : 0; + cmd_cfg["ack"] = isAck ? CFG_TRUE : CFG_FALSE; cmd_cfg["type"] = "tags"; + cmd_cfg["prfx"] = arancino_id_prefix ? CFG_TRUE : CFG_FALSE; return executeCommand(cmd_doc, isAck, VOID_RESPONSE); } @@ -1422,15 +1436,18 @@ void ArancinoClass::_buildArancinoJson(JsonDocument& cmd_doc, const char* cmd, c } JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); - if (cfg.pers){ + if (cfg.pers != CFG_UNSET){ cmd_cfg["pers"] = cfg.pers == CFG_FALSE ? 0 : 1; } - if (cfg.ack){ + if (cfg.ack != CFG_UNSET){ cmd_cfg["ack"] = cfg.ack == CFG_FALSE ? 0 : 1; } - if (cfg.type){ + if (cfg.type != NULL){ cmd_cfg["type"] = cfg.type; } + if (cfg.isPrefix != CFG_UNSET){ + cmd_cfg["prfx"] = cfg.isPrefix == CFG_FALSE ? 0 : 1; + } } void ArancinoClass::_buildArancinoJson(JsonDocument& cmd_doc, const char* cmd, char** keys, char** fields, char** values, int len, bool argsHasItems, bool itemsHasDict, ArancinoCFG cfg){ @@ -1462,15 +1479,18 @@ void ArancinoClass::_buildArancinoJson(JsonDocument& cmd_doc, const char* cmd, c } JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); - if (cfg.pers){ + if (cfg.pers != CFG_UNSET){ cmd_cfg["pers"] = cfg.pers == CFG_FALSE ? 0 : 1; } - if (cfg.ack){ + if (cfg.ack != CFG_UNSET){ cmd_cfg["ack"] = cfg.ack == CFG_FALSE ? 0 : 1; } - if (cfg.type){ + if (cfg.type != NULL){ cmd_cfg["type"] = cfg.type; } + if (cfg.isPrefix != CFG_UNSET){ + cmd_cfg["prfx"] = cfg.isPrefix == CFG_FALSE ? 0 : 1; + } } void ArancinoClass::systemReset(){ diff --git a/src/Arancino.h b/src/Arancino.h index 2ca528e..a37ca49 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -113,9 +113,10 @@ typedef struct { } ArancinoMetadata; typedef struct { - uint8_t pers = CFG_UNSET; - uint8_t ack = CFG_UNSET; - const char* type = CFG_UNSET; + int pers = CFG_UNSET; + int ack = CFG_UNSET; + const char* type = NULL; + int isPrefix = CFG_UNSET; //const char* signature } ArancinoCFG; diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index 6ed4fd1..6715679 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -205,9 +205,9 @@ const uint32_t BAUDRATE_DEBUG = 115200; //MsgPack #define CMD_DOC_SIZE 512 #define RSP_DOC_SIZE 256 -#define CFG_UNSET 0 -#define CFG_TRUE 1 -#define CFG_FALSE 2 +#define CFG_UNSET (-1) +#define CFG_FALSE (0) +#define CFG_TRUE (1) #define VOID_RESPONSE 0 #define KEY_VALUE_RESPONSE 1 From 2d87fc2e0f1d55ff7a92fa14528dba626b3cdc3c Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Wed, 22 Mar 2023 13:25:52 +0100 Subject: [PATCH 51/69] Updated heartbeat task with new prexif changes --- src/ArancinoTasks.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/ArancinoTasks.cpp b/src/ArancinoTasks.cpp index 6d19418..1545fdb 100644 --- a/src/ArancinoTasks.cpp +++ b/src/ArancinoTasks.cpp @@ -50,29 +50,21 @@ under the License } void ArancinoTasks::heartbeatTask(){ - uint8_t idSize = strlen(Arancino.id); - char topic[idSize + 5]; //ID_SIZE + '_HBx' + '\0' - strcpy(topic, Arancino.id); - strcat(topic, "_HB0"); - - topic[idSize+3] = '0'; //If the topic structure isn't changed i know exactly the byte I'm supposed to change - JsonObject cmd_args = (*cmd_doc).createNestedObject("args"); (*cmd_doc)["cmd"] = PUBLISH_COMMAND; JsonArray cmd_items = cmd_args.createNestedArray("items"); JsonObject items_obj = cmd_items.createNestedObject(); - items_obj["channel"] = topic; + items_obj["channel"] = "HB0"; items_obj["message"] = Arancino.getTimestamp(); JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); - cmd_cfg["ack"] = 0; - cmd_cfg["pers"] = 0; + cmd_cfg["ack"] = CFG_FALSE; + cmd_cfg["pers"] = CFG_FALSE; + cmd_cfg["prfx"] = CFG_TRUE; ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, CLIENTS_RESPONSE); - - topic[idSize+3] = '1'; //If the topic structure isn't changed i know exactly the byte I'm supposed to change - - items_obj["channel"] = topic; + + items_obj["channel"] = "HB1"; items_obj["message"] = Arancino.getTimestamp(); rsp = Arancino.executeCommand((*cmd_doc), (*rsp_doc), false, CLIENTS_RESPONSE); From d1e0afd0d71043793210ce251f4365492566d6a4 Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Thu, 23 Mar 2023 11:31:22 +0100 Subject: [PATCH 52/69] Changed use_freertos param to fw_freertos inside start command --- src/Arancino.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index 73d7b6c..8ef5398 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -117,7 +117,7 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg, const cmd_args["fw_build_time"] = str_build_time; cmd_args["fw_core_ver"] = ARANCINO_CORE_VERSION; cmd_args["fw_crtx_ver"] = CRTX_VERSION; - cmd_args["use_freertos"] = useFreeRtos ? 1 : 0; + cmd_args["fw_freertos"] = useFreeRtos ? 1 : 0; if(custom_v1) cmd_args["CUSTOM_KEY_1"] = custom_v1; if(custom_v2) From dc122fb989751699b87d45e6821e62e13d64a1c9 Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Fri, 24 Mar 2023 09:51:32 +0100 Subject: [PATCH 53/69] Removed prxf cfg attribute from store and storetags --- src/Arancino.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index 8ef5398..4321312 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -729,7 +729,6 @@ ArancinoPacket ArancinoClass::__store(const char* key, const char* value, const JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); cmd_cfg["ack"] = isAck ? CFG_TRUE : CFG_FALSE; cmd_cfg["type"] = "tse"; - cmd_cfg["prfx"] = arancino_id_prefix ? CFG_TRUE : CFG_FALSE; return executeCommand(cmd_doc, isAck, ITEMS_RESPONSE); } @@ -818,7 +817,6 @@ ArancinoPacket ArancinoClass::storetags(const char* key, char **tags, char **val JsonObject cmd_cfg = cmd_doc.createNestedObject("cfg"); cmd_cfg["ack"] = isAck ? CFG_TRUE : CFG_FALSE; cmd_cfg["type"] = "tags"; - cmd_cfg["prfx"] = arancino_id_prefix ? CFG_TRUE : CFG_FALSE; return executeCommand(cmd_doc, isAck, VOID_RESPONSE); } From 106e472637d6111981f67a9814507c9b8aa24ce2 Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Mon, 27 Mar 2023 15:59:24 +0200 Subject: [PATCH 54/69] Fixed typos when numbering examples --- examples/Arancino/{05-HSET => 04-HSET}/HSET/HSET.ino | 0 .../Arancino/{05-HSET => 04-HSET}/HSET_Packet/HSET_Packet.ino | 0 examples/Arancino/{06-HGET => 05-HGET}/HGET/HGET.ino | 0 .../Arancino/{06-HGET => 05-HGET}/HGET_Packet/HGET_Packet.ino | 0 examples/Arancino/{07-HDEL => 06-HDEL}/HDEL/HDEL.ino | 0 .../Arancino/{07-HDEL => 06-HDEL}/HDEL_Packet/HDEL_Packet.ino | 0 examples/Arancino/{08-FLUSH => 07-FLUSH}/FLUSH/FLUSH.ino | 0 .../Arancino/{08-FLUSH => 07-FLUSH}/FLUSH_Packet/FLUSH_Packet.ino | 0 examples/Arancino/{09-PUBLISH => 08-PUBLISH}/PUBLISH/PUBLISH.ino | 0 .../{09-PUBLISH => 08-PUBLISH}/PUBLISH_Packet/PUBLISH_Packet.ino | 0 examples/Arancino/{10-MSET => 09-MSET}/MSET/MSET.ino | 0 examples/Arancino/{11-MGET => 10-MGET}/MGET/MGET.ino | 0 .../Arancino/{11-MGET => 10-MGET}/MGET_Packet/MGET_Packet.ino | 0 examples/Arancino/{12-STORE => 11-STORE}/STORE/STORE.ino | 0 .../Arancino/{12-STORE => 11-STORE}/STORE_Packet/STORE_Packet.ino | 0 .../{13-STORETAGS => 12-STORETAGS}/STORETAGS/STORETAGS.ino | 0 .../STORETAGS_Packet/STORETAGS_Packet.ino | 0 examples/Arancino/{14-MSTORE => 13-MSTORE}/MSTORE/MSTORE.ino | 0 .../{14-MSTORE => 13-MSTORE}/MSTORE_Packet/MSTORE_Packet.ino | 0 examples/Arancino/{15-MQTT => 14-MQTT}/MQTT/MQTT.ino | 0 examples/Arancino/{15-MQTT => 14-MQTT}/MQTT_ESP32/MQTT_ESP32.ino | 0 .../{16-BLUETOOTH => 15-BLUETOOTH}/BLUETOOTH/BLUETOOTH.ino | 0 examples/Arancino_FreeRTOS/{05-HSET => 04-HSET}/HSET/HSET.ino | 0 .../{05-HSET => 04-HSET}/HSET_Packet/HSET_Packet.ino | 0 examples/Arancino_FreeRTOS/{06-HGET => 05-HGET}/HGET/HGET.ino | 0 .../{06-HGET => 05-HGET}/HGET_Packet/HGET_Packet.ino | 0 examples/Arancino_FreeRTOS/{07-HDEL => 06-HDEL}/HDEL/HDEL.ino | 0 .../{07-HDEL => 06-HDEL}/HDEL_Packet/HDEL_Packet.ino | 0 examples/Arancino_FreeRTOS/{08-FLUSH => 07-FLUSH}/FLUSH/FLUSH.ino | 0 .../{08-FLUSH => 07-FLUSH}/FLUSH_Packet/FLUSH_Packet.ino | 0 .../{09-PUBLISH => 08-PUBLISH}/PUBLISH/PUBLISH.ino | 0 .../{09-PUBLISH => 08-PUBLISH}/PUBLISH_Packet/PUBLISH_Packet.ino | 0 examples/Arancino_FreeRTOS/{10-MSET => 09-MSET}/MSET/MSET.ino | 0 examples/Arancino_FreeRTOS/{11-MGET => 10-MGET}/MGET/MGET.ino | 0 .../{11-MGET => 10-MGET}/MGET_Packet/MGET_Packet.ino | 0 examples/Arancino_FreeRTOS/{12-STORE => 11-STORE}/STORE/STORE.ino | 0 .../{12-STORE => 11-STORE}/STORE_Packet/STORE_Packet.ino | 0 .../{13-STORETAGS => 12-STORETAGS}/STORETAGS/STORETAGS.ino | 0 .../STORETAGS_Packet/STORETAGS_Packet.ino | 0 .../Arancino_FreeRTOS/{14-MSTORE => 13-MSTORE}/MSTORE/MSTORE.ino | 0 .../{14-MSTORE => 13-MSTORE}/MSTORE_Packet/MSTORE_Packet.ino | 0 examples/Arancino_FreeRTOS/{15-MQTT => 14-MQTT}/MQTT/MQTT.ino | 0 .../{15-MQTT => 14-MQTT}/MQTT_ESP32/MQTT_ESP32.ino | 0 .../{16-BLUETOOTH => 15-BLUETOOTH}/BLUETOOTH/BLUETOOTH.ino | 0 44 files changed, 0 insertions(+), 0 deletions(-) rename examples/Arancino/{05-HSET => 04-HSET}/HSET/HSET.ino (100%) rename examples/Arancino/{05-HSET => 04-HSET}/HSET_Packet/HSET_Packet.ino (100%) rename examples/Arancino/{06-HGET => 05-HGET}/HGET/HGET.ino (100%) rename examples/Arancino/{06-HGET => 05-HGET}/HGET_Packet/HGET_Packet.ino (100%) rename examples/Arancino/{07-HDEL => 06-HDEL}/HDEL/HDEL.ino (100%) rename examples/Arancino/{07-HDEL => 06-HDEL}/HDEL_Packet/HDEL_Packet.ino (100%) rename examples/Arancino/{08-FLUSH => 07-FLUSH}/FLUSH/FLUSH.ino (100%) rename examples/Arancino/{08-FLUSH => 07-FLUSH}/FLUSH_Packet/FLUSH_Packet.ino (100%) rename examples/Arancino/{09-PUBLISH => 08-PUBLISH}/PUBLISH/PUBLISH.ino (100%) rename examples/Arancino/{09-PUBLISH => 08-PUBLISH}/PUBLISH_Packet/PUBLISH_Packet.ino (100%) rename examples/Arancino/{10-MSET => 09-MSET}/MSET/MSET.ino (100%) rename examples/Arancino/{11-MGET => 10-MGET}/MGET/MGET.ino (100%) rename examples/Arancino/{11-MGET => 10-MGET}/MGET_Packet/MGET_Packet.ino (100%) rename examples/Arancino/{12-STORE => 11-STORE}/STORE/STORE.ino (100%) rename examples/Arancino/{12-STORE => 11-STORE}/STORE_Packet/STORE_Packet.ino (100%) rename examples/Arancino/{13-STORETAGS => 12-STORETAGS}/STORETAGS/STORETAGS.ino (100%) rename examples/Arancino/{13-STORETAGS => 12-STORETAGS}/STORETAGS_Packet/STORETAGS_Packet.ino (100%) rename examples/Arancino/{14-MSTORE => 13-MSTORE}/MSTORE/MSTORE.ino (100%) rename examples/Arancino/{14-MSTORE => 13-MSTORE}/MSTORE_Packet/MSTORE_Packet.ino (100%) rename examples/Arancino/{15-MQTT => 14-MQTT}/MQTT/MQTT.ino (100%) rename examples/Arancino/{15-MQTT => 14-MQTT}/MQTT_ESP32/MQTT_ESP32.ino (100%) rename examples/Arancino/{16-BLUETOOTH => 15-BLUETOOTH}/BLUETOOTH/BLUETOOTH.ino (100%) rename examples/Arancino_FreeRTOS/{05-HSET => 04-HSET}/HSET/HSET.ino (100%) rename examples/Arancino_FreeRTOS/{05-HSET => 04-HSET}/HSET_Packet/HSET_Packet.ino (100%) rename examples/Arancino_FreeRTOS/{06-HGET => 05-HGET}/HGET/HGET.ino (100%) rename examples/Arancino_FreeRTOS/{06-HGET => 05-HGET}/HGET_Packet/HGET_Packet.ino (100%) rename examples/Arancino_FreeRTOS/{07-HDEL => 06-HDEL}/HDEL/HDEL.ino (100%) rename examples/Arancino_FreeRTOS/{07-HDEL => 06-HDEL}/HDEL_Packet/HDEL_Packet.ino (100%) rename examples/Arancino_FreeRTOS/{08-FLUSH => 07-FLUSH}/FLUSH/FLUSH.ino (100%) rename examples/Arancino_FreeRTOS/{08-FLUSH => 07-FLUSH}/FLUSH_Packet/FLUSH_Packet.ino (100%) rename examples/Arancino_FreeRTOS/{09-PUBLISH => 08-PUBLISH}/PUBLISH/PUBLISH.ino (100%) rename examples/Arancino_FreeRTOS/{09-PUBLISH => 08-PUBLISH}/PUBLISH_Packet/PUBLISH_Packet.ino (100%) rename examples/Arancino_FreeRTOS/{10-MSET => 09-MSET}/MSET/MSET.ino (100%) rename examples/Arancino_FreeRTOS/{11-MGET => 10-MGET}/MGET/MGET.ino (100%) rename examples/Arancino_FreeRTOS/{11-MGET => 10-MGET}/MGET_Packet/MGET_Packet.ino (100%) rename examples/Arancino_FreeRTOS/{12-STORE => 11-STORE}/STORE/STORE.ino (100%) rename examples/Arancino_FreeRTOS/{12-STORE => 11-STORE}/STORE_Packet/STORE_Packet.ino (100%) rename examples/Arancino_FreeRTOS/{13-STORETAGS => 12-STORETAGS}/STORETAGS/STORETAGS.ino (100%) rename examples/Arancino_FreeRTOS/{13-STORETAGS => 12-STORETAGS}/STORETAGS_Packet/STORETAGS_Packet.ino (100%) rename examples/Arancino_FreeRTOS/{14-MSTORE => 13-MSTORE}/MSTORE/MSTORE.ino (100%) rename examples/Arancino_FreeRTOS/{14-MSTORE => 13-MSTORE}/MSTORE_Packet/MSTORE_Packet.ino (100%) rename examples/Arancino_FreeRTOS/{15-MQTT => 14-MQTT}/MQTT/MQTT.ino (100%) rename examples/Arancino_FreeRTOS/{15-MQTT => 14-MQTT}/MQTT_ESP32/MQTT_ESP32.ino (100%) rename examples/Arancino_FreeRTOS/{16-BLUETOOTH => 15-BLUETOOTH}/BLUETOOTH/BLUETOOTH.ino (100%) diff --git a/examples/Arancino/05-HSET/HSET/HSET.ino b/examples/Arancino/04-HSET/HSET/HSET.ino similarity index 100% rename from examples/Arancino/05-HSET/HSET/HSET.ino rename to examples/Arancino/04-HSET/HSET/HSET.ino diff --git a/examples/Arancino/05-HSET/HSET_Packet/HSET_Packet.ino b/examples/Arancino/04-HSET/HSET_Packet/HSET_Packet.ino similarity index 100% rename from examples/Arancino/05-HSET/HSET_Packet/HSET_Packet.ino rename to examples/Arancino/04-HSET/HSET_Packet/HSET_Packet.ino diff --git a/examples/Arancino/06-HGET/HGET/HGET.ino b/examples/Arancino/05-HGET/HGET/HGET.ino similarity index 100% rename from examples/Arancino/06-HGET/HGET/HGET.ino rename to examples/Arancino/05-HGET/HGET/HGET.ino diff --git a/examples/Arancino/06-HGET/HGET_Packet/HGET_Packet.ino b/examples/Arancino/05-HGET/HGET_Packet/HGET_Packet.ino similarity index 100% rename from examples/Arancino/06-HGET/HGET_Packet/HGET_Packet.ino rename to examples/Arancino/05-HGET/HGET_Packet/HGET_Packet.ino diff --git a/examples/Arancino/07-HDEL/HDEL/HDEL.ino b/examples/Arancino/06-HDEL/HDEL/HDEL.ino similarity index 100% rename from examples/Arancino/07-HDEL/HDEL/HDEL.ino rename to examples/Arancino/06-HDEL/HDEL/HDEL.ino diff --git a/examples/Arancino/07-HDEL/HDEL_Packet/HDEL_Packet.ino b/examples/Arancino/06-HDEL/HDEL_Packet/HDEL_Packet.ino similarity index 100% rename from examples/Arancino/07-HDEL/HDEL_Packet/HDEL_Packet.ino rename to examples/Arancino/06-HDEL/HDEL_Packet/HDEL_Packet.ino diff --git a/examples/Arancino/08-FLUSH/FLUSH/FLUSH.ino b/examples/Arancino/07-FLUSH/FLUSH/FLUSH.ino similarity index 100% rename from examples/Arancino/08-FLUSH/FLUSH/FLUSH.ino rename to examples/Arancino/07-FLUSH/FLUSH/FLUSH.ino diff --git a/examples/Arancino/08-FLUSH/FLUSH_Packet/FLUSH_Packet.ino b/examples/Arancino/07-FLUSH/FLUSH_Packet/FLUSH_Packet.ino similarity index 100% rename from examples/Arancino/08-FLUSH/FLUSH_Packet/FLUSH_Packet.ino rename to examples/Arancino/07-FLUSH/FLUSH_Packet/FLUSH_Packet.ino diff --git a/examples/Arancino/09-PUBLISH/PUBLISH/PUBLISH.ino b/examples/Arancino/08-PUBLISH/PUBLISH/PUBLISH.ino similarity index 100% rename from examples/Arancino/09-PUBLISH/PUBLISH/PUBLISH.ino rename to examples/Arancino/08-PUBLISH/PUBLISH/PUBLISH.ino diff --git a/examples/Arancino/09-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino b/examples/Arancino/08-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino similarity index 100% rename from examples/Arancino/09-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino rename to examples/Arancino/08-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino diff --git a/examples/Arancino/10-MSET/MSET/MSET.ino b/examples/Arancino/09-MSET/MSET/MSET.ino similarity index 100% rename from examples/Arancino/10-MSET/MSET/MSET.ino rename to examples/Arancino/09-MSET/MSET/MSET.ino diff --git a/examples/Arancino/11-MGET/MGET/MGET.ino b/examples/Arancino/10-MGET/MGET/MGET.ino similarity index 100% rename from examples/Arancino/11-MGET/MGET/MGET.ino rename to examples/Arancino/10-MGET/MGET/MGET.ino diff --git a/examples/Arancino/11-MGET/MGET_Packet/MGET_Packet.ino b/examples/Arancino/10-MGET/MGET_Packet/MGET_Packet.ino similarity index 100% rename from examples/Arancino/11-MGET/MGET_Packet/MGET_Packet.ino rename to examples/Arancino/10-MGET/MGET_Packet/MGET_Packet.ino diff --git a/examples/Arancino/12-STORE/STORE/STORE.ino b/examples/Arancino/11-STORE/STORE/STORE.ino similarity index 100% rename from examples/Arancino/12-STORE/STORE/STORE.ino rename to examples/Arancino/11-STORE/STORE/STORE.ino diff --git a/examples/Arancino/12-STORE/STORE_Packet/STORE_Packet.ino b/examples/Arancino/11-STORE/STORE_Packet/STORE_Packet.ino similarity index 100% rename from examples/Arancino/12-STORE/STORE_Packet/STORE_Packet.ino rename to examples/Arancino/11-STORE/STORE_Packet/STORE_Packet.ino diff --git a/examples/Arancino/13-STORETAGS/STORETAGS/STORETAGS.ino b/examples/Arancino/12-STORETAGS/STORETAGS/STORETAGS.ino similarity index 100% rename from examples/Arancino/13-STORETAGS/STORETAGS/STORETAGS.ino rename to examples/Arancino/12-STORETAGS/STORETAGS/STORETAGS.ino diff --git a/examples/Arancino/13-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino b/examples/Arancino/12-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino similarity index 100% rename from examples/Arancino/13-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino rename to examples/Arancino/12-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino diff --git a/examples/Arancino/14-MSTORE/MSTORE/MSTORE.ino b/examples/Arancino/13-MSTORE/MSTORE/MSTORE.ino similarity index 100% rename from examples/Arancino/14-MSTORE/MSTORE/MSTORE.ino rename to examples/Arancino/13-MSTORE/MSTORE/MSTORE.ino diff --git a/examples/Arancino/14-MSTORE/MSTORE_Packet/MSTORE_Packet.ino b/examples/Arancino/13-MSTORE/MSTORE_Packet/MSTORE_Packet.ino similarity index 100% rename from examples/Arancino/14-MSTORE/MSTORE_Packet/MSTORE_Packet.ino rename to examples/Arancino/13-MSTORE/MSTORE_Packet/MSTORE_Packet.ino diff --git a/examples/Arancino/15-MQTT/MQTT/MQTT.ino b/examples/Arancino/14-MQTT/MQTT/MQTT.ino similarity index 100% rename from examples/Arancino/15-MQTT/MQTT/MQTT.ino rename to examples/Arancino/14-MQTT/MQTT/MQTT.ino diff --git a/examples/Arancino/15-MQTT/MQTT_ESP32/MQTT_ESP32.ino b/examples/Arancino/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino similarity index 100% rename from examples/Arancino/15-MQTT/MQTT_ESP32/MQTT_ESP32.ino rename to examples/Arancino/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino diff --git a/examples/Arancino/16-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino b/examples/Arancino/15-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino similarity index 100% rename from examples/Arancino/16-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino rename to examples/Arancino/15-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino diff --git a/examples/Arancino_FreeRTOS/05-HSET/HSET/HSET.ino b/examples/Arancino_FreeRTOS/04-HSET/HSET/HSET.ino similarity index 100% rename from examples/Arancino_FreeRTOS/05-HSET/HSET/HSET.ino rename to examples/Arancino_FreeRTOS/04-HSET/HSET/HSET.ino diff --git a/examples/Arancino_FreeRTOS/05-HSET/HSET_Packet/HSET_Packet.ino b/examples/Arancino_FreeRTOS/04-HSET/HSET_Packet/HSET_Packet.ino similarity index 100% rename from examples/Arancino_FreeRTOS/05-HSET/HSET_Packet/HSET_Packet.ino rename to examples/Arancino_FreeRTOS/04-HSET/HSET_Packet/HSET_Packet.ino diff --git a/examples/Arancino_FreeRTOS/06-HGET/HGET/HGET.ino b/examples/Arancino_FreeRTOS/05-HGET/HGET/HGET.ino similarity index 100% rename from examples/Arancino_FreeRTOS/06-HGET/HGET/HGET.ino rename to examples/Arancino_FreeRTOS/05-HGET/HGET/HGET.ino diff --git a/examples/Arancino_FreeRTOS/06-HGET/HGET_Packet/HGET_Packet.ino b/examples/Arancino_FreeRTOS/05-HGET/HGET_Packet/HGET_Packet.ino similarity index 100% rename from examples/Arancino_FreeRTOS/06-HGET/HGET_Packet/HGET_Packet.ino rename to examples/Arancino_FreeRTOS/05-HGET/HGET_Packet/HGET_Packet.ino diff --git a/examples/Arancino_FreeRTOS/07-HDEL/HDEL/HDEL.ino b/examples/Arancino_FreeRTOS/06-HDEL/HDEL/HDEL.ino similarity index 100% rename from examples/Arancino_FreeRTOS/07-HDEL/HDEL/HDEL.ino rename to examples/Arancino_FreeRTOS/06-HDEL/HDEL/HDEL.ino diff --git a/examples/Arancino_FreeRTOS/07-HDEL/HDEL_Packet/HDEL_Packet.ino b/examples/Arancino_FreeRTOS/06-HDEL/HDEL_Packet/HDEL_Packet.ino similarity index 100% rename from examples/Arancino_FreeRTOS/07-HDEL/HDEL_Packet/HDEL_Packet.ino rename to examples/Arancino_FreeRTOS/06-HDEL/HDEL_Packet/HDEL_Packet.ino diff --git a/examples/Arancino_FreeRTOS/08-FLUSH/FLUSH/FLUSH.ino b/examples/Arancino_FreeRTOS/07-FLUSH/FLUSH/FLUSH.ino similarity index 100% rename from examples/Arancino_FreeRTOS/08-FLUSH/FLUSH/FLUSH.ino rename to examples/Arancino_FreeRTOS/07-FLUSH/FLUSH/FLUSH.ino diff --git a/examples/Arancino_FreeRTOS/08-FLUSH/FLUSH_Packet/FLUSH_Packet.ino b/examples/Arancino_FreeRTOS/07-FLUSH/FLUSH_Packet/FLUSH_Packet.ino similarity index 100% rename from examples/Arancino_FreeRTOS/08-FLUSH/FLUSH_Packet/FLUSH_Packet.ino rename to examples/Arancino_FreeRTOS/07-FLUSH/FLUSH_Packet/FLUSH_Packet.ino diff --git a/examples/Arancino_FreeRTOS/09-PUBLISH/PUBLISH/PUBLISH.ino b/examples/Arancino_FreeRTOS/08-PUBLISH/PUBLISH/PUBLISH.ino similarity index 100% rename from examples/Arancino_FreeRTOS/09-PUBLISH/PUBLISH/PUBLISH.ino rename to examples/Arancino_FreeRTOS/08-PUBLISH/PUBLISH/PUBLISH.ino diff --git a/examples/Arancino_FreeRTOS/09-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino b/examples/Arancino_FreeRTOS/08-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino similarity index 100% rename from examples/Arancino_FreeRTOS/09-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino rename to examples/Arancino_FreeRTOS/08-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino diff --git a/examples/Arancino_FreeRTOS/10-MSET/MSET/MSET.ino b/examples/Arancino_FreeRTOS/09-MSET/MSET/MSET.ino similarity index 100% rename from examples/Arancino_FreeRTOS/10-MSET/MSET/MSET.ino rename to examples/Arancino_FreeRTOS/09-MSET/MSET/MSET.ino diff --git a/examples/Arancino_FreeRTOS/11-MGET/MGET/MGET.ino b/examples/Arancino_FreeRTOS/10-MGET/MGET/MGET.ino similarity index 100% rename from examples/Arancino_FreeRTOS/11-MGET/MGET/MGET.ino rename to examples/Arancino_FreeRTOS/10-MGET/MGET/MGET.ino diff --git a/examples/Arancino_FreeRTOS/11-MGET/MGET_Packet/MGET_Packet.ino b/examples/Arancino_FreeRTOS/10-MGET/MGET_Packet/MGET_Packet.ino similarity index 100% rename from examples/Arancino_FreeRTOS/11-MGET/MGET_Packet/MGET_Packet.ino rename to examples/Arancino_FreeRTOS/10-MGET/MGET_Packet/MGET_Packet.ino diff --git a/examples/Arancino_FreeRTOS/12-STORE/STORE/STORE.ino b/examples/Arancino_FreeRTOS/11-STORE/STORE/STORE.ino similarity index 100% rename from examples/Arancino_FreeRTOS/12-STORE/STORE/STORE.ino rename to examples/Arancino_FreeRTOS/11-STORE/STORE/STORE.ino diff --git a/examples/Arancino_FreeRTOS/12-STORE/STORE_Packet/STORE_Packet.ino b/examples/Arancino_FreeRTOS/11-STORE/STORE_Packet/STORE_Packet.ino similarity index 100% rename from examples/Arancino_FreeRTOS/12-STORE/STORE_Packet/STORE_Packet.ino rename to examples/Arancino_FreeRTOS/11-STORE/STORE_Packet/STORE_Packet.ino diff --git a/examples/Arancino_FreeRTOS/13-STORETAGS/STORETAGS/STORETAGS.ino b/examples/Arancino_FreeRTOS/12-STORETAGS/STORETAGS/STORETAGS.ino similarity index 100% rename from examples/Arancino_FreeRTOS/13-STORETAGS/STORETAGS/STORETAGS.ino rename to examples/Arancino_FreeRTOS/12-STORETAGS/STORETAGS/STORETAGS.ino diff --git a/examples/Arancino_FreeRTOS/13-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino b/examples/Arancino_FreeRTOS/12-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino similarity index 100% rename from examples/Arancino_FreeRTOS/13-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino rename to examples/Arancino_FreeRTOS/12-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino diff --git a/examples/Arancino_FreeRTOS/14-MSTORE/MSTORE/MSTORE.ino b/examples/Arancino_FreeRTOS/13-MSTORE/MSTORE/MSTORE.ino similarity index 100% rename from examples/Arancino_FreeRTOS/14-MSTORE/MSTORE/MSTORE.ino rename to examples/Arancino_FreeRTOS/13-MSTORE/MSTORE/MSTORE.ino diff --git a/examples/Arancino_FreeRTOS/14-MSTORE/MSTORE_Packet/MSTORE_Packet.ino b/examples/Arancino_FreeRTOS/13-MSTORE/MSTORE_Packet/MSTORE_Packet.ino similarity index 100% rename from examples/Arancino_FreeRTOS/14-MSTORE/MSTORE_Packet/MSTORE_Packet.ino rename to examples/Arancino_FreeRTOS/13-MSTORE/MSTORE_Packet/MSTORE_Packet.ino diff --git a/examples/Arancino_FreeRTOS/15-MQTT/MQTT/MQTT.ino b/examples/Arancino_FreeRTOS/14-MQTT/MQTT/MQTT.ino similarity index 100% rename from examples/Arancino_FreeRTOS/15-MQTT/MQTT/MQTT.ino rename to examples/Arancino_FreeRTOS/14-MQTT/MQTT/MQTT.ino diff --git a/examples/Arancino_FreeRTOS/15-MQTT/MQTT_ESP32/MQTT_ESP32.ino b/examples/Arancino_FreeRTOS/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino similarity index 100% rename from examples/Arancino_FreeRTOS/15-MQTT/MQTT_ESP32/MQTT_ESP32.ino rename to examples/Arancino_FreeRTOS/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino diff --git a/examples/Arancino_FreeRTOS/16-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino b/examples/Arancino_FreeRTOS/15-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino similarity index 100% rename from examples/Arancino_FreeRTOS/16-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino rename to examples/Arancino_FreeRTOS/15-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino From e18b25f31557f5d3914fa8b81008f6a27b54240d Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Tue, 28 Mar 2023 10:24:46 +0200 Subject: [PATCH 55/69] Updated CHANGELOG --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a14e767..4618531 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +#### v 3.1.0 - 2023.x.x +* Upd: Implemented new Cortex protocol [#1jdx7ak] (https://app.clickup.com/t/1jdx7ak) +* Add: Added support to ESP32 [#863gbd6ym] (https://app.clickup.com/t/863gbd6ym) +* Add: Added support to NRF52 [#863gbd74b] (https://app.clickup.com/t/863gbd74b) +* Upd: Increased Serial timeout [#33kn3c2] (https://app.clickup.com/t/33kn3c2) +* Upd: Renamed task GetBlinkId [#31ewyzv] (https://app.clickup.com/t/31ewyzv) +* Upd: Updated examples [#23n7teq] (https://app.clickup.com/t/23n7teq) +* Upd: Manage new DB instance for configuration keys [#23fqct7] (https://app.clickup.com/t/23fqct7) +* Upd: Introduced ACK in `SET` methods [#23fpyp2] (https://app.clickup.com/t/23fpyp2) +* Upd: Service functions in a single task [#861mjudeh] (https://app.clickup.com/t/861mjudeh) +* Upd: Ifaces adapted to new protocol [#861mjue8p] (https://app.clickup.com/t/861mjue8p) +* Upd: Fixed warnings in `const char*` conversion [#863gbd62q] (https://app.clickup.com/t/863gbd62q) + #### v 3.0.0 - 2022.10.10 * Add: added interface system with MQTT and BLE_UART communication mediums [#1nwtwna] * Upd: improved debug messages handling [#1ww0cnr] From 33729c48b048665cbd0414088d3289be4998cf49 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Tue, 28 Mar 2023 10:55:09 +0200 Subject: [PATCH 56/69] Fixed typos in CHANGELOG --- CHANGELOG.md | 58 ++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4618531..2e8657a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,17 +1,17 @@ # Changelog #### v 3.1.0 - 2023.x.x -* Upd: Implemented new Cortex protocol [#1jdx7ak] (https://app.clickup.com/t/1jdx7ak) -* Add: Added support to ESP32 [#863gbd6ym] (https://app.clickup.com/t/863gbd6ym) -* Add: Added support to NRF52 [#863gbd74b] (https://app.clickup.com/t/863gbd74b) -* Upd: Increased Serial timeout [#33kn3c2] (https://app.clickup.com/t/33kn3c2) -* Upd: Renamed task GetBlinkId [#31ewyzv] (https://app.clickup.com/t/31ewyzv) -* Upd: Updated examples [#23n7teq] (https://app.clickup.com/t/23n7teq) -* Upd: Manage new DB instance for configuration keys [#23fqct7] (https://app.clickup.com/t/23fqct7) -* Upd: Introduced ACK in `SET` methods [#23fpyp2] (https://app.clickup.com/t/23fpyp2) -* Upd: Service functions in a single task [#861mjudeh] (https://app.clickup.com/t/861mjudeh) -* Upd: Ifaces adapted to new protocol [#861mjue8p] (https://app.clickup.com/t/861mjue8p) -* Upd: Fixed warnings in `const char*` conversion [#863gbd62q] (https://app.clickup.com/t/863gbd62q) +* Upd: Implemented new Cortex protocol [#1jdx7ak](https://app.clickup.com/t/1jdx7ak) +* Add: Added support to ESP32 [#863gbd6ym](https://app.clickup.com/t/863gbd6ym) +* Add: Added support to NRF52 [#863gbd74b](https://app.clickup.com/t/863gbd74b) +* Upd: Increased Serial timeout [#33kn3c2](https://app.clickup.com/t/33kn3c2) +* Upd: Renamed task GetBlinkId [#31ewyzv](https://app.clickup.com/t/31ewyzv) +* Upd: Updated examples [#23n7teq](https://app.clickup.com/t/23n7teq) +* Upd: Manage new DB instance for configuration keys [#23fqct7](https://app.clickup.com/t/23fqct7) +* Upd: Introduced ACK in `SET` methods [#23fpyp2](https://app.clickup.com/t/23fpyp2) +* Upd: Service functions in a single task [#861mjudeh](https://app.clickup.com/t/861mjudeh) +* Upd: Ifaces adapted to new protocol [#861mjue8p](https://app.clickup.com/t/861mjue8p) +* Upd: Fixed warnings in `const char*` conversion [#863gbd62q](https://app.clickup.com/t/863gbd62q) #### v 3.0.0 - 2022.10.10 * Add: added interface system with MQTT and BLE_UART communication mediums [#1nwtwna] @@ -25,32 +25,32 @@ * Fix: fixed an error in STORE_packet example #### v 2.1.0 - 2022.07.29 -* Upd: ERR_GENERIC was redefined as ERR [#1jz91mu] (https://app.clickup.com/t/1jz91mu) -* Upd: ID_PREFIX removed from `store`, `mstore` and `storeTags` commands [#23v2xn3] (https://app.clickup.com/t/23v2xn3) -* Add: added executeCommandFast command [#394mek4] (https://app.clickup.com/t/394mek4) -* Add: added `mstore` with timestamp argument [#394memb] (https://app.clickup.com/t/394memb) +* Upd: ERR_GENERIC was redefined as ERR [#1jz91mu](https://app.clickup.com/t/1jz91mu) +* Upd: ID_PREFIX removed from `store`, `mstore` and `storeTags` commands [#23v2xn3](https://app.clickup.com/t/23v2xn3) +* Add: added executeCommandFast command [#394mek4](https://app.clickup.com/t/394mek4) +* Add: added `mstore` with timestamp argument [#394memb](https://app.clickup.com/t/394memb) #### v 2.0.1 - 2022.05.27 -* Fix: bug debug for arancino mignon board. [#2g4fxvx] (https://app.clickup.com/t/2g4fxvx) +* Fix: bug debug for arancino mignon board. [#2g4fxvx](https://app.clickup.com/t/2g4fxvx) #### v 2.0.0 - 2022.01.17 -* Upd: updated unit test examples. [#1uqbjbp] (https://app.clickup.com/t/1uqbjbp) -* Add: added useFreeRtos parameter in `start` command. [#1vht0nc] (https://app.clickup.com/t/1vht0nc) -* Fix: bug into `deviceIdentification` task. [#1w8qx9m] (https://app.clickup.com/t/1w8qx9m) -* Add: added examples wthout freeRtos. [#1vhrhj2] (https://app.clickup.com/t/1vhrhj2) -* Fix: read internal temperature for STM32. [#pbbnm1] (https://app.clickup.com/t/pbbnm1) -* Udp: code revision. [#j58vz6] (https://app.clickup.com/t/j58vz6) -* Udp: examples revision. [#jd3yjq] (https://app.clickup.com/t/jd3yjq) -* Add: read internal temperature for STM32. [#pbbnm1] (https://app.clickup.com/t/pbbnm1) +* Upd: updated unit test examples. [#1uqbjbp](https://app.clickup.com/t/1uqbjbp) +* Add: added useFreeRtos parameter in `start` command. [#1vht0nc](https://app.clickup.com/t/1vht0nc) +* Fix: bug into `deviceIdentification` task. [#1w8qx9m](https://app.clickup.com/t/1w8qx9m) +* Add: added examples wthout freeRtos. [#1vhrhj2](https://app.clickup.com/t/1vhrhj2) +* Fix: read internal temperature for STM32. [#pbbnm1](https://app.clickup.com/t/pbbnm1) +* Udp: code revision. [#j58vz6](https://app.clickup.com/t/j58vz6) +* Udp: examples revision. [#jd3yjq](https://app.clickup.com/t/jd3yjq) +* Add: read internal temperature for STM32. [#pbbnm1](https://app.clickup.com/t/pbbnm1) * Add: Arduino `loop` as FreeRtos task. [#p59vhb](https://app.clickup.com/t/p59vhb) * Fix: fixed bug with float and double using FreeRtos. [#n990qu](https://app.clickup.com/t/n990qu) * Add: added interocep function. [#d2x5yt](https://app.clickup.com/t/d2x5yt) * Add: added `setReserved` function. [#n1amcu](https://app.clickup.com/t/n1amcu) -* Upd: removed deprecated arguments on the `begin` function. [fb6jve] (https://app.clickup.com/t/fb6jve) -* Upd: removed `metadata` function. [fb6hyw] (https://app.clickup.com/t/fb6hyw) -* Upd: removed check on reserved command. [fv2dmy] (https://app.clickup.com/t/fv2dmy) -* Upd: updated sync/async mode. [fd59jj] (https://app.clickup.com/t/fd59jj) -* Add: added persistent mode to `mset` and `hset` function. [aex4by] (https://app.clickup.com/t/aex4by) +* Upd: removed deprecated arguments on the `begin` function. [fb6jve](https://app.clickup.com/t/fb6jve) +* Upd: removed `metadata` function. [fb6hyw](https://app.clickup.com/t/fb6hyw) +* Upd: removed check on reserved command. [fv2dmy](https://app.clickup.com/t/fv2dmy) +* Upd: updated sync/async mode. [fd59jj](https://app.clickup.com/t/fd59jj) +* Add: added persistent mode to `mset` and `hset` function. [aex4by](https://app.clickup.com/t/aex4by) * Add: added `getReserved` function. [g31n4z](https://app.clickup.com/t/g31n4z) * Add: added `store` function. [#gk4cn8](https://app.clickup.com/t/gk4cn8) * Add: added `storetags` function. [#hf2fg6](https://app.clickup.com/t/hf2fg6) From 55668716b231aab658bd6c8d000ac147d2069fa0 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Thu, 30 Mar 2023 10:15:37 +0200 Subject: [PATCH 57/69] Forced cast to bool in DeserializationError --- src/ArancinoInterface.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index 7792118..4c78f70 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -136,7 +136,7 @@ bool SerialIface::receiveArancinoResponse(JsonDocument& response){ if (error){ this->comm_timeout = true; } - return error; + return (bool)error; } @@ -234,7 +234,7 @@ bool MqttIface::receiveArancinoResponse(JsonDocument& response){ if (_newIncomingMessage) { - error = deserializeMsgPack(response, (const char*)this->_payload, this->_length); + error = (bool)deserializeMsgPack(response, (const char*)this->_payload, this->_length); _newIncomingMessage = false; } @@ -318,7 +318,7 @@ bool BluetoothIface::receiveArancinoResponse(JsonDocument& response){ { error = deserializeMsgPack(response, *_bleSerial); } - while (error != 0 && millis() < startMillis + TIMEOUT); + while (error != DeserializationError::Ok && millis() < startMillis + TIMEOUT); if(error){ if (++_timeoutCounter == BLUETOOTH_MAX_RETRIES){ @@ -329,5 +329,5 @@ bool BluetoothIface::receiveArancinoResponse(JsonDocument& response){ _timeoutCounter = 0; } - return error; + return (bool)error; } \ No newline at end of file From afe6c9102d1a3396fe8791f8830f83cc3a5f1058 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Thu, 30 Mar 2023 13:24:36 +0200 Subject: [PATCH 58/69] Renamed task in FreeRTOS examples because of a conflict with ESP32 task --- examples/Arancino_FreeRTOS/01-SET/SET/SET.ino | 8 ++++---- .../Arancino_FreeRTOS/01-SET/SET_Packet/SET_Packet.ino | 8 ++++---- .../01-SET/SET_Persistent/SET_Persistent.ino | 6 +++--- examples/Arancino_FreeRTOS/02-GET/GET/GET.ino | 8 ++++---- .../Arancino_FreeRTOS/02-GET/GET_Packet/GET_Packet.ino | 8 ++++---- examples/Arancino_FreeRTOS/03-DEL/DEL/DEL.ino | 8 ++++---- .../Arancino_FreeRTOS/03-DEL/DEL_Packet/DEL_Packet.ino | 8 ++++---- examples/Arancino_FreeRTOS/04-HSET/HSET/HSET.ino | 8 ++++---- .../Arancino_FreeRTOS/04-HSET/HSET_Packet/HSET_Packet.ino | 8 ++++---- examples/Arancino_FreeRTOS/05-HGET/HGET/HGET.ino | 8 ++++---- .../Arancino_FreeRTOS/05-HGET/HGET_Packet/HGET_Packet.ino | 8 ++++---- examples/Arancino_FreeRTOS/06-HDEL/HDEL/HDEL.ino | 8 ++++---- .../Arancino_FreeRTOS/06-HDEL/HDEL_Packet/HDEL_Packet.ino | 8 ++++---- examples/Arancino_FreeRTOS/07-FLUSH/FLUSH/FLUSH.ino | 8 ++++---- .../07-FLUSH/FLUSH_Packet/FLUSH_Packet.ino | 8 ++++---- examples/Arancino_FreeRTOS/08-PUBLISH/PUBLISH/PUBLISH.ino | 8 ++++---- .../08-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino | 8 ++++---- examples/Arancino_FreeRTOS/09-MSET/MSET/MSET.ino | 8 ++++---- examples/Arancino_FreeRTOS/10-MGET/MGET/MGET.ino | 8 ++++---- .../Arancino_FreeRTOS/10-MGET/MGET_Packet/MGET_Packet.ino | 8 ++++---- examples/Arancino_FreeRTOS/11-STORE/STORE/STORE.ino | 8 ++++---- .../11-STORE/STORE_Packet/STORE_Packet.ino | 8 ++++---- .../12-STORETAGS/STORETAGS/STORETAGS.ino | 8 ++++---- .../12-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino | 8 ++++---- examples/Arancino_FreeRTOS/13-MSTORE/MSTORE/MSTORE.ino | 8 ++++---- .../13-MSTORE/MSTORE_Packet/MSTORE_Packet.ino | 8 ++++---- examples/Arancino_FreeRTOS/14-MQTT/MQTT/MQTT.ino | 8 ++++---- .../15-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino | 8 ++++---- .../CS_1-Sample_Sensor/CS_1-Sample_Sensor.ino | 8 ++++---- .../CS_2-Smart_Light/CS_2-Smart_Light.ino | 8 ++++---- 30 files changed, 119 insertions(+), 119 deletions(-) diff --git a/examples/Arancino_FreeRTOS/01-SET/SET/SET.ino b/examples/Arancino_FreeRTOS/01-SET/SET/SET.ino index 02978ec..b3db266 100644 --- a/examples/Arancino_FreeRTOS/01-SET/SET/SET.ino +++ b/examples/Arancino_FreeRTOS/01-SET/SET/SET.ino @@ -54,8 +54,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -83,7 +83,7 @@ void setup() { //sets the value 123.456 into the 'baz' key Arancino.set(key3, value3); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -92,7 +92,7 @@ void loop() { //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ //do something } diff --git a/examples/Arancino_FreeRTOS/01-SET/SET_Packet/SET_Packet.ino b/examples/Arancino_FreeRTOS/01-SET/SET_Packet/SET_Packet.ino index feb4b67..2257524 100644 --- a/examples/Arancino_FreeRTOS/01-SET/SET_Packet/SET_Packet.ino +++ b/examples/Arancino_FreeRTOS/01-SET/SET_Packet/SET_Packet.ino @@ -52,8 +52,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -84,7 +84,7 @@ void setup() { Arancino.free(apckt); //delete packet from memory - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -92,7 +92,7 @@ void loop() { //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ //do something } diff --git a/examples/Arancino_FreeRTOS/01-SET/SET_Persistent/SET_Persistent.ino b/examples/Arancino_FreeRTOS/01-SET/SET_Persistent/SET_Persistent.ino index 22d687a..49d03b2 100644 --- a/examples/Arancino_FreeRTOS/01-SET/SET_Persistent/SET_Persistent.ino +++ b/examples/Arancino_FreeRTOS/01-SET/SET_Persistent/SET_Persistent.ino @@ -52,8 +52,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -67,7 +67,7 @@ void setup() { Arancino.set("EX_01_3_key_4", "bar", NULL); //volatile key Arancino.set("EX_01_3_key_5", "bar"); //volatile key - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } diff --git a/examples/Arancino_FreeRTOS/02-GET/GET/GET.ino b/examples/Arancino_FreeRTOS/02-GET/GET/GET.ino index 277bc26..a06786c 100644 --- a/examples/Arancino_FreeRTOS/02-GET/GET/GET.ino +++ b/examples/Arancino_FreeRTOS/02-GET/GET/GET.ino @@ -43,8 +43,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -59,7 +59,7 @@ void setup() { Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -68,7 +68,7 @@ void loop(){ //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ //sets the value 'bar' into the 'foo' key Arancino.set("EX_02_1","bar"); diff --git a/examples/Arancino_FreeRTOS/02-GET/GET_Packet/GET_Packet.ino b/examples/Arancino_FreeRTOS/02-GET/GET_Packet/GET_Packet.ino index 4be36c5..bc381c5 100644 --- a/examples/Arancino_FreeRTOS/02-GET/GET_Packet/GET_Packet.ino +++ b/examples/Arancino_FreeRTOS/02-GET/GET_Packet/GET_Packet.ino @@ -46,8 +46,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -62,7 +62,7 @@ void setup() { Arancino.begin(amdata); //create a task for loop - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -71,7 +71,7 @@ void loop(){ //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ //sets the value 'bar' into the 'foo' key Arancino.set("EX_02_2_foo","bar"); diff --git a/examples/Arancino_FreeRTOS/03-DEL/DEL/DEL.ino b/examples/Arancino_FreeRTOS/03-DEL/DEL/DEL.ino index 5e26f98..49fac66 100644 --- a/examples/Arancino_FreeRTOS/03-DEL/DEL/DEL.ino +++ b/examples/Arancino_FreeRTOS/03-DEL/DEL/DEL.ino @@ -43,8 +43,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { iface.setSerialPort(); @@ -61,7 +61,7 @@ void setup() { num = Arancino.del("EX_03_1_foo"); Arancino.println(num ? "Key deleted" : "Key not found"); //1 - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -69,7 +69,7 @@ void loop() { //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ //do something } diff --git a/examples/Arancino_FreeRTOS/03-DEL/DEL_Packet/DEL_Packet.ino b/examples/Arancino_FreeRTOS/03-DEL/DEL_Packet/DEL_Packet.ino index ed126fb..5923cff 100644 --- a/examples/Arancino_FreeRTOS/03-DEL/DEL_Packet/DEL_Packet.ino +++ b/examples/Arancino_FreeRTOS/03-DEL/DEL_Packet/DEL_Packet.ino @@ -45,8 +45,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -92,7 +92,7 @@ void setup() { Arancino.free(apckt); //delete packet from memory - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -101,7 +101,7 @@ void loop(){ //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ //do something } diff --git a/examples/Arancino_FreeRTOS/04-HSET/HSET/HSET.ino b/examples/Arancino_FreeRTOS/04-HSET/HSET/HSET.ino index 8c83c1f..750b0f5 100644 --- a/examples/Arancino_FreeRTOS/04-HSET/HSET/HSET.ino +++ b/examples/Arancino_FreeRTOS/04-HSET/HSET/HSET.ino @@ -51,8 +51,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -63,7 +63,7 @@ void setup() { Arancino.hset("ex05_foo","bar","yeah"); Arancino.hset("ex05_foo","bar","whoo"); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -72,7 +72,7 @@ void loop() { //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ //do something } diff --git a/examples/Arancino_FreeRTOS/04-HSET/HSET_Packet/HSET_Packet.ino b/examples/Arancino_FreeRTOS/04-HSET/HSET_Packet/HSET_Packet.ino index e49d5f3..4e2da4b 100644 --- a/examples/Arancino_FreeRTOS/04-HSET/HSET_Packet/HSET_Packet.ino +++ b/examples/Arancino_FreeRTOS/04-HSET/HSET_Packet/HSET_Packet.ino @@ -48,8 +48,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -76,7 +76,7 @@ void setup() { Arancino.free(apckt); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -84,7 +84,7 @@ void loop() { //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ //do something } diff --git a/examples/Arancino_FreeRTOS/05-HGET/HGET/HGET.ino b/examples/Arancino_FreeRTOS/05-HGET/HGET/HGET.ino index e38b1bc..fbb1516 100644 --- a/examples/Arancino_FreeRTOS/05-HGET/HGET/HGET.ino +++ b/examples/Arancino_FreeRTOS/05-HGET/HGET/HGET.ino @@ -46,8 +46,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -60,7 +60,7 @@ void setup() { Arancino.hset("EX_06_1_foo","bar","yeah"); Arancino.hset("EX_06_1_foo","baz","whoo"); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -69,7 +69,7 @@ void loop(){ //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ char* value = Arancino.hget("EX_06_1_foo","bar"); Arancino.print("foo bar -> "); diff --git a/examples/Arancino_FreeRTOS/05-HGET/HGET_Packet/HGET_Packet.ino b/examples/Arancino_FreeRTOS/05-HGET/HGET_Packet/HGET_Packet.ino index e37376d..0d3d9fd 100644 --- a/examples/Arancino_FreeRTOS/05-HGET/HGET_Packet/HGET_Packet.ino +++ b/examples/Arancino_FreeRTOS/05-HGET/HGET_Packet/HGET_Packet.ino @@ -47,8 +47,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -61,7 +61,7 @@ void setup() { Arancino.hset("EX_06_2_foo","bar","yeah"); Arancino.hset("EX_06_2_foo","baz","whoo"); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -70,7 +70,7 @@ void loop(){ //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ ArancinoPacket apckt = Arancino.hget("EX_06_2_foo", "baz"); diff --git a/examples/Arancino_FreeRTOS/06-HDEL/HDEL/HDEL.ino b/examples/Arancino_FreeRTOS/06-HDEL/HDEL/HDEL.ino index 1f9b9b0..8a6a257 100644 --- a/examples/Arancino_FreeRTOS/06-HDEL/HDEL/HDEL.ino +++ b/examples/Arancino_FreeRTOS/06-HDEL/HDEL/HDEL.ino @@ -47,8 +47,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -69,7 +69,7 @@ void setup() { Arancino.free(str); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -78,7 +78,7 @@ void loop() { //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ //do something } diff --git a/examples/Arancino_FreeRTOS/06-HDEL/HDEL_Packet/HDEL_Packet.ino b/examples/Arancino_FreeRTOS/06-HDEL/HDEL_Packet/HDEL_Packet.ino index 9e9baa8..a7c1b0b 100644 --- a/examples/Arancino_FreeRTOS/06-HDEL/HDEL_Packet/HDEL_Packet.ino +++ b/examples/Arancino_FreeRTOS/06-HDEL/HDEL_Packet/HDEL_Packet.ino @@ -45,8 +45,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -78,7 +78,7 @@ void setup() { Arancino.free(apckt); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -86,7 +86,7 @@ void loop() { //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ //do something } diff --git a/examples/Arancino_FreeRTOS/07-FLUSH/FLUSH/FLUSH.ino b/examples/Arancino_FreeRTOS/07-FLUSH/FLUSH/FLUSH.ino index 91007d7..03e4a4d 100644 --- a/examples/Arancino_FreeRTOS/07-FLUSH/FLUSH/FLUSH.ino +++ b/examples/Arancino_FreeRTOS/07-FLUSH/FLUSH/FLUSH.ino @@ -42,8 +42,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -58,7 +58,7 @@ void setup() { //delete all the keys Arancino.flush(); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -67,7 +67,7 @@ void loop() { //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ //do something } diff --git a/examples/Arancino_FreeRTOS/07-FLUSH/FLUSH_Packet/FLUSH_Packet.ino b/examples/Arancino_FreeRTOS/07-FLUSH/FLUSH_Packet/FLUSH_Packet.ino index de31c17..37073ae 100644 --- a/examples/Arancino_FreeRTOS/07-FLUSH/FLUSH_Packet/FLUSH_Packet.ino +++ b/examples/Arancino_FreeRTOS/07-FLUSH/FLUSH_Packet/FLUSH_Packet.ino @@ -42,8 +42,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -72,7 +72,7 @@ void setup() { Arancino.free(apckt); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -81,7 +81,7 @@ void loop() { //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ //do something } diff --git a/examples/Arancino_FreeRTOS/08-PUBLISH/PUBLISH/PUBLISH.ino b/examples/Arancino_FreeRTOS/08-PUBLISH/PUBLISH/PUBLISH.ino index bf66fe9..c244531 100644 --- a/examples/Arancino_FreeRTOS/08-PUBLISH/PUBLISH/PUBLISH.ino +++ b/examples/Arancino_FreeRTOS/08-PUBLISH/PUBLISH/PUBLISH.ino @@ -48,8 +48,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -71,7 +71,7 @@ void setup() { //publish the value 123.456 into the 'EX_12_1_channel3' channel Arancino.publish(channel3, message3); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -80,7 +80,7 @@ void loop(){ //empty } -void loopTask(void *pvParameters) { +void customLoopTask(void *pvParameters) { while(1){ char* channel1 = "EX_12_1_channel1"; char* message1 = "hooray"; diff --git a/examples/Arancino_FreeRTOS/08-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino b/examples/Arancino_FreeRTOS/08-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino index f57a867..a4ffc1f 100644 --- a/examples/Arancino_FreeRTOS/08-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino +++ b/examples/Arancino_FreeRTOS/08-PUBLISH/PUBLISH_Packet/PUBLISH_Packet.ino @@ -47,8 +47,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -58,7 +58,7 @@ void setup() { Arancino.enableDebugMessages(); Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -67,7 +67,7 @@ void loop(){ //empty } -void loopTask(void *pvParameters) { +void customLoopTask(void *pvParameters) { while(1){ ArancinoPacket apckt = Arancino.publish("EX_12_2","Hello from Arancino"); if (!apckt.isError){ diff --git a/examples/Arancino_FreeRTOS/09-MSET/MSET/MSET.ino b/examples/Arancino_FreeRTOS/09-MSET/MSET/MSET.ino index 801a606..f62a915 100644 --- a/examples/Arancino_FreeRTOS/09-MSET/MSET/MSET.ino +++ b/examples/Arancino_FreeRTOS/09-MSET/MSET/MSET.ino @@ -54,8 +54,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); char* keys[] = {"EX_13_1_foo1", "EX_13_1_foo2", "EX_13_1_foo3"}; char* values[] = {"value1", "value2", "value3"}; @@ -87,7 +87,7 @@ void setup(){ Arancino.free(apckt); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -96,7 +96,7 @@ void loop() { //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ //do something } diff --git a/examples/Arancino_FreeRTOS/10-MGET/MGET/MGET.ino b/examples/Arancino_FreeRTOS/10-MGET/MGET/MGET.ino index c85aab7..9d02274 100644 --- a/examples/Arancino_FreeRTOS/10-MGET/MGET/MGET.ino +++ b/examples/Arancino_FreeRTOS/10-MGET/MGET/MGET.ino @@ -53,8 +53,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); char* keys[] = {"EX_14_1_foo1", "EX_14_1_foo2", "EX_14_1_foo3"}; @@ -69,7 +69,7 @@ void setup() { Arancino.set("EX_14_1_foo1", "a"); Arancino.set("EX_14_1_foo3", "c"); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); @@ -79,7 +79,7 @@ void loop(){ //empty } -void loopTask(void *pvParameters) { +void customLoopTask(void *pvParameters) { while(1){ char** result = Arancino.mget(keys, 3); diff --git a/examples/Arancino_FreeRTOS/10-MGET/MGET_Packet/MGET_Packet.ino b/examples/Arancino_FreeRTOS/10-MGET/MGET_Packet/MGET_Packet.ino index d522f0d..2f434a3 100644 --- a/examples/Arancino_FreeRTOS/10-MGET/MGET_Packet/MGET_Packet.ino +++ b/examples/Arancino_FreeRTOS/10-MGET/MGET_Packet/MGET_Packet.ino @@ -55,8 +55,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); char* keys[] = {"EX_14_2_foo1", "EX_14_2_foo2", "EX_14_2_foo3"}; @@ -72,7 +72,7 @@ void setup() { Arancino.set("EX_14_2_foo2", "b"); Arancino.set("EX_14_2_foo3", "c"); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -81,7 +81,7 @@ void loop(){ //empty } -void loopTask(void *pvParameters) { +void customLoopTask(void *pvParameters) { while(1){ ArancinoPacket apckt = Arancino.mget(keys, 3); diff --git a/examples/Arancino_FreeRTOS/11-STORE/STORE/STORE.ino b/examples/Arancino_FreeRTOS/11-STORE/STORE/STORE.ino index 4ceb315..debc539 100644 --- a/examples/Arancino_FreeRTOS/11-STORE/STORE/STORE.ino +++ b/examples/Arancino_FreeRTOS/11-STORE/STORE/STORE.ino @@ -48,8 +48,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -59,7 +59,7 @@ void setup() { Arancino.enableDebugMessages(); Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -67,7 +67,7 @@ void loop(){ //empty } -void loopTask(void *pvParameters) { +void customLoopTask(void *pvParameters) { while(1){ //do something char* key1 = "EX_sample_1"; diff --git a/examples/Arancino_FreeRTOS/11-STORE/STORE_Packet/STORE_Packet.ino b/examples/Arancino_FreeRTOS/11-STORE/STORE_Packet/STORE_Packet.ino index 53fec51..47ed355 100644 --- a/examples/Arancino_FreeRTOS/11-STORE/STORE_Packet/STORE_Packet.ino +++ b/examples/Arancino_FreeRTOS/11-STORE/STORE_Packet/STORE_Packet.ino @@ -50,8 +50,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -61,7 +61,7 @@ void setup() { Arancino.enableDebugMessages(); Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -70,7 +70,7 @@ void loop(){ //empty } -void loopTask(void *pvParameters) { +void customLoopTask(void *pvParameters) { while(1){ char* key1 = "EX_sample_1"; int sample1 = random(0,10); diff --git a/examples/Arancino_FreeRTOS/12-STORETAGS/STORETAGS/STORETAGS.ino b/examples/Arancino_FreeRTOS/12-STORETAGS/STORETAGS/STORETAGS.ino index 3c81f1f..9a92aee 100644 --- a/examples/Arancino_FreeRTOS/12-STORETAGS/STORETAGS/STORETAGS.ino +++ b/examples/Arancino_FreeRTOS/12-STORETAGS/STORETAGS/STORETAGS.ino @@ -44,8 +44,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); char* key = "EX_sample_1"; char* tags[] = {"EX_tags_1", "EX_tags_2", "EX_tags_3"}; @@ -57,7 +57,7 @@ void setup() { Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -65,7 +65,7 @@ void loop(){ //empty } -void loopTask(void *pvParameters) { +void customLoopTask(void *pvParameters) { while(1){ int val1 = random(1,10); float val2 = random(150.00,350.00)/13.00; diff --git a/examples/Arancino_FreeRTOS/12-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino b/examples/Arancino_FreeRTOS/12-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino index 1399c11..20b511b 100644 --- a/examples/Arancino_FreeRTOS/12-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino +++ b/examples/Arancino_FreeRTOS/12-STORETAGS/STORETAGS_Packet/STORETAGS_Packet.ino @@ -49,8 +49,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); char* key = "EX_sample_1"; char* tags[] = {"EX_tags_1", "EX_tags_2", "EX_tags_3"}; @@ -63,7 +63,7 @@ void setup() { Arancino.enableDebugMessages(); Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -71,7 +71,7 @@ void loop(){ //empty } -void loopTask(void *pvParameters) { +void customLoopTask(void *pvParameters) { while(1){ int val1 = random(1,10); float val2 = random(150.00,350.00)/13.00; diff --git a/examples/Arancino_FreeRTOS/13-MSTORE/MSTORE/MSTORE.ino b/examples/Arancino_FreeRTOS/13-MSTORE/MSTORE/MSTORE.ino index 1395e39..d6e3807 100644 --- a/examples/Arancino_FreeRTOS/13-MSTORE/MSTORE/MSTORE.ino +++ b/examples/Arancino_FreeRTOS/13-MSTORE/MSTORE/MSTORE.ino @@ -45,8 +45,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); char* keys[] = {"EX_sample_foo1", "EX_sample_foo2", "EX_sample_foo3"}; @@ -58,7 +58,7 @@ void setup(){ Arancino.enableDebugMessages(); Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -67,7 +67,7 @@ void loop() { //void } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ int val1 = random(1,10); float val2 = random(150,350)/13.00; diff --git a/examples/Arancino_FreeRTOS/13-MSTORE/MSTORE_Packet/MSTORE_Packet.ino b/examples/Arancino_FreeRTOS/13-MSTORE/MSTORE_Packet/MSTORE_Packet.ino index cff8f7a..4dcbc11 100644 --- a/examples/Arancino_FreeRTOS/13-MSTORE/MSTORE_Packet/MSTORE_Packet.ino +++ b/examples/Arancino_FreeRTOS/13-MSTORE/MSTORE_Packet/MSTORE_Packet.ino @@ -49,8 +49,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); char* keys[] = {"EX_sample_foo1", "EX_sample_foo2", "EX_sample_foo3"}; @@ -62,7 +62,7 @@ void setup(){ Arancino.enableDebugMessages(); Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -71,7 +71,7 @@ void loop() { //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ int val1 = random(1,10); float val2 = random(150,350)/13.00; diff --git a/examples/Arancino_FreeRTOS/14-MQTT/MQTT/MQTT.ino b/examples/Arancino_FreeRTOS/14-MQTT/MQTT/MQTT.ino index 85be504..5b7da47 100644 --- a/examples/Arancino_FreeRTOS/14-MQTT/MQTT/MQTT.ino +++ b/examples/Arancino_FreeRTOS/14-MQTT/MQTT/MQTT.ino @@ -45,8 +45,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -70,7 +70,7 @@ void setup() Arancino.attachInterface(iface); Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -79,7 +79,7 @@ void loop() { //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ Arancino.set("foo", "bar"); Arancino.println("foo -> bar"); diff --git a/examples/Arancino_FreeRTOS/15-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino b/examples/Arancino_FreeRTOS/15-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino index cda5df3..2f97fe5 100644 --- a/examples/Arancino_FreeRTOS/15-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino +++ b/examples/Arancino_FreeRTOS/15-BLUETOOTH/BLUETOOTH/BLUETOOTH.ino @@ -51,8 +51,8 @@ BLEDis bledis; // device information BLEUart bleuart; // uart over ble //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { @@ -62,7 +62,7 @@ void setup() Arancino.attachInterface(iface); Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -70,7 +70,7 @@ void loop(){ //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ Arancino.set("foo", "bar"); vTaskDelay(2000); diff --git a/examples/Arancino_FreeRTOS/CS_1-Sample_Sensor/CS_1-Sample_Sensor.ino b/examples/Arancino_FreeRTOS/CS_1-Sample_Sensor/CS_1-Sample_Sensor.ino index 1ff1da8..40cf160 100644 --- a/examples/Arancino_FreeRTOS/CS_1-Sample_Sensor/CS_1-Sample_Sensor.ino +++ b/examples/Arancino_FreeRTOS/CS_1-Sample_Sensor/CS_1-Sample_Sensor.ino @@ -39,15 +39,15 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); void setup() { iface.setSerialPort(); Arancino.attachInterface(iface); Arancino.begin(amdata); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -55,7 +55,7 @@ void loop() { //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ sampleData(); generateResults(); diff --git a/examples/Arancino_FreeRTOS/CS_2-Smart_Light/CS_2-Smart_Light.ino b/examples/Arancino_FreeRTOS/CS_2-Smart_Light/CS_2-Smart_Light.ino index 65c64e6..c07378a 100644 --- a/examples/Arancino_FreeRTOS/CS_2-Smart_Light/CS_2-Smart_Light.ino +++ b/examples/Arancino_FreeRTOS/CS_2-Smart_Light/CS_2-Smart_Light.ino @@ -41,8 +41,8 @@ ArancinoMetadata amdata = { }; //FreeRtos -TaskHandle_t loopTaskHandle; -void loopTask(void *pvParameters); +TaskHandle_t customLoopTaskHandle; +void customLoopTask(void *pvParameters); char* keys[] = {"CS_2-Red", "CS_2-Green", "CS_2-Blue"}; @@ -53,7 +53,7 @@ void setup() { char* startingValues[] = {"255", "255", "255"}; //White Arancino.mset(keys, startingValues, 3); - xTaskCreate(loopTask, "loopTask", 512, NULL, 1, &loopTaskHandle); + xTaskCreate(customLoopTask, "customLoopTask", 512, NULL, 1, &customLoopTaskHandle); Arancino.startScheduler(); } @@ -61,7 +61,7 @@ void loop() { //empty } -void loopTask(void *pvParameters){ +void customLoopTask(void *pvParameters){ while(1){ //Update RGB values char** result = Arancino.mget(keys,3); From a26d0cddf1db896d2b4e3a946e9ea3d5c73ce169 Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Fri, 31 Mar 2023 10:25:32 +0200 Subject: [PATCH 59/69] Check for ARDUINO_ARCH_NRF52 instead of ARDUINO_ARANCINO_VOLANTE --- src/Arancino.cpp | 4 ++-- src/Arancino.h | 2 +- src/ArancinoTasks.cpp | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index 4321312..5f8edcb 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -199,7 +199,7 @@ void ArancinoClass::start(JsonDocument& cmd_doc) { void ArancinoClass::startScheduler() { started = true; -#if defined(ARDUINO_ARANCINO_VOLANTE) +#if defined(ARDUINO_ARCH_NRF52) /* FreeRTOS scheduler has been already started from NRF52 core @@ -963,7 +963,7 @@ void *ArancinoClass::calloc(size_t nmemb, size_t _size) { /* Call the FreeRTOS version of malloc. */ #if defined(USEFREERTOS) -#if defined(ARDUINO_ARANCINOV12_H743ZI) || defined(ARDUINO_ARANCINOV12_H743ZI2) || defined(ARDUINO_ARANCINO_VOLANTE) || defined(ARDUINO_ARCH_RP2040) +#if defined(ARDUINO_ARANCINOV12_H743ZI) || defined(ARDUINO_ARANCINOV12_H743ZI2) || defined(ARDUINO_ARCH_NRF52) || defined(ARDUINO_ARCH_RP2040) uint8_t *ptr = (uint8_t *)malloc(nmemb * (_size)); memset(ptr, 0, nmemb); // clear the buffer #pte4c0 return ptr; diff --git a/src/Arancino.h b/src/Arancino.h index a37ca49..8bb02e8 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -55,7 +55,7 @@ extern "C" { extern "C" { #include } -#elif defined (ARDUINO_ARANCINO_VOLANTE) +#elif defined (ARDUINO_ARCH_NRF52) //need to serial #include #elif defined (ARDUINO_ARCH_RP2040) diff --git a/src/ArancinoTasks.cpp b/src/ArancinoTasks.cpp index 1545fdb..4b17b9a 100644 --- a/src/ArancinoTasks.cpp +++ b/src/ArancinoTasks.cpp @@ -93,13 +93,13 @@ under the License if(rsp.response.string != NULL && !strcmp(rsp.response.string, "1")){ for(int i=0;i < 20; i++){ - #if defined (ARDUINO_ARANCINO_VOLANTE) + #if defined (ARDUINO_ARCH_NRF52) digitalWrite(LED_BUILTIN,LOW); #else digitalWrite(LED_BUILTIN,HIGH); #endif vTaskDelay(100); - #if defined (ARDUINO_ARANCINO_VOLANTE) + #if defined (ARDUINO_ARCH_NRF52) digitalWrite(LED_BUILTIN,HIGH); #else digitalWrite(LED_BUILTIN,LOW); @@ -222,7 +222,7 @@ under the License #endif } - #elif defined (ARDUINO_ARANCINO_VOLANTE) + #elif defined (ARDUINO_ARCH_NRF52) float ArancinoTasks::mcuTemp(){ return readCPUTemperature(); } From 93e15e352133132161d32c375f1fe2ff457c468b Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Mon, 3 Apr 2023 18:33:05 +0200 Subject: [PATCH 60/69] Added prfx to identificationTask and removed manual ID concat --- src/ArancinoTasks.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/ArancinoTasks.cpp b/src/ArancinoTasks.cpp index 4b17b9a..73a4375 100644 --- a/src/ArancinoTasks.cpp +++ b/src/ArancinoTasks.cpp @@ -77,16 +77,12 @@ under the License (*cmd_doc)["cmd"] = GET_COMMAND; JsonArray cmd_items = cmd_args.createNestedArray("items"); uint8_t idSize = strlen(Arancino.id); - char blink_key[idSize + 1 + strlen(BLINK_ID_KEY)]; - strcpy(blink_key, Arancino.id); - char separator = '_'; - strncat(blink_key, &separator, 1); - strcat(blink_key, BLINK_ID_KEY); - cmd_items.add(blink_key); + cmd_items.add(BLINK_ID_KEY); JsonObject cmd_cfg = (*cmd_doc).createNestedObject("cfg"); - cmd_cfg["pers"] = 1; + cmd_cfg["pers"] = CFG_TRUE; cmd_cfg["type"] = "rsvd"; + cmd_cfg["prfx"] = CFG_TRUE; ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), true, KEY_VALUE_RESPONSE); (*cmd_doc).clear(); @@ -111,13 +107,14 @@ under the License (*cmd_doc)["cmd"] = SET_COMMAND; cmd_items = cmd_args.createNestedArray("items"); JsonObject items_obj = cmd_items.createNestedObject(); - items_obj["key"] = blink_key; + items_obj["key"] = BLINK_ID_KEY; items_obj["value"] = 0; cmd_cfg = (*cmd_doc).createNestedObject("cfg"); cmd_cfg["pers"] = 1; cmd_cfg["type"] = "rsvd"; cmd_cfg["ack"] = 0; + cmd_cfg["prfx"] = CFG_TRUE; ArancinoPacket rsp = Arancino.executeCommand((*cmd_doc), false, VOID_RESPONSE); (void)rsp; //to silence the warning From f2286f4a9d634fb73e3dd392e93e76a53c9f4a50 Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Mon, 3 Apr 2023 18:33:19 +0200 Subject: [PATCH 61/69] Fix const char* issue on MqttIface --- src/ArancinoInterface.cpp | 8 ++++---- src/ArancinoInterface.h | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index 4c78f70..52fcead 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -258,19 +258,19 @@ void MqttIface::setNetworkClient(Client& networkClient){ this->_client = &networkClient; } -void MqttIface::setUsername(char* username){ +void MqttIface::setUsername(const char* username){ this->_username = username; } -void MqttIface::setPassword(char* password){ +void MqttIface::setPassword(const char* password){ this->_password = password; } -void MqttIface::setDaemonID(char* daemonID){ +void MqttIface::setDaemonID(const char* daemonID){ this->_daemonID = daemonID; } -void MqttIface::setBrokerAddress(char* broker){ +void MqttIface::setBrokerAddress(const char* broker){ this->_broker = broker; } diff --git a/src/ArancinoInterface.h b/src/ArancinoInterface.h index 1645034..df3cb05 100644 --- a/src/ArancinoInterface.h +++ b/src/ArancinoInterface.h @@ -58,10 +58,10 @@ class SerialIface : public ArancinoIface { class MqttIface : public ArancinoIface, public PubSubClient { public: void setNetworkClient(Client& networkClient); - void setUsername(char* username); - void setPassword(char* password); - void setDaemonID(char* daemonID); - void setBrokerAddress(char* broker); + void setUsername(const char* username); + void setPassword(const char* password); + void setDaemonID(const char* daemonID); + void setBrokerAddress(const char* broker); void setPort(int port); private: @@ -71,11 +71,11 @@ class MqttIface : public ArancinoIface, public PubSubClient { void _reconnect(); - char* _username=NULL; - char* _password=NULL; - char* _daemonID; - char* _broker; //IP addresses can be passed as well hostnames (as strings) - int _port=1883; + const char* _username = NULL; + const char* _password = NULL; + const char* _daemonID; + const char* _broker; //IP addresses can be passed as well hostnames (as strings) + int _port = 1883; Client* _client; //Network client //Since callback function needs to be declared as static, every related variable needs to be static as well From 28ac948e11f883003038768521085c3de436af74 Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Thu, 6 Apr 2023 10:27:30 +0200 Subject: [PATCH 62/69] Forced connection check to broker when sending via MQTT iface --- src/ArancinoDefinitions.h | 2 -- src/ArancinoInterface.cpp | 7 ++++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index 6715679..fcd2bb0 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -196,8 +196,6 @@ const uint32_t BAUDRATE_DEBUG = 115200; #define INTEROCEPTION_PERIOD (pdMS_TO_TICKS(10000)) #define SERVICE_TASK_PERIOD (pdMS_TO_TICKS(5000)) -#define SERIAL_MAX_RETRIES 10 -#define MQTT_MAX_RETRIES 500 #define BLUETOOTH_MAX_RETRIES 100 #define ID_SIZE IDSIZE*2 //IDSIZE will be provided by microcontroller-id library diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index 52fcead..2821405 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -208,7 +208,7 @@ void MqttIface::ifaceBegin(){ void MqttIface::sendArancinoCommand(JsonDocument& command){ int counter = 0; - while (counter < MQTT_MAX_RETRIES){ + if (this->connected()){ if(this->beginPublish(_outputTopic, measureMsgPack(command),false)){ BufferingPrint bufferedClient(*this->_client, 64); serializeMsgPack(command, bufferedClient); @@ -218,9 +218,10 @@ void MqttIface::sendArancinoCommand(JsonDocument& command){ } Arancino.println("Failed to send message, retrying."); counter++; + } else { + //This should not happen. Check if still connected + this->_reconnect(); } - //This should not happen. Check if still connected - this->_reconnect(); } bool MqttIface::receiveArancinoResponse(JsonDocument& response){ From fde202c8ae0101a4c8203c6788008d82ebe3e7c8 Mon Sep 17 00:00:00 2001 From: Calapristi Marco Date: Thu, 6 Apr 2023 11:37:35 +0000 Subject: [PATCH 63/69] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e8657a..e5e641e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -#### v 3.1.0 - 2023.x.x +#### v 3.1.0 - 2023.04.06 * Upd: Implemented new Cortex protocol [#1jdx7ak](https://app.clickup.com/t/1jdx7ak) * Add: Added support to ESP32 [#863gbd6ym](https://app.clickup.com/t/863gbd6ym) * Add: Added support to NRF52 [#863gbd74b](https://app.clickup.com/t/863gbd74b) @@ -12,6 +12,7 @@ * Upd: Service functions in a single task [#861mjudeh](https://app.clickup.com/t/861mjudeh) * Upd: Ifaces adapted to new protocol [#861mjue8p](https://app.clickup.com/t/861mjue8p) * Upd: Fixed warnings in `const char*` conversion [#863gbd62q](https://app.clickup.com/t/863gbd62q) +* Upd: Added check for client connection when using MQTT [#863ge1z5k](https://app.clickup.com/t/863ge1z5k) #### v 3.0.0 - 2022.10.10 * Add: added interface system with MQTT and BLE_UART communication mediums [#1nwtwna] From cbe5072e9beaf99154c51a0dac20f6a91dc58367 Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Fri, 7 Apr 2023 11:56:29 +0200 Subject: [PATCH 64/69] Added MQTTS_LTE example as case scenario --- .../CS_3-MQTTS_LTE/CS_3-MQTTS_LTE.ino | 183 ++++++++++++++++++ .../Arancino/CS_3-MQTTS_LTE/certificates.h | 57 ++++++ 2 files changed, 240 insertions(+) create mode 100644 examples/Arancino/CS_3-MQTTS_LTE/CS_3-MQTTS_LTE.ino create mode 100644 examples/Arancino/CS_3-MQTTS_LTE/certificates.h diff --git a/examples/Arancino/CS_3-MQTTS_LTE/CS_3-MQTTS_LTE.ino b/examples/Arancino/CS_3-MQTTS_LTE/CS_3-MQTTS_LTE.ino new file mode 100644 index 0000000..8c2c7df --- /dev/null +++ b/examples/Arancino/CS_3-MQTTS_LTE/CS_3-MQTTS_LTE.ino @@ -0,0 +1,183 @@ +/* + SPDX-license-identifier: Apache-2.0 + + Copyright (C) 2023 SmartMe.IO + + Authors: Marco Calapristi + Dario Gogliandolo + + Licensed under the Apache License, Version 2.0 (the "License"); you may + not use this file except in compliance with the License. You may obtain + a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + License for the specific language governing permissions and limitations + under the License +*/ + +/* + MQTTs example via LTE + + This sketch shows how to use Arancino Protocol via LTE implementing mTLS coomunication in MQTT protocol. + In this example a BG96 modem was used with the TinyGSM library however, as shown in the MQTT example, + each client interface should work as intended. + + In order to implement the mTLS the SSLClient library was used. All libraries are listed below and please + refer to the "certificates.h" header for more info on how to create your own certificates file + + TinyGSM: https://github.com/vshymanskyy/TinyGSM + SSLClient: https://github.com/OPEnSLab-OSU/SSLClient +*/ + + +#define TINY_GSM_MODEM_BG96 +#define SerialAT Serial1 //BG96 serial +#define SerialMon SerialUSB //DEBUG serial +#define TINY_GSM_DEBUG SerialMon +#define TINY_GSM_USE_GPRS true + +// set GSM PIN, if any +#define GSM_PIN "" + +#include +#include +#include +#include "certificates.h" // This file must be regenerated + +// Set this accordingly to your LTE provider +const char apn[] = ""; +const char gprsUser[] = ""; +const char gprsPass[] = ""; + +// MQTT details +const char* broker = ""; + +// my_cert and my_key are included in the certificate header file +SSLClientParameters mTLS = SSLClientParameters::fromPEM(my_cert, sizeof my_cert, my_key, sizeof my_key); + + +ArancinoMetadata amdata = { + .fwname = "Mqtt Example", + .fwversion = "1.0.0", + .tzoffset = "+1000" +}; + +TinyGsm modem(SerialAT); +TinyGsmClient client(modem); +SSLClient gsmClientSSL(client, TAs, (size_t)TAs_NUM, A5); +MqttIface iface; + +void setup() { + SerialMon.begin(115200); + delay(10); + + // Set your broker and Arancino daemon info + iface.setDaemonID("87654321"); + iface.setBrokerAddress(broker); + iface.setUsername("user"); + iface.setPassword("pass"); + iface.setPort(8883); + iface.setNetworkClient(gsmClientSSL); + + Arancino.attachInterface(iface); + + // !!!!!!!!!!! + // Set your reset, enable, power pins here + // !!!!!!!!!!! + + SerialMon.println("Wait..."); + SerialAT.begin(115200); + + SerialMon.println("Initializing modem..."); + modem.restart(); + + String modemInfo = modem.getModemInfo(); + SerialMon.print("Modem Info: "); + SerialMon.println(modemInfo); + +#if TINY_GSM_USE_GPRS + // Unlock your SIM card with a PIN if needed + if (GSM_PIN && modem.getSimStatus() != 3) { + modem.simUnlock(GSM_PIN); + } +#endif + + + SerialMon.print("Waiting for network..."); + if (!modem.waitForNetwork()) { + SerialMon.println(" fail"); + delay(10000); + return; + } + SerialMon.println(" success"); + + if (modem.isNetworkConnected()) { + SerialMon.println("Network connected"); + } + +#if TINY_GSM_USE_GPRS + // GPRS connection parameters are usually set after network registration + SerialMon.print(F("Connecting to ")); + SerialMon.print(apn); + if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { + SerialMon.println(" fail"); + delay(10000); + return; + } + SerialMon.println(" success"); + + if (modem.isGprsConnected()) { + SerialMon.println("GPRS connected"); + } +#endif + + Arancino.enableDebugMessages(SerialUSB); + Arancino.begin(amdata); + +} + +void loop() { + // Make sure we're still registered on the network + if (!modem.isNetworkConnected()) { + SerialMon.println("Network disconnected"); + if (!modem.waitForNetwork(180000L, true)) { + SerialMon.println(" fail"); + delay(10000); + return; + } + if (modem.isNetworkConnected()) { + SerialMon.println("Network re-connected"); + } + + // and make sure GPRS/EPS is still connected + if (!modem.isGprsConnected()) { + SerialMon.println("GPRS disconnected!"); + SerialMon.print(F("Connecting to ")); + SerialMon.print(apn); + if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { + SerialMon.println(" fail"); + delay(10000); + return; + } + if (modem.isGprsConnected()) { + SerialMon.println("GPRS reconnected"); + } + } + } + + // Send some data to Arancino + Arancino.set("foo", "bar"); + + char* msg = Arancino.get("foo"); + Arancino.println(msg); + Arancino.free(msg); + + Arancino.del("foo"); + + //Some delay to avoid sending too much messages if you have limited traffic on your sim + delay(2000); +} \ No newline at end of file diff --git a/examples/Arancino/CS_3-MQTTS_LTE/certificates.h b/examples/Arancino/CS_3-MQTTS_LTE/certificates.h new file mode 100644 index 0000000..3552619 --- /dev/null +++ b/examples/Arancino/CS_3-MQTTS_LTE/certificates.h @@ -0,0 +1,57 @@ +#ifndef _CERTIFICATES_H_ +#define _CERTIFICATES_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* Board certificate and signature */ + +const char my_cert[] = +("-----BEGIN CERTIFICATE-----\r\n" +"YOUR CERTIFICATE LIKE THIS. YOU EASILY CAN GET ONE WITH OPENSSL\r\n" +"openssl x509 -in your_certificate.pem -text" +"-----END CERTIFICATE-----\r\n"); + +const char my_key[] = +("-----BEGIN RSA PRIVATE KEY-----\r\n" +"YOUR KEY LIKE THIS AS WELL\r\n" +"-----END RSA PRIVATE KEY-----\r\n"); + +//Please refer to pycert_bearssl tool for more details on how to generate the rest of this file +// https://github.com/OPEnSLab-OSU/SSLClient/tree/master/tools/pycert_bearssl + +#define TAs_NUM 1 + +static const unsigned char TA_DN0[] = { + // FIXME +}; + +static const unsigned char TA_RSA_N0[] = { + // FIXME +}; + +static const unsigned char TA_RSA_E0[] = { + // FIXME +}; + +static const br_x509_trust_anchor TAs[] = { + { + { (unsigned char *)TA_DN0, sizeof TA_DN0 }, + BR_X509_TA_CA, + { + BR_KEYTYPE_RSA, + { .rsa = { + (unsigned char *)TA_RSA_N0, sizeof TA_RSA_N0, + (unsigned char *)TA_RSA_E0, sizeof TA_RSA_E0, + } } + } + }, +}; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* ifndef _CERTIFICATES_H_ */ From 4419df0c3643118cc592825bf7f9c1ede221577c Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Fri, 14 Apr 2023 10:59:16 +0200 Subject: [PATCH 65/69] Removed typos from MQTT_ESP32 example --- examples/Arancino/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino | 2 -- examples/Arancino_FreeRTOS/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino | 2 -- 2 files changed, 4 deletions(-) diff --git a/examples/Arancino/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino b/examples/Arancino/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino index b074467..81feba9 100644 --- a/examples/Arancino/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino +++ b/examples/Arancino/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino @@ -28,7 +28,6 @@ */ #include -#include #include // Change these values accordingly with your network. @@ -36,7 +35,6 @@ const char* ssid = "ssid"; const char* password = "YourPassword!"; WiFiClient arancinoClient; -PubSubClient client(arancinoClient); MqttIface iface; diff --git a/examples/Arancino_FreeRTOS/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino b/examples/Arancino_FreeRTOS/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino index 18f5f41..e7dc0b8 100644 --- a/examples/Arancino_FreeRTOS/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino +++ b/examples/Arancino_FreeRTOS/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino @@ -28,7 +28,6 @@ */ #include -#include #include // Change these values accordingly with your network. @@ -36,7 +35,6 @@ const char* ssid = "ssid"; const char* password = "YourPassword!"; WiFiClient arancinoClient; -PubSubClient client(arancinoClient); MqttIface iface; From b560d61be23724b898473d8aa7875734b85c6d1e Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Fri, 14 Apr 2023 12:10:52 +0200 Subject: [PATCH 66/69] Implemented MQTT reconnect timeout --- src/ArancinoDefinitions.h | 2 +- src/ArancinoInterface.cpp | 18 ++++++++---------- src/ArancinoInterface.h | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index fcd2bb0..e1d4ca3 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -175,7 +175,7 @@ const uint32_t BAUDRATE_DEBUG = 115200; #if defined(ARDUINO_ARCH_ESP32) //ESP32 configMAX_PRIORITIES is 25 #define ARANCINO_TASK_PRIORITY (ESP_TASK_TCPIP_PRIO - 1) -#define SERVICETASK_STACK (1024 * 4) +#define SERVICETASK_STACK (1200 * 4) #elif defined(__SAMD21G18A__) #define ARANCINO_TASK_PRIORITY configMAX_PRIORITIES - 1 #define SERVICETASK_STACK 768 diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index 2821405..41b4cba 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -207,21 +207,16 @@ void MqttIface::ifaceBegin(){ } void MqttIface::sendArancinoCommand(JsonDocument& command){ - int counter = 0; - if (this->connected()){ + if (this->connected() || this->_reconnect()){ //check if connected otherwise attempt reconnection if(this->beginPublish(_outputTopic, measureMsgPack(command),false)){ BufferingPrint bufferedClient(*this->_client, 64); serializeMsgPack(command, bufferedClient); bufferedClient.flush(); - this-> endPublish(); + this->endPublish(); return; } - Arancino.println("Failed to send message, retrying."); - counter++; - } else { - //This should not happen. Check if still connected - this->_reconnect(); } + Arancino.println("Failed to send message, retrying."); } bool MqttIface::receiveArancinoResponse(JsonDocument& response){ @@ -281,8 +276,9 @@ void MqttIface::setPort(int port){ this->_port = port; } -void MqttIface::_reconnect(){ - while (!this->connected()){ +bool MqttIface::_reconnect(){ + unsigned long startMillis = millis(); + while (!this->connected() && (millis() < startMillis + TIMEOUT)){ if (!this->connect(Arancino.id, _username, _password)){ //If debug is enabled, tell the user that connection failed Arancino.print("Connection failed, retrying in 2 seconds. RC="); @@ -290,6 +286,8 @@ void MqttIface::_reconnect(){ Arancino.delay(2000); } } + + return this->connected(); } /******** Bluetooth interface *********/ diff --git a/src/ArancinoInterface.h b/src/ArancinoInterface.h index df3cb05..097d3ad 100644 --- a/src/ArancinoInterface.h +++ b/src/ArancinoInterface.h @@ -69,7 +69,7 @@ class MqttIface : public ArancinoIface, public PubSubClient { void sendArancinoCommand(JsonDocument& command); bool receiveArancinoResponse(JsonDocument& response); - void _reconnect(); + bool _reconnect(); const char* _username = NULL; const char* _password = NULL; From 0dba8b8693eb88bb91756c4179949a49b67c0d44 Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Fri, 14 Apr 2023 16:43:49 +0200 Subject: [PATCH 67/69] Increased service task size in ESP32. Updated mqtt reconnect as oneshot reconnect --- src/ArancinoDefinitions.h | 2 +- src/ArancinoInterface.cpp | 48 ++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index e1d4ca3..063345c 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -175,7 +175,7 @@ const uint32_t BAUDRATE_DEBUG = 115200; #if defined(ARDUINO_ARCH_ESP32) //ESP32 configMAX_PRIORITIES is 25 #define ARANCINO_TASK_PRIORITY (ESP_TASK_TCPIP_PRIO - 1) -#define SERVICETASK_STACK (1200 * 4) +#define SERVICETASK_STACK (1500 * 4) #elif defined(__SAMD21G18A__) #define ARANCINO_TASK_PRIORITY configMAX_PRIORITIES - 1 #define SERVICETASK_STACK 768 diff --git a/src/ArancinoInterface.cpp b/src/ArancinoInterface.cpp index 41b4cba..3f117fe 100644 --- a/src/ArancinoInterface.cpp +++ b/src/ArancinoInterface.cpp @@ -179,7 +179,7 @@ void MqttIface::ifaceBegin(){ //+1 because of \n _inputTopic = (char*)Arancino.calloc(strlen("arancino/cortex/") + strlen(_daemonID) + strlen(Arancino.id) + strlen("/rsp_to_mcu") + 2, sizeof(char)); _outputTopic = (char*)Arancino.calloc(strlen("arancino/cortex/") + strlen(_daemonID) + strlen(Arancino.id) + strlen("/cmd_from_mcu") + 2, sizeof(char)); - _serviceTopic = (char*)Arancino.calloc(strlen("arancino/service") + strlen(_daemonID) + strlen(Arancino.id) + 2, sizeof(char)); + _serviceTopic = (char*)Arancino.calloc(strlen("arancino/service/") + strlen(_daemonID) + 1, sizeof(char)); strcpy(_inputTopic, "arancino/cortex/"); strcat(_inputTopic, _daemonID); @@ -207,7 +207,9 @@ void MqttIface::ifaceBegin(){ } void MqttIface::sendArancinoCommand(JsonDocument& command){ - if (this->connected() || this->_reconnect()){ //check if connected otherwise attempt reconnection + if (!this->connected()) this->_reconnect(); + + if (this->connected()){ if(this->beginPublish(_outputTopic, measureMsgPack(command),false)){ BufferingPrint bufferedClient(*this->_client, 64); serializeMsgPack(command, bufferedClient); @@ -216,25 +218,33 @@ void MqttIface::sendArancinoCommand(JsonDocument& command){ return; } } - Arancino.println("Failed to send message, retrying."); + + Arancino.println("Failed to send message."); } bool MqttIface::receiveArancinoResponse(JsonDocument& response){ - unsigned long startMillis = millis(); + if (!this->connected()) this->_reconnect(); + bool error = true; - do { - this->loop(); - delay(10); - } while(!_newIncomingMessage && (millis() < startMillis + TIMEOUT)); + if (this->connected()){ + unsigned long startMillis = millis(); + do { + this->loop(); + delay(10); + } while(!_newIncomingMessage && (millis() < startMillis + TIMEOUT)); - if (_newIncomingMessage) - { - error = (bool)deserializeMsgPack(response, (const char*)this->_payload, this->_length); - _newIncomingMessage = false; + + if (_newIncomingMessage) + { + error = (bool)deserializeMsgPack(response, (const char*)this->_payload, this->_length); + _newIncomingMessage = false; + } + + return error; } - return error; + return error; // Return error if client is not connected } void MqttIface::_arancinoCallback(char* topic, byte* payload, unsigned int length){ @@ -277,14 +287,10 @@ void MqttIface::setPort(int port){ } bool MqttIface::_reconnect(){ - unsigned long startMillis = millis(); - while (!this->connected() && (millis() < startMillis + TIMEOUT)){ - if (!this->connect(Arancino.id, _username, _password)){ - //If debug is enabled, tell the user that connection failed - Arancino.print("Connection failed, retrying in 2 seconds. RC="); - Arancino.println(this->state()); - Arancino.delay(2000); - } + if (!this->connect(Arancino.id, _username, _password)){ + //If debug is enabled, tell the user that connection failed + Arancino.print("Connection failed. RC="); + Arancino.println(this->state()); } return this->connected(); From 9c4c71fb7cb392772075832b8fb39073dde7796b Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Fri, 14 Apr 2023 16:45:41 +0200 Subject: [PATCH 68/69] Updated ESP32 examples Added MQTTS ESP32 examples --- .../14-MQTT/MQTTS_ESP32/MQTTS_ESP32.ino | 100 ++++++++++++++++ .../14-MQTT/MQTT_ESP32/MQTT_ESP32.ino | 18 ++- .../14-MQTT/MQTTS_ESP32/MQTTS_ESP32.ino | 108 ++++++++++++++++++ .../14-MQTT/MQTT_ESP32/MQTT_ESP32.ino | 18 ++- 4 files changed, 222 insertions(+), 22 deletions(-) create mode 100644 examples/Arancino/14-MQTT/MQTTS_ESP32/MQTTS_ESP32.ino create mode 100644 examples/Arancino_FreeRTOS/14-MQTT/MQTTS_ESP32/MQTTS_ESP32.ino diff --git a/examples/Arancino/14-MQTT/MQTTS_ESP32/MQTTS_ESP32.ino b/examples/Arancino/14-MQTT/MQTTS_ESP32/MQTTS_ESP32.ino new file mode 100644 index 0000000..58cafd9 --- /dev/null +++ b/examples/Arancino/14-MQTT/MQTTS_ESP32/MQTTS_ESP32.ino @@ -0,0 +1,100 @@ +/* + SPDX-license-identifier: Apache-2.0 + + Copyright (C) 2023 SmartMe.IO + + Authors: Marco Calapristi + + Licensed under the Apache License, Version 2.0 (the "License"); you may + not use this file except in compliance with the License. You may obtain + a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + License for the specific language governing permissions and limitations + under the License +*/ + + +#include +#include +#include + +// Change these values accordingly with your network. +const char* ssid = "ssid"; +const char* password = "YourPassword!"; + +WiFiClientSecure arancinoClient; + +MqttIface iface; + +const char *test_root_ca = \ + "-----BEGIN CERTIFICATE-----\n" \ + "-----END CERTIFICATE-----\n"; + +const char *test_client_key = \ + "-----BEGIN RSA PRIVATE KEY-----\n" \ + "-----END RSA PRIVATE KEY-----\n"; + +const char *test_client_cert = \ + "-----BEGIN CERTIFICATE-----\n" \ + "-----END CERTIFICATE-----\n"; + + +ArancinoMetadata amdata = { + .fwname = "Mqtt ESP32 Example", + .fwversion = "1.0.0", + .tzoffset = "+1000" +}; + +void setup() +{ + Serial.begin(115200); + Serial.print("Connecting to " + (String)ssid); + + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + Arancino.enableDebugMessages(Serial); + Arancino.println("Started"); + + //Load the certificates to network client + arancinoClient.setCACert(test_root_ca); + arancinoClient.setCertificate(test_client_cert); + arancinoClient.setPrivateKey(test_client_key); + + //Set up the MQTT client + iface.setDaemonID("87654321"); + iface.setBrokerAddress("192.168.137.249"); //You can use domain names as well + iface.setUsername("arancino-daemon"); + iface.setPassword("12345678"); + iface.setPort(1883); + iface.setNetworkClient(arancinoClient); + Arancino.attachInterface(iface); + + Arancino.begin(amdata); +} + +void loop() { + //Check if WiFi is still connected + if(WiFi.status() != WL_CONNECTED){ + WiFi.begin(ssid, password); + } + + Arancino.set("foo", "bar"); + Arancino.println("SET: foo -> bar"); + delay(1000); + + char* value = Arancino.get("foo"); + Arancino.print("GET: foo -> "); + Arancino.println(value); + Arancino.free(value); //frees memory + + delay(1000); +} \ No newline at end of file diff --git a/examples/Arancino/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino b/examples/Arancino/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino index 81feba9..ce6bb7d 100644 --- a/examples/Arancino/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino +++ b/examples/Arancino/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino @@ -1,9 +1,9 @@ /* SPDX-license-identifier: Apache-2.0 - Copyright (C) 2021 SmartMe.IO + Copyright (C) 2023 SmartMe.IO - Authors: Marco Calapristi + Authors: Dario Gogliandolo Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain @@ -18,15 +18,6 @@ under the License */ -/* - Arancino MQTT example - - This sketch shows how to use Arancino Protocol via MQTT. - In this example an Ethernet shield was used, but any network client should work just fine. - - In order to do that you should first set up a MqttIface and then attach it to Arancino Library as shown below -*/ - #include #include @@ -71,6 +62,11 @@ void setup() } void loop() { + //Check if WiFi is still connected + if(WiFi.status() != WL_CONNECTED){ + WiFi.begin(ssid, password); + } + Arancino.set("foo", "bar"); Arancino.println("SET: foo -> bar"); delay(1000); diff --git a/examples/Arancino_FreeRTOS/14-MQTT/MQTTS_ESP32/MQTTS_ESP32.ino b/examples/Arancino_FreeRTOS/14-MQTT/MQTTS_ESP32/MQTTS_ESP32.ino new file mode 100644 index 0000000..fd81054 --- /dev/null +++ b/examples/Arancino_FreeRTOS/14-MQTT/MQTTS_ESP32/MQTTS_ESP32.ino @@ -0,0 +1,108 @@ +/* + SPDX-license-identifier: Apache-2.0 + + Copyright (C) 2023 SmartMe.IO + + Authors: Marco Calapristi + + Licensed under the Apache License, Version 2.0 (the "License"); you may + not use this file except in compliance with the License. You may obtain + a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + License for the specific language governing permissions and limitations + under the License +*/ + +#include +#include +#include + +// Change these values accordingly with your network. +const char* ssid = "ssid"; +const char* password = "YourPassword!"; + +WiFiClientSecure arancinoClient; + +MqttIface iface; + +const char *test_root_ca = \ + "-----BEGIN CERTIFICATE-----\n" \ + "-----END CERTIFICATE-----\n"; + +const char *test_client_key = \ + "-----BEGIN RSA PRIVATE KEY-----\n" \ + "-----END RSA PRIVATE KEY-----\n"; + +const char *test_client_cert = \ + "-----BEGIN CERTIFICATE-----\n" \ + "-----END CERTIFICATE-----\n"; + +ArancinoMetadata amdata = { + .fwname = "Mqtt ESP32 w/ FreeRTOS Example", + .fwversion = "1.0.0", + .tzoffset = "+1000" +}; + +//FreeRtos +TaskHandle_t otherLoopHandle; +void otherLoop(void *pvParameters); + +void setup() +{ + Serial.begin(115200); + Serial.print("Connecting to " + (String)ssid); + + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + //Load the certificates to network client + arancinoClient.setCACert(test_root_ca); + arancinoClient.setCertificate(test_client_cert); + arancinoClient.setPrivateKey(test_client_key); + + Arancino.enableDebugMessages(Serial); + Arancino.println("Started"); + + //Set up the MQTT client + iface.setDaemonID("87654321"); + iface.setBrokerAddress("192.168.211.41"); //You can use domain names as well + iface.setUsername("arancino-daemon"); + iface.setPassword("12345678"); + iface.setPort(1883); + iface.setNetworkClient(arancinoClient); + Arancino.attachInterface(iface); + + Arancino.begin(amdata); + xTaskCreate(otherLoop, "otherLoop", configMINIMAL_STACK_SIZE * 2, NULL, 1, &otherLoopHandle); + Arancino.startScheduler(); +} + +void loop() { + //Check if WiFi is still connected + if(WiFi.status() != WL_CONNECTED){ + WiFi.begin(ssid, password); + } + + Arancino.set("foo", "bar"); + Arancino.println("SET: foo -> bar"); + delay(1000); +} + +void otherLoop(void *pvParameters) { + while (1) { + char* value = Arancino.get("foo"); + Arancino.print("GET: foo -> "); + Arancino.println(value); + Arancino.free(value); //frees memory + + delay(1000); + } +} \ No newline at end of file diff --git a/examples/Arancino_FreeRTOS/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino b/examples/Arancino_FreeRTOS/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino index e7dc0b8..10d224a 100644 --- a/examples/Arancino_FreeRTOS/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino +++ b/examples/Arancino_FreeRTOS/14-MQTT/MQTT_ESP32/MQTT_ESP32.ino @@ -1,9 +1,9 @@ /* SPDX-license-identifier: Apache-2.0 - Copyright (C) 2021 SmartMe.IO + Copyright (C) 2023 SmartMe.IO - Authors: Marco Calapristi + Authors: Dario Gogliandolo Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain @@ -18,15 +18,6 @@ under the License */ -/* - Arancino MQTT example - - This sketch shows how to use Arancino Protocol via MQTT. - In this example an Ethernet shield was used, but any network client should work just fine. - - In order to do that you should first set up a MqttIface and then attach it to Arancino Library as shown below -*/ - #include #include @@ -77,6 +68,11 @@ void setup() } void loop() { + //Check if WiFi is still connected + if(WiFi.status() != WL_CONNECTED){ + WiFi.begin(ssid, password); + } + Arancino.set("foo", "bar"); Arancino.println("SET: foo -> bar"); delay(1000); From 564f73aad181a895a9857fd7d639eb7e5d00a774 Mon Sep 17 00:00:00 2001 From: Calapristi Marco Date: Fri, 14 Apr 2023 15:48:34 +0000 Subject: [PATCH 69/69] Update README.md --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bd815bc..089f047 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,9 @@ Arancino Library allows to export/import data to/from the Linux environment usin The Arancino Library `3.1.0` officially supports the following Arancino Core versions: |Board| Core Version | |--|--| -| SAMD21 | 1.3.1 | -| nRF52 | 1.1.0 | -| RP2040 | 1.2.0 | -| STM32 | 1.0.0 | +| SAMD21 | 1.4.0 | +| nRF52 | 1.1.1 | +| RP2040 | 1.2.1 | ## Credits