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': {},
   { [Function: require]
 resolve: [Function: resolve],
  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.
  • Apparently the messages generated by their NODEJS app took a while to get to the subscriptions. But the mosquitto_pub still does not work. – Gambit Support Sep 28 '17 at 18:44
  • Adding the -P argument to mosquitto_pub with a JWT password as that created by their NODEJS applications does not help. – Gambit Support Sep 29 '17 at 13:18

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.

  • This does not help. They REQUIRE port 8883, which is what their NODEJS example uses. – Gambit Support Sep 29 '17 at 13:17
  • Well, that is the most obvious reason for protocol mismatch, but error can happen also inside the mqtt messages, for example too long message compared to what is specified. Hard to say what generates problem in your case. – mico Sep 29 '17 at 15:38
  • 1
    The right answer is to look at wireshark. I figured out that mosquitto_pub does not send encrypted message even when --tls-version is added to the original command line, because the plaintext message is in the PCAP. – Gambit Support Oct 2 '17 at 14:18

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.