Had to fork with a different name, because of some incompatibility issues.
DeviceClient.h@0:f86732d81998, 2015-11-06 (annotated)
- Committer:
- sathipal
- Date:
- Fri Nov 06 07:09:14 2015 +0000
- Revision:
- 0:f86732d81998
- Child:
- 1:31c93319bbd8
- Child:
- 2:199ddea804cd
A library to simplify interactions with the IBM Internet of Things Foundation
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:f86732d81998 | 41 | |
sathipal | 0:f86732d81998 | 42 | public: |
sathipal | 0:f86732d81998 | 43 | DeviceClient(); |
sathipal | 0:f86732d81998 | 44 | DeviceClient(char *org, char *deviceType, char *deviceId); |
sathipal | 0:f86732d81998 | 45 | DeviceClient(char *org, char *deviceType, char *deviceId, char *authMethod, char *authToken); |
sathipal | 0:f86732d81998 | 46 | bool publishEvent(char *eventName, char *data, MQTT::QoS qos = MQTT::QOS0); |
sathipal | 0:f86732d81998 | 47 | void setCommandCallback(CommandHandler callbackFunc); |
sathipal | 0:f86732d81998 | 48 | char* getMac(char* buf, int buflen); |
sathipal | 0:f86732d81998 | 49 | void yield(int ms); |
sathipal | 0:f86732d81998 | 50 | bool connect(); |
sathipal | 0:f86732d81998 | 51 | bool disconnect(); |
sathipal | 0:f86732d81998 | 52 | }; |
sathipal | 0:f86732d81998 | 53 | } |
sathipal | 0:f86732d81998 | 54 | #endif |