Add "TARGET_RZ_A1H"as target of using Ethernet IF.
Fork of Milkcocoa_EthernetIF by
MClient.h@3:8dc743628d54, 2015-12-27 (annotated)
- Committer:
- jksoft
- Date:
- Sun Dec 27 13:36:50 2015 +0000
- Revision:
- 3:8dc743628d54
- Parent:
- 2:a174c8a8d53e
- Child:
- 5:8abe70267912
- Child:
- 6:7b9d1fed76fe
u-blox C027?3G??????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 1:4a634c06c5dc | 1 | #ifndef _MCLIENT_H_ |
jksoft | 1:4a634c06c5dc | 2 | #define _MCLIENT_H_ |
jksoft | 1:4a634c06c5dc | 3 | |
jksoft | 2:a174c8a8d53e | 4 | //#define USE_ESP8266 |
jksoft | 3:8dc743628d54 | 5 | //#define USE_ETHERNET |
jksoft | 3:8dc743628d54 | 6 | #define USE_MDM |
jksoft | 1:4a634c06c5dc | 7 | |
jksoft | 1:4a634c06c5dc | 8 | #include "mbed.h" |
jksoft | 3:8dc743628d54 | 9 | #if defined(USE_ESP8266) |
jksoft | 1:4a634c06c5dc | 10 | #include "MQTTESP8266.h" |
jksoft | 3:8dc743628d54 | 11 | #elif defined(USE_MDM) |
jksoft | 3:8dc743628d54 | 12 | #include "MQTTMDM.h" |
jksoft | 3:8dc743628d54 | 13 | #else |
jksoft | 1:4a634c06c5dc | 14 | #include "MQTTEthernet.h" |
jksoft | 1:4a634c06c5dc | 15 | #endif |
jksoft | 1:4a634c06c5dc | 16 | #include "MQTTClient.h" |
jksoft | 1:4a634c06c5dc | 17 | |
jksoft | 1:4a634c06c5dc | 18 | class MClient |
jksoft | 1:4a634c06c5dc | 19 | { |
jksoft | 1:4a634c06c5dc | 20 | public: |
jksoft | 1:4a634c06c5dc | 21 | typedef void (*messageHandler)(MQTT::MessageData&); |
jksoft | 1:4a634c06c5dc | 22 | #ifdef USE_ESP8266 |
jksoft | 1:4a634c06c5dc | 23 | MClient(MQTTESP8266 *ipstack) : client(MQTT::Client<MQTTESP8266, Countdown>(*ipstack)) |
jksoft | 3:8dc743628d54 | 24 | #elif defined(USE_MDM) |
jksoft | 3:8dc743628d54 | 25 | MClient(MQTTMDM *ipstack) : client(MQTT::Client<MQTTMDM, Countdown>(*ipstack)) |
jksoft | 1:4a634c06c5dc | 26 | #else |
jksoft | 1:4a634c06c5dc | 27 | MClient(MQTTEthernet *ipstack) : client(MQTT::Client<MQTTEthernet, Countdown>(*ipstack)) |
jksoft | 1:4a634c06c5dc | 28 | #endif |
jksoft | 1:4a634c06c5dc | 29 | { |
jksoft | 1:4a634c06c5dc | 30 | _ipstack = ipstack; |
jksoft | 1:4a634c06c5dc | 31 | } |
jksoft | 1:4a634c06c5dc | 32 | void setDefaultMessageHandler(messageHandler mh) |
jksoft | 1:4a634c06c5dc | 33 | { |
jksoft | 1:4a634c06c5dc | 34 | client.setDefaultMessageHandler(mh); |
jksoft | 1:4a634c06c5dc | 35 | } |
jksoft | 1:4a634c06c5dc | 36 | int connect(char* host,int port) |
jksoft | 1:4a634c06c5dc | 37 | { |
jksoft | 1:4a634c06c5dc | 38 | return _ipstack->connect(host, port); |
jksoft | 1:4a634c06c5dc | 39 | } |
jksoft | 1:4a634c06c5dc | 40 | int connect() |
jksoft | 1:4a634c06c5dc | 41 | { |
jksoft | 1:4a634c06c5dc | 42 | return client.connect(); |
jksoft | 1:4a634c06c5dc | 43 | } |
jksoft | 1:4a634c06c5dc | 44 | int connect(MQTTPacket_connectData& options) |
jksoft | 1:4a634c06c5dc | 45 | { |
jksoft | 1:4a634c06c5dc | 46 | return client.connect(options); |
jksoft | 1:4a634c06c5dc | 47 | } |
jksoft | 1:4a634c06c5dc | 48 | int publish(const char* topicName, MQTT::Message& message) |
jksoft | 1:4a634c06c5dc | 49 | { |
jksoft | 1:4a634c06c5dc | 50 | return client.publish(topicName,message); |
jksoft | 1:4a634c06c5dc | 51 | } |
jksoft | 1:4a634c06c5dc | 52 | int publish(const char* topicName, void* payload, size_t payloadlen, enum MQTT::QoS qos = MQTT::QOS0, bool retained = false) |
jksoft | 1:4a634c06c5dc | 53 | { |
jksoft | 1:4a634c06c5dc | 54 | return client.publish(topicName,payload,payloadlen,qos,retained); |
jksoft | 1:4a634c06c5dc | 55 | } |
jksoft | 1:4a634c06c5dc | 56 | int publish(const char* topicName, void* payload, size_t payloadlen, unsigned short& id, enum MQTT::QoS qos = MQTT::QOS1, bool retained = false) |
jksoft | 1:4a634c06c5dc | 57 | { |
jksoft | 1:4a634c06c5dc | 58 | return client.publish(topicName,payload,payloadlen,id,qos,retained); |
jksoft | 1:4a634c06c5dc | 59 | } |
jksoft | 1:4a634c06c5dc | 60 | int subscribe(const char* topicFilter, enum MQTT::QoS qos, messageHandler mh) |
jksoft | 1:4a634c06c5dc | 61 | { |
jksoft | 1:4a634c06c5dc | 62 | return client.subscribe(topicFilter,qos,mh); |
jksoft | 1:4a634c06c5dc | 63 | } |
jksoft | 1:4a634c06c5dc | 64 | int unsubscribe(const char* topicFilter) |
jksoft | 1:4a634c06c5dc | 65 | { |
jksoft | 1:4a634c06c5dc | 66 | return client.unsubscribe(topicFilter); |
jksoft | 1:4a634c06c5dc | 67 | } |
jksoft | 1:4a634c06c5dc | 68 | int disconnect() |
jksoft | 1:4a634c06c5dc | 69 | { |
jksoft | 1:4a634c06c5dc | 70 | return client.disconnect(); |
jksoft | 1:4a634c06c5dc | 71 | } |
jksoft | 1:4a634c06c5dc | 72 | int yield(unsigned long timeout_ms = 1000L) |
jksoft | 1:4a634c06c5dc | 73 | { |
jksoft | 1:4a634c06c5dc | 74 | return client.yield(timeout_ms); |
jksoft | 1:4a634c06c5dc | 75 | } |
jksoft | 1:4a634c06c5dc | 76 | bool isConnected() |
jksoft | 1:4a634c06c5dc | 77 | { |
jksoft | 1:4a634c06c5dc | 78 | return client.isConnected(); |
jksoft | 1:4a634c06c5dc | 79 | } |
jksoft | 1:4a634c06c5dc | 80 | private: |
jksoft | 1:4a634c06c5dc | 81 | #ifdef USE_ESP8266 |
jksoft | 1:4a634c06c5dc | 82 | MQTT::Client<MQTTESP8266, Countdown> client; |
jksoft | 1:4a634c06c5dc | 83 | MQTTESP8266 *_ipstack; |
jksoft | 3:8dc743628d54 | 84 | #elif defined(USE_MDM) |
jksoft | 3:8dc743628d54 | 85 | MQTT::Client<MQTTMDM, Countdown> client; |
jksoft | 3:8dc743628d54 | 86 | MQTTMDM *_ipstack; |
jksoft | 1:4a634c06c5dc | 87 | #else |
jksoft | 1:4a634c06c5dc | 88 | MQTT::Client<MQTTEthernet, Countdown> client; |
jksoft | 1:4a634c06c5dc | 89 | MQTTEthernet *_ipstack; |
jksoft | 1:4a634c06c5dc | 90 | #endif |
jksoft | 1:4a634c06c5dc | 91 | }; |
jksoft | 1:4a634c06c5dc | 92 | |
jksoft | 1:4a634c06c5dc | 93 | #endif |