added function to enable power saving mode for es_wifi driver (Inventek Systems ISM43362-M3G-L44 )
Fork of DISCO_L475VG_IOT01A_wifi by
es_wifi.c@2:9bbbcd0eff1c, 2018-01-13 (annotated)
- Committer:
- jaafaryn
- Date:
- Sat Jan 13 23:37:46 2018 +0000
- Revision:
- 2:9bbbcd0eff1c
- Parent:
- 1:b37920c1ddb9
added function to enable power saving mode
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
adustm | 0:c61a93635433 | 1 | /** |
adustm | 0:c61a93635433 | 2 | ****************************************************************************** |
adustm | 0:c61a93635433 | 3 | * @file es-wifi.c |
adustm | 0:c61a93635433 | 4 | * @author MCD Application Team |
adustm | 0:c61a93635433 | 5 | * @version V1.8.0 |
adustm | 0:c61a93635433 | 6 | * @date 21-April-2017 |
adustm | 0:c61a93635433 | 7 | * @brief This file provides a set of functions to manage the es-wifi module. |
adustm | 0:c61a93635433 | 8 | ****************************************************************************** |
adustm | 0:c61a93635433 | 9 | * @attention |
adustm | 0:c61a93635433 | 10 | * |
adustm | 0:c61a93635433 | 11 | * <h2><center>© Copyright © 2017 STMicroelectronics International N.V. |
adustm | 0:c61a93635433 | 12 | * All rights reserved.</center></h2> |
adustm | 0:c61a93635433 | 13 | * |
adustm | 0:c61a93635433 | 14 | * Redistribution and use in source and binary forms, with or without |
adustm | 0:c61a93635433 | 15 | * modification, are permitted, provided that the following conditions are met: |
adustm | 0:c61a93635433 | 16 | * |
adustm | 0:c61a93635433 | 17 | * 1. Redistribution of source code must retain the above copyright notice, |
adustm | 0:c61a93635433 | 18 | * this list of conditions and the following disclaimer. |
adustm | 0:c61a93635433 | 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
adustm | 0:c61a93635433 | 20 | * this list of conditions and the following disclaimer in the documentation |
adustm | 0:c61a93635433 | 21 | * and/or other materials provided with the distribution. |
adustm | 0:c61a93635433 | 22 | * 3. Neither the name of STMicroelectronics nor the names of other |
adustm | 0:c61a93635433 | 23 | * contributors to this software may be used to endorse or promote products |
adustm | 0:c61a93635433 | 24 | * derived from this software without specific written permission. |
adustm | 0:c61a93635433 | 25 | * 4. This software, including modifications and/or derivative works of this |
adustm | 0:c61a93635433 | 26 | * software, must execute solely and exclusively on microcontroller or |
adustm | 0:c61a93635433 | 27 | * microprocessor devices manufactured by or for STMicroelectronics. |
adustm | 0:c61a93635433 | 28 | * 5. Redistribution and use of this software other than as permitted under |
adustm | 0:c61a93635433 | 29 | * this license is void and will automatically terminate your rights under |
adustm | 0:c61a93635433 | 30 | * this license. |
adustm | 0:c61a93635433 | 31 | * |
adustm | 0:c61a93635433 | 32 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" |
adustm | 0:c61a93635433 | 33 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT |
adustm | 0:c61a93635433 | 34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
adustm | 0:c61a93635433 | 35 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY |
adustm | 0:c61a93635433 | 36 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT |
adustm | 0:c61a93635433 | 37 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
adustm | 0:c61a93635433 | 38 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
adustm | 0:c61a93635433 | 39 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
adustm | 0:c61a93635433 | 40 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
adustm | 0:c61a93635433 | 41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
adustm | 0:c61a93635433 | 42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
adustm | 0:c61a93635433 | 43 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
adustm | 0:c61a93635433 | 44 | * |
adustm | 0:c61a93635433 | 45 | ****************************************************************************** |
adustm | 0:c61a93635433 | 46 | */ |
adustm | 0:c61a93635433 | 47 | /* Includes ------------------------------------------------------------------*/ |
adustm | 0:c61a93635433 | 48 | #include "es_wifi.h" |
adustm | 0:c61a93635433 | 49 | |
adustm | 0:c61a93635433 | 50 | #define AT_OK_STRING "\r\nOK\r\n> " |
adustm | 0:c61a93635433 | 51 | #define AT_OK_STRING_LEN 8 |
adustm | 0:c61a93635433 | 52 | |
adustm | 0:c61a93635433 | 53 | #define AT_ERROR_STRING "\r\nERROR" |
adustm | 0:c61a93635433 | 54 | |
adustm | 0:c61a93635433 | 55 | |
adustm | 0:c61a93635433 | 56 | |
adustm | 0:c61a93635433 | 57 | #define CHARISHEXNUM(x) (((x) >= '0' && (x) <= '9') || \ |
adustm | 0:c61a93635433 | 58 | ((x) >= 'a' && (x) <= 'f') || \ |
adustm | 0:c61a93635433 | 59 | ((x) >= 'A' && (x) <= 'F')) |
adustm | 0:c61a93635433 | 60 | |
adustm | 0:c61a93635433 | 61 | #define CHARISNUM(x) ((x) >= '0' && (x) <= '9') |
adustm | 0:c61a93635433 | 62 | #define CHAR2NUM(x) ((x) - '0') |
adustm | 0:c61a93635433 | 63 | /* Private function prototypes -----------------------------------------------*/ |
adustm | 0:c61a93635433 | 64 | static uint8_t Hex2Num(char a); |
adustm | 0:c61a93635433 | 65 | static uint32_t ParseHexNumber(char* ptr, uint8_t* cnt); |
adustm | 0:c61a93635433 | 66 | static uint32_t ParseHexNumber(char* ptr, uint8_t* cnt); |
adustm | 0:c61a93635433 | 67 | static void ParseMAC(char* ptr, uint8_t* arr); |
adustm | 0:c61a93635433 | 68 | static void ParseIP(char* ptr, uint8_t* arr); |
adustm | 0:c61a93635433 | 69 | static ES_WIFI_SecurityType_t ParseSecurity(char* ptr); |
adustm | 0:c61a93635433 | 70 | #if (ES_WIFI_USE_UART == 1) |
adustm | 0:c61a93635433 | 71 | static void AT_ParseUARTConfig(char *pdata, ES_WIFI_UARTConfig_t *pConfig); |
adustm | 0:c61a93635433 | 72 | #endif |
adustm | 0:c61a93635433 | 73 | static void AT_ParseSystemConfig(char *pdata, ES_WIFI_SystemConfig_t *pConfig); |
adustm | 0:c61a93635433 | 74 | static void AT_ParseConnSettings(char *pdata, ES_WIFI_Network_t *NetSettings); |
adustm | 0:c61a93635433 | 75 | static ES_WIFI_Status_t AT_ExecuteCommand(ES_WIFIObject_t *Obj, uint8_t* cmd, uint8_t *pdata); |
adustm | 0:c61a93635433 | 76 | |
adustm | 0:c61a93635433 | 77 | /* Private functions ---------------------------------------------------------*/ |
adustm | 0:c61a93635433 | 78 | /** |
adustm | 0:c61a93635433 | 79 | * @brief Convert char in Hex format to integer. |
adustm | 0:c61a93635433 | 80 | * @param a: character to convert |
adustm | 0:c61a93635433 | 81 | * @retval integer value. |
adustm | 0:c61a93635433 | 82 | */ |
adustm | 0:c61a93635433 | 83 | static uint8_t Hex2Num(char a) |
adustm | 0:c61a93635433 | 84 | { |
adustm | 0:c61a93635433 | 85 | if (a >= '0' && a <= '9') { /* Char is num */ |
adustm | 0:c61a93635433 | 86 | return a - '0'; |
adustm | 0:c61a93635433 | 87 | } else if (a >= 'a' && a <= 'f') { /* Char is lowercase character A - Z (hex) */ |
adustm | 0:c61a93635433 | 88 | return (a - 'a') + 10; |
adustm | 0:c61a93635433 | 89 | } else if (a >= 'A' && a <= 'F') { /* Char is uppercase character A - Z (hex) */ |
adustm | 0:c61a93635433 | 90 | return (a - 'A') + 10; |
adustm | 0:c61a93635433 | 91 | } |
adustm | 0:c61a93635433 | 92 | |
adustm | 0:c61a93635433 | 93 | return 0; |
adustm | 0:c61a93635433 | 94 | } |
adustm | 0:c61a93635433 | 95 | |
adustm | 0:c61a93635433 | 96 | /** |
adustm | 0:c61a93635433 | 97 | * @brief Extract a hex number from a string. |
adustm | 0:c61a93635433 | 98 | * @param ptr: pointer to string |
adustm | 0:c61a93635433 | 99 | * @param cnt: pointer to the number of parsed digit |
adustm | 0:c61a93635433 | 100 | * @retval Hex value. |
adustm | 0:c61a93635433 | 101 | */ |
adustm | 0:c61a93635433 | 102 | static uint32_t ParseHexNumber(char* ptr, uint8_t* cnt) |
adustm | 0:c61a93635433 | 103 | { |
adustm | 0:c61a93635433 | 104 | uint32_t sum = 0; |
adustm | 0:c61a93635433 | 105 | uint8_t i = 0; |
adustm | 0:c61a93635433 | 106 | |
adustm | 0:c61a93635433 | 107 | while (CHARISHEXNUM(*ptr)) { /* Parse number */ |
adustm | 0:c61a93635433 | 108 | sum <<= 4; |
adustm | 0:c61a93635433 | 109 | sum += Hex2Num(*ptr); |
adustm | 0:c61a93635433 | 110 | ptr++; |
adustm | 0:c61a93635433 | 111 | i++; |
adustm | 0:c61a93635433 | 112 | } |
adustm | 0:c61a93635433 | 113 | |
adustm | 0:c61a93635433 | 114 | if (cnt != NULL) { /* Save number of characters used for number */ |
adustm | 0:c61a93635433 | 115 | *cnt = i; |
adustm | 0:c61a93635433 | 116 | } |
adustm | 0:c61a93635433 | 117 | return sum; /* Return number */ |
adustm | 0:c61a93635433 | 118 | } |
adustm | 0:c61a93635433 | 119 | |
adustm | 0:c61a93635433 | 120 | /** |
adustm | 0:c61a93635433 | 121 | * @brief Parses and returns number from string. |
adustm | 0:c61a93635433 | 122 | * @param ptr: pointer to string |
adustm | 0:c61a93635433 | 123 | * @param cnt: pointer to the number of parsed digit |
adustm | 0:c61a93635433 | 124 | * @retval integer value. |
adustm | 0:c61a93635433 | 125 | */ |
adustm | 0:c61a93635433 | 126 | static int32_t ParseNumber(char* ptr, uint8_t* cnt) |
adustm | 0:c61a93635433 | 127 | { |
adustm | 0:c61a93635433 | 128 | uint8_t minus = 0, i = 0; |
adustm | 0:c61a93635433 | 129 | int32_t sum = 0; |
adustm | 0:c61a93635433 | 130 | |
adustm | 0:c61a93635433 | 131 | if (*ptr == '-') { /* Check for minus character */ |
adustm | 0:c61a93635433 | 132 | minus = 1; |
adustm | 0:c61a93635433 | 133 | ptr++; |
adustm | 0:c61a93635433 | 134 | i++; |
adustm | 0:c61a93635433 | 135 | } |
adustm | 0:c61a93635433 | 136 | while (CHARISNUM(*ptr)) { /* Parse number */ |
adustm | 0:c61a93635433 | 137 | sum = 10 * sum + CHAR2NUM(*ptr); |
adustm | 0:c61a93635433 | 138 | ptr++; |
adustm | 0:c61a93635433 | 139 | i++; |
adustm | 0:c61a93635433 | 140 | } |
adustm | 0:c61a93635433 | 141 | if (cnt != NULL) { /* Save number of characters used for number */ |
adustm | 0:c61a93635433 | 142 | *cnt = i; |
adustm | 0:c61a93635433 | 143 | } |
adustm | 0:c61a93635433 | 144 | if (minus) { /* Minus detected */ |
adustm | 0:c61a93635433 | 145 | return 0 - sum; |
adustm | 0:c61a93635433 | 146 | } |
adustm | 0:c61a93635433 | 147 | return sum; /* Return number */ |
adustm | 0:c61a93635433 | 148 | } |
adustm | 0:c61a93635433 | 149 | |
adustm | 0:c61a93635433 | 150 | /** |
adustm | 0:c61a93635433 | 151 | * @brief Parses and returns MAC address. |
adustm | 0:c61a93635433 | 152 | * @param ptr: pointer to string |
adustm | 0:c61a93635433 | 153 | * @param arr: pointer to MAC array |
adustm | 0:c61a93635433 | 154 | * @retval None. |
adustm | 0:c61a93635433 | 155 | */ |
adustm | 0:c61a93635433 | 156 | static void ParseMAC(char* ptr, uint8_t* arr) |
adustm | 0:c61a93635433 | 157 | { |
adustm | 0:c61a93635433 | 158 | uint8_t hexnum = 0, hexcnt; |
adustm | 0:c61a93635433 | 159 | |
adustm | 0:c61a93635433 | 160 | while(* ptr) { |
adustm | 0:c61a93635433 | 161 | hexcnt = 1; |
adustm | 0:c61a93635433 | 162 | if(*ptr != ':') |
adustm | 0:c61a93635433 | 163 | { |
adustm | 0:c61a93635433 | 164 | arr[hexnum++] = ParseHexNumber(ptr, &hexcnt); |
adustm | 0:c61a93635433 | 165 | } |
adustm | 0:c61a93635433 | 166 | ptr = ptr + hexcnt; |
adustm | 0:c61a93635433 | 167 | } |
adustm | 0:c61a93635433 | 168 | } |
adustm | 0:c61a93635433 | 169 | |
adustm | 0:c61a93635433 | 170 | /** |
adustm | 0:c61a93635433 | 171 | * @brief Parses and returns IP address. |
adustm | 0:c61a93635433 | 172 | * @param ptr: pointer to string |
adustm | 0:c61a93635433 | 173 | * @param arr: pointer to IP array |
adustm | 0:c61a93635433 | 174 | * @retval None. |
adustm | 0:c61a93635433 | 175 | */ |
adustm | 0:c61a93635433 | 176 | static void ParseIP(char* ptr, uint8_t* arr) |
adustm | 0:c61a93635433 | 177 | { |
adustm | 0:c61a93635433 | 178 | uint8_t hexnum = 0, hexcnt; |
adustm | 0:c61a93635433 | 179 | |
adustm | 0:c61a93635433 | 180 | while(* ptr) { |
adustm | 0:c61a93635433 | 181 | hexcnt = 1; |
adustm | 0:c61a93635433 | 182 | if(*ptr != '.') |
adustm | 0:c61a93635433 | 183 | { |
adustm | 0:c61a93635433 | 184 | arr[hexnum++] = ParseNumber(ptr, &hexcnt); |
adustm | 0:c61a93635433 | 185 | } |
adustm | 0:c61a93635433 | 186 | ptr = ptr + hexcnt; |
adustm | 0:c61a93635433 | 187 | } |
adustm | 0:c61a93635433 | 188 | } |
adustm | 0:c61a93635433 | 189 | |
adustm | 0:c61a93635433 | 190 | /** |
adustm | 0:c61a93635433 | 191 | * @brief Parses Security type. |
adustm | 0:c61a93635433 | 192 | * @param ptr: pointer to string |
adustm | 0:c61a93635433 | 193 | * @retval Encryption type. |
adustm | 0:c61a93635433 | 194 | */ |
adustm | 0:c61a93635433 | 195 | static ES_WIFI_SecurityType_t ParseSecurity(char* ptr) |
adustm | 0:c61a93635433 | 196 | { |
adustm | 0:c61a93635433 | 197 | if(strstr(ptr,"Open")) return ES_WIFI_SEC_OPEN; |
adustm | 0:c61a93635433 | 198 | else if(strstr(ptr,"WEP")) return ES_WIFI_SEC_WEP; |
adustm | 0:c61a93635433 | 199 | else if(strstr(ptr,"WPA")) return ES_WIFI_SEC_WPA; |
adustm | 0:c61a93635433 | 200 | else if(strstr(ptr,"WPA2")) return ES_WIFI_SEC_WPA2; |
adustm | 0:c61a93635433 | 201 | else if(strstr(ptr,"WPA WPA2")) return ES_WIFI_SEC_WPA_WPA2; |
adustm | 0:c61a93635433 | 202 | else if(strstr(ptr,"WPA2 TKIP")) return ES_WIFI_SEC_WPA2_TKIP; |
adustm | 0:c61a93635433 | 203 | else return ES_WIFI_SEC_UNKNOWN; |
adustm | 0:c61a93635433 | 204 | } |
adustm | 0:c61a93635433 | 205 | |
adustm | 0:c61a93635433 | 206 | /** |
adustm | 0:c61a93635433 | 207 | * @brief Parses ES module informations and save them in the handle. |
adustm | 0:c61a93635433 | 208 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 209 | * @param ptr: pointer to string |
adustm | 0:c61a93635433 | 210 | * @retval None. |
adustm | 0:c61a93635433 | 211 | */ |
adustm | 0:c61a93635433 | 212 | static void AT_ParseInfo(ES_WIFIObject_t *Obj,uint8_t *pdata) |
adustm | 0:c61a93635433 | 213 | { |
adustm | 0:c61a93635433 | 214 | char *ptr; |
adustm | 0:c61a93635433 | 215 | uint8_t num = 0; |
adustm | 0:c61a93635433 | 216 | |
adustm | 0:c61a93635433 | 217 | ptr = strtok((char *)pdata + 2, ","); |
adustm | 0:c61a93635433 | 218 | |
adustm | 0:c61a93635433 | 219 | while (ptr != NULL){ |
adustm | 0:c61a93635433 | 220 | switch (num++) { |
adustm | 0:c61a93635433 | 221 | case 0: |
adustm | 0:c61a93635433 | 222 | strncpy((char *)Obj->Product_ID, ptr, ES_WIFI_PRODUCT_ID_SIZE); |
adustm | 0:c61a93635433 | 223 | break; |
adustm | 0:c61a93635433 | 224 | |
adustm | 0:c61a93635433 | 225 | case 1: |
adustm | 0:c61a93635433 | 226 | strncpy((char *)Obj->FW_Rev, ptr, ES_WIFI_FW_REV_SIZE ); |
adustm | 0:c61a93635433 | 227 | break; |
adustm | 0:c61a93635433 | 228 | |
adustm | 0:c61a93635433 | 229 | case 2: |
adustm | 0:c61a93635433 | 230 | strncpy((char *)Obj->API_Rev, ptr, ES_WIFI_API_REV_SIZE); |
adustm | 0:c61a93635433 | 231 | break; |
adustm | 0:c61a93635433 | 232 | |
adustm | 0:c61a93635433 | 233 | case 3: |
adustm | 0:c61a93635433 | 234 | strncpy((char *)Obj->Stack_Rev, ptr, ES_WIFI_STACK_REV_SIZE); |
adustm | 0:c61a93635433 | 235 | break; |
adustm | 0:c61a93635433 | 236 | |
adustm | 0:c61a93635433 | 237 | case 4: |
adustm | 0:c61a93635433 | 238 | strncpy((char *)Obj->RTOS_Rev, ptr, ES_WIFI_RTOS_REV_SIZE); |
adustm | 0:c61a93635433 | 239 | break; |
adustm | 0:c61a93635433 | 240 | |
adustm | 0:c61a93635433 | 241 | case 5: |
adustm | 0:c61a93635433 | 242 | Obj->CPU_Clock = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 243 | break; |
adustm | 0:c61a93635433 | 244 | |
adustm | 0:c61a93635433 | 245 | case 6: |
adustm | 0:c61a93635433 | 246 | ptr = strtok(ptr, "\r"); |
adustm | 0:c61a93635433 | 247 | strncpy((char *)Obj->Product_Name, ptr, ES_WIFI_PRODUCT_NAME_SIZE); |
adustm | 0:c61a93635433 | 248 | break; |
adustm | 0:c61a93635433 | 249 | |
adustm | 0:c61a93635433 | 250 | default: break; |
adustm | 0:c61a93635433 | 251 | } |
adustm | 0:c61a93635433 | 252 | ptr = strtok(NULL, ","); |
adustm | 0:c61a93635433 | 253 | } |
adustm | 0:c61a93635433 | 254 | } |
adustm | 0:c61a93635433 | 255 | |
adustm | 0:c61a93635433 | 256 | /** |
adustm | 0:c61a93635433 | 257 | * @brief Parses Access point configuration. |
adustm | 0:c61a93635433 | 258 | * @param APs: Access points structure |
adustm | 0:c61a93635433 | 259 | * @param ptr: pointer to string |
adustm | 0:c61a93635433 | 260 | * @retval None. |
adustm | 0:c61a93635433 | 261 | */ |
adustm | 0:c61a93635433 | 262 | static void AT_ParseAP(char *pdata, ES_WIFI_APs_t *APs) |
adustm | 0:c61a93635433 | 263 | { |
adustm | 0:c61a93635433 | 264 | uint8_t num = 0; |
adustm | 0:c61a93635433 | 265 | char *ptr; |
adustm | 0:c61a93635433 | 266 | APs->nbr = 0; |
adustm | 0:c61a93635433 | 267 | |
adustm | 0:c61a93635433 | 268 | ptr = strtok(pdata + 2, ","); |
adustm | 0:c61a93635433 | 269 | |
adustm | 0:c61a93635433 | 270 | while ((ptr != NULL) && (APs->nbr < ES_WIFI_MAX_DETECTED_AP)) { |
adustm | 0:c61a93635433 | 271 | switch (num++) { |
adustm | 0:c61a93635433 | 272 | case 0: /* Ignore index */ |
adustm | 0:c61a93635433 | 273 | case 4: /* Ignore Max Rate */ |
adustm | 0:c61a93635433 | 274 | case 5: /* Ignore Network Type */ |
adustm | 0:c61a93635433 | 275 | case 7: /* Ignore Radio Band */ |
adustm | 0:c61a93635433 | 276 | break; |
adustm | 0:c61a93635433 | 277 | |
adustm | 0:c61a93635433 | 278 | case 1: |
adustm | 0:c61a93635433 | 279 | ptr[strlen(ptr) - 1] = 0; |
adustm | 0:c61a93635433 | 280 | strncpy((char *)APs->AP[APs->nbr].SSID, ptr+ 1, ES_WIFI_MAX_SSID_NAME_SIZE + 1); |
adustm | 0:c61a93635433 | 281 | break; |
adustm | 0:c61a93635433 | 282 | |
adustm | 0:c61a93635433 | 283 | case 2: |
adustm | 0:c61a93635433 | 284 | ParseMAC(ptr, APs->AP[APs->nbr].MAC); |
adustm | 0:c61a93635433 | 285 | break; |
adustm | 0:c61a93635433 | 286 | |
adustm | 0:c61a93635433 | 287 | case 3: |
adustm | 0:c61a93635433 | 288 | APs->AP[APs->nbr].RSSI = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 289 | break; |
adustm | 0:c61a93635433 | 290 | |
adustm | 0:c61a93635433 | 291 | case 6: |
adustm | 0:c61a93635433 | 292 | APs->AP[APs->nbr].Security = ParseSecurity(ptr); |
adustm | 0:c61a93635433 | 293 | break; |
adustm | 0:c61a93635433 | 294 | |
adustm | 0:c61a93635433 | 295 | case 8: |
adustm | 0:c61a93635433 | 296 | APs->AP[APs->nbr].Channel = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 297 | APs->nbr++; |
adustm | 0:c61a93635433 | 298 | num = 1; |
adustm | 0:c61a93635433 | 299 | break; |
adustm | 0:c61a93635433 | 300 | |
adustm | 0:c61a93635433 | 301 | default: |
adustm | 0:c61a93635433 | 302 | break; |
adustm | 0:c61a93635433 | 303 | } |
adustm | 0:c61a93635433 | 304 | ptr = strtok(NULL, ","); |
adustm | 0:c61a93635433 | 305 | } |
adustm | 0:c61a93635433 | 306 | } |
adustm | 0:c61a93635433 | 307 | |
adustm | 0:c61a93635433 | 308 | #if (ES_WIFI_USE_UART == 1) |
adustm | 0:c61a93635433 | 309 | /** |
adustm | 0:c61a93635433 | 310 | * @brief Parses UART configuration. |
adustm | 0:c61a93635433 | 311 | * @param APs: UART Config structure |
adustm | 0:c61a93635433 | 312 | * @param ptr: pointer to string |
adustm | 0:c61a93635433 | 313 | * @retval None. |
adustm | 0:c61a93635433 | 314 | */ |
adustm | 0:c61a93635433 | 315 | static void AT_ParseUARTConfig(char *pdata, ES_WIFI_UARTConfig_t *pConfig) |
adustm | 0:c61a93635433 | 316 | { |
adustm | 0:c61a93635433 | 317 | uint8_t num = 0; |
adustm | 0:c61a93635433 | 318 | char *ptr; |
adustm | 0:c61a93635433 | 319 | |
adustm | 0:c61a93635433 | 320 | ptr = strtok(pdata + 2, ","); |
adustm | 0:c61a93635433 | 321 | |
adustm | 0:c61a93635433 | 322 | while (ptr != NULL) { |
adustm | 0:c61a93635433 | 323 | switch (num++) { |
adustm | 0:c61a93635433 | 324 | case 0: |
adustm | 0:c61a93635433 | 325 | pConfig->Port = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 326 | break; |
adustm | 0:c61a93635433 | 327 | |
adustm | 0:c61a93635433 | 328 | case 1: |
adustm | 0:c61a93635433 | 329 | pConfig->BaudRate = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 330 | break; |
adustm | 0:c61a93635433 | 331 | |
adustm | 0:c61a93635433 | 332 | case 2: |
adustm | 0:c61a93635433 | 333 | pConfig->DataWidth = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 334 | break; |
adustm | 0:c61a93635433 | 335 | |
adustm | 0:c61a93635433 | 336 | case 3: |
adustm | 0:c61a93635433 | 337 | pConfig->Parity = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 338 | break; |
adustm | 0:c61a93635433 | 339 | |
adustm | 0:c61a93635433 | 340 | case 4: |
adustm | 0:c61a93635433 | 341 | pConfig->StopBits = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 342 | break; |
adustm | 0:c61a93635433 | 343 | |
adustm | 0:c61a93635433 | 344 | case 5: |
adustm | 0:c61a93635433 | 345 | pConfig->Mode = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 346 | break; |
adustm | 0:c61a93635433 | 347 | |
adustm | 0:c61a93635433 | 348 | default: |
adustm | 0:c61a93635433 | 349 | break; |
adustm | 0:c61a93635433 | 350 | } |
adustm | 0:c61a93635433 | 351 | ptr = strtok(NULL, ","); |
adustm | 0:c61a93635433 | 352 | } |
adustm | 0:c61a93635433 | 353 | } |
adustm | 0:c61a93635433 | 354 | #endif |
adustm | 0:c61a93635433 | 355 | |
adustm | 0:c61a93635433 | 356 | /** |
adustm | 0:c61a93635433 | 357 | * @brief Parses System configuration. |
adustm | 0:c61a93635433 | 358 | * @param APs: System Config structure |
adustm | 0:c61a93635433 | 359 | * @param ptr: pointer to string |
adustm | 0:c61a93635433 | 360 | * @retval None. |
adustm | 0:c61a93635433 | 361 | */ |
adustm | 0:c61a93635433 | 362 | static void AT_ParseSystemConfig(char *pdata, ES_WIFI_SystemConfig_t *pConfig) |
adustm | 0:c61a93635433 | 363 | { |
adustm | 0:c61a93635433 | 364 | uint8_t num = 0; |
adustm | 0:c61a93635433 | 365 | char *ptr; |
adustm | 0:c61a93635433 | 366 | |
adustm | 0:c61a93635433 | 367 | ptr = strtok(pdata + 2, ","); |
adustm | 0:c61a93635433 | 368 | |
adustm | 0:c61a93635433 | 369 | while (ptr != NULL) { |
adustm | 0:c61a93635433 | 370 | switch (num++) { |
adustm | 0:c61a93635433 | 371 | case 0: |
adustm | 0:c61a93635433 | 372 | pConfig->Configuration = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 373 | break; |
adustm | 0:c61a93635433 | 374 | |
adustm | 0:c61a93635433 | 375 | case 1: |
adustm | 0:c61a93635433 | 376 | pConfig->WPSPin = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 377 | break; |
adustm | 0:c61a93635433 | 378 | |
adustm | 0:c61a93635433 | 379 | case 2: |
adustm | 0:c61a93635433 | 380 | pConfig->VID = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 381 | break; |
adustm | 0:c61a93635433 | 382 | |
adustm | 0:c61a93635433 | 383 | case 3: |
adustm | 0:c61a93635433 | 384 | pConfig->PID = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 385 | break; |
adustm | 0:c61a93635433 | 386 | |
adustm | 0:c61a93635433 | 387 | case 4: |
adustm | 0:c61a93635433 | 388 | ParseMAC(ptr, pConfig->MAC); |
adustm | 0:c61a93635433 | 389 | break; |
adustm | 0:c61a93635433 | 390 | |
adustm | 0:c61a93635433 | 391 | case 5: |
adustm | 0:c61a93635433 | 392 | ParseIP(ptr, pConfig->AP_IPAddress); |
adustm | 0:c61a93635433 | 393 | break; |
adustm | 0:c61a93635433 | 394 | |
adustm | 0:c61a93635433 | 395 | case 6: |
adustm | 0:c61a93635433 | 396 | pConfig->PS_Mode = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 397 | break; |
adustm | 0:c61a93635433 | 398 | |
adustm | 0:c61a93635433 | 399 | case 7: |
adustm | 0:c61a93635433 | 400 | pConfig->RadioMode = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 401 | break; |
adustm | 0:c61a93635433 | 402 | |
adustm | 0:c61a93635433 | 403 | case 8: |
adustm | 0:c61a93635433 | 404 | pConfig->CurrentBeacon = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 405 | break; |
adustm | 0:c61a93635433 | 406 | |
adustm | 0:c61a93635433 | 407 | case 9: |
adustm | 0:c61a93635433 | 408 | pConfig->PrevBeacon = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 409 | break; |
adustm | 0:c61a93635433 | 410 | |
adustm | 0:c61a93635433 | 411 | case 10: |
adustm | 0:c61a93635433 | 412 | pConfig->ProductName = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 413 | break; |
adustm | 0:c61a93635433 | 414 | |
adustm | 0:c61a93635433 | 415 | default: |
adustm | 0:c61a93635433 | 416 | break; |
adustm | 0:c61a93635433 | 417 | } |
adustm | 0:c61a93635433 | 418 | ptr = strtok(NULL, ","); |
adustm | 0:c61a93635433 | 419 | } |
adustm | 0:c61a93635433 | 420 | } |
adustm | 0:c61a93635433 | 421 | |
adustm | 0:c61a93635433 | 422 | |
adustm | 0:c61a93635433 | 423 | /** |
adustm | 0:c61a93635433 | 424 | * @brief Parses WIFI connection settings. |
adustm | 0:c61a93635433 | 425 | * @param NetSettings: settings |
adustm | 0:c61a93635433 | 426 | * @param pdata: pointer to data |
adustm | 0:c61a93635433 | 427 | * @retval None. |
adustm | 0:c61a93635433 | 428 | */ |
adustm | 0:c61a93635433 | 429 | static void AT_ParseConnSettings(char *pdata, ES_WIFI_Network_t *NetSettings) |
adustm | 0:c61a93635433 | 430 | { |
adustm | 0:c61a93635433 | 431 | uint8_t num = 0; |
adustm | 0:c61a93635433 | 432 | char *ptr; |
adustm | 0:c61a93635433 | 433 | |
adustm | 0:c61a93635433 | 434 | ptr = strtok(pdata + 2, ","); |
adustm | 0:c61a93635433 | 435 | |
adustm | 0:c61a93635433 | 436 | while (ptr != NULL) { |
adustm | 0:c61a93635433 | 437 | switch (num++) { |
adustm | 0:c61a93635433 | 438 | case 0: |
adustm | 0:c61a93635433 | 439 | strncpy((char *)NetSettings->SSID, ptr, ES_WIFI_MAX_SSID_NAME_SIZE + 1); |
adustm | 0:c61a93635433 | 440 | break; |
adustm | 0:c61a93635433 | 441 | |
adustm | 0:c61a93635433 | 442 | case 1: |
adustm | 0:c61a93635433 | 443 | strncpy((char *)NetSettings->pswd, ptr, ES_WIFI_MAX_PSWD_NAME_SIZE + 1); |
adustm | 0:c61a93635433 | 444 | break; |
adustm | 0:c61a93635433 | 445 | |
adustm | 0:c61a93635433 | 446 | case 2: |
adustm | 0:c61a93635433 | 447 | NetSettings->Security = (ES_WIFI_SecurityType_t)ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 448 | break; |
adustm | 0:c61a93635433 | 449 | |
adustm | 0:c61a93635433 | 450 | case 3: |
adustm | 0:c61a93635433 | 451 | NetSettings->DHCP_IsEnabled = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 452 | break; |
adustm | 0:c61a93635433 | 453 | |
adustm | 0:c61a93635433 | 454 | case 4: |
adustm | 0:c61a93635433 | 455 | NetSettings->IP_Ver = (ES_WIFI_IPVer_t)ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 456 | break; |
adustm | 0:c61a93635433 | 457 | |
adustm | 0:c61a93635433 | 458 | case 5: |
adustm | 0:c61a93635433 | 459 | ParseIP(ptr, NetSettings->IP_Addr); |
adustm | 0:c61a93635433 | 460 | break; |
adustm | 0:c61a93635433 | 461 | |
adustm | 0:c61a93635433 | 462 | case 6: |
adustm | 0:c61a93635433 | 463 | ParseIP(ptr, NetSettings->IP_Mask); |
adustm | 0:c61a93635433 | 464 | break; |
adustm | 0:c61a93635433 | 465 | |
adustm | 0:c61a93635433 | 466 | case 7: |
adustm | 0:c61a93635433 | 467 | ParseIP(ptr, NetSettings->Gateway_Addr); |
adustm | 0:c61a93635433 | 468 | break; |
adustm | 0:c61a93635433 | 469 | |
adustm | 0:c61a93635433 | 470 | case 8: |
adustm | 0:c61a93635433 | 471 | ParseIP(ptr, NetSettings->DNS1); |
adustm | 0:c61a93635433 | 472 | break; |
adustm | 0:c61a93635433 | 473 | |
adustm | 0:c61a93635433 | 474 | case 9: |
adustm | 0:c61a93635433 | 475 | ParseIP(ptr, NetSettings->DNS2); |
adustm | 0:c61a93635433 | 476 | break; |
adustm | 0:c61a93635433 | 477 | |
adustm | 0:c61a93635433 | 478 | case 10: |
adustm | 0:c61a93635433 | 479 | NetSettings->JoinRetries = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 480 | break; |
adustm | 0:c61a93635433 | 481 | |
adustm | 0:c61a93635433 | 482 | case 11: |
adustm | 0:c61a93635433 | 483 | NetSettings->AutoConnect = ParseNumber(ptr, NULL); |
adustm | 0:c61a93635433 | 484 | break; |
adustm | 0:c61a93635433 | 485 | |
adustm | 0:c61a93635433 | 486 | default: |
adustm | 0:c61a93635433 | 487 | break; |
adustm | 0:c61a93635433 | 488 | } |
adustm | 0:c61a93635433 | 489 | ptr = strtok(NULL, ","); |
adustm | 0:c61a93635433 | 490 | if ((ptr != NULL) && (ptr[-1] == ',')) |
adustm | 0:c61a93635433 | 491 | { /* Ignore empty fields */ |
adustm | 0:c61a93635433 | 492 | num++; |
adustm | 0:c61a93635433 | 493 | } |
adustm | 0:c61a93635433 | 494 | } |
adustm | 0:c61a93635433 | 495 | } |
adustm | 0:c61a93635433 | 496 | |
adustm | 0:c61a93635433 | 497 | /** |
adustm | 0:c61a93635433 | 498 | * @brief Execute AT command. |
adustm | 0:c61a93635433 | 499 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 500 | * @param cmd: pointer to command string |
adustm | 0:c61a93635433 | 501 | * @param pdata: pointer to returned data |
adustm | 0:c61a93635433 | 502 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 503 | */ |
adustm | 0:c61a93635433 | 504 | static ES_WIFI_Status_t AT_ExecuteCommand(ES_WIFIObject_t *Obj, uint8_t* cmd, uint8_t *pdata) |
adustm | 0:c61a93635433 | 505 | { |
adustm | 0:c61a93635433 | 506 | if(Obj->fops.IO_Send(cmd, strlen((char*)cmd), Obj->Timeout) > 0) |
adustm | 0:c61a93635433 | 507 | { |
adustm | 0:c61a93635433 | 508 | int16_t n=Obj->fops.IO_Receive(pdata, 0, Obj->Timeout); |
adustm | 0:c61a93635433 | 509 | if(n > 0) |
adustm | 0:c61a93635433 | 510 | { |
adustm | 0:c61a93635433 | 511 | *(pdata+n)=0; |
adustm | 0:c61a93635433 | 512 | if(strstr((char *)pdata, AT_OK_STRING)) |
adustm | 0:c61a93635433 | 513 | { |
adustm | 0:c61a93635433 | 514 | return ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 515 | } |
adustm | 0:c61a93635433 | 516 | else if(strstr((char *)pdata, AT_ERROR_STRING)) |
adustm | 0:c61a93635433 | 517 | { |
adustm | 0:c61a93635433 | 518 | return ES_WIFI_STATUS_ERROR; |
adustm | 0:c61a93635433 | 519 | } |
adustm | 0:c61a93635433 | 520 | } |
adustm | 0:c61a93635433 | 521 | } |
adustm | 0:c61a93635433 | 522 | return ES_WIFI_STATUS_IO_ERROR; |
adustm | 0:c61a93635433 | 523 | } |
adustm | 0:c61a93635433 | 524 | |
adustm | 0:c61a93635433 | 525 | /** |
adustm | 0:c61a93635433 | 526 | * @brief Execute AT command with data. |
adustm | 0:c61a93635433 | 527 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 528 | * @param cmd: pointer to command string |
adustm | 0:c61a93635433 | 529 | * @param pcmd_data: pointer to binary data |
adustm | 0:c61a93635433 | 530 | * @param len: binary data length |
adustm | 0:c61a93635433 | 531 | * @param pdata: pointer to returned data |
adustm | 0:c61a93635433 | 532 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 533 | */ |
adustm | 0:c61a93635433 | 534 | static ES_WIFI_Status_t AT_RequestSendData(ES_WIFIObject_t *Obj, uint8_t* cmd, uint8_t *pcmd_data, uint16_t len, uint8_t *pdata) |
adustm | 0:c61a93635433 | 535 | { |
adustm | 0:c61a93635433 | 536 | /* can send only even number of byte on first send */ |
adustm | 0:c61a93635433 | 537 | uint16_t n=strlen((char*)cmd); |
adustm | 0:c61a93635433 | 538 | if (n &1 ) return ES_WIFI_STATUS_ERROR; |
adustm | 0:c61a93635433 | 539 | if(Obj->fops.IO_Send(cmd, n, Obj->Timeout) == n) |
adustm | 0:c61a93635433 | 540 | { |
adustm | 0:c61a93635433 | 541 | int16_t n=Obj->fops.IO_Send(pcmd_data, len, Obj->Timeout); |
adustm | 0:c61a93635433 | 542 | if(n == len) |
adustm | 0:c61a93635433 | 543 | { |
adustm | 0:c61a93635433 | 544 | n = Obj->fops.IO_Receive(pdata, 0, Obj->Timeout); |
adustm | 0:c61a93635433 | 545 | if(n > 0) |
adustm | 0:c61a93635433 | 546 | { |
adustm | 0:c61a93635433 | 547 | *(pdata+n)=0; |
adustm | 0:c61a93635433 | 548 | if(strstr((char *)pdata, AT_OK_STRING)) |
adustm | 0:c61a93635433 | 549 | { |
adustm | 0:c61a93635433 | 550 | return ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 551 | } |
adustm | 0:c61a93635433 | 552 | else if(strstr((char *)pdata, AT_ERROR_STRING)) |
adustm | 0:c61a93635433 | 553 | { |
adustm | 0:c61a93635433 | 554 | return ES_WIFI_STATUS_ERROR; |
adustm | 0:c61a93635433 | 555 | } |
adustm | 0:c61a93635433 | 556 | } |
adustm | 0:c61a93635433 | 557 | } |
adustm | 0:c61a93635433 | 558 | else |
adustm | 0:c61a93635433 | 559 | { |
adustm | 0:c61a93635433 | 560 | return ES_WIFI_STATUS_ERROR; |
adustm | 0:c61a93635433 | 561 | } |
adustm | 0:c61a93635433 | 562 | } |
adustm | 0:c61a93635433 | 563 | return ES_WIFI_STATUS_IO_ERROR; |
adustm | 0:c61a93635433 | 564 | } |
adustm | 0:c61a93635433 | 565 | |
adustm | 0:c61a93635433 | 566 | |
adustm | 0:c61a93635433 | 567 | /** |
adustm | 0:c61a93635433 | 568 | * @brief Parses Received short data length. |
adustm | 0:c61a93635433 | 569 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 570 | * @param cmd:command formatted string |
adustm | 0:c61a93635433 | 571 | * @param pdata: payload |
adustm | 0:c61a93635433 | 572 | * @param Reqlen : requested Data length. |
adustm | 0:c61a93635433 | 573 | * @param ReadData : pointer to received data length. |
adustm | 0:c61a93635433 | 574 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 575 | */ |
adustm | 0:c61a93635433 | 576 | static ES_WIFI_Status_t ReceiveShortDataLen(ES_WIFIObject_t *Obj, char *pdata, uint16_t Reqlen, uint16_t *ReadData) |
adustm | 0:c61a93635433 | 577 | { |
adustm | 0:c61a93635433 | 578 | uint16_t len; |
adustm | 0:c61a93635433 | 579 | |
adustm | 0:c61a93635433 | 580 | len = Obj->fops.IO_Receive(Obj->CmdData, Reqlen + AT_OK_STRING_LEN , Obj->Timeout); |
adustm | 0:c61a93635433 | 581 | |
adustm | 0:c61a93635433 | 582 | if (len >= AT_OK_STRING_LEN) |
adustm | 0:c61a93635433 | 583 | { |
adustm | 0:c61a93635433 | 584 | if(strstr((char *)Obj->CmdData + len - AT_OK_STRING_LEN, AT_OK_STRING)) |
adustm | 0:c61a93635433 | 585 | { |
adustm | 0:c61a93635433 | 586 | *ReadData = len - AT_OK_STRING_LEN; |
adustm | 0:c61a93635433 | 587 | memcpy(pdata, Obj->CmdData, *ReadData); |
adustm | 0:c61a93635433 | 588 | return ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 589 | } |
adustm | 0:c61a93635433 | 590 | } |
adustm | 0:c61a93635433 | 591 | return ES_WIFI_STATUS_IO_ERROR; |
adustm | 0:c61a93635433 | 592 | |
adustm | 0:c61a93635433 | 593 | } |
adustm | 0:c61a93635433 | 594 | |
adustm | 0:c61a93635433 | 595 | /** |
adustm | 0:c61a93635433 | 596 | * @brief Parses Received long data length. |
adustm | 0:c61a93635433 | 597 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 598 | * @param cmd:command formatted string |
adustm | 0:c61a93635433 | 599 | * @param pdata: payload |
adustm | 0:c61a93635433 | 600 | * @param Reqlen : requested Data length. |
adustm | 0:c61a93635433 | 601 | * @param ReadData : pointer to received data length. |
adustm | 0:c61a93635433 | 602 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 603 | */ |
adustm | 0:c61a93635433 | 604 | static ES_WIFI_Status_t ReceiveLongDataLen(ES_WIFIObject_t *Obj, char *pdata, uint16_t Reqlen, uint16_t *ReadData) |
adustm | 0:c61a93635433 | 605 | { |
adustm | 0:c61a93635433 | 606 | uint16_t len, rlen; |
adustm | 0:c61a93635433 | 607 | |
adustm | 0:c61a93635433 | 608 | len = Obj->fops.IO_Receive((uint8_t *)pdata, Reqlen, Obj->Timeout); |
adustm | 0:c61a93635433 | 609 | |
adustm | 0:c61a93635433 | 610 | if (len >= AT_OK_STRING_LEN) |
adustm | 0:c61a93635433 | 611 | { |
adustm | 0:c61a93635433 | 612 | if(strstr((char *)pdata + len - AT_OK_STRING_LEN, AT_OK_STRING)) |
adustm | 0:c61a93635433 | 613 | { |
adustm | 0:c61a93635433 | 614 | *ReadData = len - AT_OK_STRING_LEN; |
adustm | 0:c61a93635433 | 615 | return ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 616 | } |
adustm | 0:c61a93635433 | 617 | else |
adustm | 0:c61a93635433 | 618 | { |
adustm | 0:c61a93635433 | 619 | memcpy(Obj->CmdData, pdata + len - AT_OK_STRING_LEN, AT_OK_STRING_LEN); |
adustm | 0:c61a93635433 | 620 | rlen = Obj->fops.IO_Receive(Obj->CmdData + AT_OK_STRING_LEN, AT_OK_STRING_LEN, Obj->Timeout); |
adustm | 0:c61a93635433 | 621 | |
adustm | 0:c61a93635433 | 622 | if(strstr((char *) Obj->CmdData + rlen, AT_OK_STRING)) |
adustm | 0:c61a93635433 | 623 | { |
adustm | 0:c61a93635433 | 624 | *ReadData = len + rlen - AT_OK_STRING_LEN; |
adustm | 0:c61a93635433 | 625 | return ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 626 | } |
adustm | 0:c61a93635433 | 627 | } |
adustm | 0:c61a93635433 | 628 | } |
adustm | 0:c61a93635433 | 629 | return ES_WIFI_STATUS_IO_ERROR; |
adustm | 0:c61a93635433 | 630 | } |
adustm | 0:c61a93635433 | 631 | |
adustm | 0:c61a93635433 | 632 | /** |
adustm | 0:c61a93635433 | 633 | * @brief Parses Received data. |
adustm | 0:c61a93635433 | 634 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 635 | * @param cmd:command formatted string |
adustm | 0:c61a93635433 | 636 | * @param pdata: payload |
adustm | 0:c61a93635433 | 637 | * @param Reqlen : requested Data length. |
adustm | 0:c61a93635433 | 638 | * @param ReadData : pointer to received data length. |
adustm | 0:c61a93635433 | 639 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 640 | */ |
adustm | 0:c61a93635433 | 641 | static ES_WIFI_Status_t AT_RequestReceiveData(ES_WIFIObject_t *Obj, uint8_t* cmd, char *pdata, uint16_t Reqlen, uint16_t *ReadData) |
adustm | 0:c61a93635433 | 642 | { |
adustm | 0:c61a93635433 | 643 | if(Obj->fops.IO_Send(cmd, strlen((char*)cmd), Obj->Timeout) > 0) |
adustm | 0:c61a93635433 | 644 | { |
adustm | 0:c61a93635433 | 645 | if(Obj->fops.IO_Receive(Obj->CmdData, 2, Obj->Timeout) == 2) /* Read Prompt */ |
adustm | 0:c61a93635433 | 646 | { |
adustm | 0:c61a93635433 | 647 | if (Reqlen <= AT_OK_STRING_LEN) return ReceiveShortDataLen(Obj,pdata, Reqlen ,ReadData); |
adustm | 0:c61a93635433 | 648 | if (Reqlen > AT_OK_STRING_LEN) return ReceiveLongDataLen(Obj,pdata, Reqlen ,ReadData); |
adustm | 0:c61a93635433 | 649 | } |
adustm | 0:c61a93635433 | 650 | } |
adustm | 0:c61a93635433 | 651 | return ES_WIFI_STATUS_IO_ERROR; |
adustm | 0:c61a93635433 | 652 | } |
adustm | 0:c61a93635433 | 653 | |
adustm | 0:c61a93635433 | 654 | |
adustm | 0:c61a93635433 | 655 | /** |
adustm | 0:c61a93635433 | 656 | * @brief Initialize WIFI module. |
adustm | 0:c61a93635433 | 657 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 658 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 659 | */ |
adustm | 0:c61a93635433 | 660 | ES_WIFI_Status_t ES_WIFI_Init(ES_WIFIObject_t *Obj) |
adustm | 0:c61a93635433 | 661 | { |
adustm | 0:c61a93635433 | 662 | ES_WIFI_Status_t ret = ES_WIFI_STATUS_ERROR; |
adustm | 0:c61a93635433 | 663 | |
adustm | 0:c61a93635433 | 664 | Obj->Timeout = ES_WIFI_TIMEOUT; |
adustm | 0:c61a93635433 | 665 | |
adustm | 0:c61a93635433 | 666 | if (Obj->fops.IO_Init() == 0) |
adustm | 0:c61a93635433 | 667 | { |
adustm | 0:c61a93635433 | 668 | ret = AT_ExecuteCommand(Obj,(uint8_t*)"I?\r\n", Obj->CmdData); |
adustm | 0:c61a93635433 | 669 | |
adustm | 0:c61a93635433 | 670 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 671 | { |
adustm | 0:c61a93635433 | 672 | AT_ParseInfo (Obj, Obj->CmdData); |
adustm | 0:c61a93635433 | 673 | } |
adustm | 0:c61a93635433 | 674 | } |
adustm | 0:c61a93635433 | 675 | return ret; |
adustm | 0:c61a93635433 | 676 | } |
adustm | 0:c61a93635433 | 677 | |
adustm | 0:c61a93635433 | 678 | /** |
adustm | 0:c61a93635433 | 679 | * @brief Return ProductID. |
adustm | 0:c61a93635433 | 680 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 681 | * @param productID: pointer productID |
adustm | 0:c61a93635433 | 682 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 683 | */ |
adustm | 0:c61a93635433 | 684 | ES_WIFI_Status_t ES_WIFI_GetProductID(ES_WIFIObject_t *Obj, uint8_t *productID) |
adustm | 0:c61a93635433 | 685 | { |
adustm | 0:c61a93635433 | 686 | strncpy((char *)productID, (char *)Obj->Product_ID, ES_WIFI_PRODUCT_ID_SIZE); |
adustm | 0:c61a93635433 | 687 | return ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 688 | } |
adustm | 0:c61a93635433 | 689 | |
adustm | 0:c61a93635433 | 690 | /** |
adustm | 0:c61a93635433 | 691 | * @brief Return Firmware Revision. |
adustm | 0:c61a93635433 | 692 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 693 | * @param productID: pointer Revision |
adustm | 0:c61a93635433 | 694 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 695 | */ |
adustm | 0:c61a93635433 | 696 | ES_WIFI_Status_t ES_WIFI_GetFWRevID(ES_WIFIObject_t *Obj, uint8_t *FWRev) |
adustm | 0:c61a93635433 | 697 | { |
adustm | 0:c61a93635433 | 698 | strncpy((char *)FWRev, (char *)Obj->FW_Rev, ES_WIFI_FW_REV_SIZE); |
adustm | 0:c61a93635433 | 699 | return ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 700 | } |
adustm | 0:c61a93635433 | 701 | |
adustm | 0:c61a93635433 | 702 | /** |
adustm | 0:c61a93635433 | 703 | * @brief Return product Name. |
adustm | 0:c61a93635433 | 704 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 705 | * @param productID: pointer product Name |
adustm | 0:c61a93635433 | 706 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 707 | */ |
adustm | 0:c61a93635433 | 708 | ES_WIFI_Status_t ES_WIFI_GetProductName(ES_WIFIObject_t *Obj, uint8_t *productName) |
adustm | 0:c61a93635433 | 709 | { |
adustm | 0:c61a93635433 | 710 | strncpy((char *)productName, (char *)Obj->Product_Name, ES_WIFI_PRODUCT_NAME_SIZE); |
adustm | 0:c61a93635433 | 711 | return ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 712 | } |
adustm | 0:c61a93635433 | 713 | |
adustm | 0:c61a93635433 | 714 | /** |
adustm | 0:c61a93635433 | 715 | * @brief Return API revision. |
adustm | 0:c61a93635433 | 716 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 717 | * @param productID: pointer API revision. |
adustm | 0:c61a93635433 | 718 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 719 | */ |
adustm | 0:c61a93635433 | 720 | ES_WIFI_Status_t ES_WIFI_GetAPIRev(ES_WIFIObject_t *Obj, uint8_t *APIRev) |
adustm | 0:c61a93635433 | 721 | { |
adustm | 0:c61a93635433 | 722 | strncpy((char *)APIRev, (char *)Obj->API_Rev, ES_WIFI_API_REV_SIZE); |
adustm | 0:c61a93635433 | 723 | return ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 724 | } |
adustm | 0:c61a93635433 | 725 | |
adustm | 0:c61a93635433 | 726 | /** |
adustm | 0:c61a93635433 | 727 | * @brief Return Stack Revision. |
adustm | 0:c61a93635433 | 728 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 729 | * @param productID: pointer Stack Revision |
adustm | 0:c61a93635433 | 730 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 731 | */ |
adustm | 0:c61a93635433 | 732 | ES_WIFI_Status_t ES_WIFI_GetStackRev(ES_WIFIObject_t *Obj, uint8_t *StackRev) |
adustm | 0:c61a93635433 | 733 | { |
adustm | 0:c61a93635433 | 734 | strncpy((char *)StackRev, (char *)Obj->Stack_Rev, ES_WIFI_STACK_REV_SIZE); |
adustm | 0:c61a93635433 | 735 | return ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 736 | } |
adustm | 0:c61a93635433 | 737 | |
adustm | 0:c61a93635433 | 738 | /** |
adustm | 0:c61a93635433 | 739 | * @brief Return RTOS Revision |
adustm | 0:c61a93635433 | 740 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 741 | * @param productID: pointer RTOS Revision |
adustm | 0:c61a93635433 | 742 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 743 | */ |
adustm | 0:c61a93635433 | 744 | ES_WIFI_Status_t ES_WIFI_GetRTOSRev(ES_WIFIObject_t *Obj, uint8_t *RTOSRev) |
adustm | 0:c61a93635433 | 745 | { |
adustm | 0:c61a93635433 | 746 | strncpy((char *)RTOSRev, (char *)Obj->RTOS_Rev, ES_WIFI_RTOS_REV_SIZE); |
adustm | 0:c61a93635433 | 747 | return ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 748 | } |
adustm | 0:c61a93635433 | 749 | |
adustm | 0:c61a93635433 | 750 | |
adustm | 0:c61a93635433 | 751 | /** |
adustm | 0:c61a93635433 | 752 | * @brief Initialize WIFI module. |
adustm | 0:c61a93635433 | 753 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 754 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 755 | */ |
adustm | 0:c61a93635433 | 756 | ES_WIFI_Status_t ES_WIFI_RegisterBusIO(ES_WIFIObject_t *Obj, IO_Init_Func IO_Init, |
adustm | 0:c61a93635433 | 757 | IO_DeInit_Func IO_DeInit, |
adustm | 0:c61a93635433 | 758 | IO_Delay_Func IO_Delay, |
adustm | 0:c61a93635433 | 759 | IO_Send_Func IO_Send, |
adustm | 0:c61a93635433 | 760 | IO_Receive_Func IO_Receive) |
adustm | 0:c61a93635433 | 761 | { |
adustm | 0:c61a93635433 | 762 | if(!Obj || !IO_Init || !IO_DeInit || !IO_Send || !IO_Receive) |
adustm | 0:c61a93635433 | 763 | { |
adustm | 0:c61a93635433 | 764 | return ES_WIFI_STATUS_ERROR; |
adustm | 0:c61a93635433 | 765 | } |
adustm | 0:c61a93635433 | 766 | |
adustm | 0:c61a93635433 | 767 | Obj->fops.IO_Init = IO_Init; |
adustm | 0:c61a93635433 | 768 | Obj->fops.IO_Send = IO_Send; |
adustm | 0:c61a93635433 | 769 | Obj->fops.IO_Receive = IO_Receive; |
adustm | 0:c61a93635433 | 770 | Obj->fops.IO_Delay = IO_Delay; |
adustm | 0:c61a93635433 | 771 | |
adustm | 0:c61a93635433 | 772 | return ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 773 | } |
adustm | 0:c61a93635433 | 774 | |
adustm | 0:c61a93635433 | 775 | /** |
adustm | 0:c61a93635433 | 776 | * @brief Change default Timeout. |
adustm | 0:c61a93635433 | 777 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 778 | * @param Timeout: Timeout in mS |
adustm | 0:c61a93635433 | 779 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 780 | */ |
adustm | 0:c61a93635433 | 781 | ES_WIFI_Status_t ES_WIFI_SetTimeout(ES_WIFIObject_t *Obj, uint32_t Timeout) |
adustm | 0:c61a93635433 | 782 | { |
adustm | 0:c61a93635433 | 783 | Obj->Timeout = Timeout; |
adustm | 0:c61a93635433 | 784 | return ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 785 | } |
adustm | 0:c61a93635433 | 786 | |
adustm | 0:c61a93635433 | 787 | /** |
adustm | 0:c61a93635433 | 788 | * @brief List all detected APs. |
adustm | 0:c61a93635433 | 789 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 790 | * @param APs: pointer Access points structure |
adustm | 0:c61a93635433 | 791 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 792 | */ |
adustm | 0:c61a93635433 | 793 | ES_WIFI_Status_t ES_WIFI_ListAccessPoints(ES_WIFIObject_t *Obj, ES_WIFI_APs_t *APs) |
adustm | 0:c61a93635433 | 794 | { |
adustm | 0:c61a93635433 | 795 | |
adustm | 0:c61a93635433 | 796 | ES_WIFI_Status_t ret; |
adustm | 0:c61a93635433 | 797 | |
adustm | 0:c61a93635433 | 798 | ret = AT_ExecuteCommand(Obj,(uint8_t*)"F0\r", Obj->CmdData); |
adustm | 0:c61a93635433 | 799 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 800 | { |
adustm | 0:c61a93635433 | 801 | AT_ParseAP((char *)Obj->CmdData, APs); |
adustm | 0:c61a93635433 | 802 | } |
adustm | 0:c61a93635433 | 803 | return ret; |
adustm | 0:c61a93635433 | 804 | } |
adustm | 0:c61a93635433 | 805 | |
adustm | 0:c61a93635433 | 806 | /** |
adustm | 0:c61a93635433 | 807 | * @brief Join an Access point. |
adustm | 0:c61a93635433 | 808 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 809 | * @param Ssid: the access point id. |
adustm | 0:c61a93635433 | 810 | * @param Password: the Access point password. |
adustm | 0:c61a93635433 | 811 | * @param SecType: Security type. |
adustm | 0:c61a93635433 | 812 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 813 | */ |
adustm | 0:c61a93635433 | 814 | ES_WIFI_Status_t ES_WIFI_Connect(ES_WIFIObject_t *Obj, const char* SSID, |
adustm | 0:c61a93635433 | 815 | const char* Password, |
adustm | 0:c61a93635433 | 816 | ES_WIFI_SecurityType_t SecType) |
adustm | 0:c61a93635433 | 817 | { |
adustm | 0:c61a93635433 | 818 | ES_WIFI_Status_t ret; |
adustm | 0:c61a93635433 | 819 | |
adustm | 0:c61a93635433 | 820 | sprintf((char*)Obj->CmdData,"C1=%s\r", SSID); |
adustm | 0:c61a93635433 | 821 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 822 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 823 | { |
adustm | 0:c61a93635433 | 824 | sprintf((char*)Obj->CmdData,"C2=%s\r", Password); |
adustm | 0:c61a93635433 | 825 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 826 | |
adustm | 0:c61a93635433 | 827 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 828 | { |
adustm | 0:c61a93635433 | 829 | Obj->Security = SecType; |
adustm | 0:c61a93635433 | 830 | sprintf((char*)Obj->CmdData,"C3=%d\r", (uint8_t)SecType); |
adustm | 0:c61a93635433 | 831 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 832 | |
adustm | 0:c61a93635433 | 833 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 834 | { |
adustm | 0:c61a93635433 | 835 | sprintf((char*)Obj->CmdData,"C0\r"); |
adustm | 0:c61a93635433 | 836 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 837 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 838 | { |
adustm | 0:c61a93635433 | 839 | Obj->NetSettings.IsConnected = 1; |
adustm | 0:c61a93635433 | 840 | } |
adustm | 0:c61a93635433 | 841 | } |
adustm | 0:c61a93635433 | 842 | } |
adustm | 0:c61a93635433 | 843 | } |
adustm | 0:c61a93635433 | 844 | return ret; |
adustm | 0:c61a93635433 | 845 | } |
adustm | 0:c61a93635433 | 846 | |
adustm | 0:c61a93635433 | 847 | /** |
jaafaryn | 1:b37920c1ddb9 | 848 | * @brief Enter power save mode. |
jaafaryn | 1:b37920c1ddb9 | 849 | * @param beacon_int: |
jaafaryn | 1:b37920c1ddb9 | 850 | * @param sleep_ms: |
jaafaryn | 1:b37920c1ddb9 | 851 | * @retval Operation Status. |
jaafaryn | 1:b37920c1ddb9 | 852 | */ |
jaafaryn | 1:b37920c1ddb9 | 853 | |
jaafaryn | 2:9bbbcd0eff1c | 854 | ES_WIFI_Status_t ES_WIFI_SetPowerSaveMode(ES_WIFIObject_t *Obj, uint8_t beacon_int, uint32_t sleep_ms) |
jaafaryn | 1:b37920c1ddb9 | 855 | { |
jaafaryn | 1:b37920c1ddb9 | 856 | ES_WIFI_Status_t ret; |
jaafaryn | 1:b37920c1ddb9 | 857 | sprintf((char*)Obj->CmdData,"ZP=2,%d\r", beacon_int); |
jaafaryn | 1:b37920c1ddb9 | 858 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
jaafaryn | 1:b37920c1ddb9 | 859 | if(ret == ES_WIFI_STATUS_OK) { |
jaafaryn | 1:b37920c1ddb9 | 860 | sprintf((char*)Obj->CmdData,"ZP=6,%d\r", sleep_ms); |
jaafaryn | 1:b37920c1ddb9 | 861 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
jaafaryn | 1:b37920c1ddb9 | 862 | } |
jaafaryn | 1:b37920c1ddb9 | 863 | return ret; |
jaafaryn | 1:b37920c1ddb9 | 864 | } |
jaafaryn | 1:b37920c1ddb9 | 865 | |
jaafaryn | 1:b37920c1ddb9 | 866 | /** |
adustm | 0:c61a93635433 | 867 | * @brief Check whether the module is connected to an access point. |
adustm | 0:c61a93635433 | 868 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 869 | */ |
adustm | 0:c61a93635433 | 870 | uint8_t ES_WIFI_IsConnected(ES_WIFIObject_t *Obj) |
adustm | 0:c61a93635433 | 871 | { |
adustm | 0:c61a93635433 | 872 | return Obj->NetSettings.IsConnected; |
adustm | 0:c61a93635433 | 873 | } |
adustm | 0:c61a93635433 | 874 | /** |
adustm | 0:c61a93635433 | 875 | * @brief Disconnect from a network. |
adustm | 0:c61a93635433 | 876 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 877 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 878 | */ |
adustm | 0:c61a93635433 | 879 | ES_WIFI_Status_t ES_WIFI_Disconnect(ES_WIFIObject_t *Obj) |
adustm | 0:c61a93635433 | 880 | { |
adustm | 0:c61a93635433 | 881 | sprintf((char*)Obj->CmdData,"CD\r"); |
adustm | 0:c61a93635433 | 882 | return AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 883 | } |
adustm | 0:c61a93635433 | 884 | /** |
adustm | 0:c61a93635433 | 885 | * @brief Return network settings. |
adustm | 0:c61a93635433 | 886 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 887 | * @param Pointer to network setting structure. |
adustm | 0:c61a93635433 | 888 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 889 | */ |
adustm | 0:c61a93635433 | 890 | ES_WIFI_Status_t ES_WIFI_GetNetworkSettings(ES_WIFIObject_t *Obj) |
adustm | 0:c61a93635433 | 891 | { |
adustm | 0:c61a93635433 | 892 | ES_WIFI_Status_t ret; |
adustm | 0:c61a93635433 | 893 | |
adustm | 0:c61a93635433 | 894 | sprintf((char*)Obj->CmdData,"C?\r"); |
adustm | 0:c61a93635433 | 895 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 896 | |
adustm | 0:c61a93635433 | 897 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 898 | { |
adustm | 0:c61a93635433 | 899 | AT_ParseConnSettings((char *)Obj->CmdData, &Obj->NetSettings); |
adustm | 0:c61a93635433 | 900 | } |
adustm | 0:c61a93635433 | 901 | return ret; |
adustm | 0:c61a93635433 | 902 | } |
adustm | 0:c61a93635433 | 903 | |
adustm | 0:c61a93635433 | 904 | /** |
adustm | 0:c61a93635433 | 905 | * @brief Configure and activate SoftAP. |
adustm | 0:c61a93635433 | 906 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 907 | * @param ApConfig : Pointer to AP config structure. |
adustm | 0:c61a93635433 | 908 | * @param ip : AP IP address |
adustm | 0:c61a93635433 | 909 | * @param mac : AP MAC address |
adustm | 0:c61a93635433 | 910 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 911 | */ |
adustm | 0:c61a93635433 | 912 | ES_WIFI_Status_t ES_WIFI_ActivateAP(ES_WIFIObject_t *Obj, ES_WIFI_APConfig_t *ApConfig) |
adustm | 0:c61a93635433 | 913 | { |
adustm | 0:c61a93635433 | 914 | ES_WIFI_Status_t ret; |
adustm | 0:c61a93635433 | 915 | |
adustm | 0:c61a93635433 | 916 | sprintf((char*)Obj->CmdData,"AS=0,%s\r", ApConfig->SSID); |
adustm | 0:c61a93635433 | 917 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 918 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 919 | { |
adustm | 0:c61a93635433 | 920 | |
adustm | 0:c61a93635433 | 921 | sprintf((char*)Obj->CmdData,"A1=%c\r", (int)ApConfig->Security + '0'); |
adustm | 0:c61a93635433 | 922 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 923 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 924 | { |
adustm | 0:c61a93635433 | 925 | |
adustm | 0:c61a93635433 | 926 | sprintf((char*)Obj->CmdData,"A2=%s\r", ApConfig->Pass); |
adustm | 0:c61a93635433 | 927 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 928 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 929 | { |
adustm | 0:c61a93635433 | 930 | |
adustm | 0:c61a93635433 | 931 | sprintf((char*)Obj->CmdData,"AC=%d\r", ApConfig->Channel); |
adustm | 0:c61a93635433 | 932 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 933 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 934 | { |
adustm | 0:c61a93635433 | 935 | |
adustm | 0:c61a93635433 | 936 | sprintf((char*)Obj->CmdData,"AT=%d\r", ApConfig->MaxConnections); |
adustm | 0:c61a93635433 | 937 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 938 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 939 | { |
adustm | 0:c61a93635433 | 940 | sprintf((char*)Obj->CmdData,"A0\r"); |
adustm | 0:c61a93635433 | 941 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 942 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 943 | { |
adustm | 0:c61a93635433 | 944 | if(strstr((char *)Obj->CmdData, "[AP ]")) |
adustm | 0:c61a93635433 | 945 | { |
adustm | 0:c61a93635433 | 946 | ret = ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 947 | } |
adustm | 0:c61a93635433 | 948 | } |
adustm | 0:c61a93635433 | 949 | } |
adustm | 0:c61a93635433 | 950 | } |
adustm | 0:c61a93635433 | 951 | } |
adustm | 0:c61a93635433 | 952 | } |
adustm | 0:c61a93635433 | 953 | } |
adustm | 0:c61a93635433 | 954 | return ret; |
adustm | 0:c61a93635433 | 955 | } |
adustm | 0:c61a93635433 | 956 | |
adustm | 0:c61a93635433 | 957 | /** |
adustm | 0:c61a93635433 | 958 | * @brief Get AP notification. |
adustm | 0:c61a93635433 | 959 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 960 | * @param ip : Assigned ip address. |
adustm | 0:c61a93635433 | 961 | * @param ip : joind device mac address. |
adustm | 0:c61a93635433 | 962 | * @retval AP State. |
adustm | 0:c61a93635433 | 963 | */ |
adustm | 0:c61a93635433 | 964 | ES_WIFI_APState_t ES_WIFI_WaitAPStateChange(ES_WIFIObject_t *Obj) |
adustm | 0:c61a93635433 | 965 | { |
adustm | 0:c61a93635433 | 966 | ES_WIFI_APState_t ret = ES_WIFI_AP_NONE; |
adustm | 0:c61a93635433 | 967 | char *ptr; |
adustm | 0:c61a93635433 | 968 | |
adustm | 0:c61a93635433 | 969 | #if (ES_WIFI_USE_UART == 1) |
adustm | 0:c61a93635433 | 970 | if(Obj->fops.IO_Receive(Obj->CmdData, 0, Obj->Timeout) > 0) |
adustm | 0:c61a93635433 | 971 | { |
adustm | 0:c61a93635433 | 972 | if(strstr((char *)Obj->CmdData, AT_ERROR_STRING)) |
adustm | 0:c61a93635433 | 973 | { |
adustm | 0:c61a93635433 | 974 | return ES_WIFI_AP_ERROR; |
adustm | 0:c61a93635433 | 975 | } |
adustm | 0:c61a93635433 | 976 | #else |
adustm | 0:c61a93635433 | 977 | do |
adustm | 0:c61a93635433 | 978 | { |
adustm | 0:c61a93635433 | 979 | sprintf((char*)Obj->CmdData,"MR\r"); |
adustm | 0:c61a93635433 | 980 | if(AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData) != ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 981 | { |
adustm | 0:c61a93635433 | 982 | return ES_WIFI_AP_ERROR; |
adustm | 0:c61a93635433 | 983 | } |
adustm | 0:c61a93635433 | 984 | #endif |
adustm | 0:c61a93635433 | 985 | else if(strstr((char *)Obj->CmdData, "[AP DHCP]")) |
adustm | 0:c61a93635433 | 986 | { |
adustm | 0:c61a93635433 | 987 | ptr = strtok((char *)Obj->CmdData + 2, " "); |
adustm | 0:c61a93635433 | 988 | ptr = strtok(NULL, " "); |
adustm | 0:c61a93635433 | 989 | ptr = strtok(NULL, " "); |
adustm | 0:c61a93635433 | 990 | ptr = strtok(NULL, " "); |
adustm | 0:c61a93635433 | 991 | ParseMAC((char *)ptr, Obj->APSettings.MAC_Addr); |
adustm | 0:c61a93635433 | 992 | ptr = strtok(NULL, " "); |
adustm | 0:c61a93635433 | 993 | ptr = strtok(NULL, "\r"); |
adustm | 0:c61a93635433 | 994 | ParseIP((char *)ptr, Obj->APSettings.IP_Addr); |
adustm | 0:c61a93635433 | 995 | ret = ES_WIFI_AP_ASSIGNED; |
adustm | 0:c61a93635433 | 996 | #if (ES_WIFI_USE_SPI == 1) |
adustm | 0:c61a93635433 | 997 | break; |
adustm | 0:c61a93635433 | 998 | #endif |
adustm | 0:c61a93635433 | 999 | } |
adustm | 0:c61a93635433 | 1000 | else if(strstr((char *)Obj->CmdData, "[JOIN ]")) |
adustm | 0:c61a93635433 | 1001 | { |
adustm | 0:c61a93635433 | 1002 | ptr = strtok((char *)Obj->CmdData + 12, ","); |
adustm | 0:c61a93635433 | 1003 | strncpy((char *)Obj->APSettings.SSID, ptr, ES_WIFI_MAX_SSID_NAME_SIZE ); |
adustm | 0:c61a93635433 | 1004 | ptr = strtok(NULL, ","); |
adustm | 0:c61a93635433 | 1005 | ParseIP((char *)ptr, Obj->APSettings.IP_Addr); |
adustm | 0:c61a93635433 | 1006 | ret = ES_WIFI_AP_JOINED; |
adustm | 0:c61a93635433 | 1007 | #if (ES_WIFI_USE_SPI == 1) |
adustm | 0:c61a93635433 | 1008 | break; |
adustm | 0:c61a93635433 | 1009 | #endif |
adustm | 0:c61a93635433 | 1010 | } |
adustm | 0:c61a93635433 | 1011 | #if (ES_WIFI_USE_UART == 1) |
adustm | 0:c61a93635433 | 1012 | } |
adustm | 0:c61a93635433 | 1013 | #else |
adustm | 0:c61a93635433 | 1014 | Obj->fops.IO_Delay(1000); |
adustm | 0:c61a93635433 | 1015 | } while (1); |
adustm | 0:c61a93635433 | 1016 | #endif |
adustm | 0:c61a93635433 | 1017 | return ret; |
adustm | 0:c61a93635433 | 1018 | } |
adustm | 0:c61a93635433 | 1019 | |
adustm | 0:c61a93635433 | 1020 | /** |
adustm | 0:c61a93635433 | 1021 | * @brief retrn the MAC address of the es module. |
adustm | 0:c61a93635433 | 1022 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1023 | * @param mac: pointer to the MAC address array. |
adustm | 0:c61a93635433 | 1024 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1025 | */ |
adustm | 0:c61a93635433 | 1026 | ES_WIFI_Status_t ES_WIFI_GetMACAddress(ES_WIFIObject_t *Obj, uint8_t *mac) |
adustm | 0:c61a93635433 | 1027 | { |
adustm | 0:c61a93635433 | 1028 | ES_WIFI_Status_t ret ; |
adustm | 0:c61a93635433 | 1029 | char *ptr; |
adustm | 0:c61a93635433 | 1030 | |
adustm | 0:c61a93635433 | 1031 | sprintf((char*)Obj->CmdData,"Z5\r"); |
adustm | 0:c61a93635433 | 1032 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1033 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1034 | { |
adustm | 0:c61a93635433 | 1035 | ptr = strtok((char *)(Obj->CmdData + 2), "\r\n"); |
adustm | 0:c61a93635433 | 1036 | ParseMAC(ptr, mac) ; |
adustm | 0:c61a93635433 | 1037 | } |
adustm | 0:c61a93635433 | 1038 | return ret; |
adustm | 0:c61a93635433 | 1039 | } |
adustm | 0:c61a93635433 | 1040 | |
adustm | 0:c61a93635433 | 1041 | /** |
adustm | 0:c61a93635433 | 1042 | * @brief retrn the IP address of the es module. |
adustm | 0:c61a93635433 | 1043 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1044 | * @param mac: pointer to the IP address array. |
adustm | 0:c61a93635433 | 1045 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1046 | */ |
adustm | 0:c61a93635433 | 1047 | ES_WIFI_Status_t ES_WIFI_GetIPAddress(ES_WIFIObject_t *Obj, uint8_t *ipaddr) |
adustm | 0:c61a93635433 | 1048 | { |
adustm | 0:c61a93635433 | 1049 | memcpy(ipaddr, Obj->NetSettings.IP_Addr, 4); |
adustm | 0:c61a93635433 | 1050 | return ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 1051 | } |
adustm | 0:c61a93635433 | 1052 | |
adustm | 0:c61a93635433 | 1053 | /** |
adustm | 0:c61a93635433 | 1054 | * @brief Set the MAC address of the es module. |
adustm | 0:c61a93635433 | 1055 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1056 | * @param mac: pointer to the MAC address array. |
adustm | 0:c61a93635433 | 1057 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1058 | */ |
adustm | 0:c61a93635433 | 1059 | ES_WIFI_Status_t ES_WIFI_SetMACAddress(ES_WIFIObject_t *Obj, uint8_t *mac) |
adustm | 0:c61a93635433 | 1060 | { |
adustm | 0:c61a93635433 | 1061 | ES_WIFI_Status_t ret ; |
adustm | 0:c61a93635433 | 1062 | |
adustm | 0:c61a93635433 | 1063 | sprintf((char*)Obj->CmdData,"Z4=%X:%X:%X:%X:%X:%X\r",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5] ); |
adustm | 0:c61a93635433 | 1064 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1065 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1066 | { |
adustm | 0:c61a93635433 | 1067 | sprintf((char*)Obj->CmdData,"Z1\r"); |
adustm | 0:c61a93635433 | 1068 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1069 | } |
adustm | 0:c61a93635433 | 1070 | return ret; |
adustm | 0:c61a93635433 | 1071 | } |
adustm | 0:c61a93635433 | 1072 | |
adustm | 0:c61a93635433 | 1073 | /** |
adustm | 0:c61a93635433 | 1074 | * @brief Reset To factory defaults. |
adustm | 0:c61a93635433 | 1075 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1076 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1077 | */ |
adustm | 0:c61a93635433 | 1078 | ES_WIFI_Status_t ES_WIFI_ResetToFactoryDefault(ES_WIFIObject_t *Obj) |
adustm | 0:c61a93635433 | 1079 | { |
adustm | 0:c61a93635433 | 1080 | ES_WIFI_Status_t ret ; |
adustm | 0:c61a93635433 | 1081 | |
adustm | 0:c61a93635433 | 1082 | sprintf((char*)Obj->CmdData,"Z0\r"); |
adustm | 0:c61a93635433 | 1083 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1084 | return ret; |
adustm | 0:c61a93635433 | 1085 | } |
adustm | 0:c61a93635433 | 1086 | |
adustm | 0:c61a93635433 | 1087 | /** |
adustm | 0:c61a93635433 | 1088 | * @brief Reset the module. |
adustm | 0:c61a93635433 | 1089 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1090 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1091 | */ |
adustm | 0:c61a93635433 | 1092 | ES_WIFI_Status_t ES_WIFI_ResetModule(ES_WIFIObject_t *Obj) |
adustm | 0:c61a93635433 | 1093 | { |
adustm | 0:c61a93635433 | 1094 | ES_WIFI_Status_t ret ; |
adustm | 0:c61a93635433 | 1095 | |
adustm | 0:c61a93635433 | 1096 | sprintf((char*)Obj->CmdData,"ZR\r"); |
adustm | 0:c61a93635433 | 1097 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1098 | return ret; |
adustm | 0:c61a93635433 | 1099 | } |
adustm | 0:c61a93635433 | 1100 | |
adustm | 0:c61a93635433 | 1101 | /** |
adustm | 0:c61a93635433 | 1102 | * @brief Set Product Name. |
adustm | 0:c61a93635433 | 1103 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1104 | * @param ProductName : pointer to product name string |
adustm | 0:c61a93635433 | 1105 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1106 | */ |
adustm | 0:c61a93635433 | 1107 | ES_WIFI_Status_t ES_WIFI_SetProductName(ES_WIFIObject_t *Obj, uint8_t *ProductName) |
adustm | 0:c61a93635433 | 1108 | { |
adustm | 0:c61a93635433 | 1109 | ES_WIFI_Status_t ret ; |
adustm | 0:c61a93635433 | 1110 | |
adustm | 0:c61a93635433 | 1111 | sprintf((char*)Obj->CmdData,"ZN=%s\r",ProductName); |
adustm | 0:c61a93635433 | 1112 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1113 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1114 | { |
adustm | 0:c61a93635433 | 1115 | sprintf((char*)Obj->CmdData,"Z1\r"); |
adustm | 0:c61a93635433 | 1116 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1117 | } |
adustm | 0:c61a93635433 | 1118 | return ret; |
adustm | 0:c61a93635433 | 1119 | } |
adustm | 0:c61a93635433 | 1120 | |
adustm | 0:c61a93635433 | 1121 | #if (ES_WIFI_USE_FIRMWAREUPDATE == 1) |
adustm | 0:c61a93635433 | 1122 | /** |
adustm | 0:c61a93635433 | 1123 | * @brief OTA Firmware Upgrade. |
adustm | 0:c61a93635433 | 1124 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1125 | * @param Upgrade link path |
adustm | 0:c61a93635433 | 1126 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1127 | */ |
adustm | 0:c61a93635433 | 1128 | ES_WIFI_Status_t ES_WIFI_OTA_Upgrade(ES_WIFIObject_t *Obj, uint8_t *link) |
adustm | 0:c61a93635433 | 1129 | { |
adustm | 0:c61a93635433 | 1130 | ES_WIFI_Status_t ret ; |
adustm | 0:c61a93635433 | 1131 | |
adustm | 0:c61a93635433 | 1132 | sprintf((char*)Obj->CmdData,"Z0=%d\r%s",strlen((char *)link), (char *)link); |
adustm | 0:c61a93635433 | 1133 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1134 | return ret; |
adustm | 0:c61a93635433 | 1135 | } |
adustm | 0:c61a93635433 | 1136 | #endif |
adustm | 0:c61a93635433 | 1137 | #if (ES_WIFI_USE_UART == 1) |
adustm | 0:c61a93635433 | 1138 | /** |
adustm | 0:c61a93635433 | 1139 | * @brief Set UART Baud Rate. |
adustm | 0:c61a93635433 | 1140 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1141 | * @param UART BAud rate |
adustm | 0:c61a93635433 | 1142 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1143 | */ |
adustm | 0:c61a93635433 | 1144 | ES_WIFI_Status_t ES_WIFI_SetUARTBaudRate(ES_WIFIObject_t *Obj, uint16_t BaudRate) |
adustm | 0:c61a93635433 | 1145 | { |
adustm | 0:c61a93635433 | 1146 | ES_WIFI_Status_t ret ; |
adustm | 0:c61a93635433 | 1147 | |
adustm | 0:c61a93635433 | 1148 | sprintf((char*)Obj->CmdData,"U2=%d\r", BaudRate); |
adustm | 0:c61a93635433 | 1149 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1150 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1151 | { |
adustm | 0:c61a93635433 | 1152 | sprintf((char*)Obj->CmdData,"U0\r"); |
adustm | 0:c61a93635433 | 1153 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1154 | } |
adustm | 0:c61a93635433 | 1155 | return ret; |
adustm | 0:c61a93635433 | 1156 | } |
adustm | 0:c61a93635433 | 1157 | |
adustm | 0:c61a93635433 | 1158 | /** |
adustm | 0:c61a93635433 | 1159 | * @brief Get UART Configuration. |
adustm | 0:c61a93635433 | 1160 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1161 | * @param pointer to UART config structure |
adustm | 0:c61a93635433 | 1162 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1163 | */ |
adustm | 0:c61a93635433 | 1164 | ES_WIFI_Status_t ES_WIFI_GetUARTConfig(ES_WIFIObject_t *Obj, ES_WIFI_UARTConfig_t *pconf) |
adustm | 0:c61a93635433 | 1165 | { |
adustm | 0:c61a93635433 | 1166 | ES_WIFI_Status_t ret ; |
adustm | 0:c61a93635433 | 1167 | |
adustm | 0:c61a93635433 | 1168 | sprintf((char*)Obj->CmdData,"U?\r"); |
adustm | 0:c61a93635433 | 1169 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1170 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1171 | { |
adustm | 0:c61a93635433 | 1172 | AT_ParseUARTConfig((char *)Obj->CmdData, pconf); |
adustm | 0:c61a93635433 | 1173 | } |
adustm | 0:c61a93635433 | 1174 | return ret; |
adustm | 0:c61a93635433 | 1175 | } |
adustm | 0:c61a93635433 | 1176 | #endif |
adustm | 0:c61a93635433 | 1177 | |
adustm | 0:c61a93635433 | 1178 | /** |
adustm | 0:c61a93635433 | 1179 | * @brief Get System Configuration. |
adustm | 0:c61a93635433 | 1180 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1181 | * @param pointer to System config structure |
adustm | 0:c61a93635433 | 1182 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1183 | */ |
adustm | 0:c61a93635433 | 1184 | ES_WIFI_Status_t ES_WIFI_GetSystemConfig(ES_WIFIObject_t *Obj, ES_WIFI_SystemConfig_t *pconf) |
adustm | 0:c61a93635433 | 1185 | { |
adustm | 0:c61a93635433 | 1186 | ES_WIFI_Status_t ret ; |
adustm | 0:c61a93635433 | 1187 | |
adustm | 0:c61a93635433 | 1188 | sprintf((char*)Obj->CmdData,"Z?\r"); |
adustm | 0:c61a93635433 | 1189 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1190 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1191 | { |
adustm | 0:c61a93635433 | 1192 | AT_ParseSystemConfig((char *)Obj->CmdData, pconf); |
adustm | 0:c61a93635433 | 1193 | } |
adustm | 0:c61a93635433 | 1194 | return ret; |
adustm | 0:c61a93635433 | 1195 | } |
adustm | 0:c61a93635433 | 1196 | |
adustm | 0:c61a93635433 | 1197 | #if (ES_WIFI_USE_PING == 1) |
adustm | 0:c61a93635433 | 1198 | /** |
adustm | 0:c61a93635433 | 1199 | * @brief Ping an IP address. |
adustm | 0:c61a93635433 | 1200 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1201 | * @param Ping: ping structure. |
adustm | 0:c61a93635433 | 1202 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1203 | */ |
adustm | 0:c61a93635433 | 1204 | ES_WIFI_Status_t ES_WIFI_Ping(ES_WIFIObject_t *Obj, uint8_t *address, uint16_t count, uint16_t interval_ms) |
adustm | 0:c61a93635433 | 1205 | { |
adustm | 0:c61a93635433 | 1206 | ES_WIFI_Status_t ret; |
adustm | 0:c61a93635433 | 1207 | |
adustm | 0:c61a93635433 | 1208 | sprintf((char*)Obj->CmdData,"T1=%d.%d.%d.%d\r", address[0],address[1], |
adustm | 0:c61a93635433 | 1209 | address[2],address[3]); |
adustm | 0:c61a93635433 | 1210 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1211 | |
adustm | 0:c61a93635433 | 1212 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1213 | { |
adustm | 0:c61a93635433 | 1214 | |
adustm | 0:c61a93635433 | 1215 | sprintf((char*)Obj->CmdData,"T2=%d\r", count); |
adustm | 0:c61a93635433 | 1216 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1217 | |
adustm | 0:c61a93635433 | 1218 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1219 | { |
adustm | 0:c61a93635433 | 1220 | sprintf((char*)Obj->CmdData,"T3=%d\r", interval_ms); |
adustm | 0:c61a93635433 | 1221 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1222 | |
adustm | 0:c61a93635433 | 1223 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1224 | { |
adustm | 0:c61a93635433 | 1225 | sprintf((char*)Obj->CmdData,"T0=\r"); |
adustm | 0:c61a93635433 | 1226 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1227 | } |
adustm | 0:c61a93635433 | 1228 | } |
adustm | 0:c61a93635433 | 1229 | } |
adustm | 0:c61a93635433 | 1230 | |
adustm | 0:c61a93635433 | 1231 | return ret; |
adustm | 0:c61a93635433 | 1232 | } |
adustm | 0:c61a93635433 | 1233 | #endif |
adustm | 0:c61a93635433 | 1234 | /** |
adustm | 0:c61a93635433 | 1235 | * @brief DNS Lookup to get IP address . |
adustm | 0:c61a93635433 | 1236 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1237 | * @param url: Domain Name. |
adustm | 0:c61a93635433 | 1238 | * @param ipaddress: IP address. |
adustm | 0:c61a93635433 | 1239 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1240 | */ |
adustm | 0:c61a93635433 | 1241 | ES_WIFI_Status_t ES_WIFI_DNS_LookUp(ES_WIFIObject_t *Obj, const char *url, uint8_t *ipaddress) |
adustm | 0:c61a93635433 | 1242 | { |
adustm | 0:c61a93635433 | 1243 | ES_WIFI_Status_t ret; |
adustm | 0:c61a93635433 | 1244 | char *ptr; |
adustm | 0:c61a93635433 | 1245 | |
adustm | 0:c61a93635433 | 1246 | sprintf((char*)Obj->CmdData,"D0=%s\r", url); |
adustm | 0:c61a93635433 | 1247 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1248 | |
adustm | 0:c61a93635433 | 1249 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1250 | { |
adustm | 0:c61a93635433 | 1251 | ptr = strtok((char *)Obj->CmdData + 2, "\r"); |
adustm | 0:c61a93635433 | 1252 | ParseIP(ptr, ipaddress); |
adustm | 0:c61a93635433 | 1253 | } |
adustm | 0:c61a93635433 | 1254 | return ret; |
adustm | 0:c61a93635433 | 1255 | } |
adustm | 0:c61a93635433 | 1256 | |
adustm | 0:c61a93635433 | 1257 | |
adustm | 0:c61a93635433 | 1258 | /** |
adustm | 0:c61a93635433 | 1259 | * @brief Configure and Start a Client connection. |
adustm | 0:c61a93635433 | 1260 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1261 | * @param conn: pointer to the connection structure |
adustm | 0:c61a93635433 | 1262 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1263 | */ |
adustm | 0:c61a93635433 | 1264 | ES_WIFI_Status_t ES_WIFI_StartClientConnection(ES_WIFIObject_t *Obj, ES_WIFI_Conn_t *conn) |
adustm | 0:c61a93635433 | 1265 | { |
adustm | 0:c61a93635433 | 1266 | ES_WIFI_Status_t ret; |
adustm | 0:c61a93635433 | 1267 | |
adustm | 0:c61a93635433 | 1268 | sprintf((char*)Obj->CmdData,"P0=%d\r", conn->Number); |
adustm | 0:c61a93635433 | 1269 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1270 | |
adustm | 0:c61a93635433 | 1271 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1272 | { |
adustm | 0:c61a93635433 | 1273 | sprintf((char*)Obj->CmdData,"P1=%d\r", conn->Type); |
adustm | 0:c61a93635433 | 1274 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1275 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1276 | { |
adustm | 0:c61a93635433 | 1277 | if ((conn->Type == ES_WIFI_UDP_CONNECTION) && (conn->LocalPort > 0)) |
adustm | 0:c61a93635433 | 1278 | { |
adustm | 0:c61a93635433 | 1279 | sprintf((char*)Obj->CmdData,"P2=%d\r", conn->RemotePort); |
adustm | 0:c61a93635433 | 1280 | if(AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData) == ES_WIFI_STATUS_ERROR) |
adustm | 0:c61a93635433 | 1281 | { |
adustm | 0:c61a93635433 | 1282 | return ES_WIFI_STATUS_ERROR; |
adustm | 0:c61a93635433 | 1283 | } |
adustm | 0:c61a93635433 | 1284 | } |
adustm | 0:c61a93635433 | 1285 | sprintf((char*)Obj->CmdData,"P4=%d\r", conn->RemotePort); |
adustm | 0:c61a93635433 | 1286 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1287 | |
adustm | 0:c61a93635433 | 1288 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1289 | { |
adustm | 0:c61a93635433 | 1290 | sprintf((char*)Obj->CmdData,"P3=%d.%d.%d.%d\r", conn->RemoteIP[0],conn->RemoteIP[1], |
adustm | 0:c61a93635433 | 1291 | conn->RemoteIP[2],conn->RemoteIP[3]); |
adustm | 0:c61a93635433 | 1292 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1293 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1294 | { |
adustm | 0:c61a93635433 | 1295 | sprintf((char*)Obj->CmdData,"P6=1\r"); |
adustm | 0:c61a93635433 | 1296 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1297 | } |
adustm | 0:c61a93635433 | 1298 | } |
adustm | 0:c61a93635433 | 1299 | } |
adustm | 0:c61a93635433 | 1300 | } |
adustm | 0:c61a93635433 | 1301 | return ret; |
adustm | 0:c61a93635433 | 1302 | } |
adustm | 0:c61a93635433 | 1303 | |
adustm | 0:c61a93635433 | 1304 | /** |
adustm | 0:c61a93635433 | 1305 | * @brief Stop Client connection. |
adustm | 0:c61a93635433 | 1306 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1307 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1308 | */ |
adustm | 0:c61a93635433 | 1309 | ES_WIFI_Status_t ES_WIFI_StopClientConnection(ES_WIFIObject_t *Obj, ES_WIFI_Conn_t *conn) |
adustm | 0:c61a93635433 | 1310 | { |
adustm | 0:c61a93635433 | 1311 | ES_WIFI_Status_t ret; |
adustm | 0:c61a93635433 | 1312 | |
adustm | 0:c61a93635433 | 1313 | sprintf((char*)Obj->CmdData,"P0=%d\r", conn->Number); |
adustm | 0:c61a93635433 | 1314 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1315 | |
adustm | 0:c61a93635433 | 1316 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1317 | { |
adustm | 0:c61a93635433 | 1318 | sprintf((char*)Obj->CmdData,"P6=0\r"); |
adustm | 0:c61a93635433 | 1319 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1320 | } |
adustm | 0:c61a93635433 | 1321 | return ret; |
adustm | 0:c61a93635433 | 1322 | } |
adustm | 0:c61a93635433 | 1323 | |
adustm | 0:c61a93635433 | 1324 | #if (ES_WIFI_USE_AWS == 1) |
adustm | 0:c61a93635433 | 1325 | /** |
adustm | 0:c61a93635433 | 1326 | * @brief Configure and Start a AWS Client connection. |
adustm | 0:c61a93635433 | 1327 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1328 | * @param conn: pointer to the connection structure |
adustm | 0:c61a93635433 | 1329 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1330 | */ |
adustm | 0:c61a93635433 | 1331 | ES_WIFI_Status_t ES_WIFI_StartAWSClientConnection(ES_WIFIObject_t *Obj, ES_WIFI_AWS_Conn_t *conn) |
adustm | 0:c61a93635433 | 1332 | { |
adustm | 0:c61a93635433 | 1333 | |
adustm | 0:c61a93635433 | 1334 | ES_WIFI_Status_t ret; |
adustm | 0:c61a93635433 | 1335 | |
adustm | 0:c61a93635433 | 1336 | sprintf((char*)Obj->CmdData,"P0=%d\r", conn->Number); |
adustm | 0:c61a93635433 | 1337 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1338 | |
adustm | 0:c61a93635433 | 1339 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1340 | { |
adustm | 0:c61a93635433 | 1341 | sprintf((char*)Obj->CmdData,"P1=%d\r", conn->Type); |
adustm | 0:c61a93635433 | 1342 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1343 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1344 | { |
adustm | 0:c61a93635433 | 1345 | sprintf((char*)Obj->CmdData,"P4=%d\r", conn->RemotePort); |
adustm | 0:c61a93635433 | 1346 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1347 | |
adustm | 0:c61a93635433 | 1348 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1349 | { |
adustm | 0:c61a93635433 | 1350 | sprintf((char*)Obj->CmdData,"PM=0,%s\r", conn->PublishTopic); |
adustm | 0:c61a93635433 | 1351 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1352 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1353 | { |
adustm | 0:c61a93635433 | 1354 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1355 | { |
adustm | 0:c61a93635433 | 1356 | sprintf((char*)Obj->CmdData,"PM=1,%s\r", conn->SubscribeTopic); |
adustm | 0:c61a93635433 | 1357 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1358 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1359 | { |
adustm | 0:c61a93635433 | 1360 | |
adustm | 0:c61a93635433 | 1361 | sprintf((char*)Obj->CmdData,"PM=2,%d\r", conn->MQTTMode); |
adustm | 0:c61a93635433 | 1362 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1363 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1364 | { |
adustm | 0:c61a93635433 | 1365 | sprintf((char*)Obj->CmdData,"PM=5,%s\r", conn->ClientID); |
adustm | 0:c61a93635433 | 1366 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1367 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1368 | { |
adustm | 0:c61a93635433 | 1369 | sprintf((char*)Obj->CmdData,"PM\r"); |
adustm | 0:c61a93635433 | 1370 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1371 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1372 | { |
adustm | 0:c61a93635433 | 1373 | sprintf((char*)Obj->CmdData,"P6=1\r"); |
adustm | 0:c61a93635433 | 1374 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1375 | } |
adustm | 0:c61a93635433 | 1376 | } |
adustm | 0:c61a93635433 | 1377 | } |
adustm | 0:c61a93635433 | 1378 | } |
adustm | 0:c61a93635433 | 1379 | } |
adustm | 0:c61a93635433 | 1380 | } |
adustm | 0:c61a93635433 | 1381 | } |
adustm | 0:c61a93635433 | 1382 | } |
adustm | 0:c61a93635433 | 1383 | } |
adustm | 0:c61a93635433 | 1384 | return ret; |
adustm | 0:c61a93635433 | 1385 | } |
adustm | 0:c61a93635433 | 1386 | #endif |
adustm | 0:c61a93635433 | 1387 | /** |
adustm | 0:c61a93635433 | 1388 | * @brief Configure and Start a Server. |
adustm | 0:c61a93635433 | 1389 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1390 | * @param conn: pointer to the connection structure |
adustm | 0:c61a93635433 | 1391 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1392 | */ |
adustm | 0:c61a93635433 | 1393 | ES_WIFI_Status_t ES_WIFI_StartServerSingleConn(ES_WIFIObject_t *Obj, ES_WIFI_Conn_t *conn) |
adustm | 0:c61a93635433 | 1394 | { |
adustm | 0:c61a93635433 | 1395 | ES_WIFI_Status_t ret = ES_WIFI_STATUS_ERROR; |
adustm | 0:c61a93635433 | 1396 | char *ptr; |
adustm | 0:c61a93635433 | 1397 | |
adustm | 0:c61a93635433 | 1398 | sprintf((char*)Obj->CmdData,"PK=1,3000\r"); |
adustm | 0:c61a93635433 | 1399 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1400 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1401 | { |
adustm | 0:c61a93635433 | 1402 | sprintf((char*)Obj->CmdData,"P0=%d\r", conn->Number); |
adustm | 0:c61a93635433 | 1403 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1404 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1405 | { |
adustm | 0:c61a93635433 | 1406 | sprintf((char*)Obj->CmdData,"P1=%d\r", conn->Type); |
adustm | 0:c61a93635433 | 1407 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1408 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1409 | { |
adustm | 0:c61a93635433 | 1410 | sprintf((char*)Obj->CmdData,"P2=%d\r", conn->LocalPort); |
adustm | 0:c61a93635433 | 1411 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1412 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1413 | { |
adustm | 0:c61a93635433 | 1414 | sprintf((char*)Obj->CmdData,"P5=1\r"); |
adustm | 0:c61a93635433 | 1415 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1416 | |
adustm | 0:c61a93635433 | 1417 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1418 | { |
adustm | 0:c61a93635433 | 1419 | #if (ES_WIFI_USE_UART == 1) |
adustm | 0:c61a93635433 | 1420 | if(Obj->fops.IO_Receive(Obj->CmdData, 0, Obj->Timeout) > 0) |
adustm | 0:c61a93635433 | 1421 | { |
adustm | 0:c61a93635433 | 1422 | if(strstr((char *)Obj->CmdData, "Accepted")) |
adustm | 0:c61a93635433 | 1423 | { |
adustm | 0:c61a93635433 | 1424 | ptr = strtok((char *)Obj->CmdData + 2, " "); |
adustm | 0:c61a93635433 | 1425 | ptr = strtok(NULL, " "); |
adustm | 0:c61a93635433 | 1426 | ptr = strtok(NULL, " "); |
adustm | 0:c61a93635433 | 1427 | ptr = strtok(NULL, ":"); |
adustm | 0:c61a93635433 | 1428 | ParseIP((char *)ptr, conn->RemoteIP); |
adustm | 0:c61a93635433 | 1429 | ret = ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 1430 | } |
adustm | 0:c61a93635433 | 1431 | } |
adustm | 0:c61a93635433 | 1432 | #else |
adustm | 0:c61a93635433 | 1433 | do |
adustm | 0:c61a93635433 | 1434 | { |
adustm | 0:c61a93635433 | 1435 | sprintf((char*)Obj->CmdData,"MR\r"); |
adustm | 0:c61a93635433 | 1436 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1437 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1438 | { |
adustm | 0:c61a93635433 | 1439 | if((strstr((char *)Obj->CmdData, "[SOMA]")) && (strstr((char *)Obj->CmdData, "[EOMA]"))) |
adustm | 0:c61a93635433 | 1440 | { |
adustm | 0:c61a93635433 | 1441 | if(strstr((char *)Obj->CmdData, "Accepted")) |
adustm | 0:c61a93635433 | 1442 | { |
adustm | 0:c61a93635433 | 1443 | ptr = strtok((char *)Obj->CmdData + 2, " "); |
adustm | 0:c61a93635433 | 1444 | ptr = strtok(NULL, " "); |
adustm | 0:c61a93635433 | 1445 | ptr = strtok(NULL, " "); |
adustm | 0:c61a93635433 | 1446 | ptr = strtok(NULL, ":"); |
adustm | 0:c61a93635433 | 1447 | ParseIP((char *)ptr, conn->RemoteIP); |
adustm | 0:c61a93635433 | 1448 | ret = ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 1449 | break; |
adustm | 0:c61a93635433 | 1450 | } |
adustm | 0:c61a93635433 | 1451 | } |
adustm | 0:c61a93635433 | 1452 | } |
adustm | 0:c61a93635433 | 1453 | else |
adustm | 0:c61a93635433 | 1454 | { |
adustm | 0:c61a93635433 | 1455 | ret = ES_WIFI_STATUS_ERROR; |
adustm | 0:c61a93635433 | 1456 | break; |
adustm | 0:c61a93635433 | 1457 | } |
adustm | 0:c61a93635433 | 1458 | Obj->fops.IO_Delay(1000); |
adustm | 0:c61a93635433 | 1459 | } while (1); |
adustm | 0:c61a93635433 | 1460 | #endif |
adustm | 0:c61a93635433 | 1461 | } |
adustm | 0:c61a93635433 | 1462 | } |
adustm | 0:c61a93635433 | 1463 | } |
adustm | 0:c61a93635433 | 1464 | } |
adustm | 0:c61a93635433 | 1465 | } |
adustm | 0:c61a93635433 | 1466 | return ret; |
adustm | 0:c61a93635433 | 1467 | } |
adustm | 0:c61a93635433 | 1468 | |
adustm | 0:c61a93635433 | 1469 | /** |
adustm | 0:c61a93635433 | 1470 | * @brief Stop a Server. |
adustm | 0:c61a93635433 | 1471 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1472 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1473 | */ |
adustm | 0:c61a93635433 | 1474 | ES_WIFI_Status_t ES_WIFI_StopServerSingleConn(ES_WIFIObject_t *Obj) |
adustm | 0:c61a93635433 | 1475 | { |
adustm | 0:c61a93635433 | 1476 | sprintf((char*)Obj->CmdData,"P5=0\r"); |
adustm | 0:c61a93635433 | 1477 | return AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1478 | } |
adustm | 0:c61a93635433 | 1479 | |
adustm | 0:c61a93635433 | 1480 | |
adustm | 0:c61a93635433 | 1481 | /** |
adustm | 0:c61a93635433 | 1482 | * @brief Configure and Start a Server. |
adustm | 0:c61a93635433 | 1483 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1484 | * @param conn: pointer to the connection structure |
adustm | 0:c61a93635433 | 1485 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1486 | */ |
adustm | 0:c61a93635433 | 1487 | ES_WIFI_Status_t ES_WIFI_StartServerMultiConn(ES_WIFIObject_t *Obj, ES_WIFI_Conn_t *conn) |
adustm | 0:c61a93635433 | 1488 | { |
adustm | 0:c61a93635433 | 1489 | ES_WIFI_Status_t ret = ES_WIFI_STATUS_ERROR; |
adustm | 0:c61a93635433 | 1490 | char *ptr; |
adustm | 0:c61a93635433 | 1491 | |
adustm | 0:c61a93635433 | 1492 | sprintf((char*)Obj->CmdData,"PK=1,3000\r"); |
adustm | 0:c61a93635433 | 1493 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1494 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1495 | { |
adustm | 0:c61a93635433 | 1496 | sprintf((char*)Obj->CmdData,"P0=%d\r", conn->Number); |
adustm | 0:c61a93635433 | 1497 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1498 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1499 | { |
adustm | 0:c61a93635433 | 1500 | sprintf((char*)Obj->CmdData,"P1=%d\r", conn->Type); |
adustm | 0:c61a93635433 | 1501 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1502 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1503 | { |
adustm | 0:c61a93635433 | 1504 | sprintf((char*)Obj->CmdData,"P2=%d\r", conn->LocalPort); |
adustm | 0:c61a93635433 | 1505 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1506 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1507 | { |
adustm | 0:c61a93635433 | 1508 | sprintf((char*)Obj->CmdData,"P8=6\r"); |
adustm | 0:c61a93635433 | 1509 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1510 | |
adustm | 0:c61a93635433 | 1511 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1512 | { |
adustm | 0:c61a93635433 | 1513 | sprintf((char*)Obj->CmdData,"P5=1\r"); |
adustm | 0:c61a93635433 | 1514 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1515 | |
adustm | 0:c61a93635433 | 1516 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1517 | { |
adustm | 0:c61a93635433 | 1518 | #if (ES_WIFI_USE_UART == 1) |
adustm | 0:c61a93635433 | 1519 | if(Obj->fops.IO_Receive(Obj->CmdData, 0, Obj->Timeout) > 0) |
adustm | 0:c61a93635433 | 1520 | { |
adustm | 0:c61a93635433 | 1521 | if(strstr((char *)Obj->CmdData, "Accepted")) |
adustm | 0:c61a93635433 | 1522 | { |
adustm | 0:c61a93635433 | 1523 | ptr = strtok((char *)Obj->CmdData + 2, " "); |
adustm | 0:c61a93635433 | 1524 | ptr = strtok(NULL, " "); |
adustm | 0:c61a93635433 | 1525 | ptr = strtok(NULL, " "); |
adustm | 0:c61a93635433 | 1526 | ptr = strtok(NULL, ":"); |
adustm | 0:c61a93635433 | 1527 | ParseIP((char *)ptr, conn->RemoteIP); |
adustm | 0:c61a93635433 | 1528 | ret = ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 1529 | } |
adustm | 0:c61a93635433 | 1530 | } |
adustm | 0:c61a93635433 | 1531 | #else |
adustm | 0:c61a93635433 | 1532 | do |
adustm | 0:c61a93635433 | 1533 | { |
adustm | 0:c61a93635433 | 1534 | sprintf((char*)Obj->CmdData,"MR\r"); |
adustm | 0:c61a93635433 | 1535 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1536 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1537 | { |
adustm | 0:c61a93635433 | 1538 | if((strstr((char *)Obj->CmdData, "[SOMA]")) && (strstr((char *)Obj->CmdData, "[EOMA]"))) |
adustm | 0:c61a93635433 | 1539 | { |
adustm | 0:c61a93635433 | 1540 | if(strstr((char *)Obj->CmdData, "Accepted")) |
adustm | 0:c61a93635433 | 1541 | { |
adustm | 0:c61a93635433 | 1542 | ptr = strtok((char *)Obj->CmdData + 2, " "); |
adustm | 0:c61a93635433 | 1543 | ptr = strtok(NULL, " "); |
adustm | 0:c61a93635433 | 1544 | ptr = strtok(NULL, " "); |
adustm | 0:c61a93635433 | 1545 | ptr = strtok(NULL, ":"); |
adustm | 0:c61a93635433 | 1546 | ParseIP((char *)ptr, conn->RemoteIP); |
adustm | 0:c61a93635433 | 1547 | ret = ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 1548 | break; |
adustm | 0:c61a93635433 | 1549 | } |
adustm | 0:c61a93635433 | 1550 | } |
adustm | 0:c61a93635433 | 1551 | } |
adustm | 0:c61a93635433 | 1552 | else |
adustm | 0:c61a93635433 | 1553 | { |
adustm | 0:c61a93635433 | 1554 | ret = ES_WIFI_STATUS_ERROR; |
adustm | 0:c61a93635433 | 1555 | break; |
adustm | 0:c61a93635433 | 1556 | } |
adustm | 0:c61a93635433 | 1557 | Obj->fops.IO_Delay(1000); |
adustm | 0:c61a93635433 | 1558 | } while (1); |
adustm | 0:c61a93635433 | 1559 | #endif |
adustm | 0:c61a93635433 | 1560 | } |
adustm | 0:c61a93635433 | 1561 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1562 | { |
adustm | 0:c61a93635433 | 1563 | sprintf((char*)Obj->CmdData,"P7=1\r"); |
adustm | 0:c61a93635433 | 1564 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1565 | |
adustm | 0:c61a93635433 | 1566 | } |
adustm | 0:c61a93635433 | 1567 | } |
adustm | 0:c61a93635433 | 1568 | } |
adustm | 0:c61a93635433 | 1569 | } |
adustm | 0:c61a93635433 | 1570 | } |
adustm | 0:c61a93635433 | 1571 | } |
adustm | 0:c61a93635433 | 1572 | return ret; |
adustm | 0:c61a93635433 | 1573 | } |
adustm | 0:c61a93635433 | 1574 | |
adustm | 0:c61a93635433 | 1575 | /** |
adustm | 0:c61a93635433 | 1576 | * @brief Stop a Server. |
adustm | 0:c61a93635433 | 1577 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1578 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1579 | */ |
adustm | 0:c61a93635433 | 1580 | ES_WIFI_Status_t ES_WIFI_StopServerMultiConn(ES_WIFIObject_t *Obj) |
adustm | 0:c61a93635433 | 1581 | { |
adustm | 0:c61a93635433 | 1582 | ES_WIFI_Status_t ret = ES_WIFI_STATUS_ERROR; |
adustm | 0:c61a93635433 | 1583 | |
adustm | 0:c61a93635433 | 1584 | /* close the socket handle for the current request. */ |
adustm | 0:c61a93635433 | 1585 | sprintf((char*)Obj->CmdData,"P7=2\r"); |
adustm | 0:c61a93635433 | 1586 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1587 | |
adustm | 0:c61a93635433 | 1588 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1589 | { |
adustm | 0:c61a93635433 | 1590 | /*Get the next request out of the queue */ |
adustm | 0:c61a93635433 | 1591 | sprintf((char*)Obj->CmdData,"P7=3\r"); |
adustm | 0:c61a93635433 | 1592 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1593 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1594 | { |
adustm | 0:c61a93635433 | 1595 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1596 | { |
adustm | 0:c61a93635433 | 1597 | if(Obj->fops.IO_Receive(Obj->CmdData, 0, Obj->Timeout) > 0) |
adustm | 0:c61a93635433 | 1598 | { |
adustm | 0:c61a93635433 | 1599 | if(strstr((char *)Obj->CmdData, "Accepted")) |
adustm | 0:c61a93635433 | 1600 | { |
adustm | 0:c61a93635433 | 1601 | ret = ES_WIFI_STATUS_OK; |
adustm | 0:c61a93635433 | 1602 | } |
adustm | 0:c61a93635433 | 1603 | } |
adustm | 0:c61a93635433 | 1604 | } |
adustm | 0:c61a93635433 | 1605 | } |
adustm | 0:c61a93635433 | 1606 | } |
adustm | 0:c61a93635433 | 1607 | return ret; |
adustm | 0:c61a93635433 | 1608 | } |
adustm | 0:c61a93635433 | 1609 | /** |
adustm | 0:c61a93635433 | 1610 | * @brief Send an amount data over WIFI. |
adustm | 0:c61a93635433 | 1611 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1612 | * @param Socket: number of the socket |
adustm | 0:c61a93635433 | 1613 | * @param pdata: pointer to data |
adustm | 0:c61a93635433 | 1614 | * @param len : length of the data to be sent |
adustm | 0:c61a93635433 | 1615 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1616 | */ |
adustm | 0:c61a93635433 | 1617 | ES_WIFI_Status_t ES_WIFI_SendData(ES_WIFIObject_t *Obj, uint8_t Socket, uint8_t *pdata, uint16_t Reqlen , uint16_t *SentLen , uint32_t Timeout) |
adustm | 0:c61a93635433 | 1618 | { |
adustm | 0:c61a93635433 | 1619 | ES_WIFI_Status_t ret = ES_WIFI_STATUS_ERROR; |
adustm | 0:c61a93635433 | 1620 | |
adustm | 0:c61a93635433 | 1621 | if(Reqlen >= ES_WIFI_PAYLOAD_SIZE ) Reqlen= ES_WIFI_PAYLOAD_SIZE; |
adustm | 0:c61a93635433 | 1622 | |
adustm | 0:c61a93635433 | 1623 | *SentLen = Reqlen; |
adustm | 0:c61a93635433 | 1624 | sprintf((char*)Obj->CmdData,"P0=%d\r", Socket); |
adustm | 0:c61a93635433 | 1625 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1626 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1627 | { |
adustm | 0:c61a93635433 | 1628 | sprintf((char*)Obj->CmdData,"S2=%lu\r",Timeout); |
adustm | 0:c61a93635433 | 1629 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1630 | |
adustm | 0:c61a93635433 | 1631 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1632 | { |
adustm | 0:c61a93635433 | 1633 | sprintf((char *)Obj->CmdData,"S3=%04d\r",Reqlen); |
adustm | 0:c61a93635433 | 1634 | ret = AT_RequestSendData(Obj, Obj->CmdData, pdata, Reqlen, Obj->CmdData); |
adustm | 0:c61a93635433 | 1635 | |
adustm | 0:c61a93635433 | 1636 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1637 | { |
adustm | 0:c61a93635433 | 1638 | if(strstr((char *)Obj->CmdData,"-1\r\n")) |
adustm | 0:c61a93635433 | 1639 | { |
adustm | 0:c61a93635433 | 1640 | ret = ES_WIFI_STATUS_ERROR; |
adustm | 0:c61a93635433 | 1641 | } |
adustm | 0:c61a93635433 | 1642 | } |
adustm | 0:c61a93635433 | 1643 | } |
adustm | 0:c61a93635433 | 1644 | } |
adustm | 0:c61a93635433 | 1645 | |
adustm | 0:c61a93635433 | 1646 | if (ret == ES_WIFI_STATUS_ERROR) *SentLen = 0; |
adustm | 0:c61a93635433 | 1647 | return ret; |
adustm | 0:c61a93635433 | 1648 | } |
adustm | 0:c61a93635433 | 1649 | |
adustm | 0:c61a93635433 | 1650 | /** |
adustm | 0:c61a93635433 | 1651 | * @brief Receive an amount data over WIFI. |
adustm | 0:c61a93635433 | 1652 | * @param Obj: pointer to module handle |
adustm | 0:c61a93635433 | 1653 | * @param Socket: number of the socket |
adustm | 0:c61a93635433 | 1654 | * @param pdata: pointer to data |
adustm | 0:c61a93635433 | 1655 | * @param len : pointer to the length of the data to be received |
adustm | 0:c61a93635433 | 1656 | * @retval Operation Status. |
adustm | 0:c61a93635433 | 1657 | */ |
adustm | 0:c61a93635433 | 1658 | ES_WIFI_Status_t ES_WIFI_ReceiveData(ES_WIFIObject_t *Obj, uint8_t Socket, uint8_t *pdata, uint16_t Reqlen, uint16_t *Receivedlen, uint32_t Timeout) |
adustm | 0:c61a93635433 | 1659 | { |
adustm | 0:c61a93635433 | 1660 | ES_WIFI_Status_t ret = ES_WIFI_STATUS_ERROR; |
adustm | 0:c61a93635433 | 1661 | |
adustm | 0:c61a93635433 | 1662 | if(Reqlen <= ES_WIFI_PAYLOAD_SIZE ) |
adustm | 0:c61a93635433 | 1663 | { |
adustm | 0:c61a93635433 | 1664 | sprintf((char*)Obj->CmdData,"P0=%d\r", Socket); |
adustm | 0:c61a93635433 | 1665 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1666 | |
adustm | 0:c61a93635433 | 1667 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1668 | { |
adustm | 0:c61a93635433 | 1669 | sprintf((char*)Obj->CmdData,"R1=%d\r", Reqlen); |
adustm | 0:c61a93635433 | 1670 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1671 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1672 | { |
adustm | 0:c61a93635433 | 1673 | sprintf((char*)Obj->CmdData,"R2=%lu\r", Timeout); |
adustm | 0:c61a93635433 | 1674 | ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData); |
adustm | 0:c61a93635433 | 1675 | if(ret == ES_WIFI_STATUS_OK) |
adustm | 0:c61a93635433 | 1676 | { |
adustm | 0:c61a93635433 | 1677 | sprintf((char*)Obj->CmdData,"R0=\r"); |
adustm | 0:c61a93635433 | 1678 | ret = AT_RequestReceiveData(Obj, Obj->CmdData, (char *)pdata, Reqlen, Receivedlen); |
adustm | 0:c61a93635433 | 1679 | } |
adustm | 0:c61a93635433 | 1680 | } |
adustm | 0:c61a93635433 | 1681 | else |
adustm | 0:c61a93635433 | 1682 | { |
adustm | 0:c61a93635433 | 1683 | *Receivedlen = 0; |
adustm | 0:c61a93635433 | 1684 | } |
adustm | 0:c61a93635433 | 1685 | } |
adustm | 0:c61a93635433 | 1686 | } |
adustm | 0:c61a93635433 | 1687 | return ret; |
adustm | 0:c61a93635433 | 1688 | } |
adustm | 0:c61a93635433 | 1689 | |
adustm | 0:c61a93635433 | 1690 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |