jeroennijhof / LoRaWAN

LoRaWAN implementation in python
116 stars 85 forks source link

Communication seems OK, but nothing on TTN console in otaa mode #3

Closed hallard closed 6 years ago

hallard commented 7 years ago

Hi there, I'm trying this lib in Python, seems to works but can't find any trace on activation or device on TTN console So I tried my board on RPI 3 with my custom LMIC port for RPI and its working fine and I can see activation and data into TTN console so it's not hardware related Of course I copied deveui/appeui/appkey from my working LMICexample to Python ttn_otaa.py, I also adjusted pin definition and device is detected in python

here the result of otaa_tty.py, I set verbose to true, there is a receive done, all seems fine but I see nothing on ttn, did I missed something ? Is there any way to have (for debug) a join request/accept callback ?

Thanks for any help

root@pi03(rw):~/LoRaWAN# ./otaa_ttn.py
Mode <- SLEEP
Mode <- FSK_STDBY
Mode <- SLEEP
Mode <- FSK_STDBY
Mode <- SLEEP
SX127x LoRa registers:
 mode               SLEEP
 freq               868.099976 MHz
 coding_rate        CR4_5
 bw                 BW125
 spreading_factor   128 chips/symb
 implicit_hdr_mode  OFF
 rx_payload_crc     ON
 tx_cont_mode       OFF
 preamble           8
 low_data_rate_opti OFF
 agc_auto_on        ON
 symb_timeout       100
 freq_hop_period    0
 hop_channel        {'fhss_present_channel': 0, 'crc_on_payload': 0, 'pll_timeout': 0}
 payload_length     1
 max_payload_length 255
 irq_flags_mask     {'valid_header': 0, 'fhss_change_ch': 0, 'cad_done': 0, 'rx_timeout': 0, 'crc_error': 0, 'cad_detected': 0, 'rx_done': 0, 'tx_done': 0}
 irq_flags          {'valid_header': 0, 'fhss_change_ch': 0, 'cad_done': 0, 'rx_timeout': 0, 'crc_error': 0, 'cad_detected': 0, 'rx_done': 0, 'tx_done': 0}
 rx_nb_byte         0
 rx_header_cnt      0
 rx_packet_cnt      0
 pkt_snr_value      64.000000
 pkt_rssi_value     -157
 rssi_value         -157
 fei                0
 pa_select          PA_BOOST
 max_power          15.000000 dBm
 output_power       14.000000 dBm
 ocp                ON
 ocp_trim           100.000000 mA
 lna_gain           NOT_USED
 lna_boost_lf       0b0
 lna_boost_hf       0b0
 detect_optimize    0x3
 detection_thresh   0xa
 sync_word          0x34
 dio_mapping 0..5   [1, 0, 0, 0, 0, 0]
 tcxo               XTAL
 pa_dac             default
 fifo_addr_ptr      0x0
 fifo_tx_base_addr  0x80
 fifo_rx_base_addr  0x0
 fifo_rx_curr_addr  0x0
 fifo_rx_byte_addr  0x0
 status             {'signal_sync': 0, 'signal_detected': 0, 'modem_clear': 0, 'header_info_valid': 0, 'rx_coding_rate': 0, 'rx_ongoing': 0}
 version            0x12

Sending LoRaWAN message

Mode <- STDBY
Mode <- TX
TxDone
Mode <- STDBY
Mode <- RXCONT
RxDone
[84, 175, 16, 19, 0, 0, 121, 32, 1, 38, 3, 1, 24, 79, 132, 232, 86, 132, 184, 94, 132, 136, 102, 132, 88, 110, 132, 0]
0
32
[237, 65, 155, 123]
[237, 65, 155, 123]
True
['0x99', '0x8f', '0x75', '0xef', '0xb2', '0x4b', '0xc0', '0x77', '0xb', '0xcf', '0xb', '0x3d', '0xc0', '0x18', '0xf9', '0x12']
['0x16', '0x35', '0x62', '0x2c', '0xa6', '0x24', '0xab', '0x3d', '0xf1', '0x50', '0x8b', '0xf8', '0x77', '0x6f', '0xcb', '0xa7']

root@pi03(rw):~/LoRaWAN#

jeroennijhof commented 7 years ago

It looks like a valid response since you now got a nwskey and appskey together with a devaddr. With this you can start sending messages in ABP mode.

You can try removing the device in TTN and recreate it and make sure you change the DEVNONCE value on everytime you do an otaa request.

Anyway I'm still refactoring the code so it will become more readable and usable. A small hack to solve the devnonce randomness is:

from random import randrange
devnonce = [randrange(256), randrange(256)]