3.0.0-alpha2 • Published 6 years ago

@raulnegreiros/flow-node v3.0.0-alpha2

Weekly downloads
1
License
GPL-3.0
Repository
github
Last release
6 years ago

@dojot/flow-node

A NodeJS library that allows you to integrate your own node on Dojot's FlowBroker.

How to build your own node

1) You need to create a class that extends the DataHandlerBase class, this class is the responsable by implements your node behavior. The following methods must be implemented:

  • getNodeRepresentationPath
  • getMetadata
  • getLocaleData
  • handleMessage

2) Is necessary to create a .html file that describes your node. You can find how to create it using the NodeRed documentation. Dojot's FlowBroker uses the NodeRed frontend.

3) You need to encapsulate your code into a docker container.

4) Publish your container in some public repository like DockerHub or some private based on DockerRegistry.

5) Call the FlowBroker endpoint to add a new node. Please check the FlowBroker documentation to check how this endpoint works.

Sample

A sample node is attached to this package to illustrate the steps described in the previous section. It's a simple node that converts a Celcius temperature measure into Kelvin.

How to build

Build the docker image:

cd sampleNode
docker build -t <your dockerHub username>/kelvin .

Publish it on your DockerHub:

docker push <your dockerHub username>/kelvin

Acquire a Dojot's token:

curl -X POST http://127.0.0.1:8000/auth \
-H 'Content-Type:application/json' \
-d '{"username": "admin", "passwd" : "admin"}'

This command will return a JWT token, you need to store it on an environment variable:

export JWT=<the value returned>

Add the Kelvin node to Dojot.

curl -H "Authorization: Bearer ${JWT}" http://localhost:8000/flows/v1/node -H 'content-type: application/json' -d '{"image": "<your dockerHub username>/kelvin:latest", "id":"kelvin"}'

Now the Kelvin node will be available on converters category into the FlowBroker Dojot's interface.