February 10, 2021 Software Update

Hi FarmBot community,

Today we released a new version of FarmBot OS (v12.3.6) as well as the web app. Here’s what’s new:

New Lua functions

In our ongoing effort to empower 3rd party developers with a powerful and easy way to extend the functionality of FarmBot with custom code, we’ve implemented some additional and highly requested features to the Lua sandbox.

First up is env(). By calling env(key, value) you can store a key/value pair to disk. This information will be stored on the device SD card and eventually synced to your web app account. By calling env(key) you can retrieve a previously stored value. This can be used to store long term data such as an API token for a 3rd party service you wish to access, or short term data that you wish to persist and use in other sequences/subsequences.

Next up is http(). As you may have guessed, this function allows you to make http requests to 3rd party services such as weather APIs, messaging platforms, another device on your local network, etc. To help you get started @RickCarlino has written up an example for sending a message to a Slack channel.

New json.encode() and json.decode() functions convert a Lua variable into stringified JSON and back again.

And finally, take_photo() takes a photo using the device camera :camera_flash:

For additional information and code examples, see our updated developer docs.

ENV editor

In addition to programmatically setting key/value pairs using env(), there is a new section in the settings panel where you can view, add, edit, and delete key/value pairs from your account, which will then sync to the FarmBot. To access this section, go to the settings panel and type “env” into the search field.

New controls panel buttons

Rather than having to choose between going to home and finding home for the home button behavior, we’ve removed that app setting and are now permanently displaying both buttons all of the time.

Home buttons

You’ll now also find a three-dot menu next to the X-AXIS, Y-AXIS, and Z-AXIS labels. Clicking this reveals a popup with controls to FIND HOME, SET HOME, and FIND LENGTH for an individual axis, sparing you from diving into the settings panel for these commonly used functions.

Single Axis Controls

Miscellaneous

  • Added a link to the Lua developer docs to the Lua and Assertion step tooltips.
  • Fixed a bug where sequence step buttons were overflowing incorrectly on small screens.

Enjoy!

5 Likes

Awesome!

Can environment variables be set and read with simple commands or must we always do it through a line of code in the Lua editor? I think of the following use case:

If I want to know the soil moisture for each individual plant before watering a low or high amount of water, I need to mount soil sensor, read sensor, unmount soil sensor, mount watering nozzle, water, unmount watering nozzle, and then proceed to next plant.

With environment variables I would: mount soil sensor, read sensor at every plant location and save result to memory (can we do this?), unmount soil sensor, mount watering nozzle, and water appropriate amount of water for each plant by reading sensor values from memory. I’d also probably destroy the variable in the process as now I’ve used it.

@mdingena If you go to the settings page and search for the word “env” you will find an ENV editor. Is this what you were looking for, or are you trying to use graphical blocks from within the sequence editor?

image

This is possible, but not very “ergonomic” yet. You could absolutely call read_pin from Lua and store the result to an ENV. Just keep in mind that by design, ENVs are just string values. You will need to call tonumber() on the value to convert it back to a number. You will need to get creative with how you store the data, since each data point is limited to 1,000 characters and you are only allowed to have 300 total ENV vars (including the ones that FarmBot uses internally for things like the weed detector). One way to do it would be keep a MOSTURE_DATA variable and serialize the data into a JSON object. Example:

key = "" .. x ... "," .. y
env("MOISTURE_DATA", json.encode({[key]= my_reading}))

In future versions, we would like to add the ability to modify a plant’s metadata so that you could call read_pin and store the value directly inside.

2 Likes