CongducPham / LowCostLoRaGw

Low-cost LoRa IoT & gateway with SX12XX (SX1261/62/68; SX1272/76/77/78/79; SX1280/81), RaspberryPI and Arduino boards
703 stars 354 forks source link

Python3 seems to break LORA stack #304

Open man4567890 opened 3 years ago

man4567890 commented 3 years ago

Hi, On a Raspberry PI4 4G running Buster, I installed python 3 and uninstall python 2.7, but that caused some issues I think, when I run

sudo ./lora_gateway --mode 1
`Running simple lora_gateway... CTRL-C to exit
^$**********Power ON
^$Frequency 865200000
^$LoRa addr 1
^$Use PA_BOOST amplifier line
^$Set LoRa txpower dBm to 14
^$Preamble Length: 8
^$Sync word: 0x12
^$SX1276,865199936hz,SF12,BW125000,CR4:5,LDRO_On,SyncWord_0x12,IQNormal,Preamble_8
^$SX1276,SLEEP,Version_12,PacketMode_LoRa,Explicit,CRC_On,AGCauto_On,LNAgain_1,LNAboostHF_On,LNAboostLF_On
^$SX127X configured as LR-BS. Waiting RF input for transparent RF-serial bridge
^$Will safely reset radio module every 100 packet received
^$Low-level gateway has downlink support
2021-03-23T11:25:08.170093
^$Low-level gw status ON

--- rxlora[1]. dst=1 type=0x12 src=20 seq=162 len=31 SNR=7 RSSIpkt=-50 BW=125 CR=4/5 SF=12
^p1,18,20,162,31,7,-50
^r125,5,12,865200
^t2021-03-23T11:25:39.971670*3288710742
ÿþ\!v/3.44/%/100/C/21.70/H/69
^$-----------------------------------------------------
^$Check for downlink requests 2021-03-23T11:25:40.8711383289610210
^$NO NEW DOWNLINK ENTRY

I get the sensor value, but with option 5, I do not see the messages coming in anymore, I used to see the messages come in with python 2.7

Enter your choice: 
5
----------------------------------------------------------------------
BEGIN OUTPUT
Following last lines of ../Dropbox/LoRa-test/post-processing.log. CTRL-C to return
Current UTC date is
Tue 23 Mar 09:28:03 UTC 2021
2021-03-23T10:05:57.443092> new rcv timestamp (^t): 2021-03-23T10:05:57.439802+02:00
2021-03-23T10:05:57.443261> got first framing byte
2021-03-23T10:05:57.443408> --> got LoRa data prefix
2021-03-23T10:05:57.443581> +++ rxlora[865200]. dst=1 type=0x12 src=20 seq=131 len=31 SNR=7 RSSIpkt=-24 BW=125 CR=4/5 SF=12
2021-03-23T10:05:57.443775> --> DATA with_appkey: read app key sequence
2021-03-23T10:05:57.443996> app key is  0x01 0x00 0x00 0x01
2021-03-23T10:05:57.444230> in app key list
2021-03-23T10:05:57.444459> valid app key: accept data
2021-03-23T10:05:57.444659> number of enabled clouds is 1
2021-03-23T10:05:57.444818> --> cloud[0]
2021-03-23T10:05:57.444961> uploading with python CloudMongoDB.py
2021-03-23T10:05:57.445106> python CloudMongoDB.py "v/3.45/%/100/C/21.00/H/73" "1,18,20,131,27,7,-24" "125,5,12,865200" "2021-03-23T10:05:57.439802+02:00" "0000DCA6323AACB5"
2021-03-23T10:05:58.218365> MongoDB with max months to store is 2
2021-03-23T10:05:58.218731> MongoDB: removing obsolete entries
2021-03-23T10:05:58.219099> MongoDB: deleting data older than 2 month(s)...
2021-03-23T10:05:58.219391> MongoDB: 0 documents deleted
2021-03-23T10:05:58.219647> MongoDB: saving the document in the collection...
2021-03-23T10:05:58.219875> {"SNR":7,"RSSI":-24,"v":3.45,"%":100,"C":21.00,"H":73}
2021-03-23T10:05:58.220090> MongoDB: saving done
2021-03-23T10:05:58.223892> --> cloud end
2021-03-23T10:05:58.224098> 
2021-03-23T10:06:07.440910> Low-level gw status ON
2021-03-23T10:06:20.635800> 2021-03-23 10:06:20.635497
2021-03-23T10:06:20.636018> post status: gw ON
2021-03-23T10:06:20.636191> post status: executing periodic tasks

I used to get the messages with python2.7 like this below

Enter your choice: 
5  
----------------------------------------------------------------------
BEGIN OUTPUT
Following last lines of ../Dropbox/LoRa-test/post-processing.log. CTRL-C to return
Current UTC date is
Tue 23 Mar 07:56:58 UTC 2021
2021-03-23T09:56:43.824452> (BW=125 CR=5 SF=12)
2021-03-23T09:56:43.824584> rcv timestamp (^t): 2021-03-23T09:56:43.818898*2247525266
2021-03-23T09:56:43.824712> 
2021-03-23T09:56:43.824834> adding time zone info
2021-03-23T09:56:43.824955> new rcv timestamp (^t): 2021-03-23T09:56:43.818898+02:00
2021-03-23T09:56:43.825080> got first framing byte
2021-03-23T09:56:43.825203> --> got LoRa data prefix
2021-03-23T09:56:43.825324> +++ rxlora[865200]. dst=1 type=0x12 src=20 seq=127 len=31 SNR=7 RSSIpkt=-24 BW=125 CR=4/5 SF=12
2021-03-23T09:56:43.825453> --> DATA with_appkey: read app key sequence
2021-03-23T09:56:43.825574> app key is  0x01 0x00 0x00 0x01
2021-03-23T09:56:43.825701> in app key list
2021-03-23T09:56:43.825851> valid app key: accept data
2021-03-23T09:56:43.825976> number of enabled clouds is 1
2021-03-23T09:56:43.826098> --> cloud[0]
2021-03-23T09:56:43.826217> uploading with python CloudMongoDB.py
2021-03-23T09:56:43.826430> python CloudMongoDB.py "v/3.45/%/100/C/20.90/H/72" "1,18,20,127,27,7,-24" "125,5,12,865200" "2021-03-23T09:56:43.818898+02:00" "0000DCA6323AACB5"
2021-03-23T09:56:44.687664> MongoDB with max months to store is 2
2021-03-23T09:56:44.687880> MongoDB: removing obsolete entries
2021-03-23T09:56:44.688008> MongoDB: deleting data older than 2 month(s)...
2021-03-23T09:56:44.688134> MongoDB: 0 documents deleted
2021-03-23T09:56:44.688268> MongoDB: saving the document in the collection...
2021-03-23T09:56:44.688411> {"SNR":7,"RSSI":-24,"v":3.45,"%":100,"C":20.90,"H":72}
2021-03-23T09:56:44.688555> MongoDB: saving done
2021-03-23T09:56:44.692715> --> cloud end
2021-03-23T09:56:44.692894> 

2021-03-23T09:59:02.226746> --- rxlora[2]. dst=1 type=0x12 src=20 seq=128 len=31 SNR=6 RSSIpkt=-27 BW=125 CR=4/5 SF=12
2021-03-23T09:59:02.227066> 2021-03-23T09:59:02.226652
2021-03-23T09:59:02.227241> rcv ctrl pkt info (^p): 1,18,20,128,31,6,-27
2021-03-23T09:59:02.227403> splitted in:  [1, 18, 20, 128, 31, 6, -27]
2021-03-23T09:59:02.227559> (dst=1 type=0x12(DATA WAPPKEY) src=20 seq=128 len=31 SNR=6 RSSI=-27)
2021-03-23T09:59:02.227730> rcv ctrl radio info (^r): 125,5,12,865200
2021-03-23T09:59:02.227900> splitted in:  [125, 5, 12, 865200]
2021-03-23T09:59:02.228052> (BW=125 CR=5 SF=12)
2021-03-23T09:59:02.228208> rcv timestamp (^t): 2021-03-23T09:59:02.225384*2385931752
2021-03-23T09:59:02.228376> 
2021-03-23T09:59:02.228527> adding time zone info
2021-03-23T09:59:02.228669> new rcv timestamp (^t): 2021-03-23T09:59:02.225384+02:00
2021-03-23T09:59:02.228838> got first framing byte
2021-03-23T09:59:02.229031> --> got LoRa data prefix
2021-03-23T09:59:02.229174> +++ rxlora[865200]. dst=1 type=0x12 src=20 seq=128 len=31 SNR=6 RSSIpkt=-27 BW=125 CR=4/5 SF=12
2021-03-23T09:59:02.229327> --> DATA with_appkey: read app key sequence
2021-03-23T09:59:02.229503> app key is  0x01 0x00 0x00 0x01
2021-03-23T09:59:02.229665> in app key list
2021-03-23T09:59:02.229813> valid app key: accept data
2021-03-23T09:59:02.229969> number of enabled clouds is 1
2021-03-23T09:59:02.230119> --> cloud[0]
2021-03-23T09:59:02.230262> uploading with python CloudMongoDB.py
2021-03-23T09:59:02.230414> python CloudMongoDB.py "v/3.45/%/100/C/20.90/H/72" "1,18,20,128,27,6,-27" "125,5,12,865200" "2021-03-23T09:59:02.225384+02:00" "0000DCA6323AACB5"
2021-03-23T09:59:03.006948> MongoDB with max months to store is 2
2021-03-23T09:59:03.007411> MongoDB: removing obsolete entries
2021-03-23T09:59:03.007866> MongoDB: deleting data older than 2 month(s)...
2021-03-23T09:59:03.008279> MongoDB: 0 documents deleted
2021-03-23T09:59:03.008626> MongoDB: saving the document in the collection...
2021-03-23T09:59:03.008964> {"SNR":6,"RSSI":-27,"v":3.45,"%":100,"C":20.90,"H":72}
2021-03-23T09:59:03.009266> MongoDB: saving done
2021-03-23T09:59:03.014672> --> cloud end
2021-03-23T09:59:03.014947> 
2021-03-23T10:01:20.630243> --- rxlora[3]. dst=1 type=0x12 src=20 seq=129 len=31 SNR=7 RSSIpkt=-24 BW=125 CR=4/5 SF=12
2021-03-23T10:01:20.630507> 2021-03-23T10:01:20.630141
2021-03-23T10:01:20.630709> rcv ctrl pkt info (^p): 1,18,20,129,31,7,-24
2021-03-23T10:01:20.630898> splitted in:  [1, 18, 20, 129, 31, 7, -24]
2021-03-23T10:01:20.631096> (dst=1 type=0x12(DATA WAPPKEY) src=20 seq=129 len=31 SNR=7 RSSI=-24)
2021-03-23T10:01:20.631296> rcv ctrl radio info (^r): 125,5,12,865200
2021-03-23T10:01:20.631485> splitted in:  [125, 5, 12, 865200]
2021-03-23T10:01:20.631679> (BW=125 CR=5 SF=12)
2021-03-23T10:01:20.631859> rcv timestamp (^t): 2021-03-23T10:01:20.628858*2524335226
2021-03-23T10:01:20.632037> 

I need python3 for other developments on the gateway, do you know if the stack build is compatible with python3? I had to change the stats.py as they do not support the Adafruit_BBIO package for the OLED on python3 anymore

pi@raspberrypi:~/lora_gateway/sensors_in_raspi $ python stats.py 
Traceback (most recent call last):
  File "stats.py", line 54, in <module>
    disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_SSD1306-1.6.2-py2.7.egg/Adafruit_SSD1306/SSD1306.py", line 243, in __init__
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_SSD1306-1.6.2-py2.7.egg/Adafruit_SSD1306/SSD1306.py", line 85, in __init__
  File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/GPIO.py", line 420, in get_platform_gpio
ImportError: No module named Adafruit_BBIO.GPIO
pi@raspberrypi:~/lora_gateway/sensors_in_raspi $

See below https://github.com/adafruit/Adafruit_Python_GPIO !!!Deprecation Warning!!! This library has been deprecated in favor of our python3 Blinka library. We have replaced all of the libraries that use this repo with CircuitPython libraries that are Python3 compatible, and support a wide variety of single board/linux computers!

Visit https://circuitpython.org/blinka for more information

I can display the stats like Date, time, IP address, CPU load, but the the message coming in, I get

pi@raspberrypi:~/lora_gateway/sensors_in_raspi $ python stats.py 
Traceback (most recent call last):
  File "stats.py", line 104, in <module>
    draw.text((x, ttop), sys.argv[1], font=font, fill=255)
IndexError: list index out of range
pi@raspberrypi:~/lora_gateway/sensors_in_raspi $

I do not know if that is related to the stack not working

Any advice please?

CongducPham commented 3 years ago

This is normal, all our python scripts are for python 2.7. We have not ported them to python 3 yet.