Lopy and Matchx usage



  • @misterlisty
    Did you try it on the REPL?

    Try print(lora.frequency())



  • @jmarcelino

    from network import LoRa
    lora = LoRa()
    lora.frequency()
    

    doesn't return anything...

    My firmware is MicroPython v1.8.6-834-g5677703c on 2017-11-13; FiPy with ESP32



  • @misterlisty
    Is your LoPy configured configured for the EU868 region by any chance?

    It should have selected 915Mhz if you chose Australia during firmware upgrade.

    Please check with

    from network import LoRa
    lora = LoRa()
    lora.frequency()
    

    also are you running the latest firmware?

    Thanks



  • @jmarcelino I get an error if i try to remove channels upto 72



  • Thanks @misterlisty

    Please remove your all add_channel and remove_channel code and replace it with the following (yes remove_channel should be first). It should then match your gateway configuration. Also change the SO_DR to 3 as mentioned in my previous post. Do try OTAA and ABP if you can.

    for i in range(0, 72):
        lora.remove_channel(i)
    
    # set the 8 channels for MatchX configuration
    for channel in range(0,8):
        lora.add_channel(channel, frequency=915200000+channel*200000, dr_min=0, dr_max=3)
    


  • @jmarcelino

    {
    	"SX1301_conf": {
    		"lorawan_public": true,
    		"clksrc": 1, /* radio_1 provides clock to concentrator */
    		"lbt_cfg": {
    			"enable": true,
    			"rssi_target": -81, /* dBm */
    			"chan_cfg":[ /* 8 channels maximum */
    				{ "freq_hz": 915200000, "scan_time_us": 5000 },
    				{ "freq_hz": 915400000, "scan_time_us": 5000 },
    				{ "freq_hz": 915600000, "scan_time_us": 5000 },
    				{ "freq_hz": 915800000, "scan_time_us": 5000 },
    				{ "freq_hz": 916000000, "scan_time_us": 5000 },
    				{ "freq_hz": 916200000, "scan_time_us": 5000 },
    				{ "freq_hz": 916400000, "scan_time_us": 5000 },
    				{ "freq_hz": 916600000, "scan_time_us": 5000 }
    			],
    			"sx127x_rssi_offset": -7 /* dB */
    		},
    		"antenna_gain": 2, /* antenna gain, in dBi */
    		"radio_0": {
    			"enable": true,
    			"type": "SX1257",
    			"freq": 915600000,
    			"rssi_offset": -166.0,
    			"tx_enable": true,
    			"tx_freq_min": 915000000,
    			"tx_freq_max": 928000000
    		},
    		"radio_1": {
    			"enable": true,
    			"type": "SX1257",
    			"freq": 916300000,
    			"rssi_offset": -166.0,
    			"tx_enable": false
    		},
    		"chan_multiSF_0": {
    			"desc": "Lora MAC, 125kHz, all SF, 915.2 MHz",
    			"enable": true,
    			"radio": 0,
    			"if": -400000
    		},
    		"chan_multiSF_1": {
    			"desc": "Lora MAC, 125kHz, all SF, 915.4 MHz",
    			"enable": true,
    			"radio": 0,
    			"if": -200000
    		},
    		"chan_multiSF_2": {
    			"desc": "Lora MAC, 125kHz, all SF, 915.6 MHz",
    			"enable": true,
    			"radio": 0,
    			"if": 0
    		},
    		"chan_multiSF_3": {
    			"desc": "Lora MAC, 125kHz, all SF, 915.8 MHz",
    			"enable": true,
    			"radio": 0,
    			"if": 200000
    		},
    		"chan_multiSF_4": {
    			"desc": "Lora MAC, 125kHz, all SF, 916.0 MHz",
    			"enable": true,
    			"radio": 1,
    			"if": -300000
    		},
    		"chan_multiSF_5": {
    			"desc": "Lora MAC, 125kHz, all SF, 916.2 MHz",
    			"enable": true,
    			"radio": 1,
    			"if": -100000
    		},
    		"chan_multiSF_6": {
    			"desc": "Lora MAC, 125kHz, all SF, 916.4 MHz",
    			"enable": true,
    			"radio": 1,
    			"if": 100000
    		},
    		"chan_multiSF_7": {
    			"desc": "Lora MAC, 125kHz, all SF, 916.6 MHz",
    			"enable": true,
    			"radio": 1,
    			"if": 300000
    		},
    		"chan_Lora_std": {
    			"desc": "Lora MAC, 500kHz, SF8, 915.825 MHz",
    			"enable": true,
    			"radio": 0,
    			"if": 250000,
    			"bandwidth": 500000,
    			"spread_factor": 8
    		},
    		"chan_FSK": {
    			"desc": "FSK disabled",
    			"enable": false
    		},
    		"tx_lut_0": {
    			/* TX gain table, index 0 */
    			"pa_gain": 0,
    			"mix_gain": 8,
    			"rf_power": -6,
    			"dig_gain": 3
    		},
    		"tx_lut_1": {
    			/* TX gain table, index 1 */
    			"pa_gain": 0,
    			"mix_gain": 10,
    			"rf_power": -3,
    			"dig_gain": 3
    		},
    		"tx_lut_2": {
    			/* TX gain table, index 2 */
    			"pa_gain": 0,
    			"mix_gain": 9,
    			"rf_power": 0,
    			"dig_gain": 0
    		},
    		"tx_lut_3": {
    			/* TX gain table, index 3 */
    			"pa_gain": 0,
    			"mix_gain": 12,
    			"rf_power": 3,
    			"dig_gain": 0
    		},
    		"tx_lut_4": {
    			/* TX gain table, index 4 */
    			"pa_gain": 1,
    			"mix_gain": 8,
    			"rf_power": 6,
    			"dig_gain": 2
    		},
    		"tx_lut_5": {
    			/* TX gain table, index 5 */
    			"pa_gain": 1,
    			"mix_gain": 9,
    			"rf_power": 10,
    			"dig_gain": 0
    		},
    		"tx_lut_6": {
    			/* TX gain table, index 6 */
    			"pa_gain": 1,
    			"mix_gain": 11,
    			"rf_power": 11,
    			"dig_gain": 2
    		},
    		"tx_lut_7": {
    			/* TX gain table, index 7 */
    			"pa_gain": 1,
    			"mix_gain": 11,
    			"rf_power": 12,
    			"dig_gain": 1
    		},
    		"tx_lut_8": {
    			/* TX gain table, index 8 */
    			"pa_gain": 1,
    			"mix_gain": 11,
    			"rf_power": 13,
    			"dig_gain": 0
    		},
    		"tx_lut_9": {
    			/* TX gain table, index 9 */
    			"pa_gain": 1,
    			"mix_gain": 12,
    			"rf_power": 14,
    			"dig_gain": 1
    		},
    		"tx_lut_10": {
    			/* TX gain table, index 10 */
    			"pa_gain": 2,
    			"mix_gain": 8,
    			"rf_power": 16,
    			"dig_gain": 0
    		},
    		"tx_lut_11": {
    			/* TX gain table, index 11 */
    			"pa_gain": 2,
    			"mix_gain": 12,
    			"rf_power": 20,
    			"dig_gain": 2
    		},
    		"tx_lut_12": {
    			/* TX gain table, index 12 */
    			"pa_gain": 2,
    			"mix_gain": 14,
    			"rf_power": 23,
    			"dig_gain": 2
    		},
    		"tx_lut_13": {
    			/* TX gain table, index 13 */
    			"pa_gain": 2,
    			"mix_gain": 15,
    			"rf_power": 25,
    			"dig_gain": 0
    		},
    		"tx_lut_14": {
    			/* TX gain table, index 14 */
    			"pa_gain": 3,
    			"mix_gain": 11,
    			"rf_power": 26,
    			"dig_gain": 3
    		},
    		"tx_lut_15": {
    			/* TX gain table, index 15 */
    			"pa_gain": 3,
    			"mix_gain": 13,
    			"rf_power": 28,
    			"dig_gain": 0
    		}
    	},
    	"gateway_conf": {
    		/* change with default server address/ports, or overwrite in local_conf.json */
    		"server_address": "aux.matchx.io",
    		"serv_port_up": 1700,
    		"serv_port_down": 1700,
    		/* adjust the following parameters for your network */
    		"keepalive_interval": 10,
    		"stat_interval": 30,
    		"push_timeout_ms": 100,
    		/* forward only valid packets */
    		"forward_crc_valid": true,
    		"forward_crc_error": false,
    		"forward_crc_disabled": false,
    		/* GPS configuration */
    		"gps_tty_path": "/dev/ttyS1",
    		/* GPS reference coordinates */
    		"ref_latitude": 0.0,
    		"ref_longitude": 0.0,
    		"ref_altitude": 0
    	}
    }
    


  • @misterlisty said in Lopy and Matchx usage:

    s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)

    Data Rate 5 isn't valid for your region, that's for EU868. Aren't you receiving an error trying to set it?

    Try data rate 3:
    s.setsockopt(socket.SOL_LORA, socket.SO_DR, 3)

    also your remove channel loop needs to remove up to channel 72, not just 16

    for i in range(3, 72):
        lora.remove_channel(i)
    

    Ideally you shouldn't set them all to the same frequency and should set channels 0 - 7 to match you frequency plan - the 8 frequencies your gateway is listen on. Can you post your frequency plan again from your gateway configuration? I think you posted it before but then removed it.



  • @jmarcelino I'm now trying to use BDP instead but i get no indication of connection from MtachX anymore..any suggestion?

    0_1514887564890_Capture.PNG

    0_1514887571530_Capture2.PNG

    Here is my code

    from network import LoRa
    import socket
    import time
    import binascii
    import struct
    
    # Initialize LoRa in LORAWAN mode.
    # lora = LoRa(mode=LoRa.LORAWAN, rx_iq=True, tx_power=14, power_mode=LoRa.ALWAYS_ON, public=True, tx_retries=1)
    
    lora = LoRa(mode=LoRa.LORAWAN)
    print("Lora send::-3")
    
    print("DevEUI[",binascii.hexlify(lora.mac()).upper().decode('utf-8'),"]")
    
    # create an OTAA authentication parameters
    # dev_eui = binascii.unhexlify('70 B3 D5 49 97 E4 4C 6E'.replace(' ','')) 
    # app_eui = binascii.unhexlify('70 B3 D5 7E D0 00 81 BD'.replace(' ',''))
    # app_key = binascii.unhexlify('77 E7 AE FA 56 67 78 3D 5C 2F 4A E0 B9 F2 E3 FC'.replace(' ',''))
    
    
    # create an ABP authentication parameters
    dev_eui = struct.unpack(">l", binascii.unhexlify('AE A7 4C 1B'.replace(' ','')))[0]
    # dev_eui = binascii.unhexlify('AE A7 4C 1B'.replace(' ',''))
    app_eui = binascii.unhexlify('39 7E 7F A3 AB 51 CB 3B 60 18 3C 85 E6 B5 56 D6'.replace(' ',''))
    app_key = binascii.unhexlify('9A 92 D8 3B 94 D2 6C DF 03 84 EF D3 59 47 14 85'.replace(' ',''))
    
    
    print("Lora send::-2")
    
    # set the 3 default channels to the same frequency
    lora.add_channel(0, frequency=915200000, dr_min=0, dr_max=4)
    lora.add_channel(1, frequency=915200000, dr_min=0, dr_max=5)
    lora.add_channel(2, frequency=915200000, dr_min=0, dr_max=5)
    # lora.add_channel(4, frequency=915800000, dr_min=0, dr_max=5)
    # lora.add_channel(5, frequency=916000000, dr_min=0, dr_max=5)
    # lora.add_channel(6, frequency=916200000, dr_min=0, dr_max=5)
    # lora.add_channel(7, frequency=916400000, dr_min=0, dr_max=5)
    # lora.add_channel(8, frequency=915600000, dr_min=0, dr_max=5)
    # lora.add_channel(9, frequency=916600000, dr_min=0, dr_max=5)
    print("Lora send::-1")
    
    
    def lora_cb(lora):
        events = lora.events() 
        if events & LoRa.RX_PACKET_EVENT:
            print('Lora packet received')
        if events & LoRa.TX_PACKET_EVENT:
            print('Lora packet sent')
    
    # lora.callback(trigger=(LoRa.RX_PACKET_EVENT | LoRa.TX_PACKET_EVENT), handler=lora_cb)
    
    # join a network using OTAA (Over the Air Activation)
    # lora.join(activation=LoRa.OTAA, auth=(dev_eui,app_eui, app_key), timeout=0)
    lora.join(activation=LoRa.ABP, auth=(dev_eui,app_eui, app_key), timeout=0)
    print("Lora send::0")
    # remove all the non-default channels
    ##for i in range(0, 16):
    ##    lora.remove_channel(i)
    
    # wait until the module has joined the network
    while not lora.has_joined():
        time.sleep(5)
        print('Not yet joined...')
    
    # remove all the non-default channels
    for i in range(3, 16):
        lora.remove_channel(i)
    
    # create a LoRa socket
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    
    print("Lora send::1")
    
    i = 0
    while True:
        print("Lora send::1")
        # set the LoRaWAN data rate
        s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
        print("Lora send::2")
        # make the socket blocking
        # (waits for the data to be sent and for the 2 receive windows to expire)
        s.setblocking(True)
        print("Lora send::3")
        # send some data
        count = s.send(bytes([i % 256]))
        print('Sent %s bytes' % count)
        print("Lora send::4")
        # make the socket non-blocking
        # (because if there's no data received it will block forever...)
        s.setblocking(False)
        print("Lora send::5")
        # get any data received (if any...)
        data = s.recv(64)
        print("Lora send::",data)
        i += 1


  • @jmarcelino Hope this helps :)

    0_1514769924638_lora2.PNG

    0_1514769946358_lora1.PNG



  • @misterlisty
    At first sight that screenshot looks fine, you have an uplink (likely the join request) from the LoPy and then a downlink on 923.3Mhz which is the RX2 window so it should be the join accept reply.

    Do you have any option to use the RX1 window instead? That would be preferrable. I haven't used MatchX backend in months.

    The MatchX is also transmitting with some crazy power (30), try to have the nodes well apart otherwise the receiver on the LoPy will be overloaded.

    If that doesn't help pos the exact macPayload for both uplink and downlinks - you need to expand fields so I can understand exactly what's being sent.



  • ok..getting some activity now...but the code says it hasn't joined yet?

    0_1514639054703_Capture.PNG



  • @misterlisty

    Yes for Australia you need to set it, what’s your channel plan on the MatchX?



  • @jmarcelino thank you, what about frequency? Do i have to set this? I'm in Austrlia.



  • @misterlisty
    Also to use the dev_eui you set you need to add it to the auth parameter like this:

    lora.join(activation=LoRa.OTAA, auth=(dev_eui, app_eui, app_key), timeout=0)



  • @misterlisty
    App is just short for Application, so use Application EUI and Application Key for app_eui and app_key respectively.



  • 0_1514588836432_Capture.PNG

    Here is my matchx setup...



  • @misterlisty
    Are you using MatchX’s own backend server? If so you to need to register a new device and get those values from there.


 

Pycom on Twitter