FarmBot is an open-source robotic hardware kit designed for gardeners, researchers, and educators to interact with agricultural projects in a more efficient way. FarmBot uses physical sensors and actuators that require a bridge between the physical garden and the software layer. In 2017, user demand for real-time response to requests, shorter development time for new features, and a significant improvement in system up-time led Farmbot to RabbitMQ - the world’s most popular open-source message broker.
FarmBot’s Genesis version can plan, plant, and manage over 30 different crops such as potatoes, peas, squash, and more. Able to manage an area of 2.9 meters × 1.4 meters and a maximum plant height of 0.5 meters, FarmBot Genesis uses manual controls that users move and operate to perform a variety of tasks.
Image source: https://farm.bot/
Thanks to the game-like interface that drags and drops plants into a map, FarmBot users immediately grasp the concept of controlling the entire growing season from start to finish. FarmBot tools and peripherals perform tasks such as watering plants, scaring birds away, taking photos of veggies, turning the lights on for a nighttime harvest, or simply impressing friends and neighbors!
Image source: https://farm.bot/
On the other side of the coin, FarmBot identifies and eliminates weeds through image analysis via an onboard camera. To practice good conservation efforts, watering is done automatically after taking into account the degree of soil moisture and the weather forecast. There is a web app version of FarmBot to allow users to control garden tasks via smartphone or tablet.
FarmBot’s architecture consists of three main parts:
- The vegetable garden, Arduino microcontroller and Raspberry Pi (runs the management software and controls the Arduino CNC)
- Web server handling requests between the field and the user
- Web app (on mobile/iPad/browser etc.) that lets the user interact with the system
Now for a deep-dive
Let’s now take a closer look at all aspects of the system.
Arduino microcontroller (firmware) and Raspberry Pi (FarmBot OS)
The firmware, named Farmduino, is the software responsible for interaction with the real world. It runs on an Arduino microcontroller, written in C++ and executes sensor and actuator commands that allow users to drive the motors, the electro-irrigation valve, and read the probe measurements.
An example of this is when FarmBot turns on the water valve or probes for soil moisture. In this case, it is the device firmware that tells the peripherals directly when and how to operate. Other parts of the system may request access to peripherals by sending commands to the firmware.
A Raspberry Pi running FarmBot OS allows FarmBot to communicate with the web application over WiFi or ethernet to synchronize (download) sequences, regimens, farm designs, events, and more activity, including uploading logs and sensor data and accepting real-time commands. The Raspberry Pi also communicates with the Arduino to send commands and receive sensor and encoder data. It can take photos with a USB or Raspberry Pi camera, and upload the photos to the web application.
The REST API, PostgreSQL, and RabbitMQ
The FarmBot API provides an HTTP based REST API, which handles a number of responsibilities that prevent data loss between reflashes by storing it in a centralized database. This allows users to edit information when the device is offline and allows users to validate and control access to data via authentication and authorization mechanisms. It also sends email notifications (such as password resets and critical errors) to end-users. All other messaging is handled by a message broker - RabbitMQ, a distinctly decoupled sub-system of the Web API. The REST API does not control FarmBot - device control is handled by the Message Broker, CeleryScript and FarmBot JS.
RabbitMQ communicates to the devices in the field by AMQP and acts as a message queue to the backend services. MQTT protocol is used for real-time events to the frontend user interface.
Frontend user interface
The frontend user interface allows users to control and configure FarmBot from any desktop computer, laptop, tablet, or smartphone. Many users end up running their own web server on-premise since it's all open source. FarmBot also provides a publicly accessible server at https://my.farm.bot/ and a staging server at http://staging.farm.bot for end users that are not familiar with Ruby on Rails application development.
Some interactions do not lend themselves well to an HTTP request/response pattern, especially remote procedure calls. A device would be forced to perform long polling, constantly making HTTP requests to the API for any new remote procedure calls. Polling would create tremendous scalability issues for the web app and provide a sub-par real-time experience for users.
For example, emergency stop messages in FarmBot should be received as soon as they are created rather than the system constantly checking the API for messages like these. Other use cases include remote procedure calls and real-time data syncing.
RabbitMQ to the rescue
In 2017, Farmbot users were asked to vote for new features to focus on for the coming new releases. Users overwhelmingly chose auto-sync and better real-time support as two feature must-haves. This forced the Farmbot community to reevaluate the architecture and seek a new way to structure the app. To meet user demand for a more responsive, more reliable version, RabbitMQ was the obvious choice for FarmBot, in part because it includes:
- Robust support of plugins such as WebSockets and MQTT
- Wide variety of wrapper libraries for Elixir, Ruby, and Typescript
- A good ecosystem, mind share, and ubiquity overall - e.g. it is not an obscure choice
RabbitMQ is now an important component of the FarmBot web API, where it handles various tasks including:
- Passing push notifications between users and devices
- Passing background messages between server background workers
- Uses a set of custom authorization plugins (to prevent unauthorized use)
Because RabbitMQ is a real-time message broker, there is no need to check for new messages. Messages, such as a user clicking the "move" button on the user interface, are sent back and forth between client, device, and server without initiating requests.
In many ways, the message broker acts as a machine-to-machine chat application. Any software package, whether it be the REST API, FarmBot OS or third-party firmware, can send a message to any other entity that is currently connected to the message broker, provided it has the correct authorization.
The rest is success
Today, FarmBot is a happy, satisfied customer of the largest hosting provider of RabbitMQ, CloudAMQP. “The interactions with customer service have been quick and pleasant, and we've seen great uptime stats,“ said Rick Carlino, Lead Software Developer at FarmBot. He continues, “We really don't have time to manage our own services on AWS and would much rather pay a premium to know that someone else is taking care of the problem if there is one.” Choosing the right technology and the right vendor often focuses on the best selection to optimize developer time. To address this, CloudAMQP provides support around the clock including built-in alarms that can be set up to detect issues with the server before it affects the business.
We really don't have time to manage our own services on AWS and would much rather pay a premium to know that someone else is taking care of the problem if there is one.
- Rick Carlino, Lead Software Developer at FarmBot
Heroku - Cloud Application Platform
The same goes for the decision to host the production servers on Heroku. Even though there would be cost savings in hosting production a traditional AWS/Kubernetes setup, it's simply too much of a risk for a small company to save only a couple hundred dollars a month. FarmBot’s Carlino added, “Every hour I spend thinking about infra is an hour that I am not spending on feature development.”
The CloudAMQP Advantage
User demand for real-time response to requests, shorter development time for new features, and a significant improvement in system up-time all led FarmBot to choose RabbitMQ and CloudAMQP.
As the leading hosting provider of RabbitMQ, CloudAMQP was able to help Farmbot to quickly format their old architecture into a message queue based system, transforming the agri-tech app into a farming powerhouse.
As FarmBot leads the way in the innovation of how food is grown, CloudAMQP is leading the RabbitMQ revolution through user success stories like this one. Let us know if it’s time to create your own successful message queue architecture? Get in touch with our friendly team of professionals today to determine the right RabbitMQ plan for your future growth.
Feel free to contact us at firstname.lastname@example.org if you have any suggestions or feedback.