A library that simplifies interactions with the IBM Internet of Things Foundation

Dependencies:   MQTT

Dependents:   IBMIoTClientLibrarySamplefinal IBMWIoTPSecureClientSample IBMIoTClientLibrarySample

Introduction

Use the mBed C++ client library to easily connect mBed devices, such as LPC1768 or FRDM-K64F, to the IBM Watson™ IoT Platform service.

Although the library uses C++, it still avoids dynamic memory allocations and the use of STL functions, because the mBed devices sometimes have idiosyncratic memory models that make porting difficult. In any case, the library allows you to make memory use as predictable as possible.

Dependencies

DependencyDescription
Eclipse Paho MQTT libraryProvides an MQTT client library for mBed devices. For more information, see Embedded MQTT C/C++ client libraries
mbed-osARM mbed OS

How to use the library

Use the mBed compiler to create your applications when you use the mBed C++ IBMIoTF client library. The mBed compiler provides a lightweight online C/C++ IDE that is configured for writing, compiling, and downloading programs to run on your mBed microcontroller.

Note: You don't have to install or set up anything to get running with mBed.

For information on how to connect an ARM mBed NXP LPC 1768 microcontroller to the Watson IoT Platform, see the mBed C++ client library for IBM Watson IoT Platform recipe.

Supported Features

FeatureSupported?
Device connectivityYes
Event publishYes
Command receiptYes
SSL/TLSYes
Device ManagementNo

License

This library is shipped under License Eclipse Public License - v 1.0 and Eclipse Distribution License v1.0

For more information about the Eclipse Public License - v 1.0, refer this page. Also, for more information about the Eclipse Distribution License v1.0, refer this page.

Contributor License Agreement

Version 1.0.0 January 14, 2014

In order for You (as defined below) to make intellectual property Contributions (as defined below) now or in the future to IBM repositories, You must agree to this Contributor License Agreement ("CLA").

Please read this CLA carefully before accepting its terms. By accepting the CLA, You are agreeing to be bound by its terms. If You submit a Pull Request against this repository You must include in the Pull Request a statement of Your acceptance of this CLA.

As used in this CLA: (i) "You" (or "Your") shall mean the entity that is making this Agreement with IBM; (ii)"Contribution" shall mean any original work of authorship, including any modifications or additions to an existing work, that is submitted by You to IBM for inclusion in, or documentation of, any of the IBM repositories; (iii) "Submit" (or "Submitted") means any form of communication sent to IBM (e.g. the content You post in the Issue or submit as part of a Pull Request).

This agreement applies to all Contributions You Submit.

This CLA, and the license(s) associated with the particular IBM repositories You are contributing to, provides a license to Your Contributions to IBM and downstream consumers, but You still own Your Contributions, and except for the licenses provided for in this CLA, You reserve all right, title and interest in Your Contributions.

IBM requires that each Contribution You Submit now or in the future comply with the following four commitments.

1) You will only Submit Contributions where You have authored 100% of the content. 2) You will only Submit Contributions to which You have the necessary rights. This means that if You are employed You have received the necessary permissions from Your employer to make the Contributions. 3) Whatever content You Contribute will be provided under the license(s) associated with the particular IBM repository You are contributing to. 4) You understand and agree that IBM repositories and Your contributions are public, and that a record of the contribution (including all personal information You submit with it) is maintained indefinitely and may be redistributed consistent with the license(s) involved. You will promptly notify the Eclipse Foundation if You become aware of any facts or circumstances that would make these commitments inaccurate in any way. To do so, please create an Issue in the appropriate repository.

