Adventures with Raspberry Pi - Part 4
As we saw in the previous post, we now have Raspberry Pi server setup and integrated with multiple mobile devices successfully, let's try a more complex integration.
API's have become the de-facto standard for communicating between devices. But, if we also wanted to implement any logic, data transformation, loose coupling between devices, then we could use an ESB. One can think of the Mule ESB as another form of IFTTT. We can use the multiple connectors to link up different kinds of devices, services and applications.
Let's two kinds of integrations - event driven and batch.
Event Driven
In this example, a service pushes data to the Raspberry Pi.
![]() |
Event Driven Flow |
I am using Anypoint Studio 7 and Mule Runtime 4. A mockup product API is created in the Mule project. This API is exposed as a REST API with a GET operation. When someone calls the API, the Mule flow is executed. In the Mule flow, the data is read from the API and sent via SFTP to a target device.
In this case, the target device is a Raspberry Pi with SFTP server running on it. As part of the Mule flow, additionally logging and error handling are also implemented.
![]() |
Mule Flow in Anypoint Studio |
Once the Mule project is built and run, the API and the flow is hosted in a Mule runtime (which in turn is running on a JVM). An API console is available to test or call the product API.
![]() |
API Console |
On invoking the product API, the data is transferred in the form of a JSON file to the Raspberry Pi SFTP folder.
![]() |
Raspberry Pi SFTP |
Batch
Let's now look at a batch example. Of course, one could also have a "reverse" flow. Raspberry Pi could monitor it's own temperature and push it to the Mule ESB as well.![]() |
Batch Mule Flow |
Setup a cron job in the Raspberry Pi that runs every minute to collect the CPU/board temperature.
![]() |
Crontab entry for a "every minute" job |
The cron job writes the temperature details to a text file locally on the Raspberry Pi. The same file is over written every minute.
![]() |
Temperature details |
There is a Mule flow that reads the text file from the Raspberry Pi using an SFTP connector. The temperature details are then emailed using an Email connector to Outlook 365. Unlike the earlier flow, this one runs as a batch driven by the Scheduler component in the first step.
![]() |
Scheduled job in a Mule Flow |
![]() |
Status emails in Outlook 365 |
Of course, now one could setup many other kinds of flows like - collect the weather from an web based API and email, monitor the stock prices and email etc.
Mule ESB on IoT
Lastly, the Mule ESB can also be run on the Raspberry PI. Both version 3.x and 4.x can be installed side-by-side in the same Pi. Below is an example of Mule 3.9 Community Runtime running in a Raspberry Pi model 3 B.![]() |
Mule CE Runtime v3.9 on a Raspberry Pi 3 B |
In addition, the New Relic APM agent is also running in the Pi and is monitoring the Mule API's, flows and JVM statistics.
![]() |
New Relic Dashboard showing Mule statistics |
Comments
Post a Comment