MQTT lib for WISEAgent
Fork of MQTT by
MQTTClient.cpp@2:dcfdd2abfe71, 2014-03-28 (annotated)
- Committer:
- icraggs
- Date:
- Fri Mar 28 13:39:25 2014 +0000
- Revision:
- 2:dcfdd2abfe71
- Parent:
- MQTTPubSub.cpp@0:fe461e4d7afe
- Child:
- 3:dbff6b768d28
Structure of API
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove | 0:fe461e4d7afe | 1 | /** |
sam_grove | 0:fe461e4d7afe | 2 | * @file MQTTPubSub.cpp |
sam_grove | 0:fe461e4d7afe | 3 | * @brief API - for MQTT |
sam_grove | 0:fe461e4d7afe | 4 | * @author |
sam_grove | 0:fe461e4d7afe | 5 | * @version 1.0 |
sam_grove | 0:fe461e4d7afe | 6 | * @see |
sam_grove | 0:fe461e4d7afe | 7 | * |
sam_grove | 0:fe461e4d7afe | 8 | * Copyright (c) 2014 |
sam_grove | 0:fe461e4d7afe | 9 | * |
sam_grove | 0:fe461e4d7afe | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sam_grove | 0:fe461e4d7afe | 11 | * you may not use this file except in compliance with the License. |
sam_grove | 0:fe461e4d7afe | 12 | * You may obtain a copy of the License at |
sam_grove | 0:fe461e4d7afe | 13 | * |
sam_grove | 0:fe461e4d7afe | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
sam_grove | 0:fe461e4d7afe | 15 | * |
sam_grove | 0:fe461e4d7afe | 16 | * Unless required by applicable law or agreed to in writing, software |
sam_grove | 0:fe461e4d7afe | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
sam_grove | 0:fe461e4d7afe | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sam_grove | 0:fe461e4d7afe | 19 | * See the License for the specific language governing permissions and |
sam_grove | 0:fe461e4d7afe | 20 | * limitations under the License. |
sam_grove | 0:fe461e4d7afe | 21 | */ |
sam_grove | 0:fe461e4d7afe | 22 | |
icraggs | 2:dcfdd2abfe71 | 23 | #include "MQTTClient.h" |
icraggs | 2:dcfdd2abfe71 | 24 | #include "MQTTPacket.h" |
icraggs | 2:dcfdd2abfe71 | 25 | |
icraggs | 2:dcfdd2abfe71 | 26 | MQTTClient::MQTTClient(char* serverURI, char* clientId, const int buffer_size) |
icraggs | 2:dcfdd2abfe71 | 27 | { |
icraggs | 2:dcfdd2abfe71 | 28 | |
icraggs | 2:dcfdd2abfe71 | 29 | buf = new char[buffer_size]; |
icraggs | 2:dcfdd2abfe71 | 30 | this->clientId = clientId; |
icraggs | 2:dcfdd2abfe71 | 31 | this->serverURI = serverURI; |
icraggs | 2:dcfdd2abfe71 | 32 | } |
icraggs | 2:dcfdd2abfe71 | 33 | |
sam_grove | 0:fe461e4d7afe | 34 | |
icraggs | 2:dcfdd2abfe71 | 35 | int MQTTClient::connect(MQTTConnectOptions* options, FP<void, MQTTResult*> resultHandler) |
icraggs | 2:dcfdd2abfe71 | 36 | { |
icraggs | 2:dcfdd2abfe71 | 37 | MQTTPacket_connectData data = MQTTPacket_connectData_initializer; |
icraggs | 2:dcfdd2abfe71 | 38 | |
icraggs | 2:dcfdd2abfe71 | 39 | data.clientID.cstring = clientId; |
icraggs | 2:dcfdd2abfe71 | 40 | if (options) |
icraggs | 2:dcfdd2abfe71 | 41 | { |
icraggs | 2:dcfdd2abfe71 | 42 | data.keepAliveInterval = options->keepAliveInterval; |
icraggs | 2:dcfdd2abfe71 | 43 | data.cleansession = options->cleansession; |
icraggs | 2:dcfdd2abfe71 | 44 | data.username.cstring = options->username; |
icraggs | 2:dcfdd2abfe71 | 45 | data.password.cstring = options->password; |
icraggs | 2:dcfdd2abfe71 | 46 | } |
icraggs | 2:dcfdd2abfe71 | 47 | |
icraggs | 2:dcfdd2abfe71 | 48 | int len = MQTTSerialize_connect(buf, buflen, &data); |
icraggs | 2:dcfdd2abfe71 | 49 | |
icraggs | 2:dcfdd2abfe71 | 50 | sendPacket(buf, buflen); // send the connect packet |
icraggs | 2:dcfdd2abfe71 | 51 | |
icraggs | 2:dcfdd2abfe71 | 52 | /* how to make this check work? |
icraggs | 2:dcfdd2abfe71 | 53 | if (resultHandler == None) |
icraggs | 2:dcfdd2abfe71 | 54 | { |
icraggs | 2:dcfdd2abfe71 | 55 | // this will be a blocking call, wait for the connack |
icraggs | 2:dcfdd2abfe71 | 56 | |
icraggs | 2:dcfdd2abfe71 | 57 | }*/ |
icraggs | 2:dcfdd2abfe71 | 58 | |
icraggs | 2:dcfdd2abfe71 | 59 | return len; |
icraggs | 2:dcfdd2abfe71 | 60 | } |
icraggs | 2:dcfdd2abfe71 | 61 |