![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
AWS IoT demonstration using the Avnet Shield (AT&T LTE) and the FRDM-K64F target board.
Dependencies: K64F_FATFileSystem
Fork of mbed-os-example-tls-tls-client by
AWS_openssl/aws_mqtt_embedded_client_lib/MQTTClient_C/src/MQTTClient.h@25:91d771247ac8, 2016-12-19 (annotated)
- Committer:
- ampembeng
- Date:
- Mon Dec 19 20:52:28 2016 +0000
- Revision:
- 25:91d771247ac8
- Parent:
- 15:6f2798e45099
Updated the look/feel of the Python GUI to match the AT&T locker demo S3 page. Added "assets" folder to support this. Updated the README.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ampembeng | 15:6f2798e45099 | 1 | /******************************************************************************* |
ampembeng | 15:6f2798e45099 | 2 | * Copyright (c) 2014 IBM Corp. |
ampembeng | 15:6f2798e45099 | 3 | * |
ampembeng | 15:6f2798e45099 | 4 | * All rights reserved. This program and the accompanying materials |
ampembeng | 15:6f2798e45099 | 5 | * are made available under the terms of the Eclipse Public License v1.0 |
ampembeng | 15:6f2798e45099 | 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. |
ampembeng | 15:6f2798e45099 | 7 | * |
ampembeng | 15:6f2798e45099 | 8 | * The Eclipse Public License is available at |
ampembeng | 15:6f2798e45099 | 9 | * http://www.eclipse.org/legal/epl-v10.html |
ampembeng | 15:6f2798e45099 | 10 | * and the Eclipse Distribution License is available at |
ampembeng | 15:6f2798e45099 | 11 | * http://www.eclipse.org/org/documents/edl-v10.php. |
ampembeng | 15:6f2798e45099 | 12 | * |
ampembeng | 15:6f2798e45099 | 13 | * Contributors: |
ampembeng | 15:6f2798e45099 | 14 | * Allan Stockdill-Mander/Ian Craggs - initial API and implementation and/or initial documentation |
ampembeng | 15:6f2798e45099 | 15 | *******************************************************************************/ |
ampembeng | 15:6f2798e45099 | 16 | |
ampembeng | 15:6f2798e45099 | 17 | #ifndef __MQTT_CLIENT_C_ |
ampembeng | 15:6f2798e45099 | 18 | #define __MQTT_CLIENT_C_ |
ampembeng | 15:6f2798e45099 | 19 | |
ampembeng | 15:6f2798e45099 | 20 | /* Library Header files */ |
ampembeng | 15:6f2798e45099 | 21 | #include "stdio.h" |
ampembeng | 15:6f2798e45099 | 22 | #include "stdint.h" |
ampembeng | 15:6f2798e45099 | 23 | #include "stddef.h" |
ampembeng | 15:6f2798e45099 | 24 | |
ampembeng | 15:6f2798e45099 | 25 | /* MQTT Specific header files */ |
ampembeng | 15:6f2798e45099 | 26 | #include "MQTTReturnCodes.h" |
ampembeng | 15:6f2798e45099 | 27 | #include "MQTTMessage.h" |
ampembeng | 15:6f2798e45099 | 28 | #include "MQTTPacket.h" |
ampembeng | 15:6f2798e45099 | 29 | |
ampembeng | 15:6f2798e45099 | 30 | /* AWS Specific header files */ |
ampembeng | 15:6f2798e45099 | 31 | #include "aws_iot_config.h" |
ampembeng | 15:6f2798e45099 | 32 | |
ampembeng | 15:6f2798e45099 | 33 | /* Platform specific implementation header files */ |
ampembeng | 15:6f2798e45099 | 34 | #include "network_interface.h" |
ampembeng | 15:6f2798e45099 | 35 | #include "timer_interface.h" |
ampembeng | 15:6f2798e45099 | 36 | |
ampembeng | 15:6f2798e45099 | 37 | #define MAX_PACKET_ID 65535 |
ampembeng | 15:6f2798e45099 | 38 | #define MAX_MESSAGE_HANDLERS AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS |
ampembeng | 15:6f2798e45099 | 39 | |
ampembeng | 15:6f2798e45099 | 40 | #define MIN_RECONNECT_WAIT_INTERVAL AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL |
ampembeng | 15:6f2798e45099 | 41 | #define MAX_RECONNECT_WAIT_INTERVAL AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL |
ampembeng | 15:6f2798e45099 | 42 | |
ampembeng | 15:6f2798e45099 | 43 | void NewTimer(Timer *); |
ampembeng | 15:6f2798e45099 | 44 | |
ampembeng | 15:6f2798e45099 | 45 | typedef struct Client Client; |
ampembeng | 15:6f2798e45099 | 46 | |
ampembeng | 15:6f2798e45099 | 47 | typedef struct MessageData MessageData; |
ampembeng | 15:6f2798e45099 | 48 | |
ampembeng | 15:6f2798e45099 | 49 | typedef void (*messageHandler)(MessageData *); |
ampembeng | 15:6f2798e45099 | 50 | typedef void (*pApplicationHandler_t)(void); |
ampembeng | 15:6f2798e45099 | 51 | typedef void (*disconnectHandler_t)(void); |
ampembeng | 15:6f2798e45099 | 52 | typedef int (*networkInitHandler_t)(Network *); |
ampembeng | 15:6f2798e45099 | 53 | |
ampembeng | 15:6f2798e45099 | 54 | struct MessageData { |
ampembeng | 15:6f2798e45099 | 55 | MQTTMessage *message; |
ampembeng | 15:6f2798e45099 | 56 | MQTTString *topicName; |
ampembeng | 15:6f2798e45099 | 57 | pApplicationHandler_t applicationHandler; |
ampembeng | 15:6f2798e45099 | 58 | }; |
ampembeng | 15:6f2798e45099 | 59 | |
ampembeng | 15:6f2798e45099 | 60 | MQTTReturnCode MQTTConnect(Client *c, MQTTPacket_connectData *options); |
ampembeng | 15:6f2798e45099 | 61 | MQTTReturnCode MQTTPublish (Client *, const char *, MQTTMessage *); |
ampembeng | 15:6f2798e45099 | 62 | MQTTReturnCode MQTTSubscribe(Client *c, const char *topicFilter, QoS qos, |
ampembeng | 15:6f2798e45099 | 63 | messageHandler messageHandler, pApplicationHandler_t applicationHandler); |
ampembeng | 15:6f2798e45099 | 64 | MQTTReturnCode MQTTResubscribe(Client *c); |
ampembeng | 15:6f2798e45099 | 65 | MQTTReturnCode MQTTUnsubscribe(Client *c, const char *topicFilter); |
ampembeng | 15:6f2798e45099 | 66 | MQTTReturnCode MQTTDisconnect (Client *); |
ampembeng | 15:6f2798e45099 | 67 | MQTTReturnCode MQTTYield (Client *, uint32_t); |
ampembeng | 15:6f2798e45099 | 68 | MQTTReturnCode MQTTAttemptReconnect(Client *c); |
ampembeng | 15:6f2798e45099 | 69 | |
ampembeng | 15:6f2798e45099 | 70 | uint8_t MQTTIsConnected(Client *); |
ampembeng | 15:6f2798e45099 | 71 | uint8_t MQTTIsAutoReconnectEnabled(Client *c); |
ampembeng | 15:6f2798e45099 | 72 | |
ampembeng | 15:6f2798e45099 | 73 | void setDefaultMessageHandler(Client *, messageHandler); |
ampembeng | 15:6f2798e45099 | 74 | MQTTReturnCode setDisconnectHandler(Client *c, disconnectHandler_t disconnectHandler); |
ampembeng | 15:6f2798e45099 | 75 | MQTTReturnCode setAutoReconnectEnabled(Client *c, uint8_t value); |
ampembeng | 15:6f2798e45099 | 76 | |
ampembeng | 15:6f2798e45099 | 77 | MQTTReturnCode MQTTClient(Client *, uint32_t, unsigned char *, size_t, unsigned char *, |
ampembeng | 15:6f2798e45099 | 78 | size_t, uint8_t, networkInitHandler_t, TLSConnectParams *); |
ampembeng | 15:6f2798e45099 | 79 | |
ampembeng | 15:6f2798e45099 | 80 | uint32_t MQTTGetNetworkDisconnectedCount(Client *c); |
ampembeng | 15:6f2798e45099 | 81 | void MQTTResetNetworkDisconnectedCount(Client *c); |
ampembeng | 15:6f2798e45099 | 82 | |
ampembeng | 15:6f2798e45099 | 83 | struct Client { |
ampembeng | 15:6f2798e45099 | 84 | uint8_t isConnected; |
ampembeng | 15:6f2798e45099 | 85 | uint8_t wasManuallyDisconnected; |
ampembeng | 15:6f2798e45099 | 86 | uint8_t isPingOutstanding; |
ampembeng | 15:6f2798e45099 | 87 | uint8_t isAutoReconnectEnabled; |
ampembeng | 15:6f2798e45099 | 88 | |
ampembeng | 15:6f2798e45099 | 89 | uint16_t nextPacketId; |
ampembeng | 15:6f2798e45099 | 90 | |
ampembeng | 15:6f2798e45099 | 91 | uint32_t commandTimeoutMs; |
ampembeng | 15:6f2798e45099 | 92 | uint32_t keepAliveInterval; |
ampembeng | 15:6f2798e45099 | 93 | uint32_t currentReconnectWaitInterval; |
ampembeng | 15:6f2798e45099 | 94 | uint32_t counterNetworkDisconnected; |
ampembeng | 15:6f2798e45099 | 95 | |
ampembeng | 15:6f2798e45099 | 96 | size_t bufSize; |
ampembeng | 15:6f2798e45099 | 97 | size_t readBufSize; |
ampembeng | 15:6f2798e45099 | 98 | |
ampembeng | 15:6f2798e45099 | 99 | unsigned char *buf; |
ampembeng | 15:6f2798e45099 | 100 | unsigned char *readbuf; |
ampembeng | 15:6f2798e45099 | 101 | |
ampembeng | 15:6f2798e45099 | 102 | TLSConnectParams tlsConnectParams; |
ampembeng | 15:6f2798e45099 | 103 | MQTTPacket_connectData options; |
ampembeng | 15:6f2798e45099 | 104 | |
ampembeng | 15:6f2798e45099 | 105 | Network networkStack; |
ampembeng | 15:6f2798e45099 | 106 | Timer pingTimer; |
ampembeng | 15:6f2798e45099 | 107 | Timer reconnectDelayTimer; |
ampembeng | 15:6f2798e45099 | 108 | |
ampembeng | 15:6f2798e45099 | 109 | struct MessageHandlers { |
ampembeng | 15:6f2798e45099 | 110 | const char *topicFilter; |
ampembeng | 15:6f2798e45099 | 111 | void (*fp) (MessageData *); |
ampembeng | 15:6f2798e45099 | 112 | pApplicationHandler_t applicationHandler; |
ampembeng | 15:6f2798e45099 | 113 | QoS qos; |
ampembeng | 15:6f2798e45099 | 114 | } messageHandlers[MAX_MESSAGE_HANDLERS]; /* Message handlers are indexed by subscription topic */ |
ampembeng | 15:6f2798e45099 | 115 | |
ampembeng | 15:6f2798e45099 | 116 | void (* defaultMessageHandler) (MessageData *); |
ampembeng | 15:6f2798e45099 | 117 | disconnectHandler_t disconnectHandler; |
ampembeng | 15:6f2798e45099 | 118 | networkInitHandler_t networkInitHandler; |
ampembeng | 15:6f2798e45099 | 119 | }; |
ampembeng | 15:6f2798e45099 | 120 | |
ampembeng | 15:6f2798e45099 | 121 | #define DefaultClient {0, 0, 0, 0, NULL, NULL, 0, 0, 0} |
ampembeng | 15:6f2798e45099 | 122 | |
ampembeng | 15:6f2798e45099 | 123 | #endif |
ampembeng | 15:6f2798e45099 | 124 | |
ampembeng | 15:6f2798e45099 | 125 |