Subscribe to MQTT-Topic and respond depending on message


I’m interested in developing a service with functionality akin to the following:

  • When I publish an MQTT message to a designated topic with specific content, I aim to receive a response from AutoPi.
  • Specifically, I intend to request the car’s location, but I prefer to initiate these requests manually instead of receiving periodic updates every 5 seconds.

I’m seeking guidance on the most straightforward method to establish this setup. Is it feasible, and if so, what steps would you recommend?

Thank you in advance.

Hi @radiokonntas

You can disable the periodic tracking of the car’s location by disabling the poll_logger from Device → Services → gnss_manager → poll_logger.

As for listining for Messages on MQTT topic we have a guide in our documentation for setting up such a service at the following link: Create Custom Services | AutoPi Documentation

As part of the service you could include an obd.manage command that is triggered when the topic receives a message, the command could looks something like this:

obd.manage run handler="connection" args="[ "gnss_location" ]" kwags="{ "decimal_degrees": true }" converter="gnss_location_to_position" returner = "cloud"


Thank you for your prompt response. I’ve seen the documentation you shared, but I’m currently facing issues with creating the trigger when a message is sent via MQTT.

Additionally, I appreciate the command you provided; however, could you please clarify where I should insert this command in the process?

Thank you in advance for your assistance.

Best regards.


The way I would go about it based on the example MQTT listener I would replace or add to the on_message function to include the command to get the location and send it to the cloud.

I’ve also noticed I gave you the wrong command previously, as the location is in the gnss manage and not OBD and it’s also meant for the cloud terminal not custom code . when running the command from the custom code you’d need to use a slightly different syntax and should look more like this.

def on_message:
__salt__["gnss.manage "](run handler="connection" args="['gnss_location']" converter="gnss_location_to_position" returner="cloud")

Thank you for providing the new details, this is exactly what I needed.

This topic was automatically closed 33 days after the last reply. New replies are no longer allowed.