Had to fork with a different name, because of some incompatibility issues.
DeviceClient.h@2:199ddea804cd, 2015-11-06 (annotated)
- Committer:
- sathipal
- Date:
- Fri Nov 06 14:56:34 2015 +0000
- Revision:
- 2:199ddea804cd
- Parent:
- 0:f86732d81998
- Child:
- 3:3d91bf839b49
A library that simplifies interactions with IBM Internet of Things Foundation.
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:199ddea804cd | 15 | * |
sathipal | 2:199ddea804cd | 16 | *******************************************************************************/ |
sathipal | 2:199ddea804cd | 17 | |
sathipal | 2:199ddea804cd | 18 | #ifndef DeviceClient_H |
sathipal | 0:f86732d81998 | 19 | #define DeviceClient_H |
sathipal | 0:f86732d81998 | 20 | |
sathipal | 0:f86732d81998 | 21 | #include "MQTTEthernet.h" |
sathipal | 0:f86732d81998 | 22 | #include "MQTTClient.h" |
sathipal | 0:f86732d81998 | 23 | #include "Command.h" |
sathipal | 0:f86732d81998 | 24 | |
sathipal | 0:f86732d81998 | 25 | // Update this to the next number *before* a commit |
sathipal | 0:f86732d81998 | 26 | #define __APP_SW_REVISION__ "0.0.1" |
sathipal | 0:f86732d81998 | 27 | |
sathipal | 0:f86732d81998 | 28 | // Configuration values needed to connect to IBM IoT Cloud |
sathipal | 0:f86732d81998 | 29 | #define QUICKSTART "quickstart" |
sathipal | 0:f86732d81998 | 30 | |
sathipal | 0:f86732d81998 | 31 | #define MQTT_PORT 1883 |
sathipal | 0:f86732d81998 | 32 | #define MQTT_TLS_PORT 8883 |
sathipal | 0:f86732d81998 | 33 | #define IBM_IOT_PORT MQTT_PORT |
sathipal | 0:f86732d81998 | 34 | |
sathipal | 0:f86732d81998 | 35 | #define IBM_IOT_MESSAGING ".messaging.internetofthings.ibmcloud.com" |
sathipal | 0:f86732d81998 | 36 | #define CONNECT_TIMEOUT 1000 * 60 |
sathipal | 0:f86732d81998 | 37 | #define MQTT_MAX_PACKET_SIZE 250 |
sathipal | 0:f86732d81998 | 38 | |
sathipal | 0:f86732d81998 | 39 | typedef void (*CommandHandler)(IoTF::Command &cmd); |
sathipal | 0:f86732d81998 | 40 | |
sathipal | 0:f86732d81998 | 41 | namespace IoTF { |
sathipal | 0:f86732d81998 | 42 | |
sathipal | 0:f86732d81998 | 43 | class DeviceClient |
sathipal | 0:f86732d81998 | 44 | { |
sathipal | 0:f86732d81998 | 45 | private: |
sathipal | 0:f86732d81998 | 46 | char *org; |
sathipal | 0:f86732d81998 | 47 | char *deviceType; |
sathipal | 0:f86732d81998 | 48 | char *deviceId; |
sathipal | 0:f86732d81998 | 49 | char *authMethod; |
sathipal | 0:f86732d81998 | 50 | char *authToken; |
sathipal | 0:f86732d81998 | 51 | MQTTEthernet ipstack; |
sathipal | 0:f86732d81998 | 52 | MQTT::Client<MQTTEthernet, Countdown, MQTT_MAX_PACKET_SIZE> mqttClient; |
sathipal | 0:f86732d81998 | 53 | |
sathipal | 0:f86732d81998 | 54 | bool tryConnect(char *hostname, MQTTPacket_connectData &data); |
sathipal | 0:f86732d81998 | 55 | int getConnTimeout(int attemptNumber); |
sathipal | 0:f86732d81998 | 56 | void logData(EthernetInterface& eth, char *hostname, char *clientId); |
sathipal | 0:f86732d81998 | 57 | int subscribeToCommands(); |
sathipal | 2:199ddea804cd | 58 | char* getMac(char* buf, int buflen); |
sathipal | 0:f86732d81998 | 59 | |
sathipal | 0:f86732d81998 | 60 | public: |
sathipal | 0:f86732d81998 | 61 | DeviceClient(); |
sathipal | 0:f86732d81998 | 62 | DeviceClient(char *org, char *deviceType, char *deviceId); |
sathipal | 0:f86732d81998 | 63 | DeviceClient(char *org, char *deviceType, char *deviceId, char *authMethod, char *authToken); |
sathipal | 0:f86732d81998 | 64 | bool publishEvent(char *eventName, char *data, MQTT::QoS qos = MQTT::QOS0); |
sathipal | 0:f86732d81998 | 65 | void setCommandCallback(CommandHandler callbackFunc); |
sathipal | 2:199ddea804cd | 66 | char* getDeviceId(char* buf, int buflen); |
sathipal | 0:f86732d81998 | 67 | void yield(int ms); |
sathipal | 0:f86732d81998 | 68 | bool connect(); |
sathipal | 0:f86732d81998 | 69 | bool disconnect(); |
sathipal | 0:f86732d81998 | 70 | }; |
sathipal | 0:f86732d81998 | 71 | } |
sathipal | 0:f86732d81998 | 72 | #endif |