Had to fork with a different name, because of some incompatibility issues.
Diff: DeviceClient.h
- Revision:
- 5:ea9f483e0294
- Parent:
- 3:3d91bf839b49
- Child:
- 8:cb2c98efdca8
--- a/DeviceClient.h Mon Mar 20 10:07:49 2017 +0000 +++ b/DeviceClient.h Tue May 30 06:24:06 2017 +0000 @@ -13,24 +13,26 @@ * Contributors: * Sathisumar Palaniappan - initial implementation * Sathisumar Palaniappan - added reconnect logic and isConnected() method + * Lokesh K Haralakatta - Port to mbed OS 5 support + * Lokesh K Haralakatta - Added SSL/TLS Support *******************************************************************************/ - - #ifndef DeviceClient_H + +#ifndef DeviceClient_H #define DeviceClient_H -#include "MQTTEthernet.h" +#include "MQTTmbed.h" #include "MQTTClient.h" +#include "MQTTNetwork.h" #include "Command.h" // Update this to the next number *before* a commit -#define __APP_SW_REVISION__ "0.0.1" +#define __APP_SW_REVISION__ "1.0" // Configuration values needed to connect to IBM IoT Cloud #define QUICKSTART "quickstart" #define MQTT_PORT 1883 #define MQTT_TLS_PORT 8883 -#define IBM_IOT_PORT MQTT_PORT #define IBM_IOT_MESSAGING ".messaging.internetofthings.ibmcloud.com" #define CONNECT_TIMEOUT 1000 * 60 @@ -39,7 +41,6 @@ typedef void (*CommandHandler)(IoTF::Command &cmd); namespace IoTF { - class DeviceClient { private: @@ -49,19 +50,20 @@ char *deviceId; char *authMethod; char *authToken; - MQTTEthernet ipstack; - MQTT::Client<MQTTEthernet, Countdown, MQTT_MAX_PACKET_SIZE> mqttClient; - + int port; + MQTTNetwork* mqttNetwork; + MQTT::Client<MQTTNetwork, Countdown> *mqttClient; + bool tryConnect(char *hostname, MQTTPacket_connectData &data); int getConnTimeout(int attemptNumber); - void logData(EthernetInterface& eth, char *hostname, char *clientId); + void logData(NetworkInterface* net, char *hostname, char *clientId); int subscribeToCommands(); char* getMac(char* buf, int buflen); + DeviceClient(); public: - DeviceClient(); - DeviceClient(char *org, char *deviceType, char *deviceId); - DeviceClient(char *org, char *deviceType, char *deviceId, char *authMethod, char *authToken); + DeviceClient(char *org, char *deviceType, char *deviceId, int port = MQTT_PORT); + DeviceClient(char *org, char *deviceType, char *deviceId, char *authMethod, char *authToken, int port = MQTT_PORT); bool publishEvent(char *eventName, char *data, MQTT::QoS qos = MQTT::QOS0); void setCommandCallback(CommandHandler callbackFunc); char* getDeviceId(char* buf, int buflen); @@ -72,4 +74,4 @@ bool reConnect(); }; } -#endif \ No newline at end of file +#endif