I have to combine two codes and run them one after the other. Unfortunately, I can't start the gps_receiver on Thonny_ide and neighter the other code on the default Geany_ide.
Can somebody help me to solve the problem? Here's my code:
GPS_Receiver (uses the waveshare gps head)
import serial
import time
# Enable Serial Communication
port = serial.Serial("../../dev/ttyS0", baudrate=115200, timeout=1)
# Transmitting AT Commands to the Modem
# '\r\n' indicates the Enter key
time.sleep(.01)
# Activate Command line
port.write("AT \r\n" .encode('utf-8'))
rcv = port.read(100)
print(rcv)
time.sleep(.01)
# Power On the gps module
port.write("AT+CGNSPWR=1 \r\n" .encode('utf-8'))
rcv = port.read(100)
print(rcv)
time.sleep(.01)
#Set the baud rate of GPS
port.write("AT+CGNSIPR=115200 \r\n" .encode('utf-8'))
rcv = port.read(100)
print(rcv)
time.sleep(.10)
chk = False
search_for = '3D'
while chk == False:
port.write("AT+CGPSSTATUS? \r\n" .encode('utf-8'))
rcv = port.read(100)
print(rcv)
is_in = search_for in rcv
if is_in == True:
chk = True
break
print(chk)
print(rcv)
#Send Data received to UART
port.write("AT+CGNSTST=1 \r\n" .encode('utf-8'))
#rcv = port.read(100)
print(rcv)
time.sleep(2.5)
port.write("AT+CGNSTST=0 \r\n" .encode('utf-8'))
#Print the GPS information
port.write("AT+CGNSINF \r\n" .encode('utf-8'))
rcv += port.read(200)
print(rcv)
time.sleep(.1)
data_raw = rcv.split(',')
print(data_raw)
index_N = data_raw.index('N')
north_str = data_raw[index_N - 1]
north_float = float(north_str)/100
index_E = data_raw.index('E')
east_str = data_raw[index_E - 1]
east_float = float(east_str)/100
location_N = str(north_float)
location_E = str(east_float)
altitude = str(data_raw[9])
satelites = str(data_raw[7])
print('location: ' + location_N + ', ' + location_E +', altitude: ' +altitude+ ', satelites: ' + satelites)
data_list = [location_N, location_E, altitude, satelites]
print(data_list)
#Stopp sending Data received to UART
port.write("AT+CGNSTST=0 \r\n" .encode('utf-8'))
#rcv = port.read(100)
#print(rcv)
#time.sleep(.5)
Error, when run on the Geany's Programing Editor
b'AT \r\r\nOK\r\n'
b'AT+CGNSPWR=1 \r\r\nOK\r\n'
b'AT+CGNSIPR=115200 \r\r\nOK\r\n'
b'AT+CGPSSTATUS? \r\r\n+CGPSSTATUS: Location 3D Fix\r\n\r\nOK\r\n'
Traceback (most recent call last):
File "/home/pi/GPS_final.py", line 38, in <module>
is_in = search_for in rcv
TypeError: a bytes-like object is required, not 'str'
QR, RFID Receiver (Input from RIFD Reader comes as a keyboard input):
# import packages gereral information
from datetime import date
from datetime import datetime
import time
import socket
# import packages kamera
import cv2
from pyzbar import pyzbar
import imutils
from imutils.video import VideoStream
import time
# import packages gps
import serial
import time
breakout_command = 'e' # ends collecting infomation and sends the information to the database
device_id = socket.gethostname() # default device id
reader_connected = True # If reader is connected variable set True
information_list = [] # Create a list where information can be stored
data_qr = {}
data_rfid = {}
def read_qr_codes():
try:
# initialize video stream and wait
vs = VideoStream( usePiCamera = True ).start()
time.sleep(2.0)
# loop over frames
while True:
frame = vs.read()
# for better performance, resize the image
frame = imutils.resize(frame, width=400)
# find and decode all barcodes in this frame
barcodes = pyzbar.decode(frame)
for barcode in barcodes:
#do anything with that data
print('Code \"' + barcode.data.decode("utf-8") + '\" detected')
tag_id_qr = barcode.data.decode("utf-8")
id_qr = {
'tag_id_qr' : str(tag_id_qr),
'device_id' : str(device_id),
'date' : str(time.strftime("%d.%m.%Y %H:%M:%S"))
}
#data_qr.update(id_qr)
information_list.append(id_qr)
except KeyboardInterrupt:
pass
def read_rfid_codes():
while reader_connected == True: # Check if reader is connected
tag_id_rfid = input('Receive id from tag') # Input is expected
if (tag_id_rfid == breakout_command):
break
id_rfid = {
'tag_id_rfid' : str(tag_id_rfid),
'device_id' : str(device_id),
'date' : str(time.strftime("%d.%m.%Y %H:%M:%S"))
#'GPS' : str(gps),
}
#data_rfid.update(id_rfid)
information_list.append(id_rfid)
#print(information_list)
read_qr_codes()
read_rfid_codes()
#get_gps_location()
information_list_cleared = []
for e in information_list:
if e not in information_list_cleared:
information_list_cleared.append(e)
print(information_list_cleared)
Error, when run in Geany's Programing Editor:
The Kamera doesn't detect the qr codes or doesn't write it in the terminal. And when pressed 'Ctrl+C' on keyboard the whole program shuts down.
In the best case I would like to run the whole prgramm in Thonny. So basicly just insert and activate the gps funktion in it.
Thanks!!