Skip to main content

· 4 min read
hezhuo

问题

  1. mqtt设备/网关发送和订阅主题与平台不一致并无法修改,怎么接入ThingsPanel平台?

  2. mqtt设备/网关json报文规范与平台规范不一致,怎么接入ThingsPanel平台?

使用规则引擎转发设备数据

使用规则引擎转发设备数据的方式常用来解决第一种问题。

  1. 在规则引擎中新建一条接入规则
  2. 拖拽一个mqtt in节点,填写设备主题接入数据
  3. 再拖拽一个mqtt out节点,与mqtt in节点连线
  4. mqtt out配置中需要添加新的mqtt-broker节点,根据平台mqtt网关/设备接入规则填写主题和认证方式(AccessToken接入填写用户名,MQTTBasic认证填写用户名和密码)
  5. 平台到设备的通信参考以上步骤
  6. 除了以上节点,合理使用其他功能节点,也可以转换报文规范并对设备传输的值加工和处理

使用编辑参数页面的数据处理脚本功能

数据处理脚本功能可解决第二种问题,它的原理相当于中间件。

  1. 创建设备后,点击编辑参数,在数据处理下拉框选择自定义协议
  2. 在弹出的自定义数据解析脚本对话框中输入上行解析脚本下行解析脚本
  3. 保存后创建其他同类设备的时候可以直接选择解析脚本
  4. 数据处理脚本通常还可对设备传输的值做加工处理
  5. 具体细节可以参考下面提供给的解析案例

案例

网关设备平台规范报文:

{
"TH180001": {
"temp": 26.5,
"hum": 45.5
},
"TH180002": {
"temp": 26.5,
"hum": 45.5
}
}

非规范设备报文:

{
"sensorDatas": {
"TH180001": {
"temp": 265,
"hum": 455
},
"TH180002": {
"temp": 265,
"hum": 455
}
},
"type": 2
}

以上行解析脚本为例:

  1. 分析发现设备发来的报文多了一层嵌套,并且数值都未做处理
  2. 创建网关设备,添加两个子设备。(注意子设备地址在编辑参数中填写,同一网关中不可重复,如下图)
  3. 首先编写代码
    var device_msg = '{"sensorDatas":{"TH180001":{"temp":265,"hum":455},"TH180002":{"temp":26.5,"hum":45.5}},"type":2}'
    var public_topic = "gateway/attributes"
    var msg = encodeInp(device_msg,public_topic)
    console.log(msg)
    function encodeInp(msg, topic){
    // 将设备自定义msg(自定义形式)数据转换为json形式数据, 设备上报数据到物联网平台时调用
    // 入参:topic string 设备上报消息的 topic
    // 入参:msg byte[] 数组 不能为空
    // 出参:string
    // 处理完后将对象转回字符串形式
    // 例,byte[]转string:var msgString = String.fromCharCode.apply(null, msg);
    // 例,string转jsonObj:msgJson = JSON.parse(msgString);
    // 例,jsonObj转string:msgString = JSON.stringify(msgJson);
    var msgString = String.fromCharCode.apply(null, msg)
    if (topic === "gateway/attributes"){
    var jsonObj = JSON.parse(msgString);
    newObj = jsonObj.sensorDatas
    for(var key in newObj){
    for(var k in newObj[key]){
    newObj[key][k] = newObj[key][k]/10
    }
    }
    msg = JSON.stringify(newObj);
    }
    return msg;
    }
  4. 使用在线js调试工具,这里用的是:https://www.lddgo.net/code/runcode/javascript
  5. 调试好以后,将函数粘贴进脚本保存(脚本在网关的编辑参数中,如图)
  6. 下行脚本的编写也同上

· 2 min read
zjhong

Release notes

This release revises many of the questions raised by previous users, especially the management of large-scale devices, access to complex devices, and how to efficiently forward data to third parties.In addition, this time it is also an overall test of performance, simulating 10,000 devices to stress test the system, and achieving a single TimescaleDB node 5000 devices/s access capability (4 cores 8G).In terms of permissions, horizontal fine to the operation and button, a relatively complete RBAC permission support has been established.Of course, it also includes a lot of detail improvements.

System demo

Demo address:http://dev.thingspanel.cn

Account password

What's new

  • Added Redis as a caching module
  • Added RBAC permission management module, using the Casbin permission framework, and the granularity of permissions is specific to devices, buttons or interfaces

  • Added a role management page to support multiple roles.

  • Added a permission management page, permissions fine-grained to the operation.

  • The system backend adds support for Docker environment variables for easy configuration.
  • Simplified deployment and increased adaptation to HUAWEI CLOUD / Alibaba Cloud.
  • Added access rule engine and data forwarding function.

  • Rewritten Business - Device Grouping - Device Module, supporting unlimited device grouping

  • Added log of operation device, support query manual operation and automatic operation records

Optimization and fixing

  • Optimized first login loading speed.
  • Optimized the overall UI.
  • Optimized indexing and sorting of some tables to improve the fluency of operations.
  • The standard of stress testing has been raised and various aspects of performance and structure have been optimized.
  • Optimized automated alerting and control strategies.
  • User added features and pages rewritten.
  • Optimized the alarm information page.

The next release is scheduled

The next version, number 0.4.0, is functionally planned to learn from HomeAssistant, implement a more open structure, increase the group of shared chart components, and make the development of plug-ins simpler and more efficient plug-in development.The major structural issues that existed before ThingsPanel will be improved, especially on large integration projects, and the efficiency will be very prominent.

· One min read
zjhong

ThingsPanel is an underlying open source software of the Internet of Things, the main function is to collect device data, visualization, automation control, for many integrators, equipment vendors, solution providers to provide rapid product and delivery solutions.

ThingsPanel's mobile app is used to provide mobile management and control support to ThingsPanel.The main implemented functions include monitoring, control, policy, and device addition management.Is a lightweight client for ThingsPanel that supports SAAS scenarios.

Features on the mobile phone include:

  • Using Uniapp development, it can be easily compiled into iOS, Android, WeChat Mini Program and other Mini Programs, H5.
  • You can scan the code to add a device (the device needs to be imported in the background first).
  • View the monitoring values.
  • 切换智能化项目和设备分组。
  • Manual control.
  • set the control policy,
  • There are two types: device trigger and time condition trigger.
  • Review the operation log.
  • Personal account management function.
  • Mobile phone verification code login.

ThingsPanel-APP mobile client login page ThingsPanel-APP landing page

ThingsPanel-APP Home ThingsPanel-APP