FarmBot / farmbot-mqtt-py

An MQTT wrapper for FarmBot written in Python
MIT License
42 stars 24 forks source link

Sending commands to FarmBot after connection #7

Closed mpresten closed 3 years ago

mpresten commented 3 years ago

Hi,

I am trying to send further commands to the FarmBot after fb.connect(handler). To do this previously, I simply disconnected from the client and then reconnected, but I then received errors that MQTT was rate limited which makes sense in hindsight.

The best way to do this seems to be putting the FarmBot instance in a background thread and queueing commands. However, once running in a background thread, how can I send the FarmBot a new command? All this seems to be handled on on_connect(...). Thanks for the help!

tmaziere commented 3 years ago

Hi @mpresten ,

What do you think about this example: https://github.com/FarmBot/farmbot-py/issues/6 Is it helpful?

mpresten commented 3 years ago

Yes, quite!

I just did something similar in which I saved the instances of the arguments of on_connect(...) in my class and thus was able to access them later to send commands (similar to the example above). Thanks for the help!