mirror of
https://github.com/manuelbl/ttn-esp32.git
synced 2025-06-15 12:24:27 +02:00
Simplify conditional compilation; add region Japan
This commit is contained in:
parent
99420c6a75
commit
f03b5c51fd
23
Kconfig
23
Kconfig
@ -14,16 +14,19 @@ config TTN_LORA_FREQ_EU_868
|
|||||||
bool "Europe (868 MHz)"
|
bool "Europe (868 MHz)"
|
||||||
|
|
||||||
config TTN_LORA_FREQ_US_915
|
config TTN_LORA_FREQ_US_915
|
||||||
bool "North America (915 Mhz)"
|
bool "North America (915 MHz)"
|
||||||
|
|
||||||
config TTN_LORA_FREQ_AU_921
|
config TTN_LORA_FREQ_AU_921
|
||||||
bool "Australia (921 Mhz)"
|
bool "Australia (921 MHz)"
|
||||||
|
|
||||||
config TTN_LORA_FREQ_AS_923
|
config TTN_LORA_FREQ_AS_923
|
||||||
bool "Asia (923 Mhz)"
|
bool "Asia (923 MHz)"
|
||||||
|
|
||||||
|
config TTN_LORA_FREQ_AS_923_JP
|
||||||
|
bool "Asia, region Japan (923 MHz)"
|
||||||
|
|
||||||
config TTN_LORA_FREQ_IN_866
|
config TTN_LORA_FREQ_IN_866
|
||||||
bool "India (866 Mhz)"
|
bool "India (866 MHz)"
|
||||||
|
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
@ -79,22 +82,22 @@ config TTN_BG_TASK_PRIO
|
|||||||
|
|
||||||
|
|
||||||
choice TTN_PROVISION_UART
|
choice TTN_PROVISION_UART
|
||||||
prompt "UART for provisioning"
|
prompt "AT commands"
|
||||||
default TTN_PROVISION_UART_DEFAULT
|
default TTN_PROVISION_UART_DEFAULT
|
||||||
help
|
help
|
||||||
Select whether to use UART for listening for provisioning commands.
|
Select whether to listen on UART for AT commands.
|
||||||
|
|
||||||
- Default is to use UART0 on pins GPIO1(TX) and GPIO3(RX).
|
- Default is to use UART0 on pins GPIO1(TX) and GPIO3(RX).
|
||||||
- If "Custom" is selected, UART0 or UART1 can be chosen,
|
- If "Custom" is selected, UART0 or UART1 can be chosen,
|
||||||
and any pins can be selected.
|
and any pins can be selected.
|
||||||
- If "None" is selected, the feature is not available.
|
- If "None" is selected, AT commands are not available.
|
||||||
|
|
||||||
config TTN_PROVISION_UART_DEFAULT
|
config TTN_PROVISION_UART_DEFAULT
|
||||||
bool "Default: UART0, TX=GPIO1, RX=GPIO3, 115,200 baud"
|
bool "Enabled - default settings: UART0, TX=GPIO1, RX=GPIO3, 115,200 baud"
|
||||||
config TTN_PROVISION_UART_CUSTOM
|
config TTN_PROVISION_UART_CUSTOM
|
||||||
bool "Custom"
|
bool "Enabled - custom UART settings"
|
||||||
config TTN_PROVISION_UART_NONE
|
config TTN_PROVISION_UART_NONE
|
||||||
bool "None"
|
bool "Disabled"
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
choice TTN_PROVISION_UART_NUM
|
choice TTN_PROVISION_UART_NUM
|
||||||
|
@ -20,6 +20,9 @@
|
|||||||
#define CFG_au921 1
|
#define CFG_au921 1
|
||||||
#elif defined(CONFIG_TTN_LORA_FREQ_AS_923)
|
#elif defined(CONFIG_TTN_LORA_FREQ_AS_923)
|
||||||
#define CFG_as923 1
|
#define CFG_as923 1
|
||||||
|
#elif defined(CONFIG_TTN_LORA_FREQ_AS_923_JP)
|
||||||
|
#define CFG_as923 1
|
||||||
|
#define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP
|
||||||
#elif defined(CONFIG_TTN_LORA_FREQ_IN_866)
|
#elif defined(CONFIG_TTN_LORA_FREQ_IN_866)
|
||||||
#define CFG_in866 1
|
#define CFG_in866 1
|
||||||
#else
|
#else
|
||||||
@ -55,6 +58,14 @@
|
|||||||
#error TTN timer must be configured using 'make menuconfig'
|
#error TTN timer must be configured using 'make menuconfig'
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(CONFIG_TTN_PROVISION_UART_NONE)
|
||||||
|
#define TTN_HAS_AT_COMMANDS 1
|
||||||
|
#if defined(CONFIG_TTN_PROVISION_UART_CONFIG_YES)
|
||||||
|
#define TTN_CONFIG_UART 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// 16 μs per tick
|
// 16 μs per tick
|
||||||
// LMIC requires ticks to be 15.5μs - 100 μs long
|
// LMIC requires ticks to be 15.5μs - 100 μs long
|
||||||
#define US_PER_OSTICK 16
|
#define US_PER_OSTICK 16
|
||||||
|
@ -130,7 +130,7 @@ public:
|
|||||||
bool provisionWithMAC(const char *appEui, const char *appKey);
|
bool provisionWithMAC(const char *appEui, const char *appKey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Start task that listens on configured UART for provisioning commands.
|
* @brief Start task that listens on configured UART for AT commands.
|
||||||
*
|
*
|
||||||
* Run 'make menuconfig' to configure it.
|
* Run 'make menuconfig' to configure it.
|
||||||
*/
|
*/
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include "lmic/lmic.h"
|
#include "lmic/lmic.h"
|
||||||
#include "hal/hal_esp32.h"
|
#include "hal/hal_esp32.h"
|
||||||
|
|
||||||
#if !defined(CONFIG_TTN_PROVISION_UART_NONE)
|
#if defined(TTN_HAS_AT_COMMANDS)
|
||||||
const uart_port_t UART_NUM = (uart_port_t) CONFIG_TTN_PROVISION_UART_NUM;
|
const uart_port_t UART_NUM = (uart_port_t) CONFIG_TTN_PROVISION_UART_NUM;
|
||||||
const int MAX_LINE_LENGTH = 128;
|
const int MAX_LINE_LENGTH = 128;
|
||||||
#endif
|
#endif
|
||||||
@ -35,7 +35,10 @@ static uint8_t global_dev_eui[8];
|
|||||||
static uint8_t global_app_eui[8];
|
static uint8_t global_app_eui[8];
|
||||||
static uint8_t global_app_key[16];
|
static uint8_t global_app_key[16];
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(TTN_HAS_AT_COMMANDS)
|
||||||
void ttn_provisioning_task_caller(void* pvParameter);
|
void ttn_provisioning_task_caller(void* pvParameter);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// --- LMIC callbacks
|
// --- LMIC callbacks
|
||||||
@ -67,7 +70,7 @@ void os_getDevKey (u1_t* buf)
|
|||||||
|
|
||||||
TTNProvisioning::TTNProvisioning()
|
TTNProvisioning::TTNProvisioning()
|
||||||
: have_keys(false)
|
: have_keys(false)
|
||||||
#if !defined(CONFIG_TTN_PROVISION_UART_NONE)
|
#if defined(TTN_HAS_AT_COMMANDS)
|
||||||
, uart_queue(nullptr), line_buf(nullptr), line_length(0), last_line_end_char(0), quit_task(false)
|
, uart_queue(nullptr), line_buf(nullptr), line_length(0), last_line_end_char(0), quit_task(false)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
@ -76,9 +79,11 @@ TTNProvisioning::TTNProvisioning()
|
|||||||
|
|
||||||
// --- Provisioning task
|
// --- Provisioning task
|
||||||
|
|
||||||
|
#if defined(TTN_HAS_AT_COMMANDS)
|
||||||
|
|
||||||
void TTNProvisioning::startTask()
|
void TTNProvisioning::startTask()
|
||||||
{
|
{
|
||||||
#if defined(CONFIG_TTN_PROVISION_UART_CONFIG_YES)
|
#if defined(TTN_CONFIG_UART)
|
||||||
configUART();
|
configUART();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -287,7 +292,10 @@ void TTNProvisioning::processLine()
|
|||||||
uart_write_bytes(UART_NUM, is_ok ? "OK\r\n" : "ERROR\r\n", is_ok ? 4 : 7);
|
uart_write_bytes(UART_NUM, is_ok ? "OK\r\n" : "ERROR\r\n", is_ok ? 4 : 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_TTN_PROVISION_UART_CONFIG_YES)
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(TTN_CONFIG_UART)
|
||||||
|
|
||||||
void TTNProvisioning::configUART()
|
void TTNProvisioning::configUART()
|
||||||
{
|
{
|
||||||
|
@ -22,23 +22,29 @@ class TTNProvisioning
|
|||||||
public:
|
public:
|
||||||
TTNProvisioning();
|
TTNProvisioning();
|
||||||
|
|
||||||
void startTask();
|
|
||||||
bool haveKeys();
|
bool haveKeys();
|
||||||
bool decodeKeys(const char *dev_eui, const char *app_eui, const char *app_key);
|
bool decodeKeys(const char *dev_eui, const char *app_eui, const char *app_key);
|
||||||
bool fromMAC(const char *app_eui, const char *app_key);
|
bool fromMAC(const char *app_eui, const char *app_key);
|
||||||
bool saveKeys();
|
bool saveKeys();
|
||||||
bool restoreKeys(bool silent);
|
bool restoreKeys(bool silent);
|
||||||
|
|
||||||
|
#if defined(TTN_HAS_AT_COMMANDS)
|
||||||
|
void startTask();
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void provisioningTask();
|
|
||||||
bool decode(bool incl_dev_eui, const char *dev_eui, const char *app_eui, const char *app_key);
|
bool decode(bool incl_dev_eui, const char *dev_eui, const char *app_eui, const char *app_key);
|
||||||
void addLineData(int numBytes);
|
|
||||||
void detectLineEnd(int start_at);
|
|
||||||
void processLine();
|
|
||||||
bool readNvsValue(nvs_handle handle, const char* key, uint8_t* data, size_t expected_length, bool silent);
|
bool readNvsValue(nvs_handle handle, const char* key, uint8_t* data, size_t expected_length, bool silent);
|
||||||
bool writeNvsValue(nvs_handle handle, const char* key, const uint8_t* data, size_t len);
|
bool writeNvsValue(nvs_handle handle, const char* key, const uint8_t* data, size_t len);
|
||||||
|
|
||||||
#if defined(CONFIG_TTN_PROVISION_UART_CONFIG_YES)
|
#if defined(TTN_HAS_AT_COMMANDS)
|
||||||
|
void provisioningTask();
|
||||||
|
void addLineData(int numBytes);
|
||||||
|
void detectLineEnd(int start_at);
|
||||||
|
void processLine();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(TTN_CONFIG_UART)
|
||||||
void configUART();
|
void configUART();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -53,15 +59,15 @@ private:
|
|||||||
private:
|
private:
|
||||||
bool have_keys = false;
|
bool have_keys = false;
|
||||||
|
|
||||||
#if !defined(CONFIG_TTN_PROVISION_UART_NONE)
|
#if defined(TTN_HAS_AT_COMMANDS)
|
||||||
QueueHandle_t uart_queue;
|
QueueHandle_t uart_queue;
|
||||||
char* line_buf;
|
char* line_buf;
|
||||||
int line_length;
|
int line_length;
|
||||||
uint8_t last_line_end_char;
|
uint8_t last_line_end_char;
|
||||||
bool quit_task;
|
bool quit_task;
|
||||||
#endif
|
|
||||||
|
|
||||||
friend void ttn_provisioning_task_caller(void* pvParameter);
|
friend void ttn_provisioning_task_caller(void* pvParameter);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -93,16 +93,21 @@ bool TheThingsNetwork::provisionWithMAC(const char *appEui, const char *appKey)
|
|||||||
return provisioning.saveKeys();
|
return provisioning.saveKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TheThingsNetwork::startProvisioningTask()
|
void TheThingsNetwork::startProvisioningTask()
|
||||||
{
|
{
|
||||||
#if !defined(CONFIG_TTN_PROVISION_UART_NONE)
|
#if defined(TTN_HAS_AT_COMMANDS)
|
||||||
provisioning.startTask();
|
provisioning.startTask();
|
||||||
|
#else
|
||||||
|
ESP_LOGE(TAG, "AT commands are disabled. Change the configuration using 'make menuconfig'");
|
||||||
|
ASSERT(0);
|
||||||
|
esp_restart();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void TheThingsNetwork::waitForProvisioning()
|
void TheThingsNetwork::waitForProvisioning()
|
||||||
{
|
{
|
||||||
#if !defined(CONFIG_TTN_PROVISION_UART_NONE)
|
#if defined(TTN_HAS_AT_COMMANDS)
|
||||||
if (isProvisioned())
|
if (isProvisioned())
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "Device is already provisioned");
|
ESP_LOGI(TAG, "Device is already provisioned");
|
||||||
@ -113,6 +118,10 @@ void TheThingsNetwork::waitForProvisioning()
|
|||||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Device successfully provisioned");
|
ESP_LOGI(TAG, "Device successfully provisioned");
|
||||||
|
#else
|
||||||
|
ESP_LOGE(TAG, "AT commands are disabled. Change the configuration using 'make menuconfig'");
|
||||||
|
ASSERT(0);
|
||||||
|
esp_restart();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user