首页 > 解决方案 > 使用 JSON 远程访问 Unet 调制解调器

问题描述

我正在尝试在调制解调器中使用 JsonTypeAdapter 从远程源传输一些数据。适配器通过调制解调器启动脚本 (JsonAdapter.enable()) 启用,并在端口 1100 处与调制解调器建立 TCP 连接。我按照 Fjåge 文档中的“Hello world”示例,将以下 JSON 发送到调制解调器:

{"action":"send","message":{"clazz":"org.arl.unet.DatagramReq","data":{"data":{"clazz":"[B","data":"aGVsbG8gd29ybGQh"},"msgID":"8152310b-155d-4303-9621-c610e036b373","perf":"REQUEST","recipient":"phy","sender":"MyCustomInterface"}}}

我已将 logLevel 设置为“ALL”,并且可以看到我在日志中获得了传入的 TCP 连接,但调制解调器没有传输任何数据。我订阅了物理代理,但在 WebShell 中没有收到任何通知(尽管使用 UnetSocket 可以正常工作)。

我猜测要么 JsonAdapter 在这个 TCP 连接上没有激活,要么 JSON 字符串有问题,要么我的应用程序没有正确发送,或者我错过了其他东西。

标签: unetstack

解决方案


我复制了任何粘贴的 JSON 消息,对我来说效果很好。我采取的步骤:

  1. 我使用unet audioSDOAM 进行了测试:
$ bin/unet -c audio
Modem web: http://localhost:8080/
> iface
tcp://192.168.1.8:1100 [API]
ws://192.168.1.8:8080/ws [API]
tcp:///192.168.1.8:1100//127.0.0.1.55832 [API]
unetsh: console://- [GroovyScriptEngine]
websh: ws://192.168.1.8:8080/fjage/shell/ws [GroovyScriptEngine]

API 接口告诉我调制解调器正在侦听哪个端口(192.168.1.8:1100端口 1100)。所以,我连接到它:

$ nc 192.168.1.8 1100
{"alive": true}

{"alive": true}告诉我我已连接到正确的端口,并且调制解调器正在说“你好” :-)

现在,我复制并粘贴您的 JSON 消息:

{"action":"send","message":{"clazz":"org.arl.unet.DatagramReq","data":{"data":{"clazz":"[B","data":"aGVsbG8gd29ybGQh"},"msgID":"8152310b-155d-4303-9621-c610e036b373","perf":"REQUEST","recipient":"phy","sender":"MyCustomInterface"}}}

我得到回复:

{"action":"send","message":{"clazz":"org.arl.fjage.Message","data":{"msgID":"41b8264c-be98-4bbe-8b72-8986606513ae","perf":"AGREE","recipient":"MyCustomInterface","sender":"phy","inReplyTo":"8152310b-155d-4303-9621-c610e036b373","sentAt":1586233766542}},"relay":false}

确认消息已收到,并正在转发到其他从属容器。紧随其后的是我的 SDOAM 发出的“嗡嗡”声以通过声卡发送帧,以及两个消息(TxFrameStartNtfTxFrameNtf)确认传输已成功完成:

{"action":"send","message":{"clazz":"org.arl.unet.phy.TxFrameStartNtf","data":{"txTime":15784016,"txDuration":1511416,"type":2,"msgID":"0a5bae1e-b16c-4bbb-8fcf-36ad55ffc64e","perf":"INFORM","recipient":"#phy__ntf","sender":"phy","inReplyTo":"8152310b-155d-4303-9621-c610e036b373","sentAt":1586233767349}},"relay":false}
{"action":"send","message":{"clazz":"org.arl.unet.phy.TxFrameNtf","data":{"txTime":15759432,"type":2,"location":{"clazz":"[D","data":""},"msgID":"f6e1dee6-ed31-4850-9d90-7b591a740971","perf":"INFORM","recipient":"MyCustomInterface","sender":"phy","inReplyTo":"8152310b-155d-4303-9621-c610e036b373","sentAt":1586233768761}},"relay":false}

推荐阅读