1
votes

I use Google IoT Core in my project as MQTT broker to connect IoT embedded devices based on Atmel MCU to Goole Cloud Plattform.

In the plattform log, i experience many "MQTT DISCONNECT" errors.

jsonPayload: {
  disconnectType: "SERVER"   
  eventType: "DISCONNECT"   
  protocol: "MQTT"   
  resourceName: "projects/xxxxxxx/locations/europe-west1/registries/xxxxxxxx/devices/1234567890"   
  serviceName: "cloudiot.googleapis.com"   
  status: {
   code: 6    
   description: "ALREADY_EXISTS"    
   message: "SERVER: The connection was closed because there is another active connection with the same device ID."    
  }
 }
labels: {
  device_id: "d1234567890"   
 }
 logName: "projects/xxxxxxxxx/logs/cloudiot.googleapis.com%2Fdevice_activity" 

The error is generated when the device boots-up and connect to MQTT server. Despite this error, the connection is successful, as is the subscription to topics and message publishing.

I understand that the previous connection was not closed gracefully, but it is imbossible by the nature of the embedded device, that is meant to be always connected, and eventually turned off by disconnecting power supply (so it cannot send a disconnect message to server before).

The device ID is always the same at every reconnection, but unique per-device; i use chip serial number as in some Google's examples.

My question is, if there is a solution to this error, that can be ignored in developement phase, but would be unwanted behavior in the production environment.

2

2 Answers

1
votes

The MQTT connection to the device bridge has a few special properties that can cause disconnects. For device connections, you are limited to one connection per-device (or device ID, for the sakes of a gateway). It looks to me like you're trying to connect the same device twice and it's causing a disconnect.

It's possible that you have a client that tries to open up two connections, or you are connecting a second client. If you're connecting the same device twice, the device will be disconnected. Maybe your client is setup to open up multiple channels or your application logic is reconnecting without disconnecting.

There are various other reasons for disconnects, for example, if you try to publish with the incorrect QoS or to an invalid topic but this doesn't appear to be that given publish is working on subsequent connections.

2
votes

I am thinking that you want the particular error excluded because of "hygiene" reasons. I am thinking that when you eyeball logs, you are on the alert for error type messages and ones of this nature would be considered distracting.

Fortunately, Stackdriver logging provides an exclusion capability. You can provide sets of filters that cause Stackdriver to discard log entries that you explicitly choose not to keep. This is described in detail here:

https://cloud.google.com/logging/docs/exclusions

I found the illustration at the page particularly helpful.

What you will likely want to do is forumulate a query that matches exactly this type of message. I haven't tested it but something loosely like:

logName = 'cloudiot.googleapis.com%2Fdevice_activity'
jsonPayload.eventType = 'DISCONNECT'
jsonPayload.status.description= 'ALREADY_EXISTS'

Once you have a filter expression that matches just the messages to be excluded, you can then use that filter as an exclusion filter.