AN-122 LoRaWAN 信标追踪器用户手册

设备信息:型号 AN-122,devEui ffffff100004c8c2,网关 IP 192.168.31.193,Modbus Slave ID 8,BACnet Device ID 107

1 协议概览

AN-122 在 Fport 210 上报附近信标 RSSI 数据、电池电压/百分比、GPS 位置及信号质量。

1.1 上行数据协议(Fport 210)

载荷格式(Fport 210):

字节位置 字段 说明
0 保留 固定 0x00(协议版本)
1 … N TLV 对 [Type(1 B)][Value(N B)] … 循环至结束

每个 Type 字节决定字段名称和后续 value 字节数:

Type Value字节数 字段名称 编码方式 换算 单位 说明
0x01 1 model uint8 型号码 = 0x57
0x93 1 batteryLevel uint8 % 0–100 % 电量
0x6D 1 packetType uint8 0x00=心跳 0x01=数据上报
0x77 1 tamperState uint8 0=正常 1=防拆
0xBA 1+N beaconData block 8字节简单信标块(长度字节 = 0x07);每包最多重复3次;详见下方子表
0x3E 4 latitude int32 BE ÷10000000 ° 如 227439186 → 22.7439186°
0x43 4 longitude int32 BE ÷10000000 ° 如 1139290611 → 113.9290611°
0xC3 1 positionAccuracy uint8 ÷10 0–254 = 精度 ÷10;255 = 无效
0x6B 2 tiltAngle uint16 BE ° 倾斜角度(°)
0xB8 1 batteryLowAlarm uint8 0=正常 1=低电量报警事件
0x03 1 tamperEvent uint8 0=正常 1=防拆事件
0xA8 1 accelerationAlarm uint8 0=正常 1=加速度报警事件
0xC2 1 tiltAlarm uint8 0=正常 1=倾斜报警事件

AN-122 0xBA 简单信标块

每个 0xBA TLV 携带一个附近信标的数据,每包最多出现 3 次。 值字段固定为 8 字节(1 字节长度 = 0x07 + 7 字节数据):

偏移 字节数 字段 编码 说明
0 1 length uint8 固定 0x07
1 4 beaconId uint32 BE 信标蓝牙 MAC 地址的后 4 字节
5 1 refRssi int8 1 m 参考 RSSI(dBm,有符号)
6 1 rssi int8 接收 RSSI(dBm,有符号)
7 1 batteryLevel uint8 0–100 %;255=无效
0xBA TLV 每检测到一个信标重复一次(最多 3 次)。
解析结果以 beacons[0]beacons[1]beacons[2] 呈现。

JavaScript 解码示例:

// AN-122 Beacon Tracker — Fport 210 uplink decoder
function decodeUplink(bytes) {
  var i = 1, r = {};
  function u16(b,o){ return (b[o]<<8)|b[o+1]; }
  function i16(b,o){ var v=u16(b,o); return v>32767?v-65536:v; }
  function u32(b,o){ return ((b[o]<<24)|(b[o+1]<<16)|(b[o+2]<<8)|b[o+3])>>>0; }
  function i32(b,o){ var v=u32(b,o); return v>0x7FFFFFFF?v-0x100000000:v; }
  function i8(b,o) { var v=b[o]&0xFF; return v>127?v-256:v; }
  while (i < bytes.length) {
    var t = bytes[i++];
    switch (t) {
      case 0x01: r.model            = bytes[i++]; break;
      case 0x03: r.tamperEvent      = bytes[i++]; break;
      case 0x6B: r.tiltAngle        = u16(bytes,i); i+=2; break; // degrees
      case 0x6D: r.packetType       = bytes[i++]; break;
      case 0x77: r.tamperState      = bytes[i++]; break;
      case 0x93: r.batteryLevel     = bytes[i++]; break; // %
      case 0x3E: r.latitude  = i32(bytes,i)/10000000; i+=4; break;
      case 0x43: r.longitude = i32(bytes,i)/10000000; i+=4; break;
      case 0xA8: r.accelerationAlarm= bytes[i++]; break;
      case 0xB8: r.batteryLowAlarm  = bytes[i++]; break;
      case 0xC2: r.tiltAlarm        = bytes[i++]; break;
      case 0xC3: { var a=bytes[i++]; r.positionAccuracy=a===255?null:a/10; break; }
      case 0xBA: {
        // 8-byte simple beacon (length byte 0x07 + 7 bytes)
        var len = bytes[i++]; // = 0x07
        if (!r.beacons) r.beacons = [];
        var id = u32(bytes,i);
        r.beacons.push({
          idHex: id.toString(16).padStart(8,'0').toUpperCase(),
          refRssi: i8(bytes, i+4),
          rssi:    i8(bytes, i+5),
          batteryLevel: bytes[i+6]
        });
        i += len; break;
      }
      default: i++; break;
    }
  }
  return r;
}

