High-level language-agnostic API

I apologize for the title being so vague but I am unable to come up with a better way to ask for what I am after.

Ideally I would be able to interact with the farmbot on a high-level, knowing nothing about the low-level implementation details such as MQ and farmbot_os, in a language-independant manner.

The picture in my head for this is:

  1. Querying status of the farmbot
    1a) Absolute location of the tool-mount
    1b) Task queue
  2. Issuing commands
    2a) Water plant ABC
    2b) Measure soil humidity of plant DEF
    2c) Run previously-defined sequence of commands

Hopefully you can see where I am going with this.

  1. Is this already done?
    1a) If so is there more work to be done? (link to tickets, labels, discussions, etc. please)
  2. Is this possible without much modification to the farmbot_os project?
  3. Is this something desired by the farmbot company and developers?
  4. Is this something desired by the community?

The existence of https://github.com/FarmBot-Labs/FarmBot-Chat-Bot indicates that something like this is definitely possible though I have not yet come across a language-agnostic solution.

The current architecture has multiple components that do not all talk to each other in every possible way, which might make what you’re describing infeasible at the moment. Some elaboration:

  • The backend server cannot yet send outbound messages to the FarmBot, thus there is no endpoint there for controlling the bot. You can only use the backend API for manipulating the data that is stored there: sequences, plants, regimens, etc. Meanwhile, the FarmBot can only post logs to the backend and download the backend’s data during a sync, which is initiated from the web browser over the MQTT protocol (not by the backend itself).
  • As far as I know, you cannot currently post or get a sequence, etc directly to/from the FarmBot - there are no endpoints on the device for that. It can only download these things from the backend and receive real-time commands from the web browser.

So any solution right now for controlling the bot in real-time and programming it with sequences, etc must use both MQTT and the backend API. It sounds like you’re asking for a way to use just one protocol/API for doing everything.

With the recent merging of the backend and frontend repositories and the upcoming switch to RabbitMQ, the backend server will be able to send outbound messages to the FarmBot. From there we could add endpoints to the backend API that allow you to control the bot in real-time as you currently can from the web browser. I’m not sure if this is something our software team wants to do though, as that type of control is much more suited to the currently implemented system of speaking directly to the bot. @RickCarlino?

Adding abilities to post and get sequences, etc directly to/from FarmBot OS in a way that mimics the functionality of the backend API is probably outside of the scope of the chosen implementation. cc @connor

@Phrohdoh Welcome! This is possible, but it is still in the early phases.

Is it already done?

Yes, you can do this via:

  • The message queue (uses MQTT, which is supported in every mainstream language).
  • A “Farmware” plugin that resides on the host (supports many common languages like Python and MRuby)
  • An API (HTTP) client. Very simple to setup but does not meet your requirement for device control- it is only useful for viewing records such as sequences.

Is there more work to be done?

Yes, there is, please contact me privately if you have specific questions or are looking for ways to contribute. Things move very quickly on our small team and maintaining a purely technical road map for public viewing has shown to be difficult. We do have a plan and a backlog of things we want to implement and improve.

Is this possible without modifying the farmbot_os project?

Yes, if you want to run a plugin in language XYZ onboard the device, you may author a “farmware”. Although it is in the alpha phases, we do have documentation available.

Is this something desired by the farmbot company, developers, community?

Absolutely!!! @mdingena was our first developer to author a third party tool and we are always happy to help developers learn the platform. It’s still very much in the early phases, so feedback is always welcome.

Other important things:

If you are interested in writing an application that commands the bot remotely (or reads the bot state remotely), we have an JSON based RPC format known as “Celery Script” which can be sent to the device over MQTT. The way it works more or less is that you:

  1. Connect to MQTT using your preferred MQTT client or library. Use your email as a user name and an MQTT token as a password.
  2. Subscribe to the relevant MQTT channels
  3. Send the appropriate Celery Script command to the device*.
  4. Let us know if you get stuck, we’re here to help.

* The FarmBotJS library provides wrapper methods, but if you wish to write in a langauge other than JS/Python, please take a look at these interface files after reading the Celery Script docs. I’d be more than happy to answer any questions you have.

Sorry if that’s a whole bunch of information all at once- I hope it helps! Please let us know where we can best focus our efforts for developer documentation. Questions such as this help guide the content of documentation, which is still very much a work in progress. We really appreciate it.

1 Like

Hello again!

Has anything major changed in the architecture from what is described in the previous comments?

I am starting to assemble my farmbot now and there are many software project ideas flowing through my head that I’d like to begin prototyping.

Thank you for your time, it is much appreciated!

@Phrohdoh Welcome back! The comments above still mostly hold true. A few things:

  • The link to farmware docs has changed: https://software.farm.bot/docs/farmware-dev
  • The platform is much more stable, but still in Alpha. As I mentioned in our discussion on Github, a formal developers portal is still in the works.

If you have any questions about “How to build a farmware to perform X” in the meantime, please don’t hesitate to ask! :tada:

Querying status of the farmbot
1a) Absolute location of the tool-mount
1b) Task queue
Issuing commands
2a) Water plant ABC
2b) Measure soil humidity of plant DEF
2c) Run previously-defined sequence of commands

just to complete the list
2d) make a photo of plant abc leaf efg
2e) something with desease detection :wink:

1 Like