LowPowerLab Forum

Software support => Coding questions => Topic started by: sheikhumar on December 17, 2019, 04:02:12 AM

Title: PySerial and RFM69 issues
Post by: sheikhumar on December 17, 2019, 04:02:12 AM
Hi, I have been trying to transmit some data from a Moteino node to a Moteino gateway using the default settings of the RFM69 library. The gateway sketch (with very little changes to the example Gateway example) works fine with the Arduino Serial Monitor but as soon I start taking readings from a Python app using PySerial it starts raising exceptions

e.g.
Code: [Select]
Exception Raised: 'utf-8' codec can't decode byte 0xaa in position 8: invalid start byte

Code: [Select]
with Serial(port='/dev/cu.usbserial-DN051KQO', baudrate=115200) as serial_port:
    reading = serial_port.readline().decode()
    print(reading)

I have tried my code with various codecs other than 'utf-8' but all run into problems. Do I need to use a specific codec to properly get the correct output from PySerial which I am missing here?

Im using the latest version of Pyserial with Python 3.5.3 and the latest release of the RFM69 library from Github.

(https://i.imgur.com/VaaQAYG.png)
Title: Re: PySerial and RFM69 issues
Post by: Felix on December 17, 2019, 12:29:55 PM
It sounds like some Pyserial problem, or the way you're consuming/interpreting the serial data via Pyserial.
Are the default settings when opening a Pyserial port the same as the usual settings (parity, stop bit etc)?

How about using the serial module as seen in this script (https://github.com/LowPowerLab/WirelessProgramming/blob/master/OTA.py) (known to work and parse serial heavy OTA/wireless programming transfers)?
Title: Re: PySerial and RFM69 issues
Post by: sheikhumar on December 18, 2019, 07:02:43 AM
Hi Felix, thanks for the reply.

I have done some testing after your reply and the code works fine on a raspberry pi, its only when I connect it to my Mac does it output these strange errors. I have created a python 3.7.5 venv on my Mac and tested with that too and the issue is still there. Then I tried using the FTDI drivers from ftdichip.com but it still throws the same exceptions. Trying to decode with 'ISO-8859-1' is much better on the Mac, it doesn't throw any exceptions but still cannot get all the values from the node properly.

On the other hand radiohead works flawlessly on the same mac with the same python code and venv.

So in short:
On Rpi 3b+ code running on Python 3.5.3 runs flawlessly.
On macOS 10.15.2 code running on the same Python 3.5.3 is throwing all sorts of exceptions while the same Python code with Radiohead works correctly

I am using the FTDI R3 Adapter with the default settings on macOS which was brought from your store.
How should I debug this further? I have also tried using the code Wireless Programming code you linked and the same problem occurs with that too. And yes I am using the default settings when opening the Pyserial port.