Examples

Acquire - Transform - Push

31 views 0

This example is a simple scenario of how to transform acquired data from sensor and push the new data to another consumer.

In this example is used the Arrowhead Tools server too.

Using RoboFuse you have access to:

  • Message Queues – default integration is with RabbitMQ
  • Computing units – implemented with Node-RED

With these 2 components easily, you can create new processes specific for your use case.

In this use case we will demonstrate how to create a new flow that is attached to data input for temperature measurement, do some computations and then publish the message to a new message queue.

We have 2 applications defined (on RoboFuse developer account).

1) Producer – with more temperature sensors connected – that send data using message queue or WoT (API)

2) Consumer application is the target where data need to be sent after are processed by Producer Application.

Consumer applications expose a message queue too, where messages need to arrive.

Producer application

On the producer application we need to activate:

  • Message Queue
  • Compute unit
  • Define and enroll temperature sensors
  • Define and activate a new Event that is sending a notification to the Events Queue once new temperature data arrived

Once that temperature sensors are connected and pushing data to Producer application, we can define the Node-RED flow that connect to the Events Queue process data and send to Consumer application.

Node-RED flow

We create a new Event, attached to the temperature data stream with worker named “aht”.

We receive data on our application message queue under the “aht” queue.

Under the Node-RED we need to define next:

  • MQTT – in that connect to the “aht” and read events messages
  • Create a transformation block
  • Create the message for target Consumer message queue application

Once the MQTT-IN node is configured events sent on “aht” worker are available here.

To connect the MQTT-IN you need credentials for you RabbitMQ application instance. You can find then under you RoboFuse application if you navigate from:

  • RoboFuse dashboard -> Your Application -> RoboFuse -> RabbitMQ

First, we create a JSON object.

Now we’d like to transform and send the data to a designated destination.

As we know, Events are sending a JSON where you can find different meta data. If you set up Channel object, then you have all needed data regarding the desired destination.

{
    "app_id": "155_1zgkcipy3ry8wsg0oss0ocwcsws8gssgwkgo4wc84c4cgwss",
    "access_token": "N2JiYWZkZDZjzOWRlNDc4NWYxZjVhNGJjZGViZDhjNdhNTFjZjhhMjQyODA2NzI3NmNlOGQzNDRjOQ",
    "user_uid": "5455b4f9-f0ee-4f23-bc99-134ec1a5ca27",
    "Channel" :{
        "url" : "https://nodered.ropardo.net/events",
        "user" : "user",
        "pwd" : "my pwd"
    },
    "stream_payload": "W3sidmFsdWUiOiAiMjEuNiIsICJ0aW1lc3RhbXAiOiAiMjAyMS0wNi0xMFQxNzowNToxMyswMzowMCIsICJ1bml0IjogIkMiLCAiZGV2aWNlSUQiOiAiNGMxMWFlZDhjZDQzLWQ2MDMwZTk3OTQ0M2I1MjgifV0="
}

In our example we have the URL, user, and password, so we are good to go.

We create a change node to prepare data.

We will use HTTP Request node to effectively send data to destination.

Here is Change node definition:

  • URL : is the URL from the Event
  • Method is POST
  • Headers: since we need to send data using user / password we need to create current header using: ‘Basic ‘& $base64encode(msg.payload.channel.user & ‘:’ & msg.payload.channel.pwd)
  • Payload : is the message payload. In this example we do not change it, if you need to do any changes you can use other function or other Node-RED nodes. We used: {“properties”:{},”routing_key”: topic,”payload”:$base64decode(payload.stream_payload),”payload_encoding”:”string”}

Now we add the HTTP Request node.

Was this helpful?

By continuing to use the site, you agree to the use of cookies. More information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close