1
votes

We have an IoT based application device which is configured to communication with our Dashboard via MQTT bridge from Various service providers like Google, AWS and Azure.

So the flow is:

  1. Device start TLS session with service provider.
  2. Subscribe to a particular topic and wait for messages from the service provider with 5 second timeout.
  3. Dashboard publishes messages to same topic periodically.
  4. IoT service provider broadcast it to all devices subscribed.

Publish and subscribe messages are with MQTT QOS 1 services.

Observation:

AWS and Azure works fine with above flow, but device stop receiving messages from Google MQTT bridge after 3-5 successful iterations even though our dashboard is publishing messages to Google IoT MQTT bridge.

For Google, we have identified that control flow is different when compared with Azure and AWS.

For Google, we need to subscribe and un-subscribe for a given topic every-time before waiting to receive message while for AWS and Azure we need to subscribe once during opening a MQTT connection.

Issue:

Sometime 5 sec device timeout occurs as it could not receive messages for subscribed topic from Google MQTT bridge. Adding multiple retries to overcome timeout issue was unsuccessful as issue still persist as device could not receive message from Google MQTT bridge after 45-60sec of device operation after powering on.

  • Is there is constraint with Google MQTT bridge to receive messages periodically without subscribing it every-time?
  • How can device receive messages without timing out (5 sec) from Google MQTT bridge?
  • Is there any workaround to recover a device once it got timed out with establishing MQTT reconnection?
2
I am also facing some problems with pub/sub of the google cloud platform, although different of yours. Are you using the google pub/sub library or implemented your own code using some mqtt library to subscribe to topics?Dalton Cézane

2 Answers

0
votes

I am using google iot core as well,the device side code for the mqtt client is golang while using paho mqtt package. this client package support OnConnect handler which while using this handler I achieve the recovery which I think you are looking for. Via this handler I am re-subscribing to the "config" topic.

I think that google does not save the subscriptions which the clients are subscribed to and therefore the client needs to re-subscribe upon successful connection

0
votes

Here's the golang code I've used (inspired by gingi007's answer, thank you!)

var onConn MQTT.OnConnectHandler
onConn = func(client MQTT.Client) {
    fmt.Println("connected")
    client.Subscribe(topic.Config, 1, handlerFunc)
}
mqttOpts.SetOnConnectHandler(onConn)
client := MQTT.NewClient(mqttOpts)

this way config updates keep flowing to my device, while if you subscribe outside of the onConnectHandler you'll just receive one config update when you connect.