mqtt specific components for the impact mbed endpoint library
Dependents: mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_mqtt_endpoint_nxp
MQTTTransport.h@49:965a65122c0f, 2014-07-08 (annotated)
- Committer:
- ansond
- Date:
- Tue Jul 08 14:59:39 2014 +0000
- Revision:
- 49:965a65122c0f
- Parent:
- 31:e5950e0677be
ported to new MQTT library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:a3fc1c6ef150 | 1 | /* Copyright C2013 Doug Anson, MIT License |
ansond | 0:a3fc1c6ef150 | 2 | * |
ansond | 0:a3fc1c6ef150 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
ansond | 0:a3fc1c6ef150 | 4 | * and associated documentation files the "Software", to deal in the Software without restriction, |
ansond | 0:a3fc1c6ef150 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
ansond | 0:a3fc1c6ef150 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
ansond | 0:a3fc1c6ef150 | 7 | * furnished to do so, subject to the following conditions: |
ansond | 0:a3fc1c6ef150 | 8 | * |
ansond | 0:a3fc1c6ef150 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
ansond | 0:a3fc1c6ef150 | 10 | * substantial portions of the Software. |
ansond | 0:a3fc1c6ef150 | 11 | * |
ansond | 0:a3fc1c6ef150 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
ansond | 0:a3fc1c6ef150 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ansond | 0:a3fc1c6ef150 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
ansond | 0:a3fc1c6ef150 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ansond | 0:a3fc1c6ef150 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
ansond | 0:a3fc1c6ef150 | 17 | */ |
ansond | 0:a3fc1c6ef150 | 18 | |
ansond | 0:a3fc1c6ef150 | 19 | #ifndef ___MQTTTRANSPORT_H_ |
ansond | 0:a3fc1c6ef150 | 20 | #define ___MQTTTRANSPORT_H_ |
ansond | 0:a3fc1c6ef150 | 21 | |
ansond | 0:a3fc1c6ef150 | 22 | // Base Class |
ansond | 0:a3fc1c6ef150 | 23 | #include "Transport.h" |
ansond | 0:a3fc1c6ef150 | 24 | |
ansond | 0:a3fc1c6ef150 | 25 | // MQTT Support |
ansond | 49:965a65122c0f | 26 | #include "MQTTEthernet.h" |
ansond | 49:965a65122c0f | 27 | #include "MQTTClient.h" |
ansond | 0:a3fc1c6ef150 | 28 | |
ansond | 0:a3fc1c6ef150 | 29 | // MBED to IOC Resource Map |
ansond | 0:a3fc1c6ef150 | 30 | #include "MBEDToIOCResourceMap.h" |
ansond | 0:a3fc1c6ef150 | 31 | |
ansond | 0:a3fc1c6ef150 | 32 | class MQTTTransport : public Transport { |
ansond | 0:a3fc1c6ef150 | 33 | private: |
ansond | 49:965a65122c0f | 34 | MQTTEthernet *m_ipstack; |
ansond | 49:965a65122c0f | 35 | MQTT::Client<MQTTEthernet, Countdown> *m_mqtt; |
ansond | 49:965a65122c0f | 36 | MBEDToIOCResourceMap *m_map; |
ansond | 49:965a65122c0f | 37 | char m_topic[MQTT_IOC_TOPIC_LEN+1]; |
ansond | 49:965a65122c0f | 38 | char m_endpoint_name[PERSONALITY_NAME_LEN+1]; |
ansond | 49:965a65122c0f | 39 | int m_ping_counter; |
ansond | 49:965a65122c0f | 40 | int m_ping_countdown; |
ansond | 0:a3fc1c6ef150 | 41 | |
ansond | 0:a3fc1c6ef150 | 42 | public: |
ansond | 0:a3fc1c6ef150 | 43 | MQTTTransport(ErrorHandler *error_handler,void *endpoint,MBEDToIOCResourceMap *map); |
ansond | 0:a3fc1c6ef150 | 44 | virtual ~MQTTTransport(); |
ansond | 0:a3fc1c6ef150 | 45 | |
ansond | 0:a3fc1c6ef150 | 46 | void processMessage(char *message_name,char *payload, unsigned int payload_length); |
ansond | 0:a3fc1c6ef150 | 47 | |
ansond | 0:a3fc1c6ef150 | 48 | virtual bool connect(); |
ansond | 0:a3fc1c6ef150 | 49 | virtual bool disconnect(); |
ansond | 0:a3fc1c6ef150 | 50 | |
ansond | 0:a3fc1c6ef150 | 51 | virtual void checkAndProcess(); |
ansond | 0:a3fc1c6ef150 | 52 | |
ansond | 0:a3fc1c6ef150 | 53 | char *getEndpointNameFromTopic(char *topic); |
ansond | 0:a3fc1c6ef150 | 54 | |
ansond | 0:a3fc1c6ef150 | 55 | bool isPongMessage(char *topic,char *payload,int payload_length); |
ansond | 0:a3fc1c6ef150 | 56 | void processPongMessage(char *payload,int payload_length); |
ansond | 0:a3fc1c6ef150 | 57 | |
ansond | 0:a3fc1c6ef150 | 58 | private: |
ansond | 0:a3fc1c6ef150 | 59 | char *makeID(char *id_template, char *buffer); |
ansond | 0:a3fc1c6ef150 | 60 | void initTopic(); |
ansond | 0:a3fc1c6ef150 | 61 | char *getTopic(); |
ansond | 0:a3fc1c6ef150 | 62 | char *mapIOCResourceToEndpointResource(char *ioc_name); |
ansond | 0:a3fc1c6ef150 | 63 | void sendResult(char *endpoint_name,char *parameter_name,char *value,bool success); |
ansond | 0:a3fc1c6ef150 | 64 | MBEDToIOCResourceMap *getMap(); |
ansond | 31:e5950e0677be | 65 | bool isDimmingResource(char *resource); |
ansond | 0:a3fc1c6ef150 | 66 | bool sendPingMessage(); |
ansond | 0:a3fc1c6ef150 | 67 | }; |
ansond | 0:a3fc1c6ef150 | 68 | |
ansond | 0:a3fc1c6ef150 | 69 | #endif // ___MQTTTRANSPORT_H_ |