Jeon byungchul
/
aws-iot-example
this is fork and i will modify for STM32
Fork of AWS-test by
aws-iot/include/aws_iot_mqtt_client_interface.h@0:cd5404401c2f, 2017-04-12 (annotated)
- Committer:
- peyo
- Date:
- Wed Apr 12 14:07:09 2017 +0200
- Revision:
- 0:cd5404401c2f
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
peyo |
0:cd5404401c2f | 1 | /* |
peyo |
0:cd5404401c2f | 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
peyo |
0:cd5404401c2f | 3 | * |
peyo |
0:cd5404401c2f | 4 | * Licensed under the Apache License, Version 2.0 (the "License"). |
peyo |
0:cd5404401c2f | 5 | * You may not use this file except in compliance with the License. |
peyo |
0:cd5404401c2f | 6 | * A copy of the License is located at |
peyo |
0:cd5404401c2f | 7 | * |
peyo |
0:cd5404401c2f | 8 | * http://aws.amazon.com/apache2.0 |
peyo |
0:cd5404401c2f | 9 | * |
peyo |
0:cd5404401c2f | 10 | * or in the "license" file accompanying this file. This file is distributed |
peyo |
0:cd5404401c2f | 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
peyo |
0:cd5404401c2f | 12 | * express or implied. See the License for the specific language governing |
peyo |
0:cd5404401c2f | 13 | * permissions and limitations under the License. |
peyo |
0:cd5404401c2f | 14 | */ |
peyo |
0:cd5404401c2f | 15 | |
peyo |
0:cd5404401c2f | 16 | // Based on Eclipse Paho. |
peyo |
0:cd5404401c2f | 17 | /******************************************************************************* |
peyo |
0:cd5404401c2f | 18 | * Copyright (c) 2014 IBM Corp. |
peyo |
0:cd5404401c2f | 19 | * |
peyo |
0:cd5404401c2f | 20 | * All rights reserved. This program and the accompanying materials |
peyo |
0:cd5404401c2f | 21 | * are made available under the terms of the Eclipse Public License v1.0 |
peyo |
0:cd5404401c2f | 22 | * and Eclipse Distribution License v1.0 which accompany this distribution. |
peyo |
0:cd5404401c2f | 23 | * |
peyo |
0:cd5404401c2f | 24 | * The Eclipse Public License is available at |
peyo |
0:cd5404401c2f | 25 | * http://www.eclipse.org/legal/epl-v10.html |
peyo |
0:cd5404401c2f | 26 | * and the Eclipse Distribution License is available at |
peyo |
0:cd5404401c2f | 27 | * http://www.eclipse.org/org/documents/edl-v10.php. |
peyo |
0:cd5404401c2f | 28 | * |
peyo |
0:cd5404401c2f | 29 | * Contributors: |
peyo |
0:cd5404401c2f | 30 | * Ian Craggs - initial API and implementation and/or initial documentation |
peyo |
0:cd5404401c2f | 31 | * Xiang Rong - 442039 Add makefile to Embedded C client |
peyo |
0:cd5404401c2f | 32 | *******************************************************************************/ |
peyo |
0:cd5404401c2f | 33 | |
peyo |
0:cd5404401c2f | 34 | /** |
peyo |
0:cd5404401c2f | 35 | * @file aws_iot_mqtt_interface.h |
peyo |
0:cd5404401c2f | 36 | * @brief Interface definition for MQTT client. |
peyo |
0:cd5404401c2f | 37 | */ |
peyo |
0:cd5404401c2f | 38 | |
peyo |
0:cd5404401c2f | 39 | #ifndef AWS_IOT_SDK_SRC_IOT_MQTT_INTERFACE_H |
peyo |
0:cd5404401c2f | 40 | #define AWS_IOT_SDK_SRC_IOT_MQTT_INTERFACE_H |
peyo |
0:cd5404401c2f | 41 | |
peyo |
0:cd5404401c2f | 42 | #ifdef __cplusplus |
peyo |
0:cd5404401c2f | 43 | extern "C" { |
peyo |
0:cd5404401c2f | 44 | #endif |
peyo |
0:cd5404401c2f | 45 | |
peyo |
0:cd5404401c2f | 46 | /* Library Header files */ |
peyo |
0:cd5404401c2f | 47 | #include "stdio.h" |
peyo |
0:cd5404401c2f | 48 | #include "stdbool.h" |
peyo |
0:cd5404401c2f | 49 | #include "stdint.h" |
peyo |
0:cd5404401c2f | 50 | #include "stddef.h" |
peyo |
0:cd5404401c2f | 51 | |
peyo |
0:cd5404401c2f | 52 | /* AWS Specific header files */ |
peyo |
0:cd5404401c2f | 53 | #include "aws_iot_error.h" |
peyo |
0:cd5404401c2f | 54 | #include "aws_iot_config.h" |
peyo |
0:cd5404401c2f | 55 | #include "aws_iot_mqtt_client.h" |
peyo |
0:cd5404401c2f | 56 | |
peyo |
0:cd5404401c2f | 57 | /* Platform specific implementation header files */ |
peyo |
0:cd5404401c2f | 58 | #include "network_interface.h" |
peyo |
0:cd5404401c2f | 59 | #include "timer_interface.h" |
peyo |
0:cd5404401c2f | 60 | |
peyo |
0:cd5404401c2f | 61 | /** |
peyo |
0:cd5404401c2f | 62 | * @brief MQTT Client Initialization Function |
peyo |
0:cd5404401c2f | 63 | * |
peyo |
0:cd5404401c2f | 64 | * Called to initialize the MQTT Client |
peyo |
0:cd5404401c2f | 65 | * |
peyo |
0:cd5404401c2f | 66 | * @param pClient Reference to the IoT Client |
peyo |
0:cd5404401c2f | 67 | * @param pInitParams Pointer to MQTT connection parameters |
peyo |
0:cd5404401c2f | 68 | * |
peyo |
0:cd5404401c2f | 69 | * @return IoT_Error_t Type defining successful/failed API call |
peyo |
0:cd5404401c2f | 70 | */ |
peyo |
0:cd5404401c2f | 71 | IoT_Error_t aws_iot_mqtt_init(AWS_IoT_Client *pClient, IoT_Client_Init_Params *pInitParams); |
peyo |
0:cd5404401c2f | 72 | |
peyo |
0:cd5404401c2f | 73 | /** |
peyo |
0:cd5404401c2f | 74 | * @brief MQTT Connection Function |
peyo |
0:cd5404401c2f | 75 | * |
peyo |
0:cd5404401c2f | 76 | * Called to establish an MQTT connection with the AWS IoT Service |
peyo |
0:cd5404401c2f | 77 | * |
peyo |
0:cd5404401c2f | 78 | * @param pClient Reference to the IoT Client |
peyo |
0:cd5404401c2f | 79 | * @param pConnectParams Pointer to MQTT connection parameters |
peyo |
0:cd5404401c2f | 80 | * |
peyo |
0:cd5404401c2f | 81 | * @return An IoT Error Type defining successful/failed connection |
peyo |
0:cd5404401c2f | 82 | */ |
peyo |
0:cd5404401c2f | 83 | IoT_Error_t aws_iot_mqtt_connect(AWS_IoT_Client *pClient, IoT_Client_Connect_Params *pConnectParams); |
peyo |
0:cd5404401c2f | 84 | |
peyo |
0:cd5404401c2f | 85 | /** |
peyo |
0:cd5404401c2f | 86 | * @brief Publish an MQTT message on a topic |
peyo |
0:cd5404401c2f | 87 | * |
peyo |
0:cd5404401c2f | 88 | * Called to publish an MQTT message on a topic. |
peyo |
0:cd5404401c2f | 89 | * @note Call is blocking. In the case of a QoS 0 message the function returns |
peyo |
0:cd5404401c2f | 90 | * after the message was successfully passed to the TLS layer. In the case of QoS 1 |
peyo |
0:cd5404401c2f | 91 | * the function returns after the receipt of the PUBACK control packet. |
peyo |
0:cd5404401c2f | 92 | * |
peyo |
0:cd5404401c2f | 93 | * @param pClient Reference to the IoT Client |
peyo |
0:cd5404401c2f | 94 | * @param pTopicName Topic Name to publish to |
peyo |
0:cd5404401c2f | 95 | * @param topicNameLen Length of the topic name |
peyo |
0:cd5404401c2f | 96 | * @param pParams Pointer to Publish Message parameters |
peyo |
0:cd5404401c2f | 97 | * |
peyo |
0:cd5404401c2f | 98 | * @return An IoT Error Type defining successful/failed publish |
peyo |
0:cd5404401c2f | 99 | */ |
peyo |
0:cd5404401c2f | 100 | IoT_Error_t aws_iot_mqtt_publish(AWS_IoT_Client *pClient, const char *pTopicName, uint16_t topicNameLen, |
peyo |
0:cd5404401c2f | 101 | IoT_Publish_Message_Params *pParams); |
peyo |
0:cd5404401c2f | 102 | |
peyo |
0:cd5404401c2f | 103 | /** |
peyo |
0:cd5404401c2f | 104 | * @brief Subscribe to an MQTT topic. |
peyo |
0:cd5404401c2f | 105 | * |
peyo |
0:cd5404401c2f | 106 | * Called to send a subscribe message to the broker requesting a subscription |
peyo |
0:cd5404401c2f | 107 | * to an MQTT topic. |
peyo |
0:cd5404401c2f | 108 | * @note Call is blocking. The call returns after the receipt of the SUBACK control packet. |
peyo |
0:cd5404401c2f | 109 | * |
peyo |
0:cd5404401c2f | 110 | * @param pClient Reference to the IoT Client |
peyo |
0:cd5404401c2f | 111 | * @param pTopicName Topic Name to publish to |
peyo |
0:cd5404401c2f | 112 | * @param topicNameLen Length of the topic name |
peyo |
0:cd5404401c2f | 113 | * @param pApplicationHandler_t Reference to the handler function for this subscription |
peyo |
0:cd5404401c2f | 114 | * @param pApplicationHandlerData Data to be passed as argument to the application handler callback |
peyo |
0:cd5404401c2f | 115 | * |
peyo |
0:cd5404401c2f | 116 | * @return An IoT Error Type defining successful/failed subscription |
peyo |
0:cd5404401c2f | 117 | */ |
peyo |
0:cd5404401c2f | 118 | IoT_Error_t aws_iot_mqtt_subscribe(AWS_IoT_Client *pClient, const char *pTopicName, uint16_t topicNameLen, |
peyo |
0:cd5404401c2f | 119 | QoS qos, pApplicationHandler_t pApplicationHandler, void *pApplicationHandlerData); |
peyo |
0:cd5404401c2f | 120 | |
peyo |
0:cd5404401c2f | 121 | /** |
peyo |
0:cd5404401c2f | 122 | * @brief Subscribe to an MQTT topic. |
peyo |
0:cd5404401c2f | 123 | * |
peyo |
0:cd5404401c2f | 124 | * Called to resubscribe to the topics that the client has active subscriptions on. |
peyo |
0:cd5404401c2f | 125 | * Internally called when autoreconnect is enabled |
peyo |
0:cd5404401c2f | 126 | * |
peyo |
0:cd5404401c2f | 127 | * @note Call is blocking. The call returns after the receipt of the SUBACK control packet. |
peyo |
0:cd5404401c2f | 128 | * |
peyo |
0:cd5404401c2f | 129 | * @param pClient Reference to the IoT Client |
peyo |
0:cd5404401c2f | 130 | * |
peyo |
0:cd5404401c2f | 131 | * @return An IoT Error Type defining successful/failed subscription |
peyo |
0:cd5404401c2f | 132 | */ |
peyo |
0:cd5404401c2f | 133 | IoT_Error_t aws_iot_mqtt_resubscribe(AWS_IoT_Client *pClient); |
peyo |
0:cd5404401c2f | 134 | |
peyo |
0:cd5404401c2f | 135 | /** |
peyo |
0:cd5404401c2f | 136 | * @brief Unsubscribe to an MQTT topic. |
peyo |
0:cd5404401c2f | 137 | * |
peyo |
0:cd5404401c2f | 138 | * Called to send an unsubscribe message to the broker requesting removal of a subscription |
peyo |
0:cd5404401c2f | 139 | * to an MQTT topic. |
peyo |
0:cd5404401c2f | 140 | * @note Call is blocking. The call returns after the receipt of the UNSUBACK control packet. |
peyo |
0:cd5404401c2f | 141 | * |
peyo |
0:cd5404401c2f | 142 | * @param pClient Reference to the IoT Client |
peyo |
0:cd5404401c2f | 143 | * @param pTopicName Topic Name to publish to |
peyo |
0:cd5404401c2f | 144 | * @param topicNameLen Length of the topic name |
peyo |
0:cd5404401c2f | 145 | * |
peyo |
0:cd5404401c2f | 146 | * @return An IoT Error Type defining successful/failed unsubscribe call |
peyo |
0:cd5404401c2f | 147 | */ |
peyo |
0:cd5404401c2f | 148 | IoT_Error_t aws_iot_mqtt_unsubscribe(AWS_IoT_Client *pClient, const char *pTopicFilter, uint16_t topicFilterLen); |
peyo |
0:cd5404401c2f | 149 | |
peyo |
0:cd5404401c2f | 150 | /** |
peyo |
0:cd5404401c2f | 151 | * @brief Disconnect an MQTT Connection |
peyo |
0:cd5404401c2f | 152 | * |
peyo |
0:cd5404401c2f | 153 | * Called to send a disconnect message to the broker. |
peyo |
0:cd5404401c2f | 154 | * |
peyo |
0:cd5404401c2f | 155 | * @param pClient Reference to the IoT Client |
peyo |
0:cd5404401c2f | 156 | * |
peyo |
0:cd5404401c2f | 157 | * @return An IoT Error Type defining successful/failed send of the disconnect control packet. |
peyo |
0:cd5404401c2f | 158 | */ |
peyo |
0:cd5404401c2f | 159 | IoT_Error_t aws_iot_mqtt_disconnect(AWS_IoT_Client *pClient); |
peyo |
0:cd5404401c2f | 160 | |
peyo |
0:cd5404401c2f | 161 | /** |
peyo |
0:cd5404401c2f | 162 | * @brief Yield to the MQTT client |
peyo |
0:cd5404401c2f | 163 | * |
peyo |
0:cd5404401c2f | 164 | * Called to yield the current thread to the underlying MQTT client. This time is used by |
peyo |
0:cd5404401c2f | 165 | * the MQTT client to manage PING requests to monitor the health of the TCP connection as |
peyo |
0:cd5404401c2f | 166 | * well as periodically check the socket receive buffer for subscribe messages. Yield() |
peyo |
0:cd5404401c2f | 167 | * must be called at a rate faster than the keepalive interval. It must also be called |
peyo |
0:cd5404401c2f | 168 | * at a rate faster than the incoming message rate as this is the only way the client receives |
peyo |
0:cd5404401c2f | 169 | * processing time to manage incoming messages. |
peyo |
0:cd5404401c2f | 170 | * |
peyo |
0:cd5404401c2f | 171 | * @param pClient Reference to the IoT Client |
peyo |
0:cd5404401c2f | 172 | * @param timeout_ms Maximum number of milliseconds to pass thread execution to the client. |
peyo |
0:cd5404401c2f | 173 | * |
peyo |
0:cd5404401c2f | 174 | * @return An IoT Error Type defining successful/failed client processing. |
peyo |
0:cd5404401c2f | 175 | * If this call results in an error it is likely the MQTT connection has dropped. |
peyo |
0:cd5404401c2f | 176 | * iot_is_mqtt_connected can be called to confirm. |
peyo |
0:cd5404401c2f | 177 | */ |
peyo |
0:cd5404401c2f | 178 | IoT_Error_t aws_iot_mqtt_yield(AWS_IoT_Client *pClient, uint32_t timeout_ms); |
peyo |
0:cd5404401c2f | 179 | |
peyo |
0:cd5404401c2f | 180 | /** |
peyo |
0:cd5404401c2f | 181 | * @brief MQTT Manual Re-Connection Function |
peyo |
0:cd5404401c2f | 182 | * |
peyo |
0:cd5404401c2f | 183 | * Called to establish an MQTT connection with the AWS IoT Service |
peyo |
0:cd5404401c2f | 184 | * using parameters from the last time a connection was attempted |
peyo |
0:cd5404401c2f | 185 | * Use after disconnect to start the reconnect process manually |
peyo |
0:cd5404401c2f | 186 | * Makes only one reconnect attempt Sets the client state to |
peyo |
0:cd5404401c2f | 187 | * pending reconnect in case of failure |
peyo |
0:cd5404401c2f | 188 | * |
peyo |
0:cd5404401c2f | 189 | * @param pClient Reference to the IoT Client |
peyo |
0:cd5404401c2f | 190 | * |
peyo |
0:cd5404401c2f | 191 | * @return An IoT Error Type defining successful/failed connection |
peyo |
0:cd5404401c2f | 192 | */ |
peyo |
0:cd5404401c2f | 193 | IoT_Error_t aws_iot_mqtt_attempt_reconnect(AWS_IoT_Client *pClient); |
peyo |
0:cd5404401c2f | 194 | |
peyo |
0:cd5404401c2f | 195 | #ifdef __cplusplus |
peyo |
0:cd5404401c2f | 196 | } |
peyo |
0:cd5404401c2f | 197 | #endif |
peyo |
0:cd5404401c2f | 198 | |
peyo |
0:cd5404401c2f | 199 | #endif |