Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/caowm/thingsboard-widget
thingsboard widget
https://github.com/caowm/thingsboard-widget
chatroom iot remote-shell thingsboard white-board widget
Last synced: 3 months ago
JSON representation
thingsboard widget
- Host: GitHub
- URL: https://github.com/caowm/thingsboard-widget
- Owner: caowm
- Created: 2022-03-30T02:59:16.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-08-08T04:46:56.000Z (about 2 years ago)
- Last Synced: 2024-06-30T04:17:04.420Z (4 months ago)
- Topics: chatroom, iot, remote-shell, thingsboard, white-board, widget
- Language: JavaScript
- Homepage:
- Size: 46.9 KB
- Stars: 10
- Watchers: 1
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-thingsboard - thingsboard-widget - inter-widget communication, based on [thingsboard/thingsboard#976](https://github.com/thingsboard/thingsboard/issues/976) (Widgets)
README
# thingsboard-widget
## nodejs rpc remote shell
特性:
* 这是一个用node程序模拟的mqtt设备,定时发送内存/CPU使用率,接收shell命令
* 完全适配thingsboard内部部件"Contronl widgets>RPC remote shell"
* 可以看作thingsboard版本的ssh1. 启动shell-device
```
cd node-device
npm install# 修改配置文件 config/index.js:mqtt broker, token
nano config/index.js
npm run shell-device
```2. 在thingsboard看板添加RPC remote shell部件,绑定的设备和第一步配置的设备相同
## 部件之间通讯交互示例:send_message.json/receive_message.json
这里使用的TB版本是3.3.3,发送消息:
```js
self.onInit = function() {
self.ctx.$scope.sendMessage = function() {
const $injector = self.ctx.$scope.$injector;
const broadcastService = $injector.get(self.ctx.servicesMap.get('broadcastService'));
broadcastService.broadcast('SOME_CUSTOM_EVENT', {
message: 'Hello ThingsBoard'
});
}
}```
接收消息:
```js
self.onInit = function() {
const $injector = self.ctx.$scope.$injector;
const broadcastService = $injector.get(self.ctx.servicesMap.get('broadcastService'));
broadcastService.on('SOME_CUSTOM_EVENT', (evt, data) => {
// data 是个数组
console.log('broadcast message', data);
self.ctx.$scope.message = data[0].message;
self.ctx.detectChanges();
});
}
```> 使用broadcastService进行部件之间的通讯是最佳方式,使用全局对象也可以,比如一个部件对self.ctx.userService定义新方法,然后在其他部件进行调用。或者使用window.onmessage和window.postMessage。
参考:https://github.com/thingsboard/thingsboard/issues/976
## 聊天室部件:chatroom.json
用法:导入部件后,在仪表板添加此部件。数据源添加任意一设备(此设备在多个客户之间共享),遥测名称为“chat”。时间窗口数据聚合功能选“空”,一定!原理:
* 把聊天记录当作遥测进行发送
```js
self.ctx.http.post(`api/plugins/telemetry/DEVICE/${entityId}/timeseries/ANY`,
{
chat: {
userId: self.ctx.currentUser.userId,
nick: self.ctx.currentUser.firstName + self.ctx.currentUser.lastName,
content: self.ctx.$scope.content
}
},
{
'headers': {
'content-type': 'application/json',
'X-Authorization': 'bearer ' + localStorage.getItem('jwt_token')
}
}).subscribe(() => {
self.ctx.$scope.content = "";
});
```
* 设置好数据源,面板通过WebSocket自动订阅遥测,我们只需要根据数据做展示## 白板部件:drawing-board.json
用法:导入部件后,在仪表板添加此部件。数据源添加任意一设备(此设备在多个客户之间共享),遥测名称为“draw_event”。时间窗口数据聚合功能选“空”,一定!原理:
* 把绘画动作当作遥测进行发送
* 根据drawingboard提供的各种绘图事件构建遥测(一个json对象)并发送描点动作:
```js
{
cmd: {
name: 'stroke',
points: self.ctx.$scope.points,
color: self.ctx.$scope.board.mode === 'pencil' ? self.ctx.$scope.board.color : 'white',
lineWidth: self.ctx.$scope.board.ctx.lineWidth
},
drawId: ++self.ctx.$scope.drawId,
userId: self.ctx.currentUser.userId,
session: self.ctx.$scope.session
}```
填充动作:
```js
{
cmd: {
name: 'fill',
coords: event.coords,
color: self.ctx.$scope.board.color
},
drawId: ++self.ctx.$scope.drawId,
userId: self.ctx.currentUser.userId,
session: self.ctx.$scope.session
}
```* session属性表示发送方,发送方据此无需重复绘图
* 根据遥测信息调用drawingboard提供的绘图方法
* 可多人同时操作缺点:
* 只要遇到reset动作,图像被全部清空
* 多人同时操作,撤销动作的效果会不一样,这是因为各人进入的时间不一样,得到的绘图动作数量不一样,而且最开始的绘制过程因为性能原因没有保存每一步的history,只在最后保存了history参考:http://leimi.github.io/drawingboard.js/
## 手绘风格白板Excalidraw部件:excalidraw_embed.json
把强大的excalidraw嵌入到thingsboard面板
参考:
* https://www.npmjs.com/package/@excalidraw/excalidraw
* https://codesandbox.io/s/excalidraw-ehlz3?file=/src/App.js作者:caowm ([email protected])