{"id":21043546,"url":"https://github.com/thingspanel/http-protocol-plugin","last_synced_at":"2026-03-09T06:32:53.496Z","repository":{"id":165222942,"uuid":"640181144","full_name":"ThingsPanel/http-protocol-plugin","owner":"ThingsPanel","description":null,"archived":false,"fork":false,"pushed_at":"2023-10-23T07:56:31.000Z","size":207,"stargazers_count":2,"open_issues_count":0,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-06T16:42:22.029Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ThingsPanel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-05-13T08:47:31.000Z","updated_at":"2024-11-26T10:08:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"e136251b-a453-4a9c-b1bf-9a996d6c9d29","html_url":"https://github.com/ThingsPanel/http-protocol-plugin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ThingsPanel/http-protocol-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThingsPanel%2Fhttp-protocol-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThingsPanel%2Fhttp-protocol-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThingsPanel%2Fhttp-protocol-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThingsPanel%2Fhttp-protocol-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ThingsPanel","download_url":"https://codeload.github.com/ThingsPanel/http-protocol-plugin/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThingsPanel%2Fhttp-protocol-plugin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30284776,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T02:57:19.223Z","status":"ssl_error","status_checked_at":"2026-03-09T02:56:26.373Z","response_time":61,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T14:13:12.559Z","updated_at":"2026-03-09T06:32:53.476Z","avatar_url":"https://github.com/ThingsPanel.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# http-procotol-plugin\r\n\r\n## 功能和部署\r\n\r\n- 在服务器上使用git命令获取仓库源码\r\n\r\n  ```bash\r\n  git clone https://github.com/ThingsPanel/http-protocol-plugin.git\r\n  ```\r\n\r\n- http协议插件需要单独部署，如果与Mqtt Broker和ThingsPanel后端在一个服务器（同一个网络），则不需要修改配置文件；否则修改./config.yaml的mqtt服务端地址、ThingsPanel的Address。\r\n- 如果使用了TimescaleDB以外的时序数据库，需要修改配置文件中的db_type为other(默认是timescaledb)。\r\n- 安装go环境（1.18版本）后，执行命令启动HTTP协议插件服务(可选择pm2进行托管)\r\n\r\n  ```bash\r\n  go run .\r\n  ```\r\n\r\n- 确保9988端口可被设备访问到\r\n\r\n## 插件如何注册到平台\r\n\r\n手动注册\r\n\r\n- 使用super@super.cn用户登录平台后，点击 `应用管理`-\u003e`接入协议`-\u003e`注册插件`\r\n- 填入插件信息\r\n\r\n  |名称|示例|说明|\r\n  |-|-|-|  \r\n  |**名称**|HTTP协议|创建设备时，会显示在选择协议下拉框中  \r\n  |**设备类型**|设备|必填，选直连设备  \r\n  |**协议类型**|HTTP|必填，标志http协议\r\n  |**接入地址**|dev.thingspanel.cn:9988|插件服务的ip地址和端口，在设备对接中作为平台中的提示信息\r\n  |**HTTP服务地址**|1270.0.1:9988|插件服务的ip地址和端口（必填，供平台后端调用）\r\n  |**插件订阅主题前缀**|plugin/http/ |必填\r\n\r\n- 注册成功后便可创建设备，选择HTTP协议\r\n\r\n## 设备上报数据\r\n\r\n- 设备上报数据\r\n\r\n  ```txt\r\n  http请求，POST方法，RUL示例：\r\n  http://dev.thingspanel.cn:9988/api/device/b2d162c4-bfcf-1830-d00d-ecc1897a9511/attributes\r\n  b2d162c4-bfcf-1830-d00d-ecc1897a9511为AccessToken\r\n  请求body示例（json）:\r\n  {\r\n    \"temp\": 18.5,\r\n    \"hum\": 40,  \r\n  }\r\n  ```\r\n\r\n## 协议插件开发相关\r\n\r\n以下内容为协议插件开发相关，使用协议插件不需要了解\r\n\r\n### 结构图\r\n\r\n![结构图](./images/协议插件.png)\r\n\r\n![时序图](images/时序图.png)\r\n\r\n### 插件表单\r\n\r\n`./form_config.json` （表单规则详情请参考modbus-protocol-plugin案例） ThingsPanel前端通过 `/api/form/config`接口获取表单配置，生成子设备的表单，用户填写的表单数据会出现在ThingsPanel提供的 `/api/plugin/device/config`接口返回的数据中。\r\n\r\n### 交换数据相关\r\n\r\n设备post发送json数据至插件\r\n\r\napi/device/AccessToken/attributes\r\n\r\n（api前面需链接为http协议插件所部署地址，例如http://127.0.0.1:9988/api/device/AccessToken/attributes;AccessToken为在ThingsPanel平台，添加设备绑定插件时获得的，或自定义的值）\r\n\r\n转发至mqtt的device/attributes 主题\r\n\r\njson数据格式：\r\n\r\n```\r\n{\r\n    \"temp\": 18.5,\r\n    \"low\": 40,\r\n    ...\r\n}\r\n```\r\n\r\n响应体：\r\n\r\n```\r\n{\r\n  \"code\": 200,//200：成功，404：失败\r\n  \"ts\": //时间戳 微秒\r\n}\r\n```\r\n\r\n插件发送数据至ThingsPanel平台\r\n\r\n1.直连设备\r\n\r\nmqtt用户：root （使用thingspanel-go配置文件中的用户名和密码）\r\n\r\n发布主题：device/attributes\r\n\r\n报文规范：{\"token\":device_token,\"values\":{key:value...}}\r\n\r\n或自定义报文：{\"token\":device_token,\"values\":自定义报文}\r\n\r\ntoken：设备AccessToken或子设备AccessToken\r\n\r\n2.在线离线通知\r\n\r\nmqtt用户：root （使用thingspanel-go配置文件中的用户名和密码）\r\n\r\n发布主题：device/status\r\n\r\n报文规范：{\"accessToken\":accessToken,\"values\":{\"status\":status}}\r\n\r\naccessToken:设备或网关连接时送来的密钥\r\n\r\nstatus: \"0\"-离线 \"1\"-上线\r\n\r\n或自定义报文：自定义报文\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthingspanel%2Fhttp-protocol-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthingspanel%2Fhttp-protocol-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthingspanel%2Fhttp-protocol-plugin/lists"}