Remove features that are not implemented yet

This commit is contained in:
Manuel Bleichenbacher 2018-07-17 22:07:35 +02:00
parent 06387b4e57
commit 6378c17e39
3 changed files with 35 additions and 43 deletions

View File

@ -18,13 +18,14 @@
// The LoRaWAN frequency and the radio chip must be configured by running 'make menuconfig'.
// Go to Components / The Things Network, select the appropriate values and save.
// Copy the below two lines from bottom of your device's overview page in the TTN console
// Copy the below hex string from the "Device EUI" field
// on your device's overview page in the TTN console.
const char *devEui = "????????????????";;
// Copy the below two lines from bottom of the same page
const char *appEui = "????????????????";
const char *appKey = "????????????????????????????????";
// Copy the below hex string from the "Device EUI" field on the same pag.
const char *devEui = "????????????????";;
static TheThingsNetwork ttn;
@ -64,7 +65,7 @@ extern "C" void app_main(void)
ttn.configurePins(HSPI_HOST, 18, TTN_NOT_CONNECTED, 14, 26, 33);
ttn.provision(appEui, appKey, devEui);
ttn.provision(devEui, appEui, appKey);
printf("Joining...\n");
ttn.join();

View File

@ -51,11 +51,8 @@ class TheThingsNetwork
public:
/**
* @brief Construct a new The Things Network device
*
* @param sf The spreading factor. 7 to 10 for US915 frequency plan. 7 to 12 for other frequency plans. Defaults to 7.
* @param fsb Optional custom frequency subband. 1 to 8. Defaults to 2.
*/
TheThingsNetwork(uint8_t sf = TTN_DEFAULT_SF, uint8_t fsb = TTN_DEFAULT_FSB);
TheThingsNetwork();
/**
* @brief Destroy the The Things Network device.
@ -88,46 +85,42 @@ public:
*
* Call join() without the first 2 arguments to activate.
*
* @param devEui Device EUI (16 character string with hexadecimal data)
* @param appEui Application EUI of the device (16 character string with hexadecimal data)
* @param appKey App Key of the device (32 character string with hexadecimal data)
* @param devEui Device EUI (16 character string with hexadecimal data) or NULL if already set
* @return true if the provisioning was successful
* @return false if the provisioning failed
*/
bool provision(const char *appEui, const char *appKey, const char *devEui = NULL);
bool provision(const char *devEui, const char *appEui, const char *appKey);
/**
* @brief Activate the device via OTAA.
*
* @param appEui Application EUI of the device (16 character string with hexadecimal data)
* @param appKey App Key of the device (32 character string with hexadecimal data)
* @param devEui Device EUI (16 character string with hexadecimal data) or NULL if already set
* @param retries Number of times to retry after failed or unconfirmed join. Defaults to -1 which means infinite.
* @param retryDelay Delay in ms between attempts. Defaults to 10 seconds.
* @param devEui Device EUI (16 character string with hexadecimal data)
* @param appEui Application EUI of the device (16 character string with hexadecimal data)
* @param appKey App Key of the device (32 character string with hexadecimal data)
* @return true
* @return false
*/
bool join(const char *appEui, const char *appKey, const char *devEui = NULL, int8_t retries = -1, uint32_t retryDelay = 10000);
bool join(const char *devEui, const char *appEui, const char *appKey);
/**
* @brief Activate the device via OTAA.
*
* The app EUI and key must already have been provisioned.
* The app EUI, app key and dev EUI must already have been provisioned.
*
* @param retries Number of times to retry after failed or unconfirmed join. Defaults to -1 which means infinite.
* @param retryDelay Delay in ms between attempts. Defaults to 10 seconds.
* @return true
* @return false
*/
bool join(int8_t retries = -1, uint32_t retryDelay = 10000);
bool join();
ttn_response_t sendBytes(const uint8_t *payload, size_t length, port_t port = 1, bool confirm = false, uint8_t sf = 0);
ttn_response_t sendBytes(const uint8_t *payload, size_t length, port_t port = 1, bool confirm = false);
private:
uint8_t spreadingFactor = TTN_DEFAULT_SF;
uint8_t frequencySubband = TTN_DEFAULT_FSB;
bool decodeKeys(const char *appEui, const char *appKey, const char *devEui);
bool decodeKeys(const char *devEui, const char *appEui, const char *appKey);
};
#endif

View File

@ -21,9 +21,9 @@
static const char *TAG = "ttn";
static TheThingsNetwork* ttnInstance;
static uint8_t devEui[8];
static uint8_t appEui[8];
static uint8_t appKey[16];
static uint8_t devEui[8];
static QueueHandle_t result_queue;
@ -33,12 +33,10 @@ static int hexDigitToVal(char ch);
static void swapByteOrder(uint8_t* buf, int len);
TheThingsNetwork::TheThingsNetwork(uint8_t sf, uint8_t fsb)
TheThingsNetwork::TheThingsNetwork()
{
ASSERT(ttnInstance == NULL);
ttnInstance = this;
spreadingFactor = sf;
frequencySubband = fsb;
hal_initCriticalSection();
}
@ -72,13 +70,21 @@ void TheThingsNetwork::reset()
hal_leaveCriticalSection();
}
bool TheThingsNetwork::provision(const char *appEui, const char *appKey, const char* devEui)
bool TheThingsNetwork::provision(const char *devEui, const char *appEui, const char *appKey)
{
return decodeKeys(appEui, appKey, devEui);
return decodeKeys(devEui, appEui, appKey);
}
bool TheThingsNetwork::decodeKeys(const char *appEui, const char *appKey, const char* devEui)
bool TheThingsNetwork::decodeKeys(const char *devEui, const char *appEui, const char *appKey)
{
if (strlen(devEui) != 16 || !hexStringToBin(devEui, ::devEui, 8))
{
ESP_LOGW(TAG, "Invalid device EUI: %s", devEui);
return false;
}
swapByteOrder(::devEui, 8);
if (strlen(appEui) != 16 || !hexStringToBin(appEui, ::appEui, 8))
{
ESP_LOGW(TAG, "Invalid application EUI: %s", appEui);
@ -93,26 +99,18 @@ bool TheThingsNetwork::decodeKeys(const char *appEui, const char *appKey, const
return false;
}
if (strlen(devEui) != 16 || !hexStringToBin(devEui, ::devEui, 8))
{
ESP_LOGW(TAG, "Invalid device EUI: %s", devEui);
return false;
}
swapByteOrder(::devEui, 8);
return true;
}
bool TheThingsNetwork::join(const char *appEui, const char *appKey, const char *devEui, int8_t retries, uint32_t retryDelay)
bool TheThingsNetwork::join(const char *devEui, const char *appEui, const char *appKey)
{
if (!decodeKeys(appEui, appKey, devEui))
if (!decodeKeys(devEui, appEui, appKey))
return false;
return join(retries, retryDelay);
return join();
}
bool TheThingsNetwork::join(int8_t retries, uint32_t retryDelay)
bool TheThingsNetwork::join()
{
hal_enterCriticalSection();
LMIC_startJoining();
@ -130,7 +128,7 @@ bool TheThingsNetwork::join(int8_t retries, uint32_t retryDelay)
return result == EV_JOINED;
}
ttn_response_t TheThingsNetwork::sendBytes(const uint8_t *payload, size_t length, port_t port, bool confirm, uint8_t sf)
ttn_response_t TheThingsNetwork::sendBytes(const uint8_t *payload, size_t length, port_t port, bool confirm)
{
hal_enterCriticalSection();
if (LMIC.opmode & OP_TXRXPEND)