脚本下载:LPP.zip

版本说明: LPP.js 基于 ChirpStack v4.17.0 开发和测试。不同版本的 ChirpStack JavaScript 编解码器 API 可能存在差异——如果您使用的是其他版本,请在部署前检查并根据需要调整脚本。

2 获取上行数据

⚠️ 以下示例中的 IP 地址(192.168.31.205 / 192.168.31.193)、ChirpStack API token、Slave ID、BACnet Device ID 及 devEui 均为演示示例,请替换为实际网关 IP、ChirpStack API token 及设备参数。

2.1 ChirpStack MQTT 订阅

订阅 MQTT topic 以接收实时上行数据:

应用 ID3ef9e6b9-ec54-4eda-86b8-a5fb46899f39 是网关内置的出厂默认 ChirpStack 应用。
如果您创建了其他应用,请替换为实际的应用 ID。

网关 IP192.168.31.193 为示例网关 WAN 口 IP,
请替换为您实际的网关 IP 地址。

设备 EUIffffff100004c8c2 为示例设备 EUI,
请替换为网关设备列表中显示的实际 EUI;
也可用 + 通配符一次订阅所有设备的数据。
# 订阅指定设备
mosquitto_sub -h 192.168.31.193 -p 1883 \
  -u gateway -P mqtt88888888 \
  -t "application/3ef9e6b9-ec54-4eda-86b8-a5fb46899f39/device/ffffff100004c8c2/event/up"

# 订阅所有应用下所有设备(通配符)
mosquitto_sub -h 192.168.31.193 -p 1883 \
  -u gateway -P mqtt88888888 \
  -t "application/+/device/+/event/up"

上行数据载荷示例(JSON):

{
  "devEui": "ffffff100004c8c2",
  "fPort": 210,
  "object": {
    ...  (已解码的 LPP 字段)
  }
}

2.2 IoT Hub HTTP API

发送 GET 请求获取设备最新状态:

curl -s "http://192.168.31.193:8070/api/getStatus?devEui=ffffff100004c8c2"
{
  "success": true,
  "result": {
    "batteryLevel": 99,
    "tamper": 1,
    "latitude": 22.743225,
    "longitude": 113.929123,
    "positionAccuracy": 2.3,
    "beaconBatteryValid": false,
    "tiltAngle": 1,
    "batteryLowAlarm": false,
    "accelerationAlarm": false,
    "tiltAlarm": false,
    "model": "AN-122"
  }
}

2.3 IoT Hub Modbus TCP — Python 脚本

脚本下载:modbus_tcp_read.py

使用 modbus_tcp_read.py 一次性读取所有寄存器:

python3 modbus_tcp_read.py --ip 192.168.31.193 --port 502 \
    --slaveId 8 --sensorType AN-122
