Pygate, lopy4 & TTN



  • Greetings all! I am a junior copypasteprofessional so please be gentle & patient with me... Just entering the LoRa and Pycom world and it really isn't straighforward for a beginner... I agree with some fellow writers that there is awfully much more room to make much more detailed guidance for beginner-enthusiasts like myself. Making videos on youtube on the real basics would be helpful. I mean really start with a blank sheet that one shows how to download Atom etc. for someone who has never been touching micropython or any other programming languages, one should really try to make the threshhold as low as possible - perhaps using willing noobs like myself as partners. Sorry long intro...

    Trying to connect Pygate with Lopy4 to TTN. I have the PoE adapter to Pygate. I have copy pasted the good examples from Pycom websites and somehow managed (via copying them to notepad as text files and then renaming them .py and .json - yes a beginner) to include them in Atom. I don't know how to run a "project" in Atom (its always downloading the whole .atom folder if I try) so I made a sub-folder and placed main.py and config.json there. "Running selected file" I get the main.py running but it always gets stuck somewhere. I cleared many hurdles... It connects to my phone's wlan network but obviously that does not mean internet access as the RTC does not get readings. Managed to fix that by copy-pasting code that fires up the ethernet.
    eth = ETH()
    eth.ifconfig(config=('192.168.1.13','255.255.255.0','192.168.1.1','192.168.1.1'))
    I forced an ip and it claims it is in internet connection (it was some command I copy pasted from Pycom website, ending () ) but again this does not get a TTN connected (never been visible even). I was long stuck at the fp = open('/flash/config.json','r') line and then bumped into advice that one should change the r to wb and then back to r - and it really worked. But just crazy in its absence of logic (or is it?) but again that is cleared. Now I get the red light up in the Lopy4 up and before obviously some attempts for connection tarting LoRaWAN concentrator but here I get stuck and would appreciate your help... what is the issue of main and it not being a json file? Again, this could be a quick fix but for a beginner likemyself difficult (but a nice journey). Really the main.py and config.json files I have are just copy paste's (apart from now taking the wlan away and adding the ethernet) so I am not including them here.

    ETH Connection established
    Syncing RTC via ntp.............. OK

    [1187370997] lorapf: INFO_ lora_gw_init() start fh=347600 high=7508 LORA_GW_STACK_SIZE=15000
    [1187370998] lorapf: INFO_ lora_gw_init() done fh=332596 high=7508
    [1187371054] lorapf: INFO_ *** Packet Forwarder for Lora PicoCell Gateway ***
    Version: undefined
    [1187371055] lorapf: INFO_ lorapf *** Lora concentrator HAL library version info ***
    Version: " 0.2.3 ";
    [1187371062] lorapf: INFO_ [main] Little endian host
    [1187371066] lorapf: ERROR [main] is not a valid JSON file
    [1187371071] lorapf: INFO_ [main] Stopping concentrator

    The additional questions I have relate to the Lopy4 (I think). Namely when I try to run the code that I can find at Pycom website like

    from network import LoRa

    import binascii

    lora = LoRa(mode=LoRa.LORAWAN)

    It always crashes. I have been downloading I think all the software versions I can find in the updater, and I am using the pygate one; I have been clicking the 3 boxes that erases the previous data etc.. But again with the goal of getting TTN connection, I might need to be able run these codes (?). Is there some incompatibility issue with PoE and Lopy4? I would not like to use wifi and that is why I chose the PoE. Sorry the long and poor explanations.... The main question perhaps relates to the issue in [1187371066] lorapf: ERROR [main] is not a valid JSON file
    I am pretty confident that I have done everything correctly at TTN website with the identifications and frequencies. I will not have a wireless lora coverage to the nearest signal, but isnt that exactly what for example PoE should "cover". Thanks for any ideas.



  • @Copypastepro
    I was trying to connect a gateway to TTN as well last Friday, and for some reason I had a hard time with that as well. The initial discovery was really slow (that might also be caused by me using different pygates under the same EUI, sometimes (accidentally) simultaneously), so I cannot tell you where the fault is exactly. Great to see you got it working.
    the line

    1452258414] lorapf: INFO_ [main] gateway MAC address is configured to lX
    

    saying lX at the end is my fault, I will get it fixed in the next pygate firmware! (If you're interested, we switched from using printf(..) to mp_printf(..) to make the logs also show up on telnet, but apparently the format that prints the MAC, %016llX, is not implemented in the latter)

    Gijs



  • @Copypastepro said in Pygate, lopy4 & TTN:

    @Gijs Greetings, I got it working. After perhaps 30 save/save all/hard and soft boots / closing Atom and opening again. So brute force, and I really don't know what was the reason. Thanks anyway!

    One more question if I may... I have on the houses outer wall a 4G mobile antenna (Pyonting) which is not in use anymore, but which has 2 SMA antennas. I connected Pygate the the other. What is the best way to know if the antenna is really connected? Any other concerns I should have? The antenna is (I think) at least to some degree directional but not all that narrow if I gather right.



  • @Gijs Greetings, I got it working. After perhaps 30 save/save all/hard and soft boots / closing Atom and opening again. So brute force, and I really don't know what was the reason. Thanks anyway!



  • @Gijs Thanks once again. But I have that part correctly. Green light OK, so the router.eu.thethings.network works well. If I drop the "router" from the script and download it, it changes the server address accordingly, but it does not matter what I do with the gateway ID part, that will not have an affect, it stays always says "lX".

    1452258414] lorapf: INFO_ [main] gateway MAC address is configured to lX

    I tried also adding a new gateway to TTN but to no effect. What can it be...?



  • @Copypastepro said in Pygate, lopy4 & TTN:

    The issue with Lora not working with Pygate firmware is just too confusing to my small head... If I understand correctly, there is no need for Lopy4 LoRa for me, I get the gateway up and running with the internal LoRa of Gygate...?

    I get that this might indeed be confusing to you. To explain, you could also run a Wipy or Gpy on a Pygate expansionboard. The LoRa gateway module used by the Pygate uses the LoRa radio on the Pygate, instead of the onboard LoRa radio of the Lopy4. Now there is a pin-conflict that disallows the LoRa radio of the Lopy4 to be used while the Pygate firmware version is loaded. (Also, there is no real usecase to built a LoRa node on top of a Pygate)

    Now, it seems that the Gateway ID (EUI) you set on the Pygate does not match the Gateway ID in TTN.

    Did you perhaps not set the gateway ID in the config.json like here:

    "gateway_conf": {
    		"gateway_ID": "XXXXXXXXXXXXXXXX",
    		"server_address": "router.eu.thethings.network",
    		"serv_port_up": 1700,
    		"serv_port_down": 1700,
    		"keepalive_interval": 10,
    		"stat_interval": 30,
    		"push_timeout_ms": 100,
    		"forward_crc_valid": true,
    		"forward_crc_error": false,
    		"forward_crc_disabled": false
    	}
    

    Other than that, the responses seem fine to me!

    Let me know!
    Gijs



  • Thank you! I managed to come rather far after having the "project" properly assigned. Light turns green on Lopy4. But still no connection to TTN. I gather that there is some problem with the MAC address (or is this the same what TTN calls gateway ID?), its not transmitting the details I have for gateway ID in the config.json (and matching at TTN). If any idea what might be the reason, much appreciated.

    The issue with Lora not working with Pygate firmware is just too confusing to my small head... If I understand correctly, there is no need for Lopy4 LoRa for me, I get the gateway up and running with the internal LoRa of Gygate...?

    [1376073791] lorapf: INFO_ [main] gateway MAC address is configured to lX

    ETH Connection established
    [1379734467] lorapf: INFO_ lora_gw_init() start fh=347888 high=7556 LORA_GW_STACK_SIZE=15000
    [1379734469] lorapf: INFO_ lora_gw_init() done fh=332884 high=7556
    Pycom MicroPython 1.20.2.rc11 [v1.11-d574024] on 2020-08-25; LoPy4 with ESP32
    Pybytes Version: 1.5.2
    Type "help()" for more information.

    [1379734483] lorapf: INFO_ *** Packet Forwarder for Lora PicoCell Gateway ***
    Version: undefined
    [1379734491] lorapf: INFO_ lorapf *** Lora concentrator HAL library version info ***
    Version: " 0.2.3 ";
    [1379734501] lorapf: INFO_ [main] Little endian host
    [1379734547] lorapf: INFO_ [main] lorawan_public 1, clksrc 1
    lgw_board_setconf:592: Note: board configuration; lorawan_public:1, clksrc:1
    [1379734548] lorapf: INFO_ [main] antenna_gain 0 dBi
    [1379734556] lorapf: INFO_ [main] Configuring TX LUT with 16 indexes
    [1379734559] lorapf: INFO_ [main] radio 0 enabled (type SX1257), center frequency 867500000, RSSI offset -165.999994, tx enabled 1
    lgw_rxrf_setconf:626: Note: rf_chain 0 configuration; en:1 freq:867500000 rssi_offset:-166.000000 radio_type:2 tx_enable:1
    [1379734581] lorapf: INFO_ [main] radio 1 enabled (type SX1257), center frequency 868500000, RSSI offset -165.999994, tx enabled 0
    lgw_rxrf_setconf:626: Note: rf_chain 1 configuration; en:1 freq:868500000 rssi_offset:-166.000000 radio_type:2 tx_enable:0
    [1379734603] lorapf: INFO_ [main] Lora multi-SF channel 0> radio 1, IF -400000 Hz, 125 kHz bw, SF 7 to 12
    lgw_rxif_setconf:745: Note: LoRa 'multi' if_chain 0 configuration; en:1 freq:-400000 SF_mask:0x7e
    [1379734621] lorapf: INFO_ [main] Lora multi-SF channel 1> radio 1, IF -200000 Hz, 125 kHz bw, SF 7 to 12
    lgw_rxif_setconf:745: Note: LoRa 'multi' if_chain 1 configuration; en:1 freq:-200000 SF_mask:0x7e
    [1379734639] lorapf: INFO_ [main] Lora multi-SF channel 2> radio 1, IF 0 Hz, 125 kHz bw, SF 7 to 12
    lgw_rxif_setconf:745: Note: LoRa 'multi' if_chain 2 configuration; en:1 freq:0 SF_mask:0x7e
    [1379734656] lorapf: INFO_ [main] Lora multi-SF channel 3> radio 0, IF -400000 Hz, 125 kHz bw, SF 7 to 12
    lgw_rxif_setconf:745: Note: LoRa 'multi' if_chain 3 configuration; en:1 freq:-400000 SF_mask:0x7e
    [1379734674] lorapf: INFO_ [main] Lora multi-SF channel 4> radio 0, IF -200000 Hz, 125 kHz bw, SF 7 to 12
    lgw_rxif_setconf:745: Note: LoRa 'multi' if_chain 4 configuration; en:1 freq:-200000 SF_mask:0x7e
    [1379734692] lorapf: INFO_ [main] Lora multi-SF channel 5> radio 0, IF 0 Hz, 125 kHz bw, SF 7 to 12
    lgw_rxif_setconf:745: Note: LoRa 'multi' if_chain 5 configuration; en:1 freq:0 SF_mask:0x7e
    [1379734709] lorapf: INFO_ [main] Lora multi-SF channel 6> radio 0, IF 200000 Hz, 125 kHz bw, SF 7 to 12
    lgw_rxif_setconf:745: Note: LoRa 'multi' if_chain 6 configuration; en:1 freq:200000 SF_mask:0x7e
    [1379734727] lorapf: INFO_ [main] Lora multi-SF channel 7> radio 0, IF 400000 Hz, 125 kHz bw, SF 7 to 12
    lgw_rxif_setconf:745: Note: LoRa 'multi' if_chain 7 configuration; en:1 freq:400000 SF_mask:0x7e
    [1379734744] lorapf: INFO_ [main] Lora std channel> radio 1, IF -200000 Hz, 250000 Hz bw, SF 7
    lgw_rxif_setconf:719: Note: LoRa 'std' if_chain 8 configuration; en:1 freq:-200000 bw:2 dr:2
    [1379734761] lorapf: INFO_ [main] FSK channel> radio 1, IF 300000 Hz, 125000 Hz bw, 50000 bps datarate
    lgw_rxif_setconf:775: Note: FSK if_chain 9 configuration; en:1 freq:300000 bw:3 dr:50000 (50000 real dr) sync:0xc194c1
    [1379734825] lorapf: INFO_ [main] gateway MAC address is configured to lX
    [1379734826] lorapf: INFO_ [main] server hostname or IP address is configured to "router.eu.thethings.network"
    [1379734830] lorapf: INFO_ [main] upstream port is configured to "1700"
    [1379734836] lorapf: INFO_ [main] downstream port is configured to "1700"
    [1379734843] lorapf: INFO_ [main] packets received with a valid CRC will be forwarded
    [1379734850] lorapf: INFO_ [main] packets received with a CRC error will NOT be forwarded
    [1379734858] lorapf: INFO_ [main] packets received with no CRC will NOT be forwarded
    [1379734869] lorapf: INFO_ [main] found global configuration file and parsed correctly
    lgw_calibrate_sx125x:511: Note: calibration started (time: 2300 ms)
    lgw_calibrate_sx125x:532: Note: calibration finished (status = 0xBF)
    lgw_calibrate_sx125x:569: calibration a_i = 102
    lgw_calibrate_sx125x:569: calibration a_i = 81
    lgw_calibrate_sx125x:569: calibration a_i = 64
    lgw_calibrate_sx125x:569: calibration a_i = 55
    lgw_calibrate_sx125x:569: calibration a_i = 42
    lgw_calibrate_sx125x:569: calibration a_i = 34
    lgw_calibrate_sx125x:569: calibration a_i = 27
    lgw_calibrate_sx125x:569: calibration a_i = 21
    lgw_calibrate_sx125x:511: Note: calibration started (time: 2300 ms)
    lgw_calibrate_sx125x:532: Note: calibration finished (status = 0xBF)
    lgw_calibrate_sx125x:569: calibration a_i = 55
    lgw_calibrate_sx125x:569: calibration a_i = 42
    lgw_calibrate_sx125x:569: calibration a_i = 34
    lgw_calibrate_sx125x:569: calibration a_i = 27
    lgw_calibrate_sx125x:569: calibration a_i = 21
    lgw_calibrate_sx125x:569: calibration a_i = 17
    lgw_calibrate_sx125x:569: calibration a_i = 14
    lgw_calibrate_sx125x:569: calibration a_i = 11
    Info: Initialising AGC firmware...
    Info: putting back original RADIO_SELECT value
    [1379740950] lorapf: INFO_ [main] concentrator started, packet can now be received
    [1379740952] lorapf: INFO_ [13797L40953Ra GW sta[r[upte ]d
    [1379740954]] lorapf: I1379740954] start
    NFO_ [down] stalorapf: INFrt
    O_ [ts lorapf: IN] start
    FO_ [jit ] start
    [1379741362] lorapf: INFO_ [up ] received pkt from mote: D0036C44 (fcnt=46037/B3D5), RSSI -29.0
    [1379741415] lorapf: WARN_ [up ] PUSH_ACK recieve timeout 0
    [1379770955] lorapf: INFO_ [main] report

    2020-10-22 21:36:12 GMT

    [UPSTREAM]

    RF packets received by concentrator: 1

    CRC_OK: 100.00%, CRC_FAIL: 0.00%, NO_CRC: 0.00%

    RF packets forwarded: 1 (23 bytes)

    PUSH_DATA datagrams sent: 1 (203 bytes)

    PUSH_DATA acknowledged: 100.00%

    [DOWNSTREAM]

    PULL_DATA sent: 6 (100.00% acknowledged)

    PULL_RESP(onse) datagrams received: 0 (0 bytes)

    RF packets sent to concentrator: 0 (0 bytes)

    TX errors: 0

    [JIT]

    [jit] queue is empty

    [GPS]

    GPS sync is disabled

    END

    [1379771077] lorapf: WARN_ [up ] PUSH_ACK recieve timeout 0

    Downloading project (main folder)...

    [1379781226] lorapf: INFO_ [jit ] end
    Safe booting device... (see settings for more info)
    [1379781237] lorapf: INFO_ [up ] End of upstream thread

    Pycom MicroPython 1.20.2.rc11 [v1.11-d574024] on 2020-08-25; LoPy4 with ESP32
    Pybytes Version: 1.5.2
    Type "help()" for more information.

    Reading files from board



  • Hi,
    First of all, thanks for the feedback, we work hard on making our products accessible for first-time users and it is hard to assume a starting level somewhere. For me, I learned my way around the products by trying examples and evaluating the results. Now I know, we could do with much better examples and more step-by-step guides to improve the process but I want to believe we've come a long way already :)

    To answer your questions in some sort of order, the project we refer to is just a folder, nothing more. In Atom, you can go to File->Add project folder and open or create a new folder. Then you can add files to the folder by naming them main.py and boot.py (you could even do without the boot.py if you do not plan to use it) and the config.json.

    Now it seems the JSON file is not uploading to your device (As to why you first have to write it, using wb). With an empty JSON file, it is indeed not reading the configuration as you mention.

    Then, if you have the correct files in the 'project' folder, you can upload them to the device using the upload button in Pymakr, not the Play button). You will see the upload happening in the REPL terminal.

    Another culprit here is, while counterintuitive I agree, it is not possible to use LoRa on the Lopy4 with Pygate firmware, If you plan to use LoRa on the Lopy, load the pybytes firmware. The Pygate expansion board has a separate LoRa radio that is used for the Gateway.

    Sorry, long explanation as well. Let me know if I was clear!
    Best,
    Gijs


Log in to reply
 

Pycom on Twitter