【mbed OS5対応バージョン】データの保存、更新、取得ができるWebサービス「milkcocoa」に接続し、データのプッシュ、送信、取得ができるライブラリです。 https://mlkcca.com/
Dependents: mbed-os-example-wifi-milkcocoa MilkcocoaOsSample_Eth MilkcocoaOsSample_ESP8266 MilkcocoaOsSample_Eth_DigitalIn
MQTT/MQTTPacket/MQTTConnect.h@0:0a2f634d3324, 2017-02-09 (annotated)
- Committer:
- jksoft
- Date:
- Thu Feb 09 07:26:57 2017 +0000
- Revision:
- 0:0a2f634d3324
??
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:0a2f634d3324 | 1 | /******************************************************************************* |
jksoft | 0:0a2f634d3324 | 2 | * Copyright (c) 2014, 2015 IBM Corp. |
jksoft | 0:0a2f634d3324 | 3 | * |
jksoft | 0:0a2f634d3324 | 4 | * All rights reserved. This program and the accompanying materials |
jksoft | 0:0a2f634d3324 | 5 | * are made available under the terms of the Eclipse Public License v1.0 |
jksoft | 0:0a2f634d3324 | 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. |
jksoft | 0:0a2f634d3324 | 7 | * |
jksoft | 0:0a2f634d3324 | 8 | * The Eclipse Public License is available at |
jksoft | 0:0a2f634d3324 | 9 | * http://www.eclipse.org/legal/epl-v10.html |
jksoft | 0:0a2f634d3324 | 10 | * and the Eclipse Distribution License is available at |
jksoft | 0:0a2f634d3324 | 11 | * http://www.eclipse.org/org/documents/edl-v10.php. |
jksoft | 0:0a2f634d3324 | 12 | * |
jksoft | 0:0a2f634d3324 | 13 | * Contributors: |
jksoft | 0:0a2f634d3324 | 14 | * Ian Craggs - initial API and implementation and/or initial documentation |
jksoft | 0:0a2f634d3324 | 15 | * Ian Craggs - add connack return code definitions |
jksoft | 0:0a2f634d3324 | 16 | *******************************************************************************/ |
jksoft | 0:0a2f634d3324 | 17 | |
jksoft | 0:0a2f634d3324 | 18 | #ifndef MQTTCONNECT_H_ |
jksoft | 0:0a2f634d3324 | 19 | #define MQTTCONNECT_H_ |
jksoft | 0:0a2f634d3324 | 20 | |
jksoft | 0:0a2f634d3324 | 21 | enum connack_return_codes |
jksoft | 0:0a2f634d3324 | 22 | { |
jksoft | 0:0a2f634d3324 | 23 | MQTT_CONNECTION_ACCEPTED = 0, |
jksoft | 0:0a2f634d3324 | 24 | MQTT_UNNACCEPTABLE_PROTOCOL = 1, |
jksoft | 0:0a2f634d3324 | 25 | MQTT_CLIENTID_REJECTED = 2, |
jksoft | 0:0a2f634d3324 | 26 | MQTT_SERVER_UNAVAILABLE = 3, |
jksoft | 0:0a2f634d3324 | 27 | MQTT_BAD_USERNAME_OR_PASSWORD = 4, |
jksoft | 0:0a2f634d3324 | 28 | MQTT_NOT_AUTHORIZED = 5, |
jksoft | 0:0a2f634d3324 | 29 | }; |
jksoft | 0:0a2f634d3324 | 30 | |
jksoft | 0:0a2f634d3324 | 31 | |
jksoft | 0:0a2f634d3324 | 32 | typedef union |
jksoft | 0:0a2f634d3324 | 33 | { |
jksoft | 0:0a2f634d3324 | 34 | unsigned char all; /**< all connect flags */ |
jksoft | 0:0a2f634d3324 | 35 | #if defined(REVERSED) |
jksoft | 0:0a2f634d3324 | 36 | struct |
jksoft | 0:0a2f634d3324 | 37 | { |
jksoft | 0:0a2f634d3324 | 38 | unsigned int username : 1; /**< 3.1 user name */ |
jksoft | 0:0a2f634d3324 | 39 | unsigned int password : 1; /**< 3.1 password */ |
jksoft | 0:0a2f634d3324 | 40 | unsigned int willRetain : 1; /**< will retain setting */ |
jksoft | 0:0a2f634d3324 | 41 | unsigned int willQoS : 2; /**< will QoS value */ |
jksoft | 0:0a2f634d3324 | 42 | unsigned int will : 1; /**< will flag */ |
jksoft | 0:0a2f634d3324 | 43 | unsigned int cleansession : 1; /**< clean session flag */ |
jksoft | 0:0a2f634d3324 | 44 | unsigned int : 1; /**< unused */ |
jksoft | 0:0a2f634d3324 | 45 | } bits; |
jksoft | 0:0a2f634d3324 | 46 | #else |
jksoft | 0:0a2f634d3324 | 47 | struct |
jksoft | 0:0a2f634d3324 | 48 | { |
jksoft | 0:0a2f634d3324 | 49 | unsigned int : 1; /**< unused */ |
jksoft | 0:0a2f634d3324 | 50 | unsigned int cleansession : 1; /**< cleansession flag */ |
jksoft | 0:0a2f634d3324 | 51 | unsigned int will : 1; /**< will flag */ |
jksoft | 0:0a2f634d3324 | 52 | unsigned int willQoS : 2; /**< will QoS value */ |
jksoft | 0:0a2f634d3324 | 53 | unsigned int willRetain : 1; /**< will retain setting */ |
jksoft | 0:0a2f634d3324 | 54 | unsigned int password : 1; /**< 3.1 password */ |
jksoft | 0:0a2f634d3324 | 55 | unsigned int username : 1; /**< 3.1 user name */ |
jksoft | 0:0a2f634d3324 | 56 | } bits; |
jksoft | 0:0a2f634d3324 | 57 | #endif |
jksoft | 0:0a2f634d3324 | 58 | } MQTTConnectFlags; /**< connect flags byte */ |
jksoft | 0:0a2f634d3324 | 59 | |
jksoft | 0:0a2f634d3324 | 60 | |
jksoft | 0:0a2f634d3324 | 61 | |
jksoft | 0:0a2f634d3324 | 62 | /** |
jksoft | 0:0a2f634d3324 | 63 | * Defines the MQTT "Last Will and Testament" (LWT) settings for |
jksoft | 0:0a2f634d3324 | 64 | * the connect packet. |
jksoft | 0:0a2f634d3324 | 65 | */ |
jksoft | 0:0a2f634d3324 | 66 | typedef struct |
jksoft | 0:0a2f634d3324 | 67 | { |
jksoft | 0:0a2f634d3324 | 68 | /** The eyecatcher for this structure. must be MQTW. */ |
jksoft | 0:0a2f634d3324 | 69 | char struct_id[4]; |
jksoft | 0:0a2f634d3324 | 70 | /** The version number of this structure. Must be 0 */ |
jksoft | 0:0a2f634d3324 | 71 | int struct_version; |
jksoft | 0:0a2f634d3324 | 72 | /** The LWT topic to which the LWT message will be published. */ |
jksoft | 0:0a2f634d3324 | 73 | MQTTString topicName; |
jksoft | 0:0a2f634d3324 | 74 | /** The LWT payload. */ |
jksoft | 0:0a2f634d3324 | 75 | MQTTString message; |
jksoft | 0:0a2f634d3324 | 76 | /** |
jksoft | 0:0a2f634d3324 | 77 | * The retained flag for the LWT message (see MQTTAsync_message.retained). |
jksoft | 0:0a2f634d3324 | 78 | */ |
jksoft | 0:0a2f634d3324 | 79 | unsigned char retained; |
jksoft | 0:0a2f634d3324 | 80 | /** |
jksoft | 0:0a2f634d3324 | 81 | * The quality of service setting for the LWT message (see |
jksoft | 0:0a2f634d3324 | 82 | * MQTTAsync_message.qos and @ref qos). |
jksoft | 0:0a2f634d3324 | 83 | */ |
jksoft | 0:0a2f634d3324 | 84 | char qos; |
jksoft | 0:0a2f634d3324 | 85 | } MQTTPacket_willOptions; |
jksoft | 0:0a2f634d3324 | 86 | |
jksoft | 0:0a2f634d3324 | 87 | |
jksoft | 0:0a2f634d3324 | 88 | #define MQTTPacket_willOptions_initializer { {'M', 'Q', 'T', 'W'}, 0, {NULL, {0, NULL}}, {NULL, {0, NULL}}, 0, 0 } |
jksoft | 0:0a2f634d3324 | 89 | |
jksoft | 0:0a2f634d3324 | 90 | |
jksoft | 0:0a2f634d3324 | 91 | typedef struct |
jksoft | 0:0a2f634d3324 | 92 | { |
jksoft | 0:0a2f634d3324 | 93 | /** The eyecatcher for this structure. must be MQTC. */ |
jksoft | 0:0a2f634d3324 | 94 | char struct_id[4]; |
jksoft | 0:0a2f634d3324 | 95 | /** The version number of this structure. Must be 0 */ |
jksoft | 0:0a2f634d3324 | 96 | int struct_version; |
jksoft | 0:0a2f634d3324 | 97 | /** Version of MQTT to be used. 3 = 3.1 4 = 3.1.1 |
jksoft | 0:0a2f634d3324 | 98 | */ |
jksoft | 0:0a2f634d3324 | 99 | unsigned char MQTTVersion; |
jksoft | 0:0a2f634d3324 | 100 | MQTTString clientID; |
jksoft | 0:0a2f634d3324 | 101 | unsigned short keepAliveInterval; |
jksoft | 0:0a2f634d3324 | 102 | unsigned char cleansession; |
jksoft | 0:0a2f634d3324 | 103 | unsigned char willFlag; |
jksoft | 0:0a2f634d3324 | 104 | MQTTPacket_willOptions will; |
jksoft | 0:0a2f634d3324 | 105 | MQTTString username; |
jksoft | 0:0a2f634d3324 | 106 | MQTTString password; |
jksoft | 0:0a2f634d3324 | 107 | } MQTTPacket_connectData; |
jksoft | 0:0a2f634d3324 | 108 | |
jksoft | 0:0a2f634d3324 | 109 | typedef union |
jksoft | 0:0a2f634d3324 | 110 | { |
jksoft | 0:0a2f634d3324 | 111 | unsigned char all; /**< all connack flags */ |
jksoft | 0:0a2f634d3324 | 112 | #if defined(REVERSED) |
jksoft | 0:0a2f634d3324 | 113 | struct |
jksoft | 0:0a2f634d3324 | 114 | { |
jksoft | 0:0a2f634d3324 | 115 | unsigned int sessionpresent : 1; /**< session present flag */ |
jksoft | 0:0a2f634d3324 | 116 | unsigned int : y; /**< unused */ |
jksoft | 0:0a2f634d3324 | 117 | } bits; |
jksoft | 0:0a2f634d3324 | 118 | #else |
jksoft | 0:0a2f634d3324 | 119 | struct |
jksoft | 0:0a2f634d3324 | 120 | { |
jksoft | 0:0a2f634d3324 | 121 | unsigned int : 7; /**< unused */ |
jksoft | 0:0a2f634d3324 | 122 | unsigned int sessionpresent : 1; /**< session present flag */ |
jksoft | 0:0a2f634d3324 | 123 | } bits; |
jksoft | 0:0a2f634d3324 | 124 | #endif |
jksoft | 0:0a2f634d3324 | 125 | } MQTTConnackFlags; /**< connack flags byte */ |
jksoft | 0:0a2f634d3324 | 126 | |
jksoft | 0:0a2f634d3324 | 127 | #define MQTTPacket_connectData_initializer { {'M', 'Q', 'T', 'C'}, 0, 4, {NULL, {0, NULL}}, 60, 1, 0, \ |
jksoft | 0:0a2f634d3324 | 128 | MQTTPacket_willOptions_initializer, {NULL, {0, NULL}}, {NULL, {0, NULL}} } |
jksoft | 0:0a2f634d3324 | 129 | |
jksoft | 0:0a2f634d3324 | 130 | int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData* options); |
jksoft | 0:0a2f634d3324 | 131 | int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, int len); |
jksoft | 0:0a2f634d3324 | 132 | |
jksoft | 0:0a2f634d3324 | 133 | int MQTTSerialize_connack(unsigned char* buf, int buflen, unsigned char connack_rc, unsigned char sessionPresent); |
jksoft | 0:0a2f634d3324 | 134 | int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, int buflen); |
jksoft | 0:0a2f634d3324 | 135 | |
jksoft | 0:0a2f634d3324 | 136 | int MQTTSerialize_disconnect(unsigned char* buf, int buflen); |
jksoft | 0:0a2f634d3324 | 137 | int MQTTSerialize_pingreq(unsigned char* buf, int buflen); |
jksoft | 0:0a2f634d3324 | 138 | |
jksoft | 0:0a2f634d3324 | 139 | #endif /* MQTTCONNECT_H_ */ |