Target: 192.168.31.193:502 | Slave ID: 8 | Sensor: AN-122
================================================================================================================================================================
Attribute                | Addr   | FC  | Format     | Order        | Cnt | Scale    | Raw(Hex)            | Value              | Unit
----------------------------------------------------------------------------------------------------------------------------------------------------------------
online                   | 6      | 03  | Bit/Bool   | Big(ABCD)    | 1   | x1       | 0001                | true               | none
lastOnlineTime           | 7      | 03  | UnixTime   | Big(ABCD)    | 2   | x1       | 69CC CE99           | 1775029913         | second
batteryLevel             | 9      | 03  | Int16      | Big(ABCD)    | 1   | x1       | 0063                | 99.0               | percent
tamper                   | 10     | 03  | Int16      | Big(ABCD)    | 1   | x1       | 0001                | 1.0                | none
latitude                 | 11     | 03  | Float32    | Big(ABCD)    | 2   | x1       | 41B5 F220           | 22.743225          | degrees
longitude                | 13     | 03  | Float32    | Big(ABCD)    | 2   | x1       | 42E3 DBB6           | 113.929123         | degrees
positionAccuracy         | 15     | 03  | Float32    | Big(ABCD)    | 2   | x1       | 4013 3333           | 2.30               | meter
beaconIdHex              | 17     | 03  | String(32B) | ASCII        | 16  | x1       | 0000 0000 0000 0000 ... |                    | none
beaconRefRssi            | 33     | 03  | Int16      | Big(ABCD)    | 1   | x1       | 0000                | 0.0                | none
beaconRssi               | 34     | 03  | Int16      | Big(ABCD)    | 1   | x1       | 0000                | 0.0                | none
beaconBatteryLevel       | 35     | 03  | Int16      | Big(ABCD)    | 1   | x1       | 0000                | 0.0                | percent
beaconBatteryValid       | 36     | 03  | Bit/Bool   | Big(ABCD)    | 1   | x1       | 0000                | false              | none
... (20 fields total)

2.4 IoT Hub Modbus TCP — Modbus Poll

工具下载:Modbus Poll 9.5.0.1507.zip

  1. 打开 Modbus Poll,连接 192.168.31.193:502,Slave ID 8
  2. 菜单 Setup → Read/Write Definition,功能码选 FC03,起始地址 6,长度 74
  3. 点击 OK — 数值实时刷新

2.5 IoT Hub BACnet BIP — Python 脚本

脚本下载:bacnet_read.py

使用 bacnet_read.py 读取所有 BACnet 对象:

python3 bacnet_read.py --ip 192.168.31.193 --port 47808 --id 107
Target: 192.168.31.193:47808 | BACnet ID: 107 | Scan: 10700-10799
------------------------------------------------------------
Type | Instance | Offset | Value                    | Object Name
------------------------------------------------------------
BI   | 10702    | 2      | active                   | ffffff100004c8c2.online
AI   | 10703    | 3      | 1775029888.00            | ffffff100004c8c2.lastOnlineTime
AI   | 10704    | 4      | 99.00                    | ffffff100004c8c2.batteryLevel
AI   | 10705    | 5      | 1.00                     | ffffff100004c8c2.tamper
AI   | 10706    | 6      | 22.743225                | ffffff100004c8c2.latitude
AI   | 10707    | 7      | 113.929123               | ffffff100004c8c2.longitude
AI   | 10708    | 8      | 2.30                     | ffffff100004c8c2.positionAccuracy
CV   | 10709    | 9      |                          | ffffff100004c8c2.beaconIdHex
AI   | 10710    | 10     | 0.00                     | ffffff100004c8c2.beaconRefRssi
AI   | 10711    | 11     | 0.00                     | ffffff100004c8c2.beaconRssi
AI   | 10712    | 12     | 0.00                     | ffffff100004c8c2.beaconBatteryLevel
BI   | 10713    | 13     | inactive                 | ffffff100004c8c2.beaconBatteryValid
... (20 objects total)

2.6 IoT Hub BACnet BIP — YABE

工具下载:SetupYabe_v2.1.0.exe

  1. 打开 YABE,连接 192.168.31.193:47808
  2. 在设备树中展开设备 107
  3. 浏览 AI/BI/AV/BV/CV 对象,查看实时数值