MQTT client for IBM Bluemix

Dependencies:   HTS221 LIS3MDL LPS22HB LSM303AGR LSM6DSL MQTT VL53L0X

Getting started with IBM Bluemix

This is the MQTT Client example for mbed OS. It demonstrates how to connect a device with IBM Bluemix, how to get values from sensors, and how to see them on the IBM quickstart website. If you are unfamiliar with IBM Bluemix, we recommend that you read the introduction starting here.

Demo workflow:

  • Connection to the local network with 6LoWPAN ND connection.
  • Connection to the Quickstart Bluemix.
  • Read data sensors.
  • Sends data sensors to the Quickstart Bluemix

You can compile this project in three ways:

1. Using the Online compiler. Just clicking here:

/media/uploads/rspelta/import-mqtt.jpg

Information

Learn how to use the Online compiler reading https://docs.mbed.com/docs/mbed-os-handbook/en/latest/dev_tools/online_comp/ page.

2. Using the compiler on your PC:

Information

Learn how to use the mbed-cli reading https://docs.mbed.com/docs/mbed-os-handbook/en/latest/dev_tools/cli/ page.
The name of the machine is SILICA_SENSOR_NODE.

3. Exporting to 3rd party tools (IDE) like eclipse, IAR, uvision 5 and more others

Information

Learn how to use the mbed-cli reading https://docs.mbed.com/docs/mbed-os-handbook/en/latest/dev_tools/third_party/ page.

Warning

This example requires a Border Router board. For more details please read the Border Router paragraph from this page.

Please read carefully the next pages:

  • What to do before to compile the project: read here. This step is indipendent from the way you compile the project.
Committer:
rspelta
Date:
Thu Nov 02 11:01:13 2017 +0100
Revision:
0:e673387d5add
release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rspelta 0:e673387d5add 1 #ifndef _MQTTNETWORK_H_
rspelta 0:e673387d5add 2 #define _MQTTNETWORK_H_
rspelta 0:e673387d5add 3
rspelta 0:e673387d5add 4 #include "NetworkInterface.h"
rspelta 0:e673387d5add 5
rspelta 0:e673387d5add 6 class MQTTNetwork {
rspelta 0:e673387d5add 7 public:
rspelta 0:e673387d5add 8 MQTTNetwork(NetworkInterface* aNetwork) : network(aNetwork) {
rspelta 0:e673387d5add 9 socket = new TCPSocket();
rspelta 0:e673387d5add 10 }
rspelta 0:e673387d5add 11
rspelta 0:e673387d5add 12 ~MQTTNetwork() {
rspelta 0:e673387d5add 13 delete socket;
rspelta 0:e673387d5add 14 }
rspelta 0:e673387d5add 15
rspelta 0:e673387d5add 16 int read(unsigned char* buffer, int len, int timeout) {
rspelta 0:e673387d5add 17 return socket->recv(buffer, len);
rspelta 0:e673387d5add 18 }
rspelta 0:e673387d5add 19
rspelta 0:e673387d5add 20 int write(unsigned char* buffer, int len, int timeout) {
rspelta 0:e673387d5add 21 return socket->send(buffer, len);
rspelta 0:e673387d5add 22 }
rspelta 0:e673387d5add 23
rspelta 0:e673387d5add 24 int connect(const char* hostname, int port) {
rspelta 0:e673387d5add 25 socket->open(network);
rspelta 0:e673387d5add 26 return socket->connect(hostname, port);
rspelta 0:e673387d5add 27 }
rspelta 0:e673387d5add 28
rspelta 0:e673387d5add 29 int disconnect() {
rspelta 0:e673387d5add 30 return socket->close();
rspelta 0:e673387d5add 31 }
rspelta 0:e673387d5add 32
rspelta 0:e673387d5add 33 private:
rspelta 0:e673387d5add 34 NetworkInterface* network;
rspelta 0:e673387d5add 35 TCPSocket* socket;
rspelta 0:e673387d5add 36 };
rspelta 0:e673387d5add 37
rspelta 0:e673387d5add 38 #endif // _MQTTNETWORK_H_