Closed Alixpat closed 5 months ago
That's a weird Exception. Your devaddr is correct (valid ttn devaddr begins with 38) so no exception should be thrown. Can you paste/attach the cache.json for me to look at plz. Also check dragino.py indentation hasn't gotten out of kilter. Note, I'm halfway through a bottle of wine right now so would only make sense in the morning. Lol.
I have a sneaking suspicion that the devaddr has been cached as a bytearray instead of a list. If you delete cache.json and run the test.py again the code will rejoin TTN and store fresh data in cache.json. That may or may not work.
cache.json :
{"data_rate": 3, "channelJoinFrequencies": [868.1, 868.3, 868.5], "channelTxFrequencies": [868.1, 868.3, 868.5, 867.1, 867.3, 867.5, 868.7, 867.9], "channelRX1Frequencies": [868.1, 868.3, 868.5, 867.1, 867.3, 867.5, 868.7, 867.9], "output_power": 15, "max_power": 15, "duty_cycle": 1, "rx1_DR": 3, "rx2_DR": 3, "rx1_freq_fixed": false, "rx2_frequency": 869.525, "rx1_delay": 5, "rx2_delay": 1, "appkey": [5, 164, 28, 178, 1, 211, 183, 215, 203, 94, 232, 60, 155, 89, 238, 86], "appeui": [170, 170, 170, 170, 170, 170, 170, 170], "deveui": [112, 179, 213, 126, 208, 6, 110, 35], "devaddr": [38, 11, 89, 61], "appskey": [211, 201, 209, 25, 141, 23, 253, 4, 69, 39, 66, 148, 125, 255, 59, 206], "nwkskey": [152, 85, 14, 179, 75, 201, 101, 250, 245, 50, 1, 230, 104, 39, 137, 56], "fCntUp": 1, "fCntDn": 0, "max_duty_cycle": 1.0}
I remove cache.json, try again, I have a new devaddr but the error is the same
My original suspicion was wrong - the devaddr is not stored as a bytearray but I have found a typo in dragino.py at line 575
if not devaddr[0] in self.config[DEVADDR][VAILD_DEVADDR]:
should be
if not devaddr[0] in self.config[DEVADDR][VALID_DEVADDR]:
that might be the cause. I have updated the repo.
I do apologise for this, the code was being developed on a couple of devices simultaneously. Careless of me.
I have cloned the modified repository. However, I am still encountering the same error.
2024-04-23 19:21:05,505 - registered - 583 - INFO - whilst checking devaddr [38, 11, 85, 170] error was 'devaddr'
2024-04-23 19:21:07,507 - registered - 557 - INFO - checking if already registered.
2024-04-23 19:21:07,508 - registered - 563 - INFO - devaddr [38, 11, 85, 170] len 4.
2024-04-23 19:21:07,508 - registered - 583 - INFO - whilst checking devaddr [38, 11, 85, 170] error was 'devaddr'
2024-04-23 19:21:09,511 - registered - 557 - INFO - checking if already registered.
2024-04-23 19:21:09,512 - registered - 563 - INFO - devaddr [38, 11, 85, 170] len 4.
2024-04-23 19:21:09,512 - registered - 583 - INFO - whilst checking devaddr [38, 11, 85, 170] error was 'devaddr'
on line 51 in Strings.py change this
VALID_DEVADDR="VALID_DEV_ADDR"
to this.
VALID_DEVADDR="validDevAddr"
it needs to match the case in dragino.toml. Gosh, I need to be more careful. It's difficult to track changes made on several machines.
I have updated the repo.
I am still encountering the same error :
2024-04-23 19:51:33,961 - saveCache - 489 - INFO - Saving MAC settings
2024-04-23 19:51:33,976 - process_JOIN_ACCEPT - 269 - DEBUG - devaddr: [38, 11, 39, 53]
2024-04-23 19:51:33,977 - process_JOIN_ACCEPT - 270 - DEBUG - nwkskey: [104, 219, 224, 120, 18, 237, 40, 138, 224, 46, 225, 108, 155, 228, 44, 37]
2024-04-23 19:51:33,977 - process_JOIN_ACCEPT - 271 - DEBUG - appskey: [67, 72, 79, 20, 249, 229, 7, 107, 35, 139, 249, 195, 151, 94, 56, 80]
2024-04-23 19:51:33,978 - saveCache - 489 - INFO - Saving MAC settings
2024-04-23 19:51:34,004 - saveCache - 489 - INFO - Saving MAC settings
2024-04-23 19:51:34,487 - registered - 557 - INFO - checking if already registered.
2024-04-23 19:51:34,488 - registered - 563 - INFO - devaddr [38, 11, 39, 53] len 4.
2024-04-23 19:51:34,488 - registered - 583 - INFO - whilst checking devaddr [38, 11, 39, 53] error was 'devaddr'
2024-04-23 19:51:36,491 - registered - 557 - INFO - checking if already registered.
2024-04-23 19:51:36,492 - registered - 563 - INFO - devaddr [38, 11, 39, 53] len 4.
2024-04-23 19:51:36,493 - registered - 583 - INFO - whilst checking devaddr [38, 11, 39, 53] error was 'devaddr'
This is a really weird error - I'd expect Python to say something like the devaddr key doesn't exist. I have added a traceback.print_exception(e) to dragino.py - maybe it can tell me exactly which line is causing the grief.
This would appear in the console window not in the log file.
pi@raspberry:~/dragino-1 $ ./test.py Configuring GPIOs BOARD SpiDev created SX127x chip version is 0x12 initial mode is HF_LORA_RXCONT set_mode : HF_FSK_STDBY initial mode changed to HF_FSK_STDBY set_mode : HF_LORA_SLEEP set_mode : HF_LORA_RXCONT set_mode : HF_LORA_STDBY set_mode : HF_LORA_TX Waiting for JOIN ACCEPT .set_mode : HF_LORA_SLEEP set_mode : HF_LORA_RXCONT ..Traceback (most recent call last): File "/home/pi/dragino-1/dragino/dragino.py", line 577, in registered if not devaddr[0] in self.config[DEVADDR][VALID_DEVADDR]: KeyError: 'devaddr'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/dragino-1/./test.py", line 30, in
That's more helpful. I can see the problem./
if not devaddr[0] in self.config[DEVADDR][VALID_DEVADDR]:
for now just put quotes around DEVADDR - its a misuse of the DEVADDR as defined in Strings.py (devaddr). It needs to be capitalised for accessing the toml file section. I'll probably just underscore it in a minute or two
if not devaddr[0] in self.config["DEVADDR"][VALID_DEVADDR]:
Ok have just pushed an update to Strings.py and Dragino.py - I think that will fix it.
The bug is now fixed !
pi@raspberry:~/dragino-1 $ ./test.py
Configuring GPIOs
BOARD SpiDev created
SX127x chip version is 0x12
initial mode is HF_LORA_RXCONT
set_mode : HF_FSK_STDBY
initial mode changed to HF_FSK_STDBY
set_mode : HF_LORA_SLEEP
set_mode : HF_LORA_RXCONT
set_mode : HF_LORA_STDBY
set_mode : HF_LORA_TX
Waiting for JOIN ACCEPT
.set_mode : HF_LORA_SLEEP
set_mode : HF_LORA_RXCONT
..
Joined
set_mode : HF_LORA_SLEEP
set_mode : HF_LORA_RXCONT
set_mode : HF_LORA_STDBY
set_mode : HF_LORA_TX
Sent Hello World message
set_mode : HF_LORA_SLEEP
set_mode : HF_LORA_RXCONT
set_mode : HF_LORA_SLEEP
set_mode : HF_LORA_RXCONT
set_mode : HF_LORA_STDBY
set_mode : HF_LORA_TX
Sent Hello World message
set_mode : HF_LORA_SLEEP
set_mode : HF_LORA_RXCONT
set_mode : HF_LORA_SLEEP
set_mode : HF_LORA_RXCONT
set_mode : HF_LORA_STDBY
set_mode : HF_LORA_TX
Sent Hello World message
set_mode : HF_LORA_SLEEP
set_mode : HF_LORA_RXCONT
set_mode : HF_LORA_SLEEP
set_mode : HF_LORA_RXCONT
set_mode : HF_LORA_STDBY
set_mode : HF_LORA_TX
Sent Hello World message
set_mode : HF_LORA_SLEEP
set_mode : HF_LORA_RXCONT
set_mode : HF_LORA_SLEEP
set_mode : HF_LORA_RXCONT
set_mode : HF_LORA_STDBY
set_mode : HF_LORA_TX
Sent Hello World message
set_mode : HF_LORA_SLEEP
set_mode : HF_LORA_RXCONT
Thanks a lot again !
No, thank you for helping fix my incompetence.
Dear @BNNorman,
I am experiencing difficulties in establishing an OTAA connection using the library. Below are the logs captured during my attempt to connect with test.py :
It appears that despite receiving a JOIN_ACCEPT packet, the device does not seem to be properly registered, as indicated by the repeated 'devaddr' error.
Could you please advise if there are specific configurations or steps I might have missed? Any help in resolving this issue would be greatly appreciated.
Thank you for your time and assistance.
Best regards,