These examples are old.
FarmBot now offers a Python library to handle low level MQTT management.
Consider using the Python library instead.
- Read about CeleryScript and our use of MQTT first. This is important stuff!
- Install Paho-MQTT
- Try the examples below, preferably in order.
IMPORTANT NOTE: If you do not generate a token via token_generation_example.py
, none of these examples will work.
token_generation_example.py
- Learn how to create an API token. You need this to login to the MQTT server.subscribe_example.py
- Learn how to listen to incoming data. Running this script is a great way to observe real world commands used by the Web App.publish_example.py
- Learn how to send CeleryScript RPC nodes to the device.
- FarmBot uses JSON Web Tokens (JWTs) for authorization.
- JWTs can contain "claims". A claim is just data encoded inside a token.
- The
"mqtt"
claim in a FarmBot JWT is important because it tells you which MQTT server your account must use. - Currently, all users are routed to
clever-octopus.rmq.cloudamqp.com
as their MQTT server, but this may change in the future without notice. - It is a best practice to not hardcode the MQTT server URL and instead extract the URL from the Token.
- This will prevent your application from losing connectivity if the MQTT server changes in the future.
An example of extracting the MQTT server hostname from a token can be found here.
Read more about FarmBot API tokens here.