博主头像
NoColor's Blog

Hodie mecum eris in paradiso.

Riotee Board Stella 通信协议使用

尝试使用Riotee Board进行数据采集的时候发现内置的蓝牙协议为非标准实现,只能发不能收。还好Kai给我们提供了一个另外的Stella 通信协议,在这里记录一下折腾过程。

软&硬件要求

  • Nordic Semiconductor nRF52840-Dongle x1 (经测试也可以用Arduino Nano 33 BLE)
  • 能运行Python 3.10及以上环境的主机一台 (我这里用的树莓派3B)

Riotee Gateway 固件刷写

为了实现Riotee Board和主机的双向通信,需要有一台设备作为Gateway进行通信协议的转换。按照官方文档的要求,该设备必须通过串口连接nRF52840-Dongle,以便发送和接收数据包。然而我手头只有Arduino Nano 33 BLE,虽然它们都使用nRF52840控制器,但是Arduino在刷写固件上添加了一些限制,以下是我尝试将Riotee Gateway 固件写入Arduino Nano 33 BLE的过程。

固件获取

如果你是使用的nRF52840-Dongle,可以直接从release界面下载编译好的固件并写入。如果你像我一样使用Arduino Nano 33 BLE,Arduino不支持直接刷入hex格式的固件,需要克隆整个项目获取固件源码,使用Zephyr提供的工具链编译并写入。工具链的安装可以参考官方教程。安装完成后可直接通过命令编译需要的固件。

固件编译

west build -b arduino_nano_33_ble path/to/Riotee_Gateway/firmware

编译之后会生成一个bin文件,这就是Arduino可接受的固件。

固件写入

在刷写固件之前,还需要找到Arduino提供的bossac。需要安装Arduino IDE并写入任意程序,Windows可在%USERPROFILE%\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.9.1-arduino2目录下找到,Linux一般在$HOME/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac目录下。找到并记录bossac路径,之后就可以将之前编译的固件写入Arduino Nano 33 BLE。

west flash --bossac=%USERPROFILE%\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.9.1-arduino2\bossac.exe --bossac-port="串口名称"

Riotee Gateway 软件安装

Riotee Gateway可以通过Pip安装

pip install riotee-gateway

安装成功之后可以通过命令查看Riotee Gateway的用法

riotee-gateway --help

在刷写好nRF52840-Dongle的固件之后,将Dongle插入USB,确认用户有读取USB串口的权限,可以直接运行Gateway服务

riotee-gateway server

该服务默认监听8000端口,以HTTP的形式进行数据交互。

Riotee Gateway交互

Riotee Board写入示例程序

#include "riotee.h"
#include "riotee_stella.h"
#include "riotee_timing.h"
#include "printf.h"

static unsigned int counter = 0;

/* Buffer for receiving incoming packet. */
uint8_t rx_buf[RIOTEE_STELLA_MAX_DATA];

void lateinit(void) {
  riotee_stella_init();
}

int main() {
  riotee_rc_t rc;
  for (;;) {
    riotee_wait_cap_charged();
    rc = riotee_stella_transceive(rx_buf, sizeof(rx_buf), &counter, sizeof(counter));
    if (rc < 0)
      printf("Error %d\r\n", rc);
    else if (rc == 0)
      printf("Successful transmission. No data received.\r\n");
    else
      printf("Successful transmission. Received %d bytes from basestation.\r\n");
    counter++;
  }
}

可以通过命令查看接收范围内的Riotee Board

riotee-gateway client --host [SERVER] devices

也可通过Python程序实现Riotee Board消息读取,可以在能够与Riotee Gateway通信的任意主机上运行。

from riotee_gateway import GatewayClient
gc = GatewayClient(host="localhost", port=8000)

for dev_id in gc.get_devices():
    # Get the first packet in the queue.
    gc.pop(dev_id)
    # Iterate all packets in the queue.
    for pkt in gc.pops(dev_id):
        print(pkt.pkt_id, pkt.data)
Riotee Board Stella 通信协议使用
https://nocolor.cc/archives/163/
本文作者 NoColor
发布时间 2025-05-14
许可协议 CC BY-NC-SA 4.0
发表新评论