In my last article, I demonstrated how I used Machine Learning on the Raspberry Pi to determine if a photograph contained a bird. This article can be found at https://powerwire.eu/raspberry-pi-and-machine-learning if you missed it.
In this follow-up article, we will be using the Raspberry Pi to send details to our IBM I server to inform it of all the details.
You can hopefully, use the basis of this exercise to tailor to your own company needs.
To send details to the IBM i we will be using ActiveMQ which we installed in my article https://powerwire.eu/activemq
In our scenerio we have the following
- Raspberry Pi will take the photo
- Machine Learning will decided if there is a bird in the photo
- If there is publish a message to ActiveMQ, using the topic of PowerWire
- Have a node client running on the IBM i that is subscribed to the queue PowerWire
- Then when the node client recieves any messages it stores the details of the photo in a database
We covered the Raspberry pi steps one and two
We covered the ActiveMQ the installation of the messaging broker (aka message server) so we have that installed
The parts we will be covering in this article are;
Step 3 – publish a message to ActiveMQ
Step 4 – subscribe to the topic of PowerWire and wait to receive any messages
Step 5 – store information in database on the IBM i
Before we go further into the details of how we achieve this last part of the project, I would like a word about the database we are going to use.
As I had used Node-RED on the Raspberry Pi, it seemed to make sense to use Node-RED on the IBM i to process the data our ActiveMQ had received from the Raspberry Pi.
My first choice of a database is DB2 for i, always has been for the last 40 years.
In Node-RED, I attempted to install the db2-for-i module – failed the install. (Very disappointing)
Right, what other choices do we have, I’ll use MariaDB. That installed, I tried to use it in Node-RED with a simple query and fail!
Next on the list, PostgreSQL. I’ll load that module into Node-RED on IBM i. Yes it installed and yes a quick query proved the installation. Fantastic, finally a database that works with Node-RED on IBM i.
Using our bird application I explained in my previous article, all I had to do was to get the check from the Machine Learning module, that had decided that a bird was present in the photograph, to publish a message to our ActiveMQ on the IBM i.
As I explained in my last article, I would be using the MQTT protocol to achieve this. Node-RED has included both a transmit and a receive node to do this job.
In the figure below we can see where I’ve plugged the MQTT out node into our flow.
The flow in Node-RED on the IBM i is shown below.
The next few figures show the properties for the main players in the flow.
The configuration for the MQTT in node (Step one in the previous figure)
The configuration for the MQTT in node
- The name of the ActiveMQ server, in this case, it is running on the same server as the Node-RED so we can use localhost on port number 1883
- The topic to subscribe to is PowerWire
The configuration for the function node, number 3 in the flow diagram.
- Build the message parameters value as needed by the Postgresql
- Send the message object
The configuration for the PostgreSQL in node (Step five in the main flow figure).
- The server running the Postgresql server
- The insert SQL statement using the parameters passed from the function
Now a check to see if the results are getting populated in our database.
A quick select * from birds shows our results in a postgress shell window.
That rounds off this little project, we used a Raspberry Pi to take a photo, process that through a Machine Learning module, if a bird was found send the details to ActiveMQ. A process on the IBM i receives the message from ActiveMQ and stores the details in the database.
A fun little project to work on!
All the examples I have written for this article, and previous ones, can be found on my open-source repository on GitHub, which can be found at https://github.com/formaserve/f_Learning
If you have any questions, either on this article, or anything else on the IBM i, use the comments below, or send me a message on twitter @AndyYouens
Andy Youens is an IBM i consultant/instructor at Milton Keynes, UK-based FormaServe Systems with over 40 years IBM midrange experience.