From 7e9b972c23d6d88b1249a0777e4f585279b33adf Mon Sep 17 00:00:00 2001 From: beegee-tokyo Date: Sun, 30 Apr 2023 13:13:50 +0800 Subject: [PATCH] Add AT command for fPort setting --- CHANGELOG.md | 3 +++ README.md | 2 ++ library.json | 2 +- library.properties | 2 +- src/at_cmd.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e54a42..e35703f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ Arduino library for RAKWireless WisBlock Core modules that takes all the LoRaWAN # Release Notes +## 2.0.4 Add AT command + - Add AT command to change fPort when using LoRaWAN. Thanks to @xoseperez + ## 2.0.3 Fix value overflow - Fix value overflow in AT command AT+MASK ## 2.0.2 Fix P2P bandwidths diff --git a/README.md b/README.md index 21292a0..87ea2fc 100644 --- a/README.md +++ b/README.md @@ -1175,6 +1175,8 @@ AT Command functions: Taylor Lee (taylor.lee@rakwireless.com) ---- # Changelog [Code releases](CHANGELOG.md) +- 2023-04-30 + - Added option to set the LoRaWAN port using the AT command set. Thanks to @xoseperez - 2023-04-07 - Fix value overflow in AT command AT+MASK - 2023-03-18 diff --git a/library.json b/library.json index 9a29ead..149c6b9 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "WisBlock-API-V2", - "version": "2.0.3", + "version": "2.0.4", "keywords": [ "lora", "Semtech", diff --git a/library.properties b/library.properties index 4204e0a..adb0609 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=WisBlock-API-V2 -version=2.0.3 +version=2.0.4 author=Bernd Giesecke maintainer=Bernd Giesecke sentence=API for WisBlock Core module diff --git a/src/at_cmd.cpp b/src/at_cmd.cpp index e02780e..b5d636a 100644 --- a/src/at_cmd.cpp +++ b/src/at_cmd.cpp @@ -1507,6 +1507,44 @@ static int at_exec_adr(char *str) return AT_SUCCESS; } +/** + * @brief AT+PORT=? Get current port + * + * @return int + */ +static int at_query_port(void) +{ + snprintf(g_at_query_buf, ATQUERY_SIZE, "%d", g_lorawan_settings.app_port); + return AT_SUCCESS; +} + +/** + * @brief AT+PORT=X Set port + * + * @param str 1 to 224 + * @return int 0 if correct parameter + */ +static int at_exec_port(char *str) +{ + if (!g_lorawan_settings.lorawan_enable) + { + return AT_ERRNO_NOALLOW; + } + uint8_t port; + + port = strtol(str, NULL, 0); + + if ((port < 1) || (port > 223)) + { + return AT_ERRNO_PARA_VAL; + } + + g_lorawan_settings.app_port = port; + save_settings(); + + return AT_SUCCESS; +} + /** * @brief AT+TXP=? Get current TX power setting * @@ -2176,6 +2214,7 @@ static atcmd_t g_at_cmd_list[] = { // Custom AT commands {"+STATUS", "Status, Show LoRaWAN status", at_query_status, NULL, NULL, "R"}, {"+SENDINT", "Send interval, Get or Set the automatic send interval", at_query_sendint, at_exec_sendint, NULL, "RW"}, + {"+PORT", "Get or Set the Port=[1..223]", at_query_port, at_exec_port, NULL}, }; /** @@ -2204,7 +2243,7 @@ static int at_exec_list_all(void) for (unsigned int idx = 1; idx < sizeof(g_at_cmd_list) / sizeof(atcmd_t); idx++) { - if ((strcmp(g_at_cmd_list[idx].cmd_name, (char *)"+STATUS") == 0) || (strcmp(g_at_cmd_list[idx].cmd_name, (char *)"+SENDINT") == 0)) + if ((strcmp(g_at_cmd_list[idx].cmd_name, (char *)"+STATUS") == 0) || (strcmp(g_at_cmd_list[idx].cmd_name, (char *)"+SENDINT") == 0) || (strcmp(g_at_cmd_list[idx].cmd_name, (char *)"+PORT") == 0)) { AT_PRINTF("ATC%s,%s: %s", g_at_cmd_list[idx].cmd_name, g_at_cmd_list[idx].permission, g_at_cmd_list[idx].cmd_desc); }