Analog Devices Wi-Fi Software Reference Manual  Release 1.0.0
adi_wifi.h
Go to the documentation of this file.
1 
56 #ifndef ADI_WIFI_H
57 #define ADI_WIFI_H
58 
60 #include <stdint.h>
61 #include <string.h>
62 #include <adi_callback.h>
63 #include <rtos_map/adi_rtos_map.h>
66 #include <MQTTPacket.h>
67 #include <MQTTConnect.h>
68 
70 #define ADI_WIFI_LOCK(timeout)
71 
73 #define ADI_WIFI_UNLOCK_RADIO()
74 
76 #define ADI_WIFI_WAIT_FOR_COMPLETION(timeout) adi_wifi_WaitForResponseWithTimeout(timeout, gWiFiDevice.eCurCmdOpCode);
77 
79 #define ADI_WIFI_RADIO_CMD_START(x) { \
80  memset(pWiFiDevice->pDataPkt, 0u, sizeof(pWiFiDevice->pDataPkt)); \
81  pWiFiDevice->eCurCmdOpCode = x; \
82  pWiFiDevice->nResponseSize = 0; \
83  }
84 
86 #define ADI_WIFI_RADIO_CMD_END() { \
87  pWiFiDevice->eCurCmdOpCode = 0; \
88  }
89 
91 #define ADI_WIFI_RADIO_CMD_TIMEOUT (10000u)
92 
94 #define ADI_WIFI_RADIO_RST_DELAY (0xFFFFFFu)
95 
97 #define ADI_WIFI_RADIO_BOOT_DELAY (0xFFFFFu)
98 
100 #define ADI_WIFI_RADIO_PUBREL_RETRIES (0x5u)
101 
103 #define ADI_WIFI_RADIO_MAX_MODE (3u)
104 
106 #define ADI_WIFI_RADIO_MAX_NUM_CONNECTIONS (5u)
107 
109 #define ADI_WIFI_RADIO_MAX_KEEPALIVE (7200u)
110 
112 #define ADI_WIFI_RADIO_CIPSTATUS_RESP (0x3a)
113 
115 #define ADI_WIFI_MAX_SSID (32u)
116 
118 #define ADI_WIFI_MAX_PASSWORD (64u)
119 
121 #define ADI_WIFI_MAX_BSSID (48u)
122 
124 #define ADI_WIFI_MAX_IP_ADDR_SIZE (39u)
125 
127 #define ADI_WIFI_MAX_PORT_SIZE (5u)
128 
130 #define ADI_WIFI_AT_CMD "AT\r\n"
131 
133 #define ADI_WIFI_RST_CMD "AT+RST\r\n"
134 
136 #define ADI_WIFI_GMR_CMD "AT+GMR\r\n"
137 
139 #define ADI_WIFI_CWMODE_CMD "AT+CWMODE"
140 
142 #define ADI_WIFI_CWJAP_CMD "AT+CWJAP"
143 
145 #define ADI_WIFI_CWQAP_CMD "AT+CWQAP\r\n"
146 
148 #define ADI_WIFI_CIPSTART_CMD "AT+CIPSTART="
149 
151 #define ADI_WIFI_CIPSEND_CMD "AT+CIPSEND="
152 
154 #define ADI_WIFI_CIPMUX_CMD "AT+CIPMUX"
155 
157 #define ADI_WIFI_CIPSTATUS_CMD "AT+CIPSTATUS"
158 
159 #ifdef __cplusplus
160 extern "C" {
161 #endif /* __cplusplus */
162 
167 typedef enum
168 {
169  /* Overriding command interface with application specific callback events. */
170  CMD_NONE,
171  CMD_HW_ERROR,
173  /* Basic AT commands */
174  CMD_AT,
175  CMD_AT_RST,
176  CMD_AT_GMR,
177  CMD_AT_GSLP,
179  /* WiFi layer commands */
180  CMD_AT_CWMODE,
181  CMD_AT_CWJAP,
182  CMD_AT_CWLAP,
183  CMD_AT_CWQAP,
184  CMD_AT_CWSAP,
185  CMD_AT_CWLIF,
186  CMD_AT_CWDHCP,
187  CMD_AT_CIPSTAMAC,
188  CMD_AT_CIPAPMAC,
189  CMD_AT_CIPSTA,
190  CMD_AT_CIPAP,
192  /* TCP/IP layer */
193  CMD_AT_CIPSTATUS,
194  CMD_AT_CIPSTART,
195  CMD_AT_CIPSEND,
196  CMD_AT_CIPSEND_CONN,
197  CMD_AT_CIPSEND_DISCONN,
198  CMD_AT_CIPSEND_PUB,
199  CMD_AT_CIPSEND_PUBREL,
200  CMD_AT_CIPSEND_SUB,
201  CMD_AT_CIPSEND_PINGREQ,
202  CMD_AT_CIPCLOSE,
203  CMD_AT_CIFSR,
204  CMD_AT_CIPMUX,
205  CMD_AT_CIPSERVER,
206  CMD_AT_CIPMODE,
207  CMD_AT_CIPSTO,
208  CMD_AT_CIUPDATE,
209  CMD_AT_IPD,
211  CMD_AT_INVALID
212 } ADI_WIFI_AT_CMDCODE;
213 
214 
219 typedef enum
220 {
221  ADI_WIFI_SUCCESS,
222  ADI_WIFI_FAILURE,
224 } ADI_WIFI_RESULT;
225 
232 typedef struct
233 {
234  uint8_t nLinkID;
235  uint8_t *pType;
236  uint8_t *pIP;
237  uint8_t *pPort;
238  uint16_t nTCPKeepAlive;
239 }ADI_WIFI_TCP_CONNECT_CONFIG;
240 
247 typedef struct
248 {
249  uint8_t nLinkID;
250  uint8_t nVersion;
251  uint8_t *pName;
252  uint16_t nMQTTKeepAlive;
253 }ADI_WIFI_MQTT_CONNECT_CONFIG;
254 
261 typedef struct
262 {
263  uint8_t *pMQTTData;
264  uint32_t nMQTTDataSize;
265  uint8_t *pTopic;
266  uint8_t nLinkID;
267  uint8_t nQos;
268  uint8_t nPacketId;
269 }ADI_WIFI_PUBLISH_CONFIG;
270 
277 typedef struct
278 {
279  uint8_t nLinkID;
280  uint8_t *pData;
281  uint16_t nDataLength;
282 }ADI_WIFI_SEND_DATA_CONFIG;
283 
290 typedef struct
291 {
292  uint8_t *pTopic;
293  uint8_t nLinkID;
294  uint8_t nQos;
295  uint8_t nPacketId;
296 }ADI_WIFI_SUBSCRIBE_CONFIG;
297 
298 /* command APIs */
299 ADI_WIFI_RESULT adi_wifi_radio_Init(ADI_CALLBACK pCallbackFunc);
300 ADI_WIFI_RESULT adi_wifi_radio_TestAT(void);
301 ADI_WIFI_RESULT adi_wifi_radio_GetAP(uint8_t * const pAPInfo, uint32_t nBufSize);
302 ADI_WIFI_RESULT adi_wifi_radio_GetConnectionStatus(uint8_t * const pStatus);
303 ADI_WIFI_RESULT adi_wifi_radio_Restart(void);
304 ADI_WIFI_RESULT adi_wifi_radio_GetVersionInfo(uint8_t * const pVersionInfoBuf, uint32_t nBufSize);
305 ADI_WIFI_RESULT adi_wifi_radio_SetWiFiMode(uint32_t nMode);
306 ADI_WIFI_RESULT adi_wifi_radio_ConnectToAP(const uint8_t * const pSSID, const uint8_t * const pPassword, const uint8_t * const pBSSID);
307 ADI_WIFI_RESULT adi_wifi_radio_DisconnectFromAP(void);
308 ADI_WIFI_RESULT adi_wifi_radio_EstablishTCPConnection(ADI_WIFI_TCP_CONNECT_CONFIG *eTCPConnect);
309 ADI_WIFI_RESULT adi_wifi_radio_SendData(ADI_WIFI_SEND_DATA_CONFIG * const pSendDataConfig, ADI_WIFI_AT_CMDCODE eCipSendCmd);
310 ADI_WIFI_RESULT adi_wifi_radio_EnableMultipleConnections(uint8_t nEnable);
311 ADI_WIFI_RESULT adi_wifi_radio_MQTTConnect(ADI_WIFI_MQTT_CONNECT_CONFIG * const pMQTTConnect);
312 ADI_WIFI_RESULT adi_wifi_radio_MQTTPublish(ADI_WIFI_PUBLISH_CONFIG * const ePublishConfig);
313 ADI_WIFI_RESULT adi_wifi_radio_MQTTPing(uint32_t nLinkID);
314 ADI_WIFI_RESULT adi_wifi_radio_MQTTDisconnect(uint32_t nLinkID);
315 ADI_WIFI_RESULT adi_wifi_radio_MQTTSubscribe(ADI_WIFI_SUBSCRIBE_CONFIG * const pSubscribeConfig);
316 ADI_WIFI_RESULT adi_wifi_ParseSubscriberData(void);
317 ADI_WIFI_RESULT adi_wifi_GetEvent(ADI_WIFI_AT_CMDCODE eCommandType);
318 void adi_wifi_GetData(uint8_t * const pPacket, uint32_t * nValidBytes);
319 
320 #ifdef __cplusplus
321 }
322 #endif /* __cplusplus */
323 
324 #endif /* ADI_WIFI_H */
325 
326 
327 /* @} */
ADI_WIFI_RESULT adi_wifi_radio_MQTTPing(uint32_t nLinkID)
Ping the MQTT broker.
Definition: adi_wifi.c:909
ADI_WIFI_RESULT adi_wifi_radio_GetAP(uint8_t *const pAPInfo, uint32_t nBufSize)
Get information on the access point the Wi-Fi module is connected to.
Definition: adi_wifi.c:193
void adi_wifi_GetData(uint8_t *const pPacket, uint32_t *nValidBytes)
Get data packet.
Definition: adi_wifi.c:1238
: Header file for adi_wifi_transport.c Copyright (c) 2017 Analog Devices, Inc.
ADI_WIFI_RESULT adi_wifi_radio_MQTTSubscribe(ADI_WIFI_SUBSCRIBE_CONFIG *const pSubscribeConfig)
Subscribe to a topic.
Definition: adi_wifi.c:946
ADI_WIFI_RESULT adi_wifi_radio_GetVersionInfo(uint8_t *const pVersionInfoBuf, uint32_t nBufSize)
Get the AT command version and SDK version info.
Definition: adi_wifi.c:340
ADI_WIFI_RESULT adi_wifi_radio_SendData(ADI_WIFI_SEND_DATA_CONFIG *const pSendDataConfig, ADI_WIFI_AT_CMDCODE eCipSendCmd)
Send data to server.
Definition: adi_wifi.c:632
ADI_WIFI_RESULT adi_wifi_radio_ConnectToAP(const uint8_t *const pSSID, const uint8_t *const pPassword, const uint8_t *const pBSSID)
Connect to the access point.
Definition: adi_wifi.c:446
ADI_WIFI_RESULT adi_wifi_radio_Init(ADI_CALLBACK pCallbackFunc)
Initialize Wi-Fi module.
Definition: adi_wifi.c:100
ADI_WIFI_RESULT adi_wifi_radio_MQTTConnect(ADI_WIFI_MQTT_CONNECT_CONFIG *const pMQTTConnect)
Connect to a MQTT broker.
Definition: adi_wifi.c:776
ADI_WIFI_RESULT adi_wifi_radio_MQTTDisconnect(uint32_t nLinkID)
Disconnect from the MQTT broker.
Definition: adi_wifi.c:876
ADI_WIFI_RESULT adi_wifi_radio_DisconnectFromAP()
Disconnect from the access point.
Definition: adi_wifi.c:500
support functions to log wifi events
ADI_WIFI_RESULT adi_wifi_radio_TestAT()
Test AT command.
Definition: adi_wifi.c:257
ADI_WIFI_RESULT adi_wifi_radio_EnableMultipleConnections(uint8_t nEnable)
Enable/disable multiple connections.
Definition: adi_wifi.c:729
ADI_WIFI_RESULT adi_wifi_GetEvent(ADI_WIFI_AT_CMDCODE eCommandType)
Application event interface.
Definition: adi_wifi.c:985
ADI_WIFI_RESULT adi_wifi_radio_GetConnectionStatus(uint8_t *const pStatus)
Get information about the connection.
Definition: adi_wifi.c:134
ADI_WIFI_RESULT adi_wifi_radio_MQTTPublish(ADI_WIFI_PUBLISH_CONFIG *const pPublishConfig)
Publish MQTT data.
Definition: adi_wifi.c:819
ADI_WIFI_RESULT adi_wifi_radio_SetWiFiMode(uint32_t nMode)
Set the Wi-Fi mode.
Definition: adi_wifi.c:403
ADI_WIFI_RESULT adi_wifi_ParseSubscriberData()
Parse the +IPD messages received when the Wi-Fi module is acting as an MQTT subscriber.
Definition: adi_wifi.c:1191
ADI_WIFI_RESULT adi_wifi_radio_EstablishTCPConnection(ADI_WIFI_TCP_CONNECT_CONFIG *const pTCPConnect)
Establish TCP connection.
Definition: adi_wifi.c:546
ADI_WIFI_RESULT adi_wifi_radio_Restart()
Restart Wi-Fi module.
Definition: adi_wifi.c:290