# iot-bridge **Repository Path**: iotfit/iot-bridge ## Basic Information - **Project Name**: iot-bridge - **Description**: 保利飞桥 IoT Bridge - **Primary Language**: Go - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2024-02-04 - **Last Updated**: 2024-08-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: IOT ## README # iot-bridge ## 架构图 ![流程](gateway.jpg) - 设备:传感器、PLC 等; - DTU: 数采网关,将 RS485、RS232 等接口的设备数据转换为 TCP、UDP、MQTT 等协议; - Bridge:负责设备与 [Zipper](https://yomo.run/docs/cli/zipper) 之间的通信桥梁,支持 TCP、UDP、MQTT 等协议; - TCP Bridge:支持 TCP 协议的 Bridge; - Managers: - Device Manager:设备管理,负责设备的注册、连接管理等; - Sender Manager:数据发送管理,负责将 Bridge 的数据发送给 Zipper;每种设备类型对应一个 Sender; - Receiver Manager:数据接收管理,负责接收 Zipper 发送的数据,并发给对应的 DTU 连接;每种设备类型对应一个 Receiver; - Zipper:负责数据编排、转发等; - Sfn: [云函数](https://yomo.run/docs/api/sfn),用于定时下发指令,接收并解析设备数据; ## 代码结构 - bridge: 各种 IoT 协议的 Bridge 实现,如 TCP、UDP、MQTT 等; - cmd: Gateway 的命令行工具; - config: 配置文件的定义和解析; - device: 设备映射管理、数据发送、接收管理; - example: 示例代码; - gateway: Gateway 的核心逻辑; - logger: 日志记录; ## Gateway 命令行工具 ### 编译、安装 ```sh make build cp ./bin/gateway /usr/local/bin/. ``` ### 运行 ```sh gateway start -c ./example/gateway.yaml -d ./example/device_type.yaml ``` ### 配置文件 #### gateway.yaml: Gateway 的配置文件 - id: Gateway 的 ID; - project_id: 项目 APP ID; - zipper_addr: Zipper 的地址; - bridges: Bridge 的配置列表; ```yaml id: gateway-1 project_id: project-app-id zipper_addr: 127.0.0.1:9000 bridges: tcp: host: 0.0.0.0 port: 8080 ``` #### device_type.yaml: 设备类型的配置文件 - name: 设备类型的名称; - tags: 设备类型的 data tags; - sender: Sender 的 data tag; - receiver: Receiver 的 data tag; - device_ips: 设备的 IP 列表; ```yaml device_types: - name: device type 1 tags: sender: 0x50 receiver: 0x51 device_ips: - 127.0.0.1 - ::1 ``` ## 示例代码 - [TCP](./example/tcp/README.md)