Had to fork with a different name, because of some incompatibility issues.
DeviceClient.h@23:1523bdaba8c8, 2020-03-10 (annotated)
- Committer:
- lamell
- Date:
- Tue Mar 10 21:26:49 2020 -0400
- Revision:
- 23:1523bdaba8c8
- Parent:
- 16:3f8558ebff65
- Child:
- 25:f4727705353b
Changed NetworkInterface to EthernetInterchange.
Used mbed-os-5.14.1
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 | 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 |
lamell | 10:665cfb0da4c5 | 29 | #define __APP_SW_REVISION__ "1.1" |
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 |
lamell | 10:665cfb0da4c5 | 39 | #define MQTT_MAX_PACKET_SIZE 1250 |
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; |
lamell | 16:3f8558ebff65 | 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); |
lamell |
23:1523bdaba8c8 | 59 | //void logData(NetworkInterface* net, char *hostname, char *clientId); |
lamell |
23:1523bdaba8c8 | 60 | void logData(EthernetInterface* net, char *hostname, char *clientId); |
sathipal | 0:f86732d81998 | 61 | int subscribeToCommands(); |
sathipal | 2:199ddea804cd | 62 | char* getMac(char* buf, int buflen); |
sathipal | 0:f86732d81998 | 63 | |
lokeshhk | 5:ea9f483e0294 | 64 | DeviceClient(); |
sathipal | 0:f86732d81998 | 65 | public: |
lamell | 16:3f8558ebff65 | 66 | MQTTNetwork* mqttNetwork; |
lamell | 16:3f8558ebff65 | 67 | |
lokeshhk | 5:ea9f483e0294 | 68 | DeviceClient(char *org, char *deviceType, char *deviceId, int port = MQTT_PORT); |
lokeshhk | 5:ea9f483e0294 | 69 | DeviceClient(char *org, char *deviceType, char *deviceId, char *authMethod, char *authToken, int port = MQTT_PORT); |
sathipal | 0:f86732d81998 | 70 | bool publishEvent(char *eventName, char *data, MQTT::QoS qos = MQTT::QOS0); |
sathipal | 0:f86732d81998 | 71 | void setCommandCallback(CommandHandler callbackFunc); |
sathipal | 2:199ddea804cd | 72 | char* getDeviceId(char* buf, int buflen); |
sathipal | 0:f86732d81998 | 73 | void yield(int ms); |
sathipal | 3:3d91bf839b49 | 74 | bool isConnected(); |
sathipal | 0:f86732d81998 | 75 | bool connect(); |
sathipal | 0:f86732d81998 | 76 | bool disconnect(); |
sathipal | 3:3d91bf839b49 | 77 | bool reConnect(); |
lamell | 8:cb2c98efdca8 | 78 | char* ipaddress(); |
lamell | 10:665cfb0da4c5 | 79 | //NetworkInterface* eth(); |
sathipal | 0:f86732d81998 | 80 | }; |
sathipal | 0:f86732d81998 | 81 | } |
lokeshhk | 5:ea9f483e0294 | 82 | #endif |