Had to fork with a different name, because of some incompatibility issues.

Dependencies:   MQTT

Committer:
sathipal
Date:
Fri Nov 06 09:01:29 2015 +0000
Revision:
1:31c93319bbd8
Parent:
0:f86732d81998
Added a GetDeviceId() method and hidden getMac()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sathipal 0:f86732d81998 1 #ifndef DeviceClient_H
sathipal 0:f86732d81998 2 #define DeviceClient_H
sathipal 0:f86732d81998 3
sathipal 0:f86732d81998 4 #include "MQTTEthernet.h"
sathipal 0:f86732d81998 5 #include "MQTTClient.h"
sathipal 0:f86732d81998 6 #include "Command.h"
sathipal 0:f86732d81998 7
sathipal 0:f86732d81998 8 // Update this to the next number *before* a commit
sathipal 0:f86732d81998 9 #define __APP_SW_REVISION__ "0.0.1"
sathipal 0:f86732d81998 10
sathipal 0:f86732d81998 11 // Configuration values needed to connect to IBM IoT Cloud
sathipal 0:f86732d81998 12 #define QUICKSTART "quickstart"
sathipal 0:f86732d81998 13
sathipal 0:f86732d81998 14 #define MQTT_PORT 1883
sathipal 0:f86732d81998 15 #define MQTT_TLS_PORT 8883
sathipal 0:f86732d81998 16 #define IBM_IOT_PORT MQTT_PORT
sathipal 0:f86732d81998 17
sathipal 0:f86732d81998 18 #define IBM_IOT_MESSAGING ".messaging.internetofthings.ibmcloud.com"
sathipal 0:f86732d81998 19 #define CONNECT_TIMEOUT 1000 * 60
sathipal 0:f86732d81998 20 #define MQTT_MAX_PACKET_SIZE 250
sathipal 0:f86732d81998 21
sathipal 0:f86732d81998 22 typedef void (*CommandHandler)(IoTF::Command &cmd);
sathipal 0:f86732d81998 23
sathipal 0:f86732d81998 24 namespace IoTF {
sathipal 0:f86732d81998 25
sathipal 0:f86732d81998 26 class DeviceClient
sathipal 0:f86732d81998 27 {
sathipal 0:f86732d81998 28 private:
sathipal 0:f86732d81998 29 char *org;
sathipal 0:f86732d81998 30 char *deviceType;
sathipal 0:f86732d81998 31 char *deviceId;
sathipal 0:f86732d81998 32 char *authMethod;
sathipal 0:f86732d81998 33 char *authToken;
sathipal 0:f86732d81998 34 MQTTEthernet ipstack;
sathipal 0:f86732d81998 35 MQTT::Client<MQTTEthernet, Countdown, MQTT_MAX_PACKET_SIZE> mqttClient;
sathipal 0:f86732d81998 36
sathipal 0:f86732d81998 37 bool tryConnect(char *hostname, MQTTPacket_connectData &data);
sathipal 0:f86732d81998 38 int getConnTimeout(int attemptNumber);
sathipal 0:f86732d81998 39 void logData(EthernetInterface& eth, char *hostname, char *clientId);
sathipal 0:f86732d81998 40 int subscribeToCommands();
sathipal 1:31c93319bbd8 41 char* getMac(char* buf, int buflen);
sathipal 0:f86732d81998 42
sathipal 0:f86732d81998 43 public:
sathipal 0:f86732d81998 44 DeviceClient();
sathipal 0:f86732d81998 45 DeviceClient(char *org, char *deviceType, char *deviceId);
sathipal 0:f86732d81998 46 DeviceClient(char *org, char *deviceType, char *deviceId, char *authMethod, char *authToken);
sathipal 0:f86732d81998 47 bool publishEvent(char *eventName, char *data, MQTT::QoS qos = MQTT::QOS0);
sathipal 0:f86732d81998 48 void setCommandCallback(CommandHandler callbackFunc);
sathipal 1:31c93319bbd8 49 char* getDeviceId(char* buf, int buflen);
sathipal 0:f86732d81998 50 void yield(int ms);
sathipal 0:f86732d81998 51 bool connect();
sathipal 0:f86732d81998 52 bool disconnect();
sathipal 0:f86732d81998 53 };
sathipal 0:f86732d81998 54 }
sathipal 0:f86732d81998 55 #endif