ESP-NOW数据吞吐量记录GPS坐标
我正在使用两个ESP32板进行ESP-NOW通信,其中一个ESP正在发送数据包,而另一个ESP则在将这些数据与GPS一起记录这些数据时接收到它们,以在某个坐标处测量吞吐量,以便我在移动和更改时获得吞吐量率发件人和接收器之间的速率。
ESP32接收器和GPS模块已连接到RPI,该RPI正在运行从串行COM端口读取数据,解析并将其写入文件的脚本。
import serial
import time
import pandas as pd
# Receiver
esp_com = '/dev/ttyUSB1'
esp_baud = 115200
ser = serial.Serial(port=esp_com, baudrate=esp_baud, timeout=0.1)
# GPS
gps_com = '/dev/ttyUSB0'
gps_baud = 4800
sergps = serial.Serial(port=gps_com, baudrate=gps_baud, timeout=0.1)
# title of the file to write data in
title = 'ESP-NOW LoRa'
# time step at which data is logged
timestep = 1
# create lists
XCV = []
# initial dropped/received packets data
drp = 0
rcv = 0
counter = 0
waiting_for_recv = False
# outputs empty data table
df = pd.DataFrame()
# outputs time in seconds since the timer started
then = time.time()
then1 = time.time()
# clear ESP buffers
ser.flushInput()
ser.flushOutput()
# initial data
RECEIVED = 0
RECEIVED = []
LAT = []
LON = []
T = []
t = 0
gpsdata = ''
# loop
while True:
try:
xcv = ser.readline().decode() # decodes string
if xcv != '':
xcv = xcv.split("\r\n")
for x in xcv:
if x != '':
print(x)
XCV.append(x)
if 'RECV' in x:
RECEIVED = int(x[4:]) # sliced first 4 characters
while True:
cvb = sergps.readline()
if cvb != b'':
if 'GNGGA' in cvb.decode():
gpsdata = cvb.decode()
else:
break
now = time.time()
if now > then+timestep:
print(now)
df.at[counter, 'timestamp'] = now
df.at[counter, 'received'] = RECEIVED
drp = 0
rcv = 0
RECEIVED = 0
then = now
counter += 1
vbn = gpsdata.split(',')
if('GNGGA' in vbn[0]) & (vbn[2] != "") & (len(vbn) >= 5):
print('GPS has a fix')
tt = vbn[1]
lat = vbn[2]
lon = vbn[4]
lat = int(lat[0:2])+float(lat[2:])/60
lon = int(lon[0:3])+float(lon[3:])/60
LAT.append(lat)
LON.append(lon)
T.append(t)
t += 1
print('LAT: {}, LON: {}'.format(lat, lon))
else:
print('GPS does not have a fix')
LAT.append(0)
LON.append(0)
# write data to file every 30 seconds
if now > then1+30:
then1 = now
# print GPS dataframe to columns
df['lat'] = LAT
df['lon'] = LON
df.to_excel(title+'.xlsx') # writes data to excel file
except Exception as e:
print(e)
我遇到了一个问题,一旦GPS有修复程序,并开始与坐标发送完整的NMEA消息,接收/丢弃的数据包数据丢失了,整个脚本都会挂起。我可以在变量中看到GPS NMEA数据正确解析,并且当GPS没有修复时,一切都起作用,但是一旦它开始发送完整的NMEA消息,脚本会断开脚本。
我自己真的无法弄清楚为什么,我认为代码本身需要优化。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看到已经有一段时间了,但是我遇到了这篇文章。
因此,我看到的一个问题:
在这里,您将在任何数据来自GPS模块时陷入困境。获得
GPSDATA
后,您可能还需要休息。另一件事,您有布尔值,因此请使用
和
(逻辑)而不是&
(bitwise):在此处阅读更多:'>'and'(boolean)vs'&'' (位)
I see it's been a while, but I have bumped in to this post.
So one issue I see:
Here you will stuck in the loop while the ANY data is coming from GPS module. You might want to break also after you get
gpsdata
.One other thing here you have boolean values so use
and
(logical) and not&
(bitwise):Read more here: 'and' (boolean) vs '&' (bitwise)