Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C027_Support C12832 StatusReporter LM75B MQTT-ansond c027_radios endpoint_core endpoint_mqtt mbed-rtos mbed
MQTTTransport.h@129:c4fa24308e33, 2014-03-16 (annotated)
- Committer:
- ansond
- Date:
- Sun Mar 16 17:30:59 2014 +0000
- Revision:
- 129:c4fa24308e33
- Parent:
- 69:090e16acccb7
- Child:
- 131:27f29e230bbb
updates
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ansond | 0:ae2a45502448 | 1 | /* Copyright C2013 Doug Anson, MIT License |
| ansond | 0:ae2a45502448 | 2 | * |
| ansond | 0:ae2a45502448 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
| ansond | 0:ae2a45502448 | 4 | * and associated documentation files the "Software", to deal in the Software without restriction, |
| ansond | 0:ae2a45502448 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
| ansond | 0:ae2a45502448 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| ansond | 0:ae2a45502448 | 7 | * furnished to do so, subject to the following conditions: |
| ansond | 0:ae2a45502448 | 8 | * |
| ansond | 0:ae2a45502448 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
| ansond | 0:ae2a45502448 | 10 | * substantial portions of the Software. |
| ansond | 0:ae2a45502448 | 11 | * |
| ansond | 0:ae2a45502448 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
| ansond | 0:ae2a45502448 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| ansond | 0:ae2a45502448 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| ansond | 0:ae2a45502448 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| ansond | 0:ae2a45502448 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| ansond | 0:ae2a45502448 | 17 | */ |
| ansond | 0:ae2a45502448 | 18 | |
| ansond | 0:ae2a45502448 | 19 | #ifndef ___MQTTTRANSPORT_H_ |
| ansond | 0:ae2a45502448 | 20 | #define ___MQTTTRANSPORT_H_ |
| ansond | 0:ae2a45502448 | 21 | |
| ansond | 0:ae2a45502448 | 22 | // Base Class |
| ansond | 0:ae2a45502448 | 23 | #include "Transport.h" |
| ansond | 0:ae2a45502448 | 24 | |
| ansond | 15:e44d75d95b38 | 25 | // MQTT Support |
| ansond | 15:e44d75d95b38 | 26 | #include "PubSubClient.h" |
| ansond | 15:e44d75d95b38 | 27 | |
| ansond | 0:ae2a45502448 | 28 | // MBED to IOC Resource Map |
| ansond | 0:ae2a45502448 | 29 | #include "MBEDToIOCResourceMap.h" |
| ansond | 0:ae2a45502448 | 30 | |
| ansond | 0:ae2a45502448 | 31 | class MQTTTransport : public Transport { |
| ansond | 0:ae2a45502448 | 32 | private: |
| ansond | 0:ae2a45502448 | 33 | PubSubClient *m_mqtt; |
| ansond | 0:ae2a45502448 | 34 | MBEDToIOCResourceMap *m_map; |
| ansond | 8:45f9a920e82c | 35 | char m_topic[MQTT_IOC_TOPIC_LEN+1]; |
| ansond | 6:34c07e145caa | 36 | char m_endpoint_name[LIGHT_NAME_LEN+1]; |
| ansond | 129:c4fa24308e33 | 37 | int m_ping_counter; |
| ansond | 129:c4fa24308e33 | 38 | int m_ping_countdown; |
| ansond | 0:ae2a45502448 | 39 | |
| ansond | 0:ae2a45502448 | 40 | public: |
| ansond | 15:e44d75d95b38 | 41 | MQTTTransport(ErrorHandler *error_handler,void *endpoint,MBEDToIOCResourceMap *map); |
| ansond | 0:ae2a45502448 | 42 | virtual ~MQTTTransport(); |
| ansond | 0:ae2a45502448 | 43 | |
| ansond | 69:090e16acccb7 | 44 | void processMessage(char *message_name,char *payload, unsigned int payload_length); |
| ansond | 0:ae2a45502448 | 45 | |
| ansond | 0:ae2a45502448 | 46 | virtual bool connect(); |
| ansond | 0:ae2a45502448 | 47 | virtual bool disconnect(); |
| ansond | 0:ae2a45502448 | 48 | |
| ansond | 0:ae2a45502448 | 49 | virtual void checkAndProcess(); |
| ansond | 6:34c07e145caa | 50 | |
| ansond | 6:34c07e145caa | 51 | char *getEndpointNameFromTopic(char *topic); |
| ansond | 0:ae2a45502448 | 52 | |
| ansond | 129:c4fa24308e33 | 53 | bool isPongMessage(char *topic,char *payload,int payload_length); |
| ansond | 129:c4fa24308e33 | 54 | void processPongMessage(char *payload,int payload_length); |
| ansond | 129:c4fa24308e33 | 55 | |
| ansond | 0:ae2a45502448 | 56 | private: |
| ansond | 0:ae2a45502448 | 57 | char *makeID(char *id_template, char *buffer); |
| ansond | 8:45f9a920e82c | 58 | void initTopic(); |
| ansond | 8:45f9a920e82c | 59 | char *getTopic(); |
| ansond | 13:25448d92c205 | 60 | char *mapIOCResourceToEndpointResource(char *ioc_name); |
| ansond | 8:45f9a920e82c | 61 | void sendResult(char *endpoint_name,char *parameter_name,char *value,bool success); |
| ansond | 15:e44d75d95b38 | 62 | MBEDToIOCResourceMap *getMap(); |
| ansond | 129:c4fa24308e33 | 63 | |
| ansond | 129:c4fa24308e33 | 64 | bool sendPingMessage(); |
| ansond | 0:ae2a45502448 | 65 | }; |
| ansond | 0:ae2a45502448 | 66 | |
| ansond | 0:ae2a45502448 | 67 | #endif // ___MQTTTRANSPORT_H_ |