Use MQTT with mbedTLS in Keil uVision 5 (MDK)

Today’s post is rather short as it is the end of the series on IoT communication nears.

As per the previous blog post, a TLS connection was established. A few issues like client-side certificate verification were solved. In this post, all I sort to show was doing the MQTT communication on a secure port.

The changes done to the code are as shown in commit b85db2c9. The MQTT broker used is hosted at iot.eclipse.org:8883. I printed out the bytes sent and received using a simple hex dump function which I added in commit 82b44fec. The hex dump function gives a print of the ASCII representation where applicable. The results of the communication are shown below. Details about what each non-ASCII byte represents may be found in the MQTT-3.1.1 spec on OASIS.

  . Seeding the random number generator... ok
. Loading the CA root certificate ... ok (0 skipped)
. Connecting to tcp/iot.eclipse.org/8883... ok
. Setting up the SSL/TLS structure... ok
. Performing the SSL/TLS handshake... ok
. Verifying peer X.509 certificate... ok

To enable communication with iot.eclipse.org:8883, the certificate provided on their site was added to the list of known CAs (certificate authorities) as evident in commit 2b902433.

I used the MQTT paho library for embedded C and in particular the MQTT Packet because it is lightweight. I needed to see what was sent on the wire and that seemed the best way to do so. Please do not crucify me for how I did the MQTT process in the while loop because it was just for this example.

In the next post, we shall consider sending this information to a secure broker which can be connected to other solutions in the cloud. This results in delivering a complete end-to-end solution. Till then, enjoy yourself.

Learning to live the best life I can

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store