Google Cloud IoT Core - JWT Refresh

  1. My goal is:

Refresh JWT with Mongoose OS before timeout without disconnecting to IoT Core.

  1. My actions are:

Using MOS GCP Lib to connect to IoT Core.

  1. The result I see is:

MOS console:
mgos_gcp.c:86 Dropping MQTT connection due to imminent token expiration

On IoT Core I get this error with every timeout:
image

IoT Core logs:

 jsonPayload: {
  disconnectType: "SERVER"   
  eventType: "DISCONNECT"   
  protocol: "MQTT"   
  resourceName: "projects/..."   
  serviceName: "cloudiot.googleapis.com"   
  status: {
   code: 9    
   description: "FAILED_PRECONDITION"    
   message: "The connection broke or was closed by the client."    
  }
 }
  1. My expectation & question is:

The device should stay connected to IoT Core. The disconnection results in a loss of data if, for example, data is to be sent via commands. Is it possible to refresh the token without a disconnect?

Looks like this was intentionally added:

Unfortunately it’s not possible to get around this due to the token being sent when the initial connection is made, so it has to create a new connection, so at a minimum it would have to be handled immediately after the disconnect, but i havent’ dug into it to see for sure

I came across it afterwards. Apparently it was integrated to solve this problem until it reappeared.

Google talks about how to reconnect without “disconnecting” a device:
https://cloud.google.com/iot/docs/how-tos/credentials/jwts#refreshing_jwts

I’m currently not sure where to see the issue. If refreshing is only possible by reconnecting (disconnet followed by a connect), why does GCP issue an error message?

Hi. Is there any news here. One year later and I see the same issue.

My devides disconnect after raising as an error and connect again 4 or 5 seconds later

AFAIK it is not possible to refresh the JWT without disconnecting and reconnecting. In fact, the examples in the link seem to actually disconnect MQTT and reconnect.
When I tested (mOS 2.17 during 2020), I didn’t see errors but timely disconnect/reconnects every hour (IIRC).
Please check if 2.17 behavior is different for you.
Some developers have been working on some cloud stuff and that includes GCP (IIRC); but I don’t know whether that includes JWT refresh stuff nor if nor when it will be released.

I am using the Mongoose OS command line tool 2.18.0.