Committer:
lokeshhk
Date:
Tue May 30 06:36:04 2017 +0000
Revision:
6:5f037f24ce29
Parent:
5:ea9f483e0294
Added mbed-os and mqtt dependencies for the library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sathipal 2:199ddea804cd 1 /*******************************************************************************
sathipal 2:199ddea804cd 2 * Copyright (c) 2015 IBM Corp.
sathipal 2:199ddea804cd 3 *
sathipal 2:199ddea804cd 4 * All rights reserved. This program and the accompanying materials
sathipal 2:199ddea804cd 5 * are made available under the terms of the Eclipse Public License v1.0
sathipal 2:199ddea804cd 6 * and Eclipse Distribution License v1.0 which accompany this distribution.
sathipal 2:199ddea804cd 7 *
sathipal 2:199ddea804cd 8 * The Eclipse Public License is available at
sathipal 2:199ddea804cd 9 * http://www.eclipse.org/legal/epl-v10.html
sathipal 2:199ddea804cd 10 * and the Eclipse Distribution License is available at
sathipal 2:199ddea804cd 11 * http://www.eclipse.org/org/documents/edl-v10.php.
sathipal 2:199ddea804cd 12 *
sathipal 2:199ddea804cd 13 * Contributors:
sathipal 2:199ddea804cd 14 * Sathisumar Palaniappan - initial implementation
sathipal 3:3d91bf839b49 15 * Sathisumar Palaniappan - added reconnect logic and isConnected() method
lokeshhk 5:ea9f483e0294 16 * Lokesh K Haralakatta - Port to mbed OS 5 support
lokeshhk 5:ea9f483e0294 17 * Lokesh K Haralakatta - Added SSL/TLS Support
sathipal 2:199ddea804cd 18 *******************************************************************************/
lokeshhk 5:ea9f483e0294 19
lokeshhk 5:ea9f483e0294 20 #ifndef DeviceClient_H
sathipal 0:f86732d81998 21 #define DeviceClient_H
sathipal 0:f86732d81998 22
lokeshhk 5:ea9f483e0294 23 #include "MQTTmbed.h"
sathipal 0:f86732d81998 24 #include "MQTTClient.h"
lokeshhk 5:ea9f483e0294 25 #include "MQTTNetwork.h"
sathipal 0:f86732d81998 26 #include "Command.h"
sathipal 0:f86732d81998 27
sathipal 0:f86732d81998 28 // Update this to the next number *before* a commit
lokeshhk 5:ea9f483e0294 29 #define __APP_SW_REVISION__ "1.0"
sathipal 0:f86732d81998 30
sathipal 0:f86732d81998 31 // Configuration values needed to connect to IBM IoT Cloud
sathipal 0:f86732d81998 32 #define QUICKSTART "quickstart"
sathipal 0:f86732d81998 33
sathipal 0:f86732d81998 34 #define MQTT_PORT 1883
sathipal 0:f86732d81998 35 #define MQTT_TLS_PORT 8883
sathipal 0:f86732d81998 36
sathipal 0:f86732d81998 37 #define IBM_IOT_MESSAGING ".messaging.internetofthings.ibmcloud.com"
sathipal 0:f86732d81998 38 #define CONNECT_TIMEOUT 1000 * 60
sathipal 0:f86732d81998 39 #define MQTT_MAX_PACKET_SIZE 250
sathipal 0:f86732d81998 40
sathipal 0:f86732d81998 41 typedef void (*CommandHandler)(IoTF::Command &cmd);
sathipal 0:f86732d81998 42
sathipal 0:f86732d81998 43 namespace IoTF {
sathipal 0:f86732d81998 44 class DeviceClient
sathipal 0:f86732d81998 45 {
sathipal 0:f86732d81998 46 private:
sathipal 3:3d91bf839b49 47 bool connected;
sathipal 0:f86732d81998 48 char *org;
sathipal 0:f86732d81998 49 char *deviceType;
sathipal 0:f86732d81998 50 char *deviceId;
sathipal 0:f86732d81998 51 char *authMethod;
sathipal 0:f86732d81998 52 char *authToken;
lokeshhk 5:ea9f483e0294 53 int port;
lokeshhk 5:ea9f483e0294 54 MQTTNetwork* mqttNetwork;
lokeshhk 5:ea9f483e0294 55 MQTT::Client<MQTTNetwork, Countdown> *mqttClient;
lokeshhk 5:ea9f483e0294 56
sathipal 0:f86732d81998 57 bool tryConnect(char *hostname, MQTTPacket_connectData &data);
sathipal 0:f86732d81998 58 int getConnTimeout(int attemptNumber);
lokeshhk 5:ea9f483e0294 59 void logData(NetworkInterface* net, char *hostname, char *clientId);
sathipal 0:f86732d81998 60 int subscribeToCommands();
sathipal 2:199ddea804cd 61 char* getMac(char* buf, int buflen);
sathipal 0:f86732d81998 62
lokeshhk 5:ea9f483e0294 63 DeviceClient();
sathipal 0:f86732d81998 64 public:
lokeshhk 5:ea9f483e0294 65 DeviceClient(char *org, char *deviceType, char *deviceId, int port = MQTT_PORT);
lokeshhk 5:ea9f483e0294 66 DeviceClient(char *org, char *deviceType, char *deviceId, char *authMethod, char *authToken, int port = MQTT_PORT);
sathipal 0:f86732d81998 67 bool publishEvent(char *eventName, char *data, MQTT::QoS qos = MQTT::QOS0);
sathipal 0:f86732d81998 68 void setCommandCallback(CommandHandler callbackFunc);
sathipal 2:199ddea804cd 69 char* getDeviceId(char* buf, int buflen);
sathipal 0:f86732d81998 70 void yield(int ms);
sathipal 3:3d91bf839b49 71 bool isConnected();
sathipal 0:f86732d81998 72 bool connect();
sathipal 0:f86732d81998 73 bool disconnect();
sathipal 3:3d91bf839b49 74 bool reConnect();
sathipal 0:f86732d81998 75 };
sathipal 0:f86732d81998 76 }
lokeshhk 5:ea9f483e0294 77 #endif