computenodes / dragino

LoRaWAN implementation in python
GNU Affero General Public License v3.0
27 stars 11 forks source link

Can't get test.py to work #5

Closed MelBadura closed 3 years ago

MelBadura commented 3 years ago

Hey, I've tried your code with a raspi 4 and a dragino hat and I get this error. Unfortunately I don't understand it. Help would be much appreciated.

Mode <- SLEEP Mode <- FSK_STDBY Traceback (most recent call last): File "/home/pi/Downloads/dragino-master/test.py", line 13, in D = Dragino("dragino.ini", logging_level=logging.DEBUG) File "/home/pi/Downloads/dragino-master/dragino/dragino.py", line 55, in init super(Dragino, self).init(logging_level < logging.INFO) File "/home/pi/Downloads/dragino-master/dragino/SX127x/LoRa.py", line 100, in init self.rx_chain_calibration(calibration_freq) File "/home/pi/Downloads/dragino-master/dragino/SX127x/LoRa.py", line 854, in rx_chain_calibration self.set_mode(op_mode_bkup) File "/home/pi/Downloads/dragino-master/dragino/SX127x/LoRa.py", line 221, in set_mode sys.stderr.write("Mode <- %s\n" % MODE.lookup[mode]) KeyError: 0

Greetings Mel

pjb304 commented 3 years ago

Hi Mel,

That's not an error I've seen before. From where it appears in the code it's before it attempts to do anything with the credentials given in the dragino.ini file. I suspect the problem is that the code is failing to speak to the loRa module, but the error it's given is not particularly helpful.

Have you enabled SPI on the pi and added the extra overlay file needed for the extra CS pins?

Phil

MelBadura commented 3 years ago

Hi Phil,

yes I've done that. I also know that LoRa works on that raspi with the LMIC library. I justed wanted something in python.

pjb304 commented 3 years ago

Curious,

I'm afraid my next step for debugging would be to attach a logic analyser and check that the data flowing back and forth matches what I'd expect. To me it looks like the op_mode_bkup = self.get_mode() line (834 LoRa.py) is giving an invalid response, which then causes grief when the python tries to send the value back to the LoRa device.

BNNorman commented 3 years ago

This message:-

sys.stderr.write("Mode <- %s\n" % MODE.lookup[mode])
KeyError: 0

Tells me that the value of mode is zero and that it is not a value currently in the list of modes (key error)

If you look at dragino/SX127x/LoRa.py line 837 the rx_chain_calibration() method uses get_mode() to save a copy of the current mode which is then used on line 837 and throws an error there because get_mode() returned zero. Now, get_mode() uses SPI to read a transciever register. So as pjb304 suggested, your SPI isn't working. Well, not returning a value.

Do any LEDs on the Dragino HAT light up? If not the power is missing. Try reseating the Dragino HAT. You may have a bad connection on the SPI bus pins.

I must say that my HAT is alive and well and never suffered this problem. I'm also using a Pi4.

Note: The dragino code , as it stands, does not support downlinks (if you are using it with TTN). I have modified my dragino.py to pass downlink messages into my code and it works just fine. If you want to know how to do that just ask, once you've gotten test.py working.

MelBadura commented 3 years ago

Thanks for your answers, The LED is on, I will try to reset the Dragino HAT and check the SPI aswell.

MelBadura commented 3 years ago

I just installed Raspian new and enabled SPI again and now it's working fine. Thank you very much for your help.