How the Web App knows Farmbot is connected

Hi guys,

I am trying to make a full software to communicate with the Farmbot (via MQTT), but I would like to know, because I do not find this information anywhere, how the Web App knows that the Farmbot is connected. I have been reading the MQTT messages that the systems exchange with each other, and there is no one to make this step.

Thank you.

Hi @hormigo,

We use a combination of techniques:

  • Once connected, we use MQTT last will and testament messages. The MQTT server will send us the LWT message when FarmBot goes offline. The log message is sent to the bot/device_123/logs channel and will contain the text “device_123 is offline!”. If you ever see this message, it is a sign that FarmBot’s internet connection was lost.
  • You can also send the bot the current time and store it in the LAST_CLIENT_CONNECTED variable using the set_user_env command. If you send the command and never receive LAST_CLIENT_CONNECTED data via the MQTT /bot/device_123/status channel, then FarmBot is certainly offline or unresponsive. The name LAST_CLIENT_CONNECTED is somewhat arbitrary, but it is the name that we use on the web app for this purpose. Here is example source code from the web app source.

It may also be helpful to read this article about FarmBot’s RPC format if you have not done so already.

1 Like

Ahh, all right!

Thank you :wink:

1 Like

No problem! Let us know if you hit any other issues. We always like to see what sort of software people build for FarmBot.