Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud IoT Core: mqtt: SERVER:The authorization token expired. #1264

Closed
mkahn5 opened this issue Dec 10, 2017 · 9 comments
Closed

Cloud IoT Core: mqtt: SERVER:The authorization token expired. #1264

mkahn5 opened this issue Dec 10, 2017 · 9 comments
Assignees

Comments

@mkahn5
Copy link

mkahn5 commented Dec 10, 2017

In which file did you encounter the issue?

https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/iot/api-client/mqtt_example/cloudiot_mqtt_example.py

and my version on:
https://github.com/mkahn5/iot-projects/blob/master/RaspberryPi_Thermostat_Cloud_IoT/pubsub_thermostat_f10.py

Did you change the file? If so, how?

Just changed the payload in my version, https://github.com/mkahn5/iot-projects/blob/master/RaspberryPi_Thermostat_Cloud_IoT/pubsub_thermostat_f10.py

Describe the issue

After the script is running for awhile I will receive the error mqtt: SERVER:The authorization token expired. in Cloud IoT core. The script is only publishing every 120 seconds to PubSub. It will resolve itself over time, sometimes it does not. How long does the MQTT token last for?

Here is the script failing then recovering:

Publishing payload {"temp": 68.0, "time": "12/10/2017 13:17:41 PST"}
Connection Result: 4: The client is not currently connected.
Disconnected: 5: The connection was refused.
Publishing payload {"temp": 68.0, "time": "12/10/2017 13:19:41 PST"}
Connection Result: 4: The client is not currently connected.
Disconnected: 5: The connection was refused.
Creating JWT using RS256 from private key file rsa_private.pem
Connection Result: 0: No error.
Publishing payload {"temp": 68.0, "time": "12/10/2017 13:21:42 PST"}
Subscribed: (1,)
Received message '' on topic '/devices/temphome/config' with Qos 1
Published message acked, sleeping 120 sec
Publishing payload {"temp": 68.0, "time": "12/10/2017 13:23:42 PST"}
Published message acked, sleeping 120 sec
Publishing payload {"temp": 68.0, "time": "12/10/2017 13:25:43 PST"}
Published message acked, sleeping 120 sec
Publishing payload {"temp": 68.0, "time": "12/10/2017 13:27:43 PST"}
Published message acked, sleeping 120 sec
Publishing payload {"temp": 68.0, "time": "12/10/2017 13:29:43 PST"}

@mkahn5 mkahn5 changed the title mqtt: SERVER:The authorization token expired. Cloud IoT Core: mqtt: SERVER:The authorization token expired. Dec 10, 2017
@mkahn5
Copy link
Author

mkahn5 commented Dec 10, 2017

screen shot 2017-12-10 at 1 44 49 pm

@theacodes
Copy link
Contributor

@gguuss can you take a look?

@gguuss
Copy link
Contributor

gguuss commented Dec 11, 2017

Yup, I was seeing strange things from the console last week as well.

@gguuss
Copy link
Contributor

gguuss commented Dec 11, 2017

I'm guessing that you're not refreshing the JWT after 3600 seconds. @mkahn5 do you have code similar to the following that is executing:

    if seconds_since_issue > 60 * jwt_exp_mins:
        print('Refreshing token after {}s').format(seconds_since_issue)
        client.loop_stop()
        jwt_iat = datetime.datetime.utcnow()
        client = get_client(
            args.project_id, args.cloud_region,
            args.registry_id, args.device_id, args.private_key_file,
            args.algorithm, args.ca_certs, args.mqtt_bridge_hostname,
            args.mqtt_bridge_port)

@mkahn5
Copy link
Author

mkahn5 commented Dec 11, 2017

@gguuss Nope, I was unaware of the JWT expiration. I can try that snip see if it works. Maybe I missed the JWT refresh in the quickstart example.

@mkahn5
Copy link
Author

mkahn5 commented Dec 11, 2017

@gguuss Couldnt find any documentation on refreshing JWT for cloud iot core. Can you make a pull request on my project? https://github.com/mkahn5/iot-projects/blob/master/raspberrypi_temp_monitor_cloud_iot/temp_monitor.py

@gguuss
Copy link
Contributor

gguuss commented Dec 14, 2017

Done, let me know if the PR helps!

@gguuss gguuss closed this as completed Dec 14, 2017
@gguuss
Copy link
Contributor

gguuss commented Jan 4, 2018

@mkahn5 I'm not sure I've seen this error before - is this happening after a duration of time or are you seeing it at random?

@mkahn5
Copy link
Author

mkahn5 commented Jan 5, 2018

@gguuss Deleted comment in thread, error was from another device. Will provide feedback on the PR and JWT refresh soon. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants