Coder Social home page Coder Social logo

farmbot-py's Introduction

This Farmbot client is made to allow synchronous programming against the Farmbot MQTT API. It currently only implements commands that are useful to run your own sequences.

The current implementation expects an rpc_ok return message with the same uuid as the command message. If this message is not sent this client will block indefinitely. It's known that there are some commands where there is no rpc_ok return message, so that still needs to be fixed.

There are also some compound commands for common sequences, like picking up a tool. All these compound commands use a safe move by first moving the tool mount to max height before moving horizontally.

This code has used the examples in https://github.com/FarmBot-Labs/FarmBot-Python-Examples.

Installation

This code will not run on Python 2.

This code depends on the paho-mqtt and request libraries (pip install...).

You will need to add your own config.json in your project root. Use the template src/farmbot/config-template.json for this. You will need your device ID and token to be able to connect to your FarmBot.

  ...
  "device_id": "device_9999",
  "token": "iufhahwiawfhaw....",
  ...

Basic usage

This code will blink lights, plant a seed and water it. An initial call to bot.start() is possible but not needed, this will be called lazily before the first command is executed. bot.stop() is needed to cleanly end the MQTT client loop.

cfg = FarmBotConfiguration('./config.json')
bot = FarmBot(cfg, FarmBotConnection(cfg))
try:
    print("Hello Farmbot! Blinking the lights!")
    bot.blink_lights(3)
    print("Planting a seed from the Seed Bin into (100, 100, -100)..."
    bot.plant_seed(ToolBay.SeedBin, (100, 100, -100))
    # Smartly returning tools is a TODO
    bot.return_tool(ToolBay.Seeder)
    print("Watering at location (100, 100) for 4 seconds...")
    bot.water((100, 100), 4)
finally:
    bot.stop()

See the FarmBot class to see all implemented commands.

The listener

The farmbot_listener can be used to monitor all messages, you can run it independently.

Testing

Run unittests with python -m unittest discover -v -s ./test -t . from the project root

Docker and Kubernetes

Build the docker image

docker build --rm -t eu.gcr.io/farmbot-b787d/water-garden:0.1.0 .

Test the docker image

docker run --rm -it eu.gcr.io/farmbot-b787d/water-garden

Update the kubernetes cronjob

Before you push images or update kubernetes resources you should connect to the cluster listed on this page: https://console.cloud.google.com/kubernetes/list?project=farmbot-b787d If you don't have access contact Dennis Meelis ([email protected]). When you update docker container versions don't forget to update the k8s/farmbot-water-garden-cron-job.yaml resource with the new container tag.

docker push eu.gcr.io/farmbot-b787d/water-garden:0.1.0
cd k8s
kubectl apply -f farmbot-water-garden-cron-job.yaml

farmbot-py's People

Contributors

sbeaumont avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.