Open Source Farm Management

Over the past few months, I've dedicated a fair amount of time to two different activities: experimenting with indoor farming and building an open source farm management platform

ktech_farms

Introduction

Over the past few months, I've dedicated a fair amount of time to two different activities:

  1. Experimenting with indoor farming
  2. Building an open source farm management platform

I've always been interested in agriculture and had the opportunity to help my grandpa on his farm when I was younger. I left for college though, and over time moved more into technology - starting with helpdesk and moving my way into software development.

Back in 2019, I discovered CEA and vertical farming, which is when I began tinkering with a few ideas around automated growing devices and what not. I loved the idea of being able to control the environment and provide high quality food with limited chemical and pesticide use, especially considering the growing population and increasingly common weather issues (i.e. droughts, floods, etc.). It was the perfect opportunity to combine my interests in agriculture and technology.

Fast forward to Q3 of 2022, and I finally began growing crops indoors (more on this to come later!) So far, I've been successful with various herbs, microgreens, and lettuce. I even have a couple strawberry plants now. As I went through this process, I decided to make a go at this as a business and not just a hobby. In order to make it a business though, I realized I was going to need a way to manage a lot of documentation and data.

growtent
My first grow tent with a 4 shelf rack and 4 ZipGrow towers

I have no interest in keeping stacks of written records, and also thought it would be nice to have a way to trace produce from seed to customer, tie into a sales platform, and a myriad of other functions. I found a couple software platforms such as farmOS, Tania, and LiteFarm, but they either didn't fit my use case or were missing features that I wanted. Enter Farm Manager - my take on an open source farm management software.

All of the code is available on GitLab, and the latest release has functionality such as:

  • Viewing and controlling devices remotely
  • Management of locations, categories, units, and products
  • Tracking crops from planting to harvest
  • Inventory management
  • Crop reports
  • And 3rd party integrations with services such as SendGrid and Square

I plan on going into more detail with regard to functionality later (you can view some videos on YouTube), but today I wanted to touch on some of the technology I'm using.

Hosting

The first thing I want to mention is that I'm building Farm Manager with the goal to be cloud native and limit costs as much as possible. To do that, I'm utilizing Linux Azure App Service Plans and docker containers. This allows hosting a basic database, azure container registry, and two app services for less than $25.00 per month. That being said, it's totally possible to run on-prem as well

⚠️
At the current moment, an internet connection is still required, but there are plans to eliminate this requirement, with the understanding that doing so limits some functionalities

Deployment

One major requirement I have for this project is that it must be easy to setup and deploy. The way I'm doing that is by utilizing docker and Azure Container Registry. Getting it running should be as simple as

  • Building the docker image
  • Publishing the image to an Azure Container Registry
  • Using the Azure Container Registry as the source for the Azure App Services

Unfortunately, the Azure setup isn't quite so straight forward, as several different resources are used. Future state, I hope to utilize Docker Compose and have a script or ARM template that can create everything automatically. At that point, I believe it'd be possible to get running just by updating some config values and double clicking a script.

Tech Stack

The tech stack is primarily Microsoft and .Net based. There's a .Net web api and a Blazor WASM application for the client. What I like about that is I don't have to use one language for the backend and something else for the frontend, because it's all in C#.

Again, I'm using Azure for everything hosting and infrastructure related - Microsoft SQL database, Azure SignalR, Azure App Service Plans, Azure App Configuration, Azure IoT Hub, Azure Storage, etc.

Azure IoT Hub

When it comes to devices, Azure IoT Hub is what allows a connection between the actual device and the core Farm Management software. One of the best things (In my opinion) about using IoT Hub and Azure hosting is that since everything's cloud based, I can have devices in different physical locations all connected to the same system. It also allows for controlling the devices remotely, assuming they're setup for it.

So what is a device? They could be anything from physical hardware to software running on a computer. An example of a physical device might be a Raspberry pi that controls a water pump and submits temperature, and humidity readings. Software, on the other hand, could be something that collects and forwards telemetry from 3rd party devices that don't have a direct connection to the Farm Manager software.

As I build out this project, I will also be providing open source plans & code for any devices that I create in my Devices repo.

Azure Service Bus

One of my goals with Farm Manager was to make it modular and easy to expand when needed. I decided to use a messaging system for this and leverage Azure Service Bus. For the most part, this is utilized for handling events to and from 3rd party systems like Square (for payment processing) and SendGrid (for email notifications).

Obviously, the target use case at the moment are small individual farms, but should there be a need to scale the system, it should be relatively easy to migrate to a micro-service architecture.

⚠️
Currently, all messaging utilizes queues, rather than topics and subscriptions. The primary reason for this was to utilize the free version of Azure Service Bus. I'm looking into adding support for RabbitMQ to address this and allow on-prem hosting

Azure SignalR

Going back to device communication and the Azure IoT Hub, one feature that I setup was real time updates of telemetry when viewing device information. This is accomplished by utilizing Azure SignalR to push incoming telemetry to the web clients.

telemetry
Real-time telemetry being sent from a prototype device

An added bonus to using Azure SignalR is that you don't have to worry about devices not receiving notifications if the api scales to multiple instances, since everything shares a single SignalR "host"

Microsoft Graph

One area that's always a concern is security. With Farm Manager, I decided to use Azure AD for authentication. The client and api are registered in azure, and the Blazor app passes user credentials to the API. This makes it easy to control who has access to which endpoints, and Azure is considered the source of truth for all users. Any time that user information is utilized or displayed, data comes from Azure and the Microsoft Graph SDK.

Documentation

As with any project or technology, having documentation on how to use it and get started is important. Everything's documented and available on a dedicated documentation site. You'll be able to find detailed information on all of the technology, setup, installation, etc.

docs

There's also a detailed guide on how to perform every action in the application and upgrade from one version to another. Each time a new version becomess available, the documentation site is updated first.

guide

Support

Part of why I decided to make Farm Manager open source was to help other farmers get started. As I go through this myself, it's apparent that starting a farm is extremely difficult, especially considering the high price of land and equipment. Not only does Farm Manager help run the business, but it can be modified and / or updated and all of the code and documentation is freely available.

That being said, I know not everyone is technical, so as things progress, I'll be offering support services consisting of:

  1. A one time setup
  2. and monthly, ongoing support

Of course, there's always the ability to just report a bug through GitLab or in-app as well.

Conclusion

I've been using this in production for the past month or two, feel like it works pretty well, and hope someone else can benefit from it too. I'm always looking for feedback and things to improve, so if anyone tries it out or has some feedback, let me know in the comments!