12

Has anyone gotten the example in their quickstart to work? They provide NodeJS code to connect to their MQTT bridge, but for me it does not work:

[root@centos7 google-iot-mqtt]# node cloudiot_mqtt_example_nodejs.js \
>     --project_id=curious-furnace-181313 \
>     --registry_id=my-registry \
>     --device_id=mimic1 \
>     --private_key_file=./rsa_private.pem \
>     --algorithm=RS256
Google Cloud IoT Core MQTT example.
connect { '0': {},
   '1': 
   { [Function: require]
 resolve: [Function: resolve],
 main: 
  Module {
    id: '.',
    exports: {},
    parent: null,
    filename: '/home/tmp/uwe/google-iot-mqtt/cloudiot_mqtt_example_nodejs.js',
    loaded: true,
    children: [Object],
    paths: [Object] },

(thousands more lines of stack trace) and no activity in the Google IoT Core dashboard, nor any messages in any pull subscription.

A mosquitto_pub returns a strange error:

% ./mosquitto_pub -d -h mqtt.googleapis.com -p 8883 -i projects/curious-furnace-181313/locations/us-central1/registries/my-registry/devices/mimic1 -u unused --key ~/mimic/scripts/mqtt/google-iot/rsa_private.pem --cert ~/mimic/scripts/mqtt/google-iot/rsa_cert.pem -t /devices/mimic1/events -m hello --insecure
Client projects/curious-furnace-181313/locations/us-central1/registries/my-registry/devices/mimic1 sending CONNECT
Error: Unrecognised command 16

Error: A network protocol error occurred when communicating with the broker.
Aurora0001
  • 18,520
  • 13
  • 55
  • 169
Gambit Support
  • 678
  • 3
  • 12

2 Answers2

5

This error occurs, when there is a protocol mismatch on the request you send to Google MQTT API.

You use 8883 port that is for MQTT over SSL. In my eye the address you call is normal http address (without https nor http the default falls to be http), which would use 1883, the port of plain MQTT.

If you intent to use 8883 and SSL, make call to address using https. If you did not mean MQTT over SSL at all, fix the port to 1883.

mico
  • 4,351
  • 1
  • 18
  • 27
2

I have fixed by adding the ca certificate to the mosquitto_pub command --cafile ./roots.pem

Google ca root cert: https://cloud.google.com/iot/docs/how-tos/mqtt-bridge