Maximize your investment in IoT devices with FLOGO
There are a few reasons why Flogo stands out for IoT. It can be installed on any hardware due to its size, plus packs more functionality in less space on top of that it provides the flexibility to develop your own customised solutions empowered by the strength of Golang.
Here in this blog, I will explain how I built a custom solution around a use case where data collected by an edge device was made available at a remote location for data analysis and prediction. The solution involved a directory poller waiting for an input file with data collected by edge device and publishing it to a MQTT topic.
In a world increasingly driven by data, solutions need to effectively manage and utilize data to make more informed decisions to realize greater levels of success.Wireless network, data aggregator and iPass providers have improved customer service proposition, gained new insights into business and even introduced new product lines. Many a times the data collected by sensors are huge and may not fit into the limited space in an edge device, so there comes a need to shift that data from the device or sometimes the demand of the situation is that you need to take some action as soon as a file is modified, like some data value crosses the threshold limit and the concerned team should be notified as soon as it happens. In situations like such, a poller can be the tool we might look for which. It can also provide the intellegence to the device to decide whether to keep a data or not. The primary purpose of any data you collect or manage is to derive actionable insights from that data using various types of data analytics.
All the data aggregated by the sensors have to be presented to a computing mechanism and provided the limited abilities of already existing edge devices, sending and receiving messages becomes a challenge. MQTT is designed for connections with remote locations where a "small code footprint" is required or the network bandwidth is limited. This was reason we worked on an activity to send the data read by the poller to the destined remote location.
When I was coding this out, I ran into errors but it’s an integral part in every developer's life and I think that’s good, because it made me learn a lot and I wish to share my learnigs with my fellow developers.
I’m super excited to share this guide with you. So let’s get started right away!
Before getting started, you need to ensure that the machine you’re using is equipped with the required tools and kit.
- Install docker: https://docs.docker.com/install/ , Flogo has a docker image which helps you to work on the flogo web UI.
- Golang : All the development will be done using Golang.
- Install Flogo CLI for local development: http://www.flogo.io/
To keep you away from all the above steps, I have created a docker image of the development environment. https://hub.docker.com/r/akamatibco/golang-flogo-dev/
Now that your machine is all set, we can start coding!
The Fun Part :)
We will first create the Flogo Trigger. A trigger is that module of flow which initiates the flow depending on a stimulus.
In our case the trigger will be either creation or modification of a file inside a directory being tracked. We will be developing a "Directory Poller" for tracking the target directory.
Firing up Flogo CLI
Run the below command and flogo cli will set up the required files for you to start coding.
flogogen trigger DirectoryPoller
This creates a directory in the current working directory with three files inside it.
- Activity.go is where our implementation goes.
- Activity.json contains the configurations used by our trigger.
- Activity_test.go implements the unit test for our trigger.
You can get the implementation here: https://github.com/Ganitagya/Custom_flogo_activity/tree/master/dirpoll
The file reader is here : https://github.com/Ganitagya/flogo-contrib/tree/master/activity/ReadFile
The MQTT Publisher can be found here : https://github.com/Ganitagya/flogo-contrib/tree/master/activity/MQTT_noCert
The Flogo Web UI
Now our food is cooked and it needs to be garnished and served.
Install the trigger and activities by providing the corresponding GitHub links and once installed, fill in the parameters and build your flow as per your system.
- For Linux users : use the x86/Linux option to build
- Mac users : use the Darwin/OSX
- build For those who wish to make it
- work in Raspberry Pi : use the ARM/Linux option
The food is served and ready to be enjoyed :)