- How about this project
- How to use
- API
- Project config -- config.json
- Create a webhook with thingsboard
- Run the demo code to observe how the service parse data
- How to Deploy (Linux & Docker)
this is a simple service that can listen the request and response result
- node 16.13.0
- create a simple service
- can recieve a data input and parse data by the header given
- can dynamic add, delete and change data parse rule by the json file
- can use the thingsboard
API Calls rule node
to create a webhook to handle data - don't have other library
- no queue
- can not handle array data now
{
"server": {
"port": 8000,
"dev_host": "127.0.0.1",
"product_host": "0.0.0.0",
"debug": true,
"production": false
},
"device": {
"device_type_A": {
"get_cpu_loading": {
"path": "CPU.loading"
},
"get_mem_loading": {
"path": "MEM.loading"
},
"get_two": {
"path": "Value.one.two"
},
"get_deep_value": {
"path": "Value.one.two.three"
}
}
}
}
npm run start
This service will listen at POST http://host:port/device
you can use the postman to check this service API is work: thingsboard sendbox public postman
curl --location --request POST 'http://127.0.0.1:8000/device' \
--header 'datapath: MEM.loading' \
--header 'devicetype: device_type_A' \
--header 'Content-Type: application/json' \
--data-raw '{
"MEM": {
"loading": 77
}
}'
-
datapath
- can tell the service how to parse data
- please use
.
to split if you want to parse data deeper
-
devicetype
- can tell the service current data is send by some device type
- any data (json format) send by device or others
{
"server": {
"port": 8000,
"dev_host": "127.0.0.1",
"product_host": "0.0.0.0",
"debug": true,
"production": false
},
"device": {
"device_type_A": {
"get_cpu_loading": {
"path": "CPU.loading"
}
},
"device_type_B": {
"get_mem_loading": {
"path": "MEM.loading"
}
}
}
}
- port
- server port
- dev_host
- server listen host during dev mode
- product_host
- server listen host during production mode
- debug
- can print some debug log
- production
- if this attribute is
true
, the service will listen theproduct_host
- otherwise the service listen the
dev_host
- if this attribute is
- you can set your device type name
- this config will tell this service will receive which device type data
- you can set the function name
- the service don't care the name of function
- you can use it to tell the service how to get some value
- assump there is a data like as follow
{ "data": { "one": 1 } }
- if you want to get the "one" value in this structure, you can set the
path
todata.one
- the
.
can tell the service how path to query the data
- assump there is a data like as follow
There are two header params at bottom are datapath
and devicetype
The datapath
can tell the service how to get the data. (data format please reference API chapter)
Another devicetype
can tell the service current data is send by some device type. (how this service use it please reference config chapter)
- there are some files in
demo
folder - the demo folder has isolated environment to run the core process
- you can change the
demo/config.demo.json
and runnpm run demo
to observe how the service parse data
"server": {
"port": 8000,
"dev_host": "127.0.0.1",
"product_host": "0.0.0.0",
"debug": true,
"production": true // if true, the service will listen `product_host`
},
// other setting...
sudo npm run project-deploy
cd release
sudo ./build.sh
sudo ./deploy.sh
sudo docker ps | grep thingsboard-sendbox
you can see the container is runninng like as follow.
you can reference Test the API can parse data
# project build
OUTPUT_FOLDER=output # create folder in root path
OUTPUT_IMAGE_FILE_NAME=thingsboard-sendbox
# deploy
DEPLOY_VERSION=v0.2.0-beta
DEPLOY_PORT=8000
SERVER_LISTEN=8000 # must equal to the "config.json" at root folder
# docker
IMAGE_NAME=thingsboard-sendbox
CONTAINER_NAME=thingsboard-sendbox