nvidia nx平台传递GPS信息调试

free-jdx 2021-07-22 14:48:32 4029
1. 前言

尝试一种从Jertson传递GPS信息到微软Azure物联网中心的方法
Jetson上安装Azure IoT SDK:

https://github.com/Azure/azure-iot-sdks#microsoft-azure-iot-sdks-1

使用诸如MQQT之类的消息代理传递GPS的非microsoft方法
DeepStream与Azure IoT框架集成(它也支持MQQT):

https://docs.nvidia.com/metropolis/deepstream/dev-guide/text/DS_plugin_gst-nvmsgbroker.html
2. 转发/dev/pts/26

它不是很清楚如何使用元数据缓冲区,因为我只是想转发像/dev/pts/26输出与它,对吗?

terminal 1:
nvidia@nx_xavier:~$  socat -d -d pty,raw,echo=0 pty,raw,echo=0
2021/05/06 13:13:55 socat[23720] N PTY is /dev/pts/25
2021/05/06 13:13:55 socat[23720] N PTY is /dev/pts/26
2021/05/06 13:13:55 socat[23720] N starting data transfer loop with FDs [5,5] and [7,7]
terminal 2:
sudo apt install csh -y
wget https://iweb.dl.sourceforge.net/project/gpsfeed/gpsfeed-latest.zip
unzip gpsfeed-latest.zip
nvidia@nx_xavier:~$ tclsh8.6 gpsfeed+.tcl 

例如:

in serial section goes代替default COM1→/dev/pts/25;波特率→9600

然后在第二个GUI窗口=按play[在左上角-一个圆点在中心的圆圈图标;]
从第三个终端可以看到GPS信号

~$ cat /dev/pts/26
$GPGGA,180756,3756.2421,N,02346.8948,E,1,04,5.6,724.4,M,34.5,M,,*43
$GPRMC,180756,A,3756.2421,N,02346.8948,E,,,060521,5,E,A*01
$GPGGA,180758,3751.4936,N,02349.1123,E,1,04,5.6,384.3,M,34.5,M,,*4D
$GPRMC,180758,A,3751.4936,N,02349.1123,E,9109.2,159.8,060521,5,E,A*30
$GPGGA,180800,3747.8756,N,02353.0000,E,1,04,5.6,134.0,M,34.5,M,,*4C
$GPRMC,180800,A,3747.8756,N,02353.0000,E,8541.7,139.7,060521,5,E,A*3E
$GPGGA,180802,3745.9547,N,02358.0261,E,1,04,5.6,9.7,M,34.5,M,,*49
$GPRMC,180802,A,3745.9547,N,02358.0261,E,7942.4,115.8,060521,5,E,A*31

想尝试绕过DeepStream来传递GPS信息

如果您想绕过DeepStream,那么似乎可以选择安装Azure IoT SDK并使用它
或者直接使用MQTT之类的消息代理
看起来有一个Python包paho-mqtt

3. 订阅paho-mqtt到/dev/pts/26

没有确切的步骤如何加载输出/dev/pst/26
例如paho mqqt

Dockerfile很简单

FROM alpine

RUN apk update
RUN apk add mosquitto

CMD /usr/sbin/mosquitto   

这张图片使用Alpine作为基础,然后添加mosquitto
最后,它使用CMD值启动代理
要构建它,运行以下命令:

docker build -t mosquitto -f Dockerfile.mosquitto .

要在默认网络上运行:

docker run -it --rm --name mosquitto -p 1883:1883 mosquitto

想要找出的是如何准确地订阅paho-mqtt到/dev/pts/26
这就是想要弄清楚的,可能应该有一个简单的命令来做这件事
应该有这样的命令

python
import paho-mqtt
4. 脚本编写

需要在Python中打开/dev/tty文件
(如果需要,也可以使用pyserial模块)
并以编程方式提取数据,以便为代理构造消息
或者可能有一些命令行工具可以从其他文件中转消息

cat pts_v2.py 
import sys                                           

with open("/dev/pts/26", "wb+", buffering=0) as term:
        while True:
            print(term.read(26).decode(), end='')
        sys.stdout.flush()
