-1

After 20 minutes the devices take around 15 seconds to respond (an unacceptable time to the project). After a command, the next ones respond in a maximum of 5 seconds (an acceptable time). I'm using a device with Paho MQTT and connecting myself as follows: client.connect (mqtt_bridge_hostname, mqtt_bridge_port, keepalive = 60) I researched and saw that Paho sends the PINGREQ package for the time set by keepalive, so I do not understand why the system goes into idleness.

bruno
  • 91
  • 2
  • 12
  • is the `keepalive` just a network/TCP level thing? maybe you need to things higher up in the stack to force the device to stay awake… – Sam Mason Oct 31 '18 at 21:58
  • Sorry, but I did not understand. I'm just trying to follow what I found [in the documentation](https://cloud.google.com/iot/docs/how-tos/mqtt-bridge#device_authentication). – bruno Nov 05 '18 at 16:59
  • I don't know MQTT or Paho; but https://stackoverflow.com/a/48613388/1358308 suggests you need to make a background thread running for this to work… – Sam Mason Nov 05 '18 at 17:15
  • Thanks, but I'm using the loop approach, as shown on this [Google's example](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/iot/api-client/mqtt_example/cloudiot_mqtt_example.py#L242). – bruno Nov 05 '18 at 18:03

2 Answers2

1

This is unlikely to be a result of keepalive.

You need to look at the whole system, e.g. is the application (or just the message handler) being swapped out?

You need to do detailed profiling on the actual device

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • Thanks for the reply and sorry for the delay. When I run the system directly from the console, my program responds immediately. The problem is when I use Google Functions to fire the iot. On the first try it takes a long time to show CONFIG on the console, after that it is fast. Running the script in Google Functions takes about 200ms. And I've already left 2GB of resources to run as fast as possible – bruno Nov 05 '18 at 16:54
  • This sounds like normal first run spin up time – hardillb Nov 05 '18 at 18:37
  • This always happens after about 20 minutes without any command sent to the device, even with it connected and running. So I guess it goes into idle mode, even with the MQTT keepalive set up. – bruno Nov 05 '18 at 19:40
  • Then as I said earlier it's probably the function getting swapped out and having to be spun up again. – hardillb Nov 05 '18 at 19:47
0

Cloud IoT Core has its own idle time limit of 20 minutes, other than the keep-alive interval as mentioned in this link. Based on this limit, a client connection will automatically be terminated if the client doesn't send any messages for 20 minutes, even if the keep-alive interval is longer.

If a keep-alive value is not specified, the default idle timeout of 20 minutes still takes effect. Please see this link for more information on time limit quotas on Google IoT.

John Mathew
  • 419
  • 2
  • 5
  • Is there no way to tell IoT that it is still active without sending a message, as in a PING command? – bruno Nov 27 '18 at 19:46
  • 1
    As mentioned in the answer, based on the idle time limit you need to send a message or heartbeat every 20 minutes or the connection will automatically be terminated. – John Mathew Nov 28 '18 at 16:38