Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Lopy and Matchx usage

    Scheduled Pinned Locked Moved Discussion
    matchxgatewaylorawan server
    37 Posts 2 Posters 11.9k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      misterlisty @jmarcelino
      last edited by

      @jmarcelino Hope this helps :)

      0_1514769924638_lora2.PNG

      0_1514769946358_lora1.PNG

      1 Reply Last reply Reply Quote 0
      • M Offline
        misterlisty @jmarcelino
        last edited by

        @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
        
        J 1 Reply Last reply Reply Quote 0
        • J Offline
          jmarcelino @misterlisty
          last edited by jmarcelino

          @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.

          M 2 Replies Last reply Reply Quote 0
          • M Offline
            misterlisty @jmarcelino
            last edited by jmarcelino

            @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
            	}
            }
            
            J 1 Reply Last reply Reply Quote 0
            • J Offline
              jmarcelino @misterlisty
              last edited by

              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)
              
              1 Reply Last reply Reply Quote 0
              • M Offline
                misterlisty @jmarcelino
                last edited by

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

                J 1 Reply Last reply Reply Quote 0
                • J Offline
                  jmarcelino @misterlisty
                  last edited by

                  @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

                  M 2 Replies Last reply Reply Quote 0
                  • M Offline
                    misterlisty @jmarcelino
                    last edited by

                    @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

                    J 1 Reply Last reply Reply Quote 0
                    • J Offline
                      jmarcelino @misterlisty
                      last edited by

                      @misterlisty
                      Did you try it on the REPL?

                      Try print(lora.frequency())

                      1 Reply Last reply Reply Quote 0
                      • M Offline
                        misterlisty @jmarcelino
                        last edited by

                        @jmarcelino The result is 868000000

                        Appears like it isn't Australia..i assume i have to reapply firmware?

                        J 1 Reply Last reply Reply Quote 0
                        • J Offline
                          jmarcelino @misterlisty
                          last edited by jmarcelino

                          @misterlisty

                          Yes that’s set to EU868. We need to reset the device in Pycom’s database before you do a firmware upgrade to change the location. Please send me the MAC address of the WLAN via chat or email a request to support@pycom.io.

                          Thanks

                          import binascii
                          binascii.hexlify(network.WLAN().mac(),':').decode()
                          
                          M 1 Reply Last reply Reply Quote 0
                          • M Offline
                            misterlisty @jmarcelino
                            last edited by jmarcelino

                            @jmarcelino Here is my Mac <removed>

                            How do you know what setting my fopy has? DO you sedn this during firmware update?

                            J 1 Reply Last reply Reply Quote 0
                            • J Offline
                              jmarcelino @misterlisty
                              last edited by

                              Hi,

                              We have no record of your board, so I guess you never updated it?

                              We really recommend always updating all our boards first. The factory firmware tends to be very old - or set to the wrong region as yours was.

                              In any case if you run the upgrade tool and choose Australia, then it should set to 915Mhz correctly and you can use the code I posted.

                              The firmware update instructions are at: https://docs.pycom.io/chapter/gettingstarted/installation/firmwaretool.html

                              Thanks!

                              M 1 Reply Last reply Reply Quote 0
                              • M Offline
                                misterlisty @jmarcelino
                                last edited by

                                @jmarcelino I have connected a wire from GND to G23 and the fopy will not go into upgrade mode. Its connected to a pysense board while i atempt this. It just running my normal code...can i upgrade while connected to the pysense board? Instructions suggest yes.

                                J 1 Reply Last reply Reply Quote 0
                                • J Offline
                                  jmarcelino @misterlisty
                                  last edited by jmarcelino

                                  @misterlisty
                                  Yes you can use the PySense and you don't need the wire anymore.

                                  Make sure you update the Pysense firs, follow the steps here:
                                  https://docs.pycom.io/chapter/pytrackpysense/installation/firmware.html

                                  When you have the new firmware on the Pysense load the the Pycom Firmware Update tool and tick the box which says Pytrack/Pysense:

                                  0_1515239801584_Screen Shot 2018-01-06 at 11.55.52.png

                                  With this setup you don't need the jumper wire as the tool will use the Pysense to put the FiPy into programming mode.

                                  M 1 Reply Last reply Reply Quote 0
                                  • M Offline
                                    misterlisty @jmarcelino
                                    last edited by

                                    @jmarcelino Will atempt update through pysense board shortly but it not upgrading the firmware if i use an USB adapter, connect G23 & GND...its running the normal code instead of going in upgrade mode..any suggestion here?

                                    J 1 Reply Last reply Reply Quote 0
                                    • J Offline
                                      jmarcelino @misterlisty
                                      last edited by jmarcelino

                                      @misterlisty
                                      It has to go into flash programming mode, it's a very low level hardware feature.

                                      Are you sure you are connecting GND and G23 (also called P2 on the pin map https://docs.pycom.io/chapter/datasheets/downloads/fipy-pinout.pdf )

                                      Also when you use an USB adapter what exactly is your setup?

                                      In any case I think it will be easier to use the Pysense.

                                      1 Reply Last reply Reply Quote 0
                                      • M Offline
                                        misterlisty
                                        last edited by

                                        OK..here is my status..have updated Fopy to latest firmware ie 1.1.12b

                                        Here is my OTTA code..it appears to work if you look at the logs of MatchX but code says not yet joined still.

                                        from network import LoRa
                                        import socket
                                        import time
                                        import binascii
                                        import struct
                                        
                                        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(' ',''))
                                        
                                        print("Lora send::-1")
                                        
                                        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)
                                        
                                        lora.join(activation=LoRa.OTAA, auth=(dev_eui,app_eui, app_key), timeout=0)
                                        
                                        print("Lora send::0")
                                        
                                        while not lora.has_joined():
                                            time.sleep(5)
                                            print('Not yet joined...')
                                        
                                        print('Finally 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, 3)
                                            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
                                        

                                        0_1515295131632_Capture.PNG

                                        J 1 Reply Last reply Reply Quote 0
                                        • J Offline
                                          jmarcelino @misterlisty
                                          last edited by jmarcelino

                                          @misterlisty

                                          You're removing channels twice unnecessarily, remove your second part:

                                          > # remove all the non-default channels
                                          > for i in range(3, 16):
                                          >     lora.remove_channel(i)
                                          

                                          Also you're sill using RX2, there are two places for this configuration, I think you missed under Application Configuration -> Network Settings. Please set it to RX1 there.

                                          M 1 Reply Last reply Reply Quote 0
                                          • M Offline
                                            misterlisty @jmarcelino
                                            last edited by misterlisty

                                            @jmarcelino its set to to RX1 as suggested. I now have ABP working :), OTTA is yet to work...its definitely getting a lora_accept signal but the code doesn't acknowledge this.

                                            J 1 Reply Last reply Reply Quote 0

                                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                            With your input, this post could be even better 💗

                                            Register Login
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • First post
                                              Last post

                                            Pycom on Twitter

                                            Pycom