For my 2018 Developer Conference IoT session, I used Billy Bass to demonstrate how to drive motors from inside FileMaker remotely across the internet.
I’ve outlined the intended setup in figure 1. The FileMaker user types the text of what they want Billy Bass to say, Amazon AWS Polly synthesizes the text to speech, and somehow, Billy Bass speaks it.
FileMaker Server itself is also on AWS, on a Windows EC2 instance in our setup but does not need to be; your FileMaker Server can be anywhere. The fish is controlled through a Raspberry Pi and can be anywhere as long as it is reachable from the internet.
Putting it together for DevCon was quite the adventure that you can revisit in this four-part blog series.
How it Works
The magic, of course, is in how Billy Bass receives its instructions and does as it is told. For the DevCon presentation, I had settled on using a Python script running on the Raspberry Pi. The downside of that approach is that the Python script needs to be in a continuous loop to query FileMaker Server through the Data API, looking for flagged records, as outlined in figure 2 below.
It would be a lot more efficient if we could do away with the constant polling that originates from Billy Bass. So, for this redux, I decided to adopt a microservice approach in which the fish would be dormant until it receives an instruction.
Microservices and FileMaker
These are the same choices you would consider, for instance, when you need to set up a webhook integration where some system needs to send data to your FileMaker solution and you have no control over the JSON structure of that data. In my Engage 2020 session on webhooks, I talk about those choices at the 22:50 mark.
Setting up a Node.js Microservice
Like most things, setting up a Node.js micro-service is easy enough if you have done it a few times, but it can be a bit daunting if you are new to it. Fortunately, there is an option that uses Node.js in a very user-friendly fashion: node-red.
With node-red, you can create micro-services entirely in your browser by simply linking steps together into a flow. If you are familiar with Claris Connect, the basic concept is somewhat similar. In that Webhook video, I get into node-red at the 28-minute mark. You can also review other very good resources in our community:
- Jason Wood on how to set up node-red on AWS
- Marcel Moré on using node-red to build an FMS dashboard
- FileMaker ISO Magazine on how to use the FMS data API from inside node-red
Back to our setup. On the hardware side, we have the Raspberry Pi with the Squawker Talker, connected to the motors and speaker of Billy Bass.
And with node-red installed on the Raspberry Pi, the basic flow that does what we need it to do looks like this:
Reading this from left to right: the web service listens to the /fms endpoint for any GET requests, and it expects to be passed a FileMaker record id as a query parameter in the URL (which is what :id indicates).
With that record id, node-red will request the specified record from FileMaker Server through the Data API (the green Get Record node), retrieve the mp3 sound file from the container field (the green Extract Containers node), and play it. It will then respond to the caller with an “everything ok” http response code 200.
From inside FileMaker, the user types in the text they want Billy to speak.
FileMaker makes an API call to AWS Polly to convert the text to speech and then makes another API call to node-red to initiate the playback.
The script that interacts with the node-red microservice is extremely simple:
Calling any API from FileMaker is done through the Insert from URL script step on line 32. Lines 31 and 29 construct both the required URL (in the $endpoint variable) and the cURL options (in the $options variable).
Setting the hardware fiddling aside, I think you will agree that the software engineering to make this work is not complicated. Node-red allows you to very easily set up these kinds of micro-services that FileMaker can talk to, AND can interact with FileMaker themselves through the Data API. Node-red is an easy path into the world of microservices. Since it is based on Node.js, it offers a path up to actual Node.js coding if required or desired.
As always, feel free to ask any questions in a comment below and on community.claris.com.