Ive created a python code that fetches data from firebase and controls a arduino (the arduino is on a rc car and the rpi is connected to the arduino via usb) below is the error I am encountering when I try to compile the code in my rpi. I also built an app in android studio for this project, the whole purpose is that I can control the arduino with my android application. There are not issues with my app, the issue is pertained to my python code in rpi.
Exception in thread Thread-1 (start_stream):
Traceback (most recent call last):
File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
self.run()
File "/usr/lib/python3.11/threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "/home/beanz/.local/lib/python3.11/site-packages/pyrebase/pyrebase.py", line 563, in start_stream
self.stream_handler(msg_data)
File "/home/beanz/Desktop/customremote2.py", line 25, in stream_handler
ser.write(str.encode(message["data"]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: descriptor 'encode' for 'str' objects doesn't apply to a 'NoneType' object
This is my code. Ive been having issues in general with importing firebase and pyrebase. I managed to fix those with the pip upgrades and changing the .async files. As shown above that is the last of the issues hopefully. If this code runs properly, I should be able to control my rc arduino car with the android app I built, if it doesnt then idk what else could be a problem.
import pyrebase
from firebase import firebase
import serial
ser = serial.Serial('/dev/ttyACM0',9600)
config={ ##Imported from firebase to fetch data
"apiKey": "AIzaSyD0_iSPpmMqTkcyhBcuKZ_Oy-4DQACx10Q",
"authDomain": "carpilot-d4412.firebaseapp.com",
"databaseURL": "https://carpilot-d4412-default-rtdb.firebaseio.com",
"projectId": "carpilot-d4412",
"storageBucket": "carpilot-d4412.appspot.com"
}
firebase = pyrebase.initialize_app(config)
db = firebase.database()
def stream_handler(message):
ser.write(str.encode(message["data"]))
##Data will be fetched and then will send(by write function) this data after encoding
my_stream = db.child("Move/move").stream(stream_handler)
##If any child will change at Move/move then it will stream and update and this updated data will send to arduino
my_stream = db.child("Move/move").stream(stream_handler)
##If any child will change at Move/move then it will stream and update and this updated data will send to arduino