python3 pts_v2.py 
$GPGGA,191157,3756.8819,N,02404.8014,E,1,04,5.6,455.4,M,34.5,M,,*4D
$GPRMC,191157,A,3756.8819,N,02404.8014,E,3442.9,42.0,060521,5,E,A*04
$GPGGA,191159,3758.8726,N,02405.7998,E,1,04,5.6,809.2,M,34.5,M,,*4E
$GPRMC,191159,A,3758.8726,N,02405.7998,E,3853.2,21.6,060521,5,E,A*00
$GPGGA,191201,3801.1623,N,02405.9797,E,1,04,5.6,1190.8,M,34.5,M,,*73
$GPRMC,191201,A,3801.1623,N,02405.9797,E,4129.4,3.5,060521,5,E,A*39
$GPGGA,191203,3803.4176,N,02405.2627,E,1,04,5.6,1544.6,M,34.5,M,,*73
$GPRMC,191203,A,3803.4176,N,02405.2627,E,4184.8,345.9,060521,5,E,A*3C
$GPGGA,191205,3805.2904,N,02403.7043,E,1,04,5.6,1819.2,M,34.5,M,,*7E
$GPRMC,191205,A,3805.2904,N,02403.7043,E,4029.8,326.8,060521,5,E,A*32
$GPGGA,191207,3806.4714,N,02401.4940,E,1,04,5.6,1974.4,M,34.5,M,,*71

但缺少与消息代理的集成

5. 例子
#! /usr/bin/python
# Based on
# Written by Dan Mandle http://dan.mandle.me September 2012
# License: GPL 2.0

import os
from gps import *
from time import *
import time
import threading
import json
import paho.mqtt.client as paho

gpsd = None 

class GpsPoller(threading.Thread):
  def __init__(self):
    threading.Thread.__init__(self)
    global gpsd #bring it in scope
    gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
docker run -it --rm --name mosquitto -p 1883:1883 mosquitto

然后尝试修改代码,这样它就会与mosquitto一致

import os
from gps import *
from time import *
import time
import threading
import json
import paho.mqtt.client as mqtt
MQTT_BROKER = os.getenv('MQTT')

gpsd = None 

class GpsPoller(threading.Thread):
  def __init__(self):
    threading.Thread.__init__(self)
    global gpsd #bring it in scope
    gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
    self.current_value = None
    self.running = True #setting the thread running to true

  def run(self):
    global gpsd
    while gpsp.running:
      gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer

if __name__ == '__main__':
  gpsp = GpsPoller() # create the thread
  try:
    gpsp.start() # start it up
    while True:
      if gpsd.fix.latitude > 0:
        row = [ { 'latitude': str(gpsd.fix.latitude),
         'longitude': str(gpsd.fix.longitude),
         'utc': str(gpsd.utc),
         'time':   str(gpsd.fix.time),
         'altitude': str(gpsd.fix.altitude),
         'eps': str(gpsd.fix.eps),
         'epx': str(gpsd.fix.epx),
         'epv': str(gpsd.fix.epv),
         'ept': str(gpsd.fix.ept),
         'speed': str(gpsd.fix.speed),
         'climb': str(gpsd.fix.climb),
         'track': str(gpsd.fix.track),
         'mode': str(gpsd.fix.mode)} ]
json_string = json.dumps(row)
        client = mqtt.Client("P1")
        client.connect(MQTT_BROKER)
        client.publish("gps", payload=json_string, qos=0, retain=True)

        time.sleep(60)

  except (KeyboardInterrupt, SystemExit): #when you press ctrl+c
    gpsp.running = False
    gpsp.join() # wait for the thread to finish what it's doing
声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
free-jdx
红包 92 收藏 评论 打赏
评论
0个
内容存在敏感词
手气红包
    易百纳技术社区暂无数据
相关专栏
置顶时间设置
结束时间
删除原因
  • 广告/SPAM
  • 恶意灌水
  • 违规内容
  • 文不对题
  • 重复发帖
打赏作者
易百纳技术社区
free-jdx
您的支持将鼓励我继续创作!
打赏金额:
¥1易百纳技术社区
¥5易百纳技术社区
¥10易百纳技术社区
¥50易百纳技术社区
¥100易百纳技术社区
支付方式:
微信支付
支付宝支付
易百纳技术社区微信支付
易百纳技术社区
打赏成功!

感谢您的打赏,如若您也想被打赏,可前往 发表专栏 哦~

举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

审核成功

发布时间设置
发布时间:
是否关联周任务-专栏模块

审核失败

失败原因
备注
拼手气红包 红包规则
祝福语
恭喜发财,大吉大利!
红包金额
红包最小金额不能低于5元
红包数量
红包数量范围10~50个
余额支付
当前余额:
可前往问答、专栏板块获取收益 去获取
取 消 确 定

小包子的红包

恭喜发财,大吉大利

已领取20/40,共1.6元 红包规则

    易百纳技术社区