The following command-line examples guide you through the basic steps of handling messages using the Mosquitto message broker. This straightforward concept can also be applied to different client libraries, such as Paho, and programming languages, including Java, C and Python.
To get started, simply download and install the mosquitto command-line tool to use in the bash tool of your choice.
mosquitto_sub \ -p 8883 \ -h broker.xively.com \ -i 5d1e827d-bc31-48d7-bd37-f6bf13146d32 \ -u 5d1e827d-bc31-48d7-bd37-f6bf13146d32 \ -P sr845jg03lfv35=4kgk3rksdfmm1w34342mfcsdf34vn \ -t xi/blue/v1/kb133d3d-1234-5fb1-ba4v-492daac5481c/d/6df62b2c-38af-45b0-bae8-95e56191a381/example-topic \ --cafile ~/certificate.crt
mosquitto_pub \ -p 8883 \ -h broker.xively.com \ -i 6df62b2c-38af-45b0-bae8-95e56191a381 \ -u 6df62b2c-38af-45b0-bae8-95e56191a381 \ -P 238tjglf/f=2o9ymbvo3klfm3owfft4g3fvdfg-594kf \ -t xi/blue/v1/kb133d3d-1234-5fb1-ba4v-492daac5481c/d/6df62b2c-38af-45b0-bae8-95e56191a381/example-topic \ --cafile ~/certificate.crt \ -m 'Hello world'
For more on connection modes to the Xively messaging broker, see the docs on single connection mode and multi-connection mode.
Connection port for TLS communication
- Defaults to 1883 but Xively requires 8883 for secure TLS messaging
The broker's hostname
- Must be the same as the username
idof your device
- The device's secret (obtained from the Generate device credentials endpoint)
- Name of the Xively channel you want to publish your message on. Xively topics are formatted in the following way:
- Xively requires secure TLS messaging on port 8883 and providing a path to a file containing trusted CA certificates to enable encrypted certificate based communication.
- One of the certificates accepted by the Xively broker is the R1 Root certificate from GlobalSign below.
- Note: For devices in production, Xively will provide a certificate file containing redundant copies of reserve certificates, should any be compromised and/or revoked in the future.
Xively accepts the R1 Root certificate from GlobalSign. Save this in a file for usage with Mosquitto
-----BEGIN CERTIFICATE----- MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkG A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExE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4A== -----END CERTIFICATE-----
What is this certificate file?
What is it?
This certificate is a secure way to tell Mosquitto how to identify messages that are genuinely coming from Xively.
Xively's certificate has been signed by this public one above. That means that when you open a connection to Xively from Mosquitto, Mosquitto can check the certificate that Xively sends, and if it is not signed by this one above, Mosquitto will know that the handshake to start the connection isn't genuinely coming from Xively.
What is it not?
This is not your device's unique password! This certificate is not unique to you, your device, or your account. It is a way for all clients that talk to Xively to verify whether a message is really coming from Xively. This is different than the username, ID and password that you send in your MQTT messages - those are unique to your device and your account, and are the way that Xively can determine whether your device is who it says it is.