Google Cloud IoT Gateway Connection Out Of Memory

Viewed 1300

I was successful in connecting the Raspberry Pi to the Cloud IoT and was able to toggle the device easily. But after a while, the device, according to me, times out of the connection, and shows "('on_disconnect', '1: Out of memory.')" and the connect status is set to False. So I reinstalled the git packages(the community folder) and repeated the same steps and I was successful again. But, obviously, the same error raised after a while. I can't seem to narrow it down to what is causing the issue. I am new here, so let me know if I should add anymore information.

EDIT: Since I was trying to narrow it down, I found out that re-running the "export GOOGLE_CLOUD_PROJECT=your-project-id-123" command when the above problem occurs, help me to establish connection properly(without changing anything). Although this doesn't stop the "Out of memory" issue, it's something to work with for now.

EDIT: https://github.com/GoogleCloudPlatform/community/tree/master/tutorials/cloud-iot-gateways-rpi Link to the folder

2 Answers

For anyone coming here when trying out the MQTT example

The issue in my case was that I simply forgot to properly set the --project flag in the CLI example, which resolved the project name to None which apparently gives this cryptic error upstream. So you might want to check that your project is set properly. The same goes for region by the way, which may result in refused connections.

I helped the author of this question resolve this issue on another platform, but I'm reposting the solution for reference.

The issue is that the JWTs that were generated in the tutorial the OP was following expires after about an hour and also did not include the code to refresh the token once expired. For more information about creating and refreshing JWTs, see here.

edit: Upon request, adding code snippet for refreshing jwts. In this case, get_client creates the MQTT connection which also handles creating the JWT. This assumes that the JWT expires after 60 minutes, but in Cloud IoT Core, JWTs can be valid for as long as 24 hours.

seconds_since_issue = (datetime.datetime.utcnow() - jwt_iat).seconds
if seconds_since_issue > 60 * jwt_exp_mins:
    print('Refreshing token after {}s').format(seconds_since_issue)
    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)
Related