manuelbl / ttn-esp32

The Things Network device library for ESP32 (ESP-IDF) and SX127x based devices
MIT License
301 stars 64 forks source link

`join(const char *devEui, const char *appEui, const char *appKey)` writes keys to NVS. #31

Closed mkfrey closed 3 years ago

mkfrey commented 3 years ago

Hi, first of all: thank you for providing this library, it seems to be the most comprehensively documented and up-to-date LMIC library for ESP32.

While porting it to C for use in my projects, I've found a mismatch between documentation an implementation:

The in-code documentation of the function join(const char *devEui, const char *appEui, const char *appKey) explicitly states that the keys are not written into the NVS. However, this function calls TTNProvisioning::decodeKeys() which in turn calls TTNProvisioning::decode(). There, TTNProvisioning::saveKeys() is invoked, writing the keys to NVS. This also leads to the keys being written twice to NVS when calling TheThingsNetwork::provision().

Fixing this issue involves removing the call to TTNProvisioning::saveKeys() in TTNProvisioning::decodeKeys() and adapting the TTNProvisioning::processLine() function, which seems to expect that the decoding functions are automatically saving the keys.