Python programming Soil Sensor Reading

I’m trying to read rensors with Farmbot library in python.

Do you have some hints?
I would like to read the measure from the sensor and save it on a variable.
Same thing for any other peripheral.

Thanks

I used this command
fb.read_status(‘pins’)[‘59’]

And this command sequence also, but it is not working well,
fb.listen(“from_device”)
fb.api.state.last_messages[‘status’][0][‘content’][‘pins’][‘59’][‘value’]

Do somebody have an opinion and some experience about it?

Hi @leonori
I don’t use the Python package very much, but seems it has been re-written since v1.0
I think the v2.0 package API is not backwards compatible, so best to read the examples and the package code on GitHub.

Here’s a simple program I tested today

from farmbot import Farmbot
TOKEN = {... insert your token here ...}

fb = Farmbot()
fb.set_token(TOKEN)
fb.set_verbosity(0)              # set this > 0 to get info about what the package is doing

fb.read_sensor('Soil Moisture')  # Request a new Soil Moisture Sensor reading (synchronously)

pin_59 = fb.read_status(path='pins.59')

print(f'Soil Moisture {pin_59}')

Hi. For me It worked with Sensor instead of Moisture.
This command works well.

thank you

1 Like

Hi @leonori

The current (v2.0.9) Python library also does support event listeners on MQTT messages.
Just slightly different syntax.