iowfehu;gdbjwHJAOPIHO?L

Fork of X_NUCLEO_IDW01M1 by ST

Committer:
mridup
Date:
Wed May 11 06:12:16 2016 +0000
Revision:
7:0fdd186a7d90
Parent:
6:e7a3fca2df10
Child:
8:0f302a13e21b
fix recv, server sock, \r\n..\r\n issue in FW.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mridup 0:dc55f40eb04f 1 /**
mridup 0:dc55f40eb04f 2 ******************************************************************************
mridup 0:dc55f40eb04f 3 * @file wifi_interface.c
mridup 0:dc55f40eb04f 4 * @author Central LAB
mridup 0:dc55f40eb04f 5 * @version V2.0.0
mridup 0:dc55f40eb04f 6 * @date 10-February-2016
mridup 0:dc55f40eb04f 7 * @brief User APIs implementation for X-CUBE-WIFI1
mridup 0:dc55f40eb04f 8 ******************************************************************************
mridup 0:dc55f40eb04f 9 * @attention
mridup 0:dc55f40eb04f 10 *
mridup 0:dc55f40eb04f 11 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mridup 0:dc55f40eb04f 12 *
mridup 0:dc55f40eb04f 13 * Redistribution and use in source and binary forms, with or without modification,
mridup 0:dc55f40eb04f 14 * are permitted provided that the following conditions are met:
mridup 0:dc55f40eb04f 15 * 1. Redistributions of source code must retain the above copyright notice,
mridup 0:dc55f40eb04f 16 * this list of conditions and the following disclaimer.
mridup 0:dc55f40eb04f 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
mridup 0:dc55f40eb04f 18 * this list of conditions and the following disclaimer in the documentation
mridup 0:dc55f40eb04f 19 * and/or other materials provided with the distribution.
mridup 0:dc55f40eb04f 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mridup 0:dc55f40eb04f 21 * may be used to endorse or promote products derived from this software
mridup 0:dc55f40eb04f 22 * without specific prior written permission.
mridup 0:dc55f40eb04f 23 *
mridup 0:dc55f40eb04f 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mridup 0:dc55f40eb04f 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mridup 0:dc55f40eb04f 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mridup 0:dc55f40eb04f 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mridup 0:dc55f40eb04f 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mridup 0:dc55f40eb04f 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mridup 0:dc55f40eb04f 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mridup 0:dc55f40eb04f 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mridup 0:dc55f40eb04f 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mridup 0:dc55f40eb04f 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mridup 0:dc55f40eb04f 34 *
mridup 0:dc55f40eb04f 35 ******************************************************************************
mridup 0:dc55f40eb04f 36 */
mridup 0:dc55f40eb04f 37
mridup 0:dc55f40eb04f 38 /* Includes ------------------------------------------------------------------*/
mridup 0:dc55f40eb04f 39 #include "wifi_module.h"
mridup 0:dc55f40eb04f 40 //#include "stm32_spwf_wifi.h"
mridup 0:dc55f40eb04f 41 #include "ring_buffer.h"
mridup 0:dc55f40eb04f 42 #include "stdio.h"
mridup 0:dc55f40eb04f 43 #include "string.h"
mridup 0:dc55f40eb04f 44 #include "gpio_irq_api.h"
mridup 0:dc55f40eb04f 45 #include "gpio_api.h"
mridup 0:dc55f40eb04f 46 #include "wait_api.h"
mridup 0:dc55f40eb04f 47 #include "serial_api.h"
mridup 0:dc55f40eb04f 48
mridup 0:dc55f40eb04f 49 /** @addtogroup MIDDLEWARES
mridup 0:dc55f40eb04f 50 * @{
mridup 0:dc55f40eb04f 51 */
mridup 0:dc55f40eb04f 52
mridup 0:dc55f40eb04f 53
mridup 0:dc55f40eb04f 54 /** @defgroup NUCLEO_WIFI_INTERFACE
mridup 0:dc55f40eb04f 55 * @brief Wi-Fi User API modules
mridup 0:dc55f40eb04f 56 * @{
mridup 0:dc55f40eb04f 57 */
mridup 0:dc55f40eb04f 58
mridup 0:dc55f40eb04f 59
mridup 0:dc55f40eb04f 60 /** @defgroup NUCLEO_WIFI_INTERFACE_Private_Defines
mridup 0:dc55f40eb04f 61 * @{
mridup 0:dc55f40eb04f 62 */
mridup 0:dc55f40eb04f 63
mridup 0:dc55f40eb04f 64
mridup 0:dc55f40eb04f 65 /**
mridup 0:dc55f40eb04f 66 * @}
mridup 0:dc55f40eb04f 67 */
mridup 0:dc55f40eb04f 68
mridup 0:dc55f40eb04f 69 /** @addtogroup NUCLEO_WIFI_INTERFACE_Private_Variables
mridup 0:dc55f40eb04f 70 * @{
mridup 0:dc55f40eb04f 71 */
mridup 0:dc55f40eb04f 72 /* Private variables ---------------------------------------------------------*/
mridup 0:dc55f40eb04f 73
mridup 0:dc55f40eb04f 74 #if defined (USE_STM32F4XX_NUCLEO) || (USE_STM32L4XX_NUCLEO)
mridup 0:dc55f40eb04f 75 extern uint8_t WiFi_AT_Cmd_Buff[2048];
mridup 0:dc55f40eb04f 76 #else
mridup 0:dc55f40eb04f 77 extern uint8_t WiFi_AT_Cmd_Buff[1024];
mridup 0:dc55f40eb04f 78 #endif
mridup 0:dc55f40eb04f 79
mridup 0:dc55f40eb04f 80 extern volatile Wifi_Status_Var status_flag;
mridup 0:dc55f40eb04f 81
mridup 0:dc55f40eb04f 82 extern char UserDataBuff[MAX_BUFFER_GLOBAL];
mridup 5:c83ffd44f40a 83 extern buffer_e event_buff;
mridup 0:dc55f40eb04f 84 extern wifi_scan *wifi_scanned_list;//[15];
mridup 0:dc55f40eb04f 85 extern char print_msg_buff[MAX_BUFFER_GLOBAL];
mridup 0:dc55f40eb04f 86 extern uint8_t user_scan_number;
mridup 0:dc55f40eb04f 87 extern uint8_t no_of_open_client_sockets;
mridup 0:dc55f40eb04f 88 extern wifi_bool open_sockets[8];//Max open sockets allowed is 8. Each array element depicts one socket (true=open, false=closed)
mridup 0:dc55f40eb04f 89 extern WiFi_AT_CMD_Response_t WiFi_Module_State;
mridup 0:dc55f40eb04f 90 extern volatile uint8_t wifi_client_connected;
mridup 0:dc55f40eb04f 91 extern uint8_t gpio_value, gpio_direc;
mridup 0:dc55f40eb04f 92 extern volatile uint8_t wifi_connected;
mridup 0:dc55f40eb04f 93 extern uint32_t SockON_Data_Length;
mridup 0:dc55f40eb04f 94 extern uint8_t Socket_Open_ID, sockon_query_id;
mridup 0:dc55f40eb04f 95 extern volatile uint32_t WIND64_count;
mridup 0:dc55f40eb04f 96 extern uint32_t process_buffer_index;
mridup 0:dc55f40eb04f 97 extern uint32_t epoch_time;
mridup 0:dc55f40eb04f 98
mridup 0:dc55f40eb04f 99 /*SPWFSADevice Class functions and variables*/
mridup 0:dc55f40eb04f 100 void * spwf_device_class;
mridup 0:dc55f40eb04f 101 extern void callSpwfSADevice_wakeup(void* object, int wake);
mridup 0:dc55f40eb04f 102 extern void callSpwfSADevice_debug(void* object, const char * string);
mridup 0:dc55f40eb04f 103 /**
mridup 0:dc55f40eb04f 104 * @}
mridup 0:dc55f40eb04f 105 */
mridup 0:dc55f40eb04f 106
mridup 0:dc55f40eb04f 107 /** @defgroup NUCLEO_WIFI_INTERFACE_Private_Functions
mridup 0:dc55f40eb04f 108 * @{
mridup 0:dc55f40eb04f 109 */
mridup 0:dc55f40eb04f 110 #ifdef USART_PRINT_MSG
mridup 0:dc55f40eb04f 111 #define printf(arg) {sprintf((char*)print_msg_buff,arg); \
mridup 0:dc55f40eb04f 112 HAL_UART_Transmit(&UartMsgHandle, (uint8_t*)print_msg_buff, strlen(print_msg_buff), 1000);}
mridup 0:dc55f40eb04f 113 #endif
mridup 0:dc55f40eb04f 114
mridup 0:dc55f40eb04f 115 /**
mridup 0:dc55f40eb04f 116 *Changed/introduced functions for MBED implementation:
mridup 0:dc55f40eb04f 117
mridup 0:dc55f40eb04f 118 - WiFi_Status_t wifi_init(wifi_config* config)
mridup 0:dc55f40eb04f 119 - WiFi_Status_t wifi_wakeup(wifi_bool wakeup)
mridup 0:dc55f40eb04f 120 - WiFi_Status_t wifi_socket_server_write(uint16_t DataLength,char * pData)
mridup 0:dc55f40eb04f 121 - void wifi_reset(void);
mridup 0:dc55f40eb04f 122 - WiFi_Status_t wifi_enable(wifi_bool enable)
mridup 0:dc55f40eb04f 123
mridup 0:dc55f40eb04f 124 */
mridup 0:dc55f40eb04f 125
mridup 0:dc55f40eb04f 126
mridup 0:dc55f40eb04f 127 /**
mridup 0:dc55f40eb04f 128 * @brief wifi_init
mridup 0:dc55f40eb04f 129 * User API for wifi init
mridup 0:dc55f40eb04f 130 * @param None
mridup 0:dc55f40eb04f 131 * @retval None
mridup 0:dc55f40eb04f 132 */
mridup 0:dc55f40eb04f 133 WiFi_Status_t wifi_init(wifi_config* config)
mridup 0:dc55f40eb04f 134 {
mridup 0:dc55f40eb04f 135 #ifndef WIFI_USE_VCOM
mridup 0:dc55f40eb04f 136 uint8_t tx_level;
mridup 0:dc55f40eb04f 137 #endif
mridup 0:dc55f40eb04f 138
mridup 0:dc55f40eb04f 139 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 140
mridup 0:dc55f40eb04f 141 #if DEBUG_PRINT
mridup 0:dc55f40eb04f 142 printf("\r\n[SPWF]Initializing SPWF01SA1 Interface\r\n");
mridup 0:dc55f40eb04f 143 #endif
mridup 0:dc55f40eb04f 144 //callSpwfSADevice_debug(spwf_device_class, "\r\n[SPWF] Initializing mbed SPWF01SA1 Interface\r\n");
mridup 0:dc55f40eb04f 145
mridup 0:dc55f40eb04f 146 WiFi_Module_Init();
mridup 0:dc55f40eb04f 147
mridup 0:dc55f40eb04f 148 //callSpwfSADevice_debug(spwf_device_class, "\r\n[SPWF] Module Init done\r\n");
mridup 0:dc55f40eb04f 149
mridup 0:dc55f40eb04f 150 #ifndef WIFI_USE_VCOM
mridup 0:dc55f40eb04f 151
mridup 0:dc55f40eb04f 152 wifi_wakeup(WIFI_TRUE);//Prevent from going to sleep during configuration
mridup 0:dc55f40eb04f 153
mridup 0:dc55f40eb04f 154 /* Soft reset the module */
mridup 0:dc55f40eb04f 155 wifi_reset();
mridup 0:dc55f40eb04f 156
mridup 0:dc55f40eb04f 157 //callSpwfSADevice_debug(spwf_device_class, "\r\n[SPWF] Hardware started\r\n");
mridup 0:dc55f40eb04f 158
mridup 0:dc55f40eb04f 159 /* Set localecho1 to 0*/
mridup 0:dc55f40eb04f 160 status = SET_Configuration_Value(LOCALECHO1, 0);
mridup 0:dc55f40eb04f 161 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 162
mridup 0:dc55f40eb04f 163 /* Restore default setting*/
mridup 0:dc55f40eb04f 164 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 165 sprintf((char*)WiFi_AT_Cmd_Buff,AT_RESTORE_DEFAULT_SETTING);
mridup 0:dc55f40eb04f 166 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 167 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 168 {
mridup 0:dc55f40eb04f 169 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 170 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 171 }
mridup 0:dc55f40eb04f 172
mridup 0:dc55f40eb04f 173 /* Switch on HW Flow Control*/
mridup 0:dc55f40eb04f 174 status = SET_Configuration_Value(CONSOLE1_HWFC, 1);
mridup 0:dc55f40eb04f 175 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 176
mridup 0:dc55f40eb04f 177 if(config->wifi_baud_rate)
mridup 0:dc55f40eb04f 178 {
mridup 0:dc55f40eb04f 179 /* Set USART Speed*/
mridup 0:dc55f40eb04f 180 status = SET_Configuration_Value(CONSOLE1_SPEED, config->wifi_baud_rate);
mridup 0:dc55f40eb04f 181 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 182 }
mridup 0:dc55f40eb04f 183
mridup 0:dc55f40eb04f 184 /* Set wifi_mode to idle*/
mridup 0:dc55f40eb04f 185 status = SET_Configuration_Value(WIFI_MODE, WiFi_IDLE_MODE);
mridup 0:dc55f40eb04f 186 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 187
mridup 0:dc55f40eb04f 188 switch(config->ht_mode)
mridup 0:dc55f40eb04f 189 {
mridup 0:dc55f40eb04f 190 case WIFI_FALSE:
mridup 0:dc55f40eb04f 191 status = SET_Configuration_Value(WIFI_HT_MODE, 0);
mridup 0:dc55f40eb04f 192 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 193 status = SET_Configuration_Addr(WIFI_OPR_RATE_MASK, "0x00003FCF");
mridup 0:dc55f40eb04f 194 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 195 break;
mridup 0:dc55f40eb04f 196 case WIFI_TRUE:
mridup 0:dc55f40eb04f 197 status = SET_Configuration_Value(WIFI_HT_MODE, 1);
mridup 0:dc55f40eb04f 198 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 199 status = SET_Configuration_Addr(WIFI_OPR_RATE_MASK, "0x003FFFCF");
mridup 0:dc55f40eb04f 200 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 201 break;
mridup 0:dc55f40eb04f 202 default:
mridup 0:dc55f40eb04f 203 break;
mridup 0:dc55f40eb04f 204 }
mridup 0:dc55f40eb04f 205
mridup 0:dc55f40eb04f 206 switch(config->power)
mridup 0:dc55f40eb04f 207 {
mridup 0:dc55f40eb04f 208 case wifi_active:
mridup 0:dc55f40eb04f 209 status = SET_Configuration_Value(WIFI_POWERSAVE, 0);
mridup 0:dc55f40eb04f 210 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 211 status = SET_Configuration_Value(WIFI_SLEEP_ENABLED, 0);
mridup 0:dc55f40eb04f 212 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 213 break;
mridup 0:dc55f40eb04f 214 case wifi_reactive:
mridup 0:dc55f40eb04f 215 status = SET_Configuration_Value(WIFI_POWERSAVE, 1);
mridup 0:dc55f40eb04f 216 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 217 status = SET_Configuration_Value(WIFI_OPERATIONAL_MODE, 11);
mridup 0:dc55f40eb04f 218 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 219 status = SET_Configuration_Value(WIFI_BEACON_WAKEUP, 0);
mridup 0:dc55f40eb04f 220 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 221 status = SET_Configuration_Value(WIFI_LISTEN_INTERVAL, 0);
mridup 0:dc55f40eb04f 222 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 223 status = SET_Configuration_Value(WIFI_SLEEP_ENABLED, 0);
mridup 0:dc55f40eb04f 224 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 225 break;
mridup 0:dc55f40eb04f 226 case wifi_sleep:
mridup 0:dc55f40eb04f 227 status = SET_Configuration_Value(WIFI_POWERSAVE, 1);
mridup 0:dc55f40eb04f 228 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 229 status = SET_Configuration_Value(WIFI_OPERATIONAL_MODE, 12);
mridup 0:dc55f40eb04f 230 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 231 status = SET_Configuration_Value(WIFI_BEACON_WAKEUP, 10);
mridup 0:dc55f40eb04f 232 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 233 status = SET_Configuration_Value(WIFI_LISTEN_INTERVAL, 1);
mridup 0:dc55f40eb04f 234 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 235 status = SET_Configuration_Value(WIFI_SLEEP_ENABLED, 1);
mridup 0:dc55f40eb04f 236 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 237 break;
mridup 0:dc55f40eb04f 238 default:
mridup 0:dc55f40eb04f 239 break;
mridup 0:dc55f40eb04f 240 }
mridup 0:dc55f40eb04f 241
mridup 0:dc55f40eb04f 242 switch(config->power_level)
mridup 0:dc55f40eb04f 243 {
mridup 0:dc55f40eb04f 244 case low:
mridup 0:dc55f40eb04f 245 case medium:
mridup 0:dc55f40eb04f 246 case high:
mridup 0:dc55f40eb04f 247 case max:
mridup 0:dc55f40eb04f 248 tx_level=config->power_level*6;
mridup 0:dc55f40eb04f 249 status = SET_Configuration_Value(WIFI_TX_POWER, tx_level);
mridup 0:dc55f40eb04f 250 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 251 break;
mridup 0:dc55f40eb04f 252 default:
mridup 0:dc55f40eb04f 253 break;
mridup 0:dc55f40eb04f 254 }
mridup 0:dc55f40eb04f 255
mridup 0:dc55f40eb04f 256 switch(config->dhcp)
mridup 0:dc55f40eb04f 257 {
mridup 0:dc55f40eb04f 258 case off:
mridup 0:dc55f40eb04f 259 case on:
mridup 0:dc55f40eb04f 260 case custom:
mridup 0:dc55f40eb04f 261 status = SET_Configuration_Value(IP_USE_DHCP_SERVER, config->dhcp);
mridup 0:dc55f40eb04f 262 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 263 break;
mridup 0:dc55f40eb04f 264 default:
mridup 0:dc55f40eb04f 265 break;
mridup 0:dc55f40eb04f 266 }
mridup 0:dc55f40eb04f 267
mridup 0:dc55f40eb04f 268 /* Set IP address */
mridup 0:dc55f40eb04f 269 if(config->ip_addr)
mridup 0:dc55f40eb04f 270 {
mridup 0:dc55f40eb04f 271 status = SET_Configuration_Addr(WIFI_IP_ADDRESS, config->ip_addr);
mridup 0:dc55f40eb04f 272 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 273 }
mridup 0:dc55f40eb04f 274 /* Set netmask address */
mridup 0:dc55f40eb04f 275 if(config->netmask_addr)
mridup 0:dc55f40eb04f 276 {
mridup 0:dc55f40eb04f 277 status = SET_Configuration_Addr(WIFI_IP_NETMASK, config->netmask_addr);
mridup 0:dc55f40eb04f 278 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 279 }
mridup 0:dc55f40eb04f 280 /* Set default gateway address */
mridup 0:dc55f40eb04f 281 if(config->gateway_addr)
mridup 0:dc55f40eb04f 282 {
mridup 0:dc55f40eb04f 283 status = SET_Configuration_Addr(WIFI_IP_DEFAULT_GATEWAY, config->gateway_addr);
mridup 0:dc55f40eb04f 284 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 285 }
mridup 0:dc55f40eb04f 286 /* Set dns address */
mridup 0:dc55f40eb04f 287 if(config->dns_addr)
mridup 0:dc55f40eb04f 288 {
mridup 0:dc55f40eb04f 289 status = SET_Configuration_Addr(WIFI_IP_DNS, config->dns_addr);
mridup 0:dc55f40eb04f 290 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 291 }
mridup 0:dc55f40eb04f 292 /* Set hostname */
mridup 0:dc55f40eb04f 293 if(config->host_name)
mridup 0:dc55f40eb04f 294 {
mridup 0:dc55f40eb04f 295 status = SET_Configuration_Addr(WIFI_IP_HOSTNAME, config->host_name);
mridup 0:dc55f40eb04f 296 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 297 }
mridup 0:dc55f40eb04f 298
mridup 0:dc55f40eb04f 299 if(config->ap_domain_name)
mridup 0:dc55f40eb04f 300 {
mridup 0:dc55f40eb04f 301 status = SET_Configuration_Addr(WIFI_IP_APDOMAINNAME, config->ap_domain_name);
mridup 0:dc55f40eb04f 302 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 303 }
mridup 0:dc55f40eb04f 304
mridup 0:dc55f40eb04f 305 if(config->ap_config_page_name)
mridup 0:dc55f40eb04f 306 {
mridup 0:dc55f40eb04f 307 status = SET_Configuration_Addr(WIFI_IP_APREDIRECT, config->ap_config_page_name);
mridup 0:dc55f40eb04f 308 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 309 }
mridup 0:dc55f40eb04f 310
mridup 0:dc55f40eb04f 311 if(config->http_timeout)
mridup 0:dc55f40eb04f 312 {
mridup 0:dc55f40eb04f 313 status = SET_Configuration_Value(WIFI_IP_HTTP_TIMEOUT, config->http_timeout*1000);
mridup 0:dc55f40eb04f 314 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 315 }
mridup 0:dc55f40eb04f 316 if(config->dhcp_timeout)
mridup 0:dc55f40eb04f 317 {
mridup 0:dc55f40eb04f 318 status = SET_Configuration_Value(WIFI_IP_DHCP_TIMEOUT, config->dhcp_timeout);
mridup 0:dc55f40eb04f 319 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 320 }
mridup 0:dc55f40eb04f 321
mridup 0:dc55f40eb04f 322 #ifdef MODULE_VERSION_SPWF01Sx_1y
mridup 0:dc55f40eb04f 323 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 324 sprintf((char*)WiFi_AT_Cmd_Buff,AT_HTTPD, config->web_server);
mridup 0:dc55f40eb04f 325 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 326 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 327 {
mridup 0:dc55f40eb04f 328 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 329 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 330 }
mridup 0:dc55f40eb04f 331 #endif
mridup 0:dc55f40eb04f 332
mridup 0:dc55f40eb04f 333 /*AT+S.TLSCERT2=clean,all */
mridup 0:dc55f40eb04f 334 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 335 sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.TLSCERT2=clean,all\r");
mridup 0:dc55f40eb04f 336 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 337 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 338 {
mridup 0:dc55f40eb04f 339 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 340 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 341 }
mridup 0:dc55f40eb04f 342
mridup 0:dc55f40eb04f 343 /* save current setting in flash */
mridup 0:dc55f40eb04f 344 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 345 sprintf((char*)WiFi_AT_Cmd_Buff,AT_SAVE_CURRENT_SETTING);
mridup 0:dc55f40eb04f 346 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 347 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 348 {
mridup 0:dc55f40eb04f 349 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 350 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 351 }
mridup 0:dc55f40eb04f 352
mridup 0:dc55f40eb04f 353 if(config->wifi_baud_rate)
mridup 0:dc55f40eb04f 354 {
mridup 0:dc55f40eb04f 355 UART_Configuration(config->wifi_baud_rate);
mridup 0:dc55f40eb04f 356 Receive_Data();//Restart data reception
mridup 0:dc55f40eb04f 357 }
mridup 0:dc55f40eb04f 358
mridup 0:dc55f40eb04f 359 /* Soft reset the module, Do the second reset after setting all parameters and saving in flash */
mridup 0:dc55f40eb04f 360 wifi_reset();
mridup 0:dc55f40eb04f 361
mridup 0:dc55f40eb04f 362 wifi_wakeup(WIFI_FALSE);//De-assert wakeup signal (PC8) to allow sleep if enabled
mridup 0:dc55f40eb04f 363 #endif //WIFI_USE_VCOM
mridup 0:dc55f40eb04f 364
mridup 0:dc55f40eb04f 365 #if DEBUG_PRINT
mridup 0:dc55f40eb04f 366 printf("\r\nEnd of Initialization..\r\n");
mridup 0:dc55f40eb04f 367 #endif
mridup 0:dc55f40eb04f 368 //callSpwfSADevice_debug(spwf_device_class, "\r\n[SPWF] End of mbed Initialization\r\n");
mridup 0:dc55f40eb04f 369
mridup 0:dc55f40eb04f 370 return status;
mridup 0:dc55f40eb04f 371 }
mridup 0:dc55f40eb04f 372
mridup 0:dc55f40eb04f 373
mridup 0:dc55f40eb04f 374 /**
mridup 0:dc55f40eb04f 375 * @brief wifi_socket_client_security
mridup 0:dc55f40eb04f 376 * Set the security certificates and key for secure socket (TLS)
mridup 0:dc55f40eb04f 377 * @param None
mridup 0:dc55f40eb04f 378 * @retval WiFi_Status_t : return status
mridup 0:dc55f40eb04f 379 */
mridup 0:dc55f40eb04f 380 WiFi_Status_t wifi_socket_client_security(uint8_t* tls_mode, uint8_t* root_ca_server, uint8_t* client_cert, uint8_t* client_key, uint8_t* client_domain, uint32_t tls_epoch_time)
mridup 0:dc55f40eb04f 381 {
mridup 0:dc55f40eb04f 382 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 383
mridup 0:dc55f40eb04f 384 /*AT+S.TLSCERT2=clean,all */
mridup 0:dc55f40eb04f 385 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 386 sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.TLSCERT2=clean,all\r");
mridup 0:dc55f40eb04f 387 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 388 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 389 {
mridup 0:dc55f40eb04f 390 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 391 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 392 }
mridup 0:dc55f40eb04f 393
mridup 0:dc55f40eb04f 394 /* AT+S.SETTIME=<seconds> */
mridup 0:dc55f40eb04f 395 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 396 if(tls_epoch_time==0)
mridup 0:dc55f40eb04f 397 epoch_time = EPOCH_TIME;
mridup 0:dc55f40eb04f 398 else
mridup 0:dc55f40eb04f 399 epoch_time = tls_epoch_time;
mridup 0:dc55f40eb04f 400
mridup 0:dc55f40eb04f 401 sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.SETTIME=%lu\r",(unsigned long)epoch_time);
mridup 0:dc55f40eb04f 402 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 403 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 404 {
mridup 0:dc55f40eb04f 405 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 406 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 407 }
mridup 0:dc55f40eb04f 408
mridup 0:dc55f40eb04f 409 /*AT+S.TLSCERT=f_ca,<size><CR><data>*/
mridup 0:dc55f40eb04f 410 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 411 sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.TLSCERT=f_ca,%d\r%s",strlen((const char *)root_ca_server) - 1, root_ca_server);
mridup 0:dc55f40eb04f 412
mridup 0:dc55f40eb04f 413 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 414 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 415 {
mridup 0:dc55f40eb04f 416 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 417 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 418 }
mridup 0:dc55f40eb04f 419
mridup 0:dc55f40eb04f 420 /*AT+S.TLSCERT=f_cert,<size><CR><data>*/
mridup 0:dc55f40eb04f 421 if(tls_mode[0]=='m')
mridup 0:dc55f40eb04f 422 {
mridup 0:dc55f40eb04f 423 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 424 sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.TLSCERT=f_cert,%d\r%s",strlen((const char *)client_cert) - 1, client_cert);
mridup 0:dc55f40eb04f 425
mridup 0:dc55f40eb04f 426 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 427 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 428 {
mridup 0:dc55f40eb04f 429 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 430 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 431 }
mridup 0:dc55f40eb04f 432
mridup 0:dc55f40eb04f 433 /*AT+S.TLSCERT=f_key,<size><CR><data>*/
mridup 0:dc55f40eb04f 434 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 435 sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.TLSCERT=f_key,%d\r%s",strlen((const char *)client_key) - 1, client_key);
mridup 0:dc55f40eb04f 436
mridup 0:dc55f40eb04f 437 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 438 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 439 {
mridup 0:dc55f40eb04f 440 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 441 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 442 }
mridup 0:dc55f40eb04f 443 }
mridup 0:dc55f40eb04f 444
mridup 0:dc55f40eb04f 445 /*AT+S.TLSDOMAIN=f_domain,<server domain>*/
mridup 0:dc55f40eb04f 446 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 447 sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.TLSDOMAIN=f_domain,%s\r", client_domain);
mridup 0:dc55f40eb04f 448 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 449 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 450 {
mridup 0:dc55f40eb04f 451 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 452 if(status != WiFi_MODULE_SUCCESS) return status;
mridup 0:dc55f40eb04f 453 }
mridup 0:dc55f40eb04f 454
mridup 0:dc55f40eb04f 455 return status;
mridup 0:dc55f40eb04f 456 }
mridup 0:dc55f40eb04f 457
mridup 0:dc55f40eb04f 458 /**
mridup 0:dc55f40eb04f 459 * @brief wifi_socket_client_open
mridup 0:dc55f40eb04f 460 * Open a network socket
mridup 0:dc55f40eb04f 461 * @param Hostname hostname to connect to
mridup 0:dc55f40eb04f 462 * portnumber portnumber of the Host to connect to
mridup 0:dc55f40eb04f 463 * protocol tcp or udp protocol
mridup 0:dc55f40eb04f 464 * sock_id socket id of the opened socket returned to the user
mridup 0:dc55f40eb04f 465 * @retval WiFi_Status_t : return status of socket open request
mridup 0:dc55f40eb04f 466 */
mridup 0:dc55f40eb04f 467 WiFi_Status_t wifi_socket_client_open(uint8_t * hostname, uint32_t port_number, uint8_t * protocol, uint8_t * sock_id)
mridup 0:dc55f40eb04f 468 {
mridup 0:dc55f40eb04f 469 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 470
mridup 0:dc55f40eb04f 471 Queue_Client_Open_Event(hostname,port_number,protocol);
mridup 0:dc55f40eb04f 472 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 473
mridup 0:dc55f40eb04f 474 *sock_id = Socket_Open_ID; //return the socket id to the user
mridup 0:dc55f40eb04f 475
mridup 0:dc55f40eb04f 476 return status;
mridup 0:dc55f40eb04f 477 }
mridup 0:dc55f40eb04f 478
mridup 0:dc55f40eb04f 479 /**
mridup 0:dc55f40eb04f 480 * @brief Open_Serial_Port
mridup 0:dc55f40eb04f 481 * Open a network socket
mridup 0:dc55f40eb04f 482 * @param None
mridup 0:dc55f40eb04f 483 * @retval WiFi_Status_t : Wifi status
mridup 0:dc55f40eb04f 484 */
mridup 0:dc55f40eb04f 485 WiFi_Status_t Open_Serial_Port()
mridup 0:dc55f40eb04f 486 {
mridup 0:dc55f40eb04f 487 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 488 /* AT+S.SOCKOS=2<cr> */
mridup 0:dc55f40eb04f 489 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 490 //sprintf((char*)WiFi_AT_Cmd_Buff,"\rAT+S.SOCKOS=%d\r",SerialPortNo);
mridup 0:dc55f40eb04f 491 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 492
mridup 0:dc55f40eb04f 493 if(status==WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 494 {
mridup 0:dc55f40eb04f 495 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 496 }
mridup 0:dc55f40eb04f 497 return status;
mridup 0:dc55f40eb04f 498 }
mridup 0:dc55f40eb04f 499
mridup 0:dc55f40eb04f 500 /**
mridup 0:dc55f40eb04f 501 * @brief wifi_socket_client_write
mridup 0:dc55f40eb04f 502 * Write len bytes of data to socket
mridup 0:dc55f40eb04f 503 * @param sock_id socket ID of the socket to write to
mridup 0:dc55f40eb04f 504 * DataLength: data length to send
mridup 0:dc55f40eb04f 505 * pData : pointer of data buffer to be written
mridup 0:dc55f40eb04f 506 * @retval WiFi_Status_t : return status of socket write request
mridup 0:dc55f40eb04f 507 */
mridup 0:dc55f40eb04f 508 WiFi_Status_t wifi_socket_client_write(uint8_t sock_id, uint16_t DataLength, char * pData)
mridup 0:dc55f40eb04f 509 {
mridup 0:dc55f40eb04f 510 /* AT+S.SOCKW=00,11<cr> */
mridup 0:dc55f40eb04f 511 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 512
mridup 0:dc55f40eb04f 513 //Check if sock_id is open
mridup 0:dc55f40eb04f 514 if(!open_sockets[sock_id])
mridup 0:dc55f40eb04f 515 return WiFi_NOT_READY;
mridup 0:dc55f40eb04f 516
mridup 0:dc55f40eb04f 517 if(DataLength>=1021 || DataLength<=0)
mridup 0:dc55f40eb04f 518 return WiFi_NOT_SUPPORTED;
mridup 0:dc55f40eb04f 519
mridup 0:dc55f40eb04f 520 Queue_Client_Write_Event(sock_id,DataLength,pData);
mridup 0:dc55f40eb04f 521 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 522 return status;
mridup 0:dc55f40eb04f 523 }
mridup 0:dc55f40eb04f 524
mridup 0:dc55f40eb04f 525 /**
mridup 0:dc55f40eb04f 526 * @brief Socket_Read
mridup 0:dc55f40eb04f 527 * Return len bytes of data from socket
mridup 0:dc55f40eb04f 528 * @param DataLength: data length to read
mridup 0:dc55f40eb04f 529 * @retval WiFi_Status_t : return status of socket read request
mridup 0:dc55f40eb04f 530 */
mridup 0:dc55f40eb04f 531 WiFi_Status_t Socket_Read(uint16_t DataLength)
mridup 0:dc55f40eb04f 532 {
mridup 0:dc55f40eb04f 533 /* AT+S.SOCKR=01,12<cr> */
mridup 0:dc55f40eb04f 534 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 535 wait_for_command_mode();
mridup 0:dc55f40eb04f 536
mridup 0:dc55f40eb04f 537 /* AT+S.SOCKON=myserver,1234,t<cr> */
mridup 0:dc55f40eb04f 538 sprintf((char*)WiFi_AT_Cmd_Buff,AT_SOCKET_READ,sockon_query_id,DataLength);
mridup 0:dc55f40eb04f 539 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 540 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 541 {
mridup 0:dc55f40eb04f 542 if(status_flag.stop_event_dequeue == WIFI_FALSE)
mridup 0:dc55f40eb04f 543 status_flag.stop_event_dequeue = WIFI_TRUE;
mridup 0:dc55f40eb04f 544 SockON_Data_Length = DataLength;
mridup 0:dc55f40eb04f 545 status_flag.enable_sock_read = WIFI_TRUE;
mridup 0:dc55f40eb04f 546 process_buffer_index =5;
mridup 0:dc55f40eb04f 547 status_flag.enable_receive_data_chunk = WIFI_TRUE;
mridup 0:dc55f40eb04f 548 WiFi_Module_State = Process_Event;
mridup 0:dc55f40eb04f 549 status_flag.Set_AT_Cmd_Response_False = WIFI_TRUE;
mridup 0:dc55f40eb04f 550 memset(UserDataBuff, 0x00, MAX_BUFFER_GLOBAL);
mridup 0:dc55f40eb04f 551 }
mridup 0:dc55f40eb04f 552 return status;
mridup 0:dc55f40eb04f 553 }
mridup 0:dc55f40eb04f 554
mridup 0:dc55f40eb04f 555 /**
mridup 0:dc55f40eb04f 556 * @brief wifi_socket_client_close
mridup 0:dc55f40eb04f 557 * The SOCKC command allows to close socket
mridup 0:dc55f40eb04f 558 * @param sock_close_id the socket ID of the socket which needs to be closed.
mridup 0:dc55f40eb04f 559 * @retval WiFi_Status_t : return status of socket close request
mridup 0:dc55f40eb04f 560 */
mridup 0:dc55f40eb04f 561 WiFi_Status_t wifi_socket_client_close(uint8_t sock_close_id)
mridup 0:dc55f40eb04f 562 {
mridup 0:dc55f40eb04f 563 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 564
mridup 0:dc55f40eb04f 565 if(open_sockets[sock_close_id])
mridup 0:dc55f40eb04f 566 {
mridup 0:dc55f40eb04f 567 Queue_Client_Close_Event(sock_close_id);
mridup 0:dc55f40eb04f 568 return status;
mridup 0:dc55f40eb04f 569 }
mridup 0:dc55f40eb04f 570 else
mridup 0:dc55f40eb04f 571 return WiFi_MODULE_ERROR;
mridup 0:dc55f40eb04f 572
mridup 0:dc55f40eb04f 573 }
mridup 0:dc55f40eb04f 574
mridup 0:dc55f40eb04f 575 /**
mridup 0:dc55f40eb04f 576 * @brief Socket_Pending_Data
mridup 0:dc55f40eb04f 577 * Query pending data.It will returns the number of bytes of data waiting on socket
mridup 0:dc55f40eb04f 578 * @param None
mridup 0:dc55f40eb04f 579 * @retval uint8_t :number of bytes of data waiting on socket
mridup 0:dc55f40eb04f 580 */
mridup 0:dc55f40eb04f 581 void Socket_Pending_Data()
mridup 0:dc55f40eb04f 582 {
mridup 0:dc55f40eb04f 583 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 584
mridup 0:dc55f40eb04f 585 /* AT+S.SOCKQ=01<cr> */
mridup 0:dc55f40eb04f 586 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 587
mridup 0:dc55f40eb04f 588 wait_for_command_mode();
mridup 0:dc55f40eb04f 589
mridup 0:dc55f40eb04f 590 if(open_sockets[sockon_query_id])
mridup 0:dc55f40eb04f 591 {
mridup 0:dc55f40eb04f 592 if(status_flag.stop_event_dequeue == WIFI_FALSE)
mridup 0:dc55f40eb04f 593 status_flag.stop_event_dequeue = WIFI_TRUE;
mridup 0:dc55f40eb04f 594
mridup 0:dc55f40eb04f 595 sprintf((char*)WiFi_AT_Cmd_Buff,AT_QUERY_PENDING_DATA,sockon_query_id);
mridup 0:dc55f40eb04f 596 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 597 if(status==WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 598 {
mridup 0:dc55f40eb04f 599 /* EQ. Set state to Process_Event */
mridup 0:dc55f40eb04f 600 WiFi_Module_State = Process_Event;
mridup 0:dc55f40eb04f 601 status_flag.Set_AT_Cmd_Response_False = WIFI_TRUE;
mridup 0:dc55f40eb04f 602 }
mridup 0:dc55f40eb04f 603 }
mridup 0:dc55f40eb04f 604 }
mridup 0:dc55f40eb04f 605
mridup 0:dc55f40eb04f 606 /**
mridup 0:dc55f40eb04f 607 * @brief wifi_socket_server_open
mridup 0:dc55f40eb04f 608 * Open a Server socket
mridup 0:dc55f40eb04f 609 * @param None
mridup 0:dc55f40eb04f 610 * @retval WiFi_Status_t : return status of server socket request
mridup 0:dc55f40eb04f 611 */
mridup 0:dc55f40eb04f 612 WiFi_Status_t wifi_socket_server_open(uint32_t port_number, uint8_t * protocol)
mridup 0:dc55f40eb04f 613 {
mridup 0:dc55f40eb04f 614 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 7:0fdd186a7d90 615
mridup 7:0fdd186a7d90 616 //Wait till all queued events are executed
mridup 7:0fdd186a7d90 617 while(!event_empty(&event_buff));
mridup 7:0fdd186a7d90 618 Wait_For_Sock_Read_To_Complete();
mridup 7:0fdd186a7d90 619
mridup 0:dc55f40eb04f 620 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 621
mridup 0:dc55f40eb04f 622 /* AT+S.SOCKD=portNo,t<cr> */
mridup 0:dc55f40eb04f 623 sprintf((char*)WiFi_AT_Cmd_Buff,AT_SERVER_SOCKET_OPEN,(int)port_number,protocol);
mridup 0:dc55f40eb04f 624 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 625 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 626 {
mridup 0:dc55f40eb04f 627 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 628 }
mridup 0:dc55f40eb04f 629 return status;
mridup 0:dc55f40eb04f 630 }
mridup 0:dc55f40eb04f 631
mridup 0:dc55f40eb04f 632
mridup 0:dc55f40eb04f 633
mridup 0:dc55f40eb04f 634 /**
mridup 0:dc55f40eb04f 635 * @brief Server Socket Close
mridup 0:dc55f40eb04f 636 * Close a Server socket
mridup 0:dc55f40eb04f 637 * @param None
mridup 0:dc55f40eb04f 638 * @retval WiFi_Status_t : return status of server socket request
mridup 0:dc55f40eb04f 639 */
mridup 0:dc55f40eb04f 640 WiFi_Status_t wifi_socket_server_close()
mridup 0:dc55f40eb04f 641 {
mridup 0:dc55f40eb04f 642 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 7:0fdd186a7d90 643
mridup 7:0fdd186a7d90 644 //Wait till all queued events are executed
mridup 7:0fdd186a7d90 645 while(!event_empty(&event_buff));
mridup 7:0fdd186a7d90 646 Wait_For_Sock_Read_To_Complete();
mridup 7:0fdd186a7d90 647
mridup 0:dc55f40eb04f 648 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 649
mridup 0:dc55f40eb04f 650 /* AT+S.SOCKD=portNo,t<cr> */
mridup 0:dc55f40eb04f 651 sprintf((char*)WiFi_AT_Cmd_Buff,AT_SERVER_SOCKET_CLOSE);
mridup 0:dc55f40eb04f 652 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 653 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 654 {
mridup 0:dc55f40eb04f 655 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 656 }
mridup 0:dc55f40eb04f 657
mridup 0:dc55f40eb04f 658 return status;
mridup 0:dc55f40eb04f 659 }
mridup 0:dc55f40eb04f 660
mridup 0:dc55f40eb04f 661
mridup 0:dc55f40eb04f 662 /**
mridup 0:dc55f40eb04f 663 * @brief wait_for_command_mode
mridup 0:dc55f40eb04f 664 * Waits till we are in command mode
mridup 0:dc55f40eb04f 665 * @param None
mridup 0:dc55f40eb04f 666 * @retval None
mridup 0:dc55f40eb04f 667 */
mridup 0:dc55f40eb04f 668 void wait_for_command_mode(void)
mridup 0:dc55f40eb04f 669 {
mridup 0:dc55f40eb04f 670 while(!status_flag.command_mode)
mridup 0:dc55f40eb04f 671 {
mridup 0:dc55f40eb04f 672 //Make sure we are in command mode, ideally we should do this in every User API?
mridup 0:dc55f40eb04f 673 asm("NOP");
mridup 0:dc55f40eb04f 674 }
mridup 0:dc55f40eb04f 675 }
mridup 0:dc55f40eb04f 676
mridup 0:dc55f40eb04f 677
mridup 0:dc55f40eb04f 678 /**
mridup 0:dc55f40eb04f 679 * @brief wifi_file_delete
mridup 0:dc55f40eb04f 680 * Delete a file
mridup 0:dc55f40eb04f 681 * @param pFileName : File Name to be deleted
mridup 0:dc55f40eb04f 682 * @retval WiFi_Status_t : return status of delete file request
mridup 0:dc55f40eb04f 683 */
mridup 0:dc55f40eb04f 684 WiFi_Status_t wifi_file_delete(char * pFileName)
mridup 0:dc55f40eb04f 685 {
mridup 0:dc55f40eb04f 686 /* AT+S.FSD: delete an existing file */
mridup 0:dc55f40eb04f 687 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 688 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 689 /* AT+S.FSL */
mridup 0:dc55f40eb04f 690 sprintf((char*)WiFi_AT_Cmd_Buff,AT_DELETE_FILE,pFileName);
mridup 0:dc55f40eb04f 691
mridup 0:dc55f40eb04f 692 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 693 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 694 {
mridup 0:dc55f40eb04f 695 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 696 }
mridup 0:dc55f40eb04f 697 return status;
mridup 0:dc55f40eb04f 698 }
mridup 0:dc55f40eb04f 699
mridup 0:dc55f40eb04f 700 /**
mridup 0:dc55f40eb04f 701 * @brief wifi_file_list
mridup 0:dc55f40eb04f 702 * List existing filename
mridup 0:dc55f40eb04f 703 * @param None
mridup 0:dc55f40eb04f 704 * @retval WiFi_Status_t : return status of AT cmd request
mridup 0:dc55f40eb04f 705 */
mridup 0:dc55f40eb04f 706
mridup 0:dc55f40eb04f 707 WiFi_Status_t wifi_file_list()
mridup 0:dc55f40eb04f 708 {
mridup 0:dc55f40eb04f 709 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 710 Queue_Wifi_File_Event(NULL,NULL,0);
mridup 0:dc55f40eb04f 711 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 712 return status;
mridup 0:dc55f40eb04f 713 }
mridup 0:dc55f40eb04f 714
mridup 0:dc55f40eb04f 715 /**
mridup 0:dc55f40eb04f 716 * @brief wifi_file_show
mridup 0:dc55f40eb04f 717 * Print the contents of an existing file
mridup 0:dc55f40eb04f 718 * @param pFileName : pinter of file name
mridup 0:dc55f40eb04f 719 * @retval WiFi_Status_t : return status of AT cmd request
mridup 0:dc55f40eb04f 720 */
mridup 0:dc55f40eb04f 721
mridup 0:dc55f40eb04f 722 WiFi_Status_t wifi_file_show(uint8_t * pFileName)
mridup 0:dc55f40eb04f 723 {
mridup 0:dc55f40eb04f 724 if(pFileName==NULL)
mridup 0:dc55f40eb04f 725 return WiFi_MODULE_ERROR;
mridup 0:dc55f40eb04f 726
mridup 0:dc55f40eb04f 727 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 728 Queue_Wifi_File_Event(NULL,pFileName,0);
mridup 0:dc55f40eb04f 729 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 730 return status;
mridup 0:dc55f40eb04f 731 }
mridup 0:dc55f40eb04f 732
mridup 0:dc55f40eb04f 733 /**
mridup 0:dc55f40eb04f 734 * @brief wifi_file_create
mridup 0:dc55f40eb04f 735 * Create file for HTTP server
mridup 0:dc55f40eb04f 736 * @param pFileName : pointer of file name to be created
mridup 0:dc55f40eb04f 737 * alength : length of file
mridup 0:dc55f40eb04f 738 * @retval WiFi_Status_t : return status of AT cmd request
mridup 0:dc55f40eb04f 739 */
mridup 0:dc55f40eb04f 740
mridup 0:dc55f40eb04f 741 WiFi_Status_t wifi_file_create(char *pFileName, uint16_t alength, char * pUserFileBuff)
mridup 0:dc55f40eb04f 742 {
mridup 0:dc55f40eb04f 743 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 744
mridup 0:dc55f40eb04f 745 if(alength >1024)
mridup 0:dc55f40eb04f 746 return WiFi_AT_FILE_LENGTH_ERROR;
mridup 0:dc55f40eb04f 747
mridup 0:dc55f40eb04f 748 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 749
mridup 0:dc55f40eb04f 750 /* AT+S.FSC=/index.html */
mridup 0:dc55f40eb04f 751 sprintf((char*)WiFi_AT_Cmd_Buff, AT_CREATE_NEW_HTML_FILE, pFileName, alength);
mridup 0:dc55f40eb04f 752
mridup 0:dc55f40eb04f 753 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 754 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 755 {
mridup 0:dc55f40eb04f 756 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 757 int len = strlen(pUserFileBuff);
mridup 0:dc55f40eb04f 758
mridup 0:dc55f40eb04f 759 if(len >= 1024)
mridup 0:dc55f40eb04f 760 return WiFi_AT_FILE_LENGTH_ERROR;
mridup 0:dc55f40eb04f 761
mridup 0:dc55f40eb04f 762 /* AT+S.FSA=/index.html */
mridup 0:dc55f40eb04f 763 sprintf((char*)WiFi_AT_Cmd_Buff,AT_APPEND_FILE,pFileName,len);
mridup 0:dc55f40eb04f 764
mridup 0:dc55f40eb04f 765 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 766 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 767 {
mridup 0:dc55f40eb04f 768 memset(WiFi_AT_Cmd_Buff, 0x00, sizeof WiFi_AT_Cmd_Buff);
mridup 0:dc55f40eb04f 769 memcpy((char*)(char*)WiFi_AT_Cmd_Buff, (char*) pUserFileBuff,len);
mridup 0:dc55f40eb04f 770 WiFi_AT_Cmd_Buff[len+1]='\r';
mridup 0:dc55f40eb04f 771 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 772 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 773 {
mridup 0:dc55f40eb04f 774 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 775 }
mridup 0:dc55f40eb04f 776 }
mridup 0:dc55f40eb04f 777 }
mridup 0:dc55f40eb04f 778 return status;
mridup 0:dc55f40eb04f 779 }
mridup 0:dc55f40eb04f 780
mridup 0:dc55f40eb04f 781 /**
mridup 0:dc55f40eb04f 782 * @brief wifi_http_get
mridup 0:dc55f40eb04f 783 * Issue an HTTP GET of the given path to the specified host
mridup 0:dc55f40eb04f 784 * @param None
mridup 0:dc55f40eb04f 785 * @retval WiFi_Status_t : return status of AT cmd response
mridup 0:dc55f40eb04f 786 */
mridup 0:dc55f40eb04f 787
mridup 0:dc55f40eb04f 788 WiFi_Status_t wifi_http_get(uint8_t * hostname, uint8_t * path, uint32_t port_number)
mridup 0:dc55f40eb04f 789 {
mridup 0:dc55f40eb04f 790 if(hostname == NULL || path == NULL)
mridup 0:dc55f40eb04f 791 return WiFi_MODULE_ERROR;
mridup 0:dc55f40eb04f 792
mridup 0:dc55f40eb04f 793 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 794
mridup 0:dc55f40eb04f 795 while(status_flag.sock_read_ongoing || WIND64_count!= 0); //wait till any pending data is read
mridup 0:dc55f40eb04f 796 {
mridup 0:dc55f40eb04f 797 asm("NOP");
mridup 0:dc55f40eb04f 798 }
mridup 0:dc55f40eb04f 799
mridup 0:dc55f40eb04f 800 // AT+S.HTTPGET=host.example.com,/index.html, port_number<cr>
mridup 0:dc55f40eb04f 801 //Queue the http-get command
mridup 0:dc55f40eb04f 802 Queue_Http_Event(hostname, path, port_number,NULL);
mridup 0:dc55f40eb04f 803
mridup 0:dc55f40eb04f 804 //Make the user wait anyway
mridup 0:dc55f40eb04f 805 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 806
mridup 0:dc55f40eb04f 807 return status;
mridup 0:dc55f40eb04f 808
mridup 0:dc55f40eb04f 809 }
mridup 0:dc55f40eb04f 810
mridup 0:dc55f40eb04f 811 /**
mridup 0:dc55f40eb04f 812 * @brief wifi_http_post
mridup 0:dc55f40eb04f 813 * Issue an HTTP GET of the given path to the specified host
mridup 0:dc55f40eb04f 814 * @param None
mridup 0:dc55f40eb04f 815 * @retval WiFi_Status_t : status of Http Post Request
mridup 0:dc55f40eb04f 816 */
mridup 0:dc55f40eb04f 817
mridup 0:dc55f40eb04f 818 WiFi_Status_t wifi_http_post(uint8_t * pURL_path)
mridup 0:dc55f40eb04f 819 {
mridup 0:dc55f40eb04f 820 if(pURL_path == NULL)
mridup 0:dc55f40eb04f 821 return WiFi_MODULE_ERROR;
mridup 0:dc55f40eb04f 822
mridup 0:dc55f40eb04f 823 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 824
mridup 0:dc55f40eb04f 825 while(status_flag.sock_read_ongoing || WIND64_count!= 0);//wait till any pending data is read
mridup 0:dc55f40eb04f 826 {
mridup 0:dc55f40eb04f 827 asm("NOP");
mridup 0:dc55f40eb04f 828 }
mridup 0:dc55f40eb04f 829
mridup 0:dc55f40eb04f 830 // AT+S.HTTPPOST = posttestserver.com,/post.php,name=demo&email=mymail&subject=subj&body=message<cr>
mridup 0:dc55f40eb04f 831 Queue_Http_Event(NULL,NULL,0,pURL_path);
mridup 0:dc55f40eb04f 832
mridup 0:dc55f40eb04f 833 //Make the user wait anyway
mridup 0:dc55f40eb04f 834 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 835 return status;
mridup 0:dc55f40eb04f 836 }
mridup 0:dc55f40eb04f 837
mridup 0:dc55f40eb04f 838 /**
mridup 0:dc55f40eb04f 839 * @brief wifi_file_image_create
mridup 0:dc55f40eb04f 840 * Downloads an updated file system via a single HTTP GET request to the
mridup 0:dc55f40eb04f 841 * named host and path.
mridup 0:dc55f40eb04f 842 * @param None
mridup 0:dc55f40eb04f 843 * @retval WiFi_Status_t
mridup 0:dc55f40eb04f 844 */
mridup 0:dc55f40eb04f 845 WiFi_Status_t wifi_file_image_create(uint8_t * pHostName, uint8_t * pFileName, uint32_t port_number)
mridup 0:dc55f40eb04f 846 {
mridup 0:dc55f40eb04f 847 if(pHostName == NULL || pFileName == NULL || port_number ==0)
mridup 0:dc55f40eb04f 848 return WiFi_MODULE_ERROR;
mridup 0:dc55f40eb04f 849
mridup 0:dc55f40eb04f 850 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 851 Queue_Wifi_File_Event(pHostName,pFileName,port_number);
mridup 0:dc55f40eb04f 852 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 853
mridup 0:dc55f40eb04f 854 /* Soft reset the module */
mridup 0:dc55f40eb04f 855 SET_Power_State(PowerSave_State);
mridup 0:dc55f40eb04f 856 return status;
mridup 0:dc55f40eb04f 857 }
mridup 0:dc55f40eb04f 858
mridup 0:dc55f40eb04f 859 /**
mridup 0:dc55f40eb04f 860 * @brief wifi_file_erase_external_flash
mridup 0:dc55f40eb04f 861 * This API allows to erase the content of the external flash
mridup 0:dc55f40eb04f 862 * @param None
mridup 0:dc55f40eb04f 863 * @retval WiFi_Status_t
mridup 0:dc55f40eb04f 864 */
mridup 0:dc55f40eb04f 865 WiFi_Status_t wifi_file_erase_external_flash()
mridup 0:dc55f40eb04f 866 {
mridup 0:dc55f40eb04f 867 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 868
mridup 0:dc55f40eb04f 869 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 870 ResetBuffer();
mridup 0:dc55f40eb04f 871
mridup 0:dc55f40eb04f 872 /* AT+S.HTTPDFSERASE */
mridup 0:dc55f40eb04f 873 sprintf((char*)WiFi_AT_Cmd_Buff,AT_ERASE_FLASH_MEMORY);
mridup 0:dc55f40eb04f 874 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 875
mridup 0:dc55f40eb04f 876 /* Soft reset the module */
mridup 0:dc55f40eb04f 877 SET_Power_State(PowerSave_State);
mridup 0:dc55f40eb04f 878
mridup 0:dc55f40eb04f 879 return status;
mridup 0:dc55f40eb04f 880 }
mridup 0:dc55f40eb04f 881
mridup 0:dc55f40eb04f 882 /**
mridup 0:dc55f40eb04f 883 * @brief wifi_fw_update
mridup 0:dc55f40eb04f 884 * Issue an HTTP GET of the given path to the specified host and get the firmware updated
mridup 0:dc55f40eb04f 885 * @param None
mridup 0:dc55f40eb04f 886 * @retval None
mridup 0:dc55f40eb04f 887 */
mridup 0:dc55f40eb04f 888 WiFi_Status_t wifi_fw_update(uint8_t * hostname, uint8_t * filename_path, uint32_t port_number)
mridup 0:dc55f40eb04f 889 {
mridup 0:dc55f40eb04f 890 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 891 Queue_Wifi_FW_Update_Event(hostname,filename_path,port_number);
mridup 0:dc55f40eb04f 892 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 893 /* Soft reset the module */
mridup 0:dc55f40eb04f 894 SET_Power_State(PowerSave_State);
mridup 0:dc55f40eb04f 895 return status;
mridup 0:dc55f40eb04f 896 }
mridup 0:dc55f40eb04f 897
mridup 0:dc55f40eb04f 898 /**
mridup 0:dc55f40eb04f 899 * @brief wifi_network_scan
mridup 0:dc55f40eb04f 900 * Performs an immediate scan for available network
mridup 0:dc55f40eb04f 901 * @param None
mridup 0:dc55f40eb04f 902 * @retval WiFi_Status_t : WiFi status error
mridup 0:dc55f40eb04f 903 */
mridup 0:dc55f40eb04f 904 WiFi_Status_t wifi_network_scan(wifi_scan *scan_result, uint16_t max_scan_number)
mridup 0:dc55f40eb04f 905 {
mridup 0:dc55f40eb04f 906 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 907 wifi_scanned_list = scan_result;
mridup 0:dc55f40eb04f 908 if(max_scan_number>MAX_WIFI_SCAN_NETWORK)
mridup 0:dc55f40eb04f 909 return WiFi_NOT_SUPPORTED;
mridup 0:dc55f40eb04f 910 user_scan_number = max_scan_number;
mridup 0:dc55f40eb04f 911
mridup 0:dc55f40eb04f 912 if(status_flag.Scan_Ongoing)
mridup 0:dc55f40eb04f 913 {
mridup 0:dc55f40eb04f 914 return WiFi_AT_CMD_BUSY;
mridup 0:dc55f40eb04f 915 }
mridup 0:dc55f40eb04f 916
mridup 0:dc55f40eb04f 917 status_flag.Scan_Ongoing = WIFI_TRUE;
mridup 0:dc55f40eb04f 918
mridup 0:dc55f40eb04f 919 #if 0 //TBD
mridup 0:dc55f40eb04f 920 if(WiFi_Param.WiFi_Module_State == WiFi_MiniAP_MODE)
mridup 0:dc55f40eb04f 921 return WiFi_NOT_SUPPORTED;
mridup 0:dc55f40eb04f 922 #endif
mridup 0:dc55f40eb04f 923
mridup 0:dc55f40eb04f 924 /* AT+S.SCAN: performs an immediate scan for available networks */
mridup 0:dc55f40eb04f 925 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 926 sprintf((char*)WiFi_AT_Cmd_Buff,AT_WiFi_SCAN);
mridup 0:dc55f40eb04f 927 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 928 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 929 {
mridup 0:dc55f40eb04f 930 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 931 }
mridup 0:dc55f40eb04f 932
mridup 0:dc55f40eb04f 933 /*At this point we have WiFi_Scan_Buffer filled with RSSI and SSID values*/
mridup 0:dc55f40eb04f 934 return status;
mridup 0:dc55f40eb04f 935 }
mridup 0:dc55f40eb04f 936
mridup 0:dc55f40eb04f 937 /**
mridup 0:dc55f40eb04f 938 * @brief Set_MiniAP_Mode
mridup 0:dc55f40eb04f 939 * Configure Wi-Fi module in AP mode.
mridup 0:dc55f40eb04f 940 MiniAP is always configured in open mode (WEP not supported)
mridup 0:dc55f40eb04f 941 * @param None
mridup 0:dc55f40eb04f 942 * @retval WiFi_Status_t : status of AT cmd
mridup 0:dc55f40eb04f 943 */
mridup 0:dc55f40eb04f 944 WiFi_Status_t wifi_ap_start(uint8_t * ssid, uint8_t channel_num)
mridup 0:dc55f40eb04f 945 {
mridup 0:dc55f40eb04f 946 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 947
mridup 0:dc55f40eb04f 948 /* Set the SSID : AT+S.SSIDTXT=<SSID>*/
mridup 0:dc55f40eb04f 949 //if(ssid)
mridup 0:dc55f40eb04f 950 status = SET_SSID((char*)ssid);
mridup 0:dc55f40eb04f 951
mridup 0:dc55f40eb04f 952
mridup 0:dc55f40eb04f 953 if(status != WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 954 return WiFi_SSID_ERROR;
mridup 0:dc55f40eb04f 955
mridup 0:dc55f40eb04f 956 /* Set the network privacy mode : AT+S.SCFG=wifi_priv_mode,0*/
mridup 0:dc55f40eb04f 957 status = SET_Configuration_Value(WIFI_PRIV_MODE, None);
mridup 0:dc55f40eb04f 958 if(status != WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 959 return WiFi_CONFIG_ERROR;
mridup 0:dc55f40eb04f 960
mridup 0:dc55f40eb04f 961 /* Set the network mode (1 = STA, 2 = IBSS, 3 = MiniAP) :: AT+S.SCFG=wifi_mode,3*/
mridup 0:dc55f40eb04f 962 status = SET_Configuration_Value(WIFI_MODE, WiFi_MiniAP_MODE);
mridup 0:dc55f40eb04f 963 if(status != WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 964 return WiFi_CONFIG_ERROR;
mridup 0:dc55f40eb04f 965
mridup 0:dc55f40eb04f 966 /* Set the channel number */
mridup 0:dc55f40eb04f 967 status = SET_Configuration_Value(WIFI_CHANNEL_NUMBER, channel_num);
mridup 0:dc55f40eb04f 968 if(status != WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 969 return WiFi_CONFIG_ERROR;
mridup 0:dc55f40eb04f 970
mridup 0:dc55f40eb04f 971 /* Save the settings on the flash memory : AT&W*/
mridup 0:dc55f40eb04f 972 Save_Current_Setting();
mridup 0:dc55f40eb04f 973
mridup 0:dc55f40eb04f 974 status_flag.WiFi_Configuration_Done = WIFI_TRUE;
mridup 0:dc55f40eb04f 975 WiFi_Module_State = Process_Event;
mridup 0:dc55f40eb04f 976
mridup 0:dc55f40eb04f 977 /* Soft reset the module */
mridup 0:dc55f40eb04f 978 SET_Power_State(PowerSave_State);
mridup 0:dc55f40eb04f 979
mridup 0:dc55f40eb04f 980 return status;
mridup 0:dc55f40eb04f 981 }
mridup 0:dc55f40eb04f 982
mridup 0:dc55f40eb04f 983
mridup 0:dc55f40eb04f 984 /**
mridup 0:dc55f40eb04f 985 * @brief SET_WiFi_STA_Mode
mridup 0:dc55f40eb04f 986 * Configure Wi-Fi module in STA mode
mridup 0:dc55f40eb04f 987 * @param SSID : SSID name
mridup 0:dc55f40eb04f 988 * @param sec_key : security key
mridup 0:dc55f40eb04f 989 * @param priv_mode : network privecy mode
mridup 0:dc55f40eb04f 990 * @retval WiFi_Status_t : status of AT cmd
mridup 0:dc55f40eb04f 991 */
mridup 0:dc55f40eb04f 992 WiFi_Status_t wifi_connect(char * ssid, char * sec_key, WiFi_Priv_Mode priv_mode)
mridup 0:dc55f40eb04f 993 {
mridup 0:dc55f40eb04f 994 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 995 if(status_flag.AT_Cmd_Ongoing == WIFI_FALSE)
mridup 0:dc55f40eb04f 996 status_flag.AT_Cmd_Ongoing = WIFI_TRUE;
mridup 0:dc55f40eb04f 997 else
mridup 0:dc55f40eb04f 998 {
mridup 0:dc55f40eb04f 999 return WiFi_AT_CMD_BUSY;
mridup 0:dc55f40eb04f 1000 }
mridup 0:dc55f40eb04f 1001
mridup 0:dc55f40eb04f 1002 if(sec_key) {
mridup 0:dc55f40eb04f 1003 status = SET_WiFi_SecKey((char*)sec_key);
mridup 0:dc55f40eb04f 1004 if(status != WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 1005 return WiFi_SecKey_ERROR;
mridup 0:dc55f40eb04f 1006 }
mridup 0:dc55f40eb04f 1007
mridup 0:dc55f40eb04f 1008 /* Set the SSID : AT+S.SSIDTXT=<SSID>*/
mridup 0:dc55f40eb04f 1009
mridup 0:dc55f40eb04f 1010 status = SET_SSID((char*)ssid);
mridup 0:dc55f40eb04f 1011
mridup 0:dc55f40eb04f 1012 if(status != WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 1013 return WiFi_SSID_ERROR;
mridup 0:dc55f40eb04f 1014
mridup 0:dc55f40eb04f 1015 /* Set the network privacy mode : AT+S.SCFG=wifi_priv_mode,2*/
mridup 0:dc55f40eb04f 1016 status = SET_Configuration_Value(WIFI_PRIV_MODE, priv_mode);
mridup 0:dc55f40eb04f 1017 if(status != WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 1018 return WiFi_CONFIG_ERROR;
mridup 0:dc55f40eb04f 1019
mridup 0:dc55f40eb04f 1020 /* Set the network mode (1 = STA, 2 = IBSS, 3 = MiniAP) :: AT+S.SCFG=wifi_mode,1*/
mridup 0:dc55f40eb04f 1021 status = SET_Configuration_Value(WIFI_MODE, WiFi_STA_MODE);
mridup 0:dc55f40eb04f 1022 if(status != WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 1023 return WiFi_CONFIG_ERROR;
mridup 0:dc55f40eb04f 1024
mridup 0:dc55f40eb04f 1025 /* Save the settings on the flash memory : AT&W*/
mridup 0:dc55f40eb04f 1026 Save_Current_Setting();
mridup 0:dc55f40eb04f 1027
mridup 0:dc55f40eb04f 1028 status_flag.WiFi_Configuration_Done = WIFI_TRUE;
mridup 0:dc55f40eb04f 1029 //WiFi_Module_State = WiFi_Process_Event;
mridup 0:dc55f40eb04f 1030
mridup 0:dc55f40eb04f 1031 /* Soft reset the module */
mridup 0:dc55f40eb04f 1032 SET_Power_State(PowerSave_State);
mridup 0:dc55f40eb04f 1033
mridup 0:dc55f40eb04f 1034 status_flag.AT_Cmd_Ongoing = WIFI_FALSE;
mridup 0:dc55f40eb04f 1035
mridup 0:dc55f40eb04f 1036 return status;
mridup 0:dc55f40eb04f 1037 }
mridup 0:dc55f40eb04f 1038
mridup 0:dc55f40eb04f 1039 /**
mridup 0:dc55f40eb04f 1040 * @brief SET_WiFi_IBSS_Mode
mridup 0:dc55f40eb04f 1041 * Configure Wi-Fi module in IBSS mode
mridup 0:dc55f40eb04f 1042 * @param SSID : SSID name
mridup 0:dc55f40eb04f 1043 * @param priv_mode : network privecy mode
mridup 0:dc55f40eb04f 1044 * @retval WiFi_Status_t : status of AT cmd
mridup 0:dc55f40eb04f 1045 */
mridup 0:dc55f40eb04f 1046 WiFi_Status_t wifi_adhoc_create(uint8_t * ssid, WiFi_Priv_Mode priv_mode)
mridup 0:dc55f40eb04f 1047 {
mridup 0:dc55f40eb04f 1048 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 1049
mridup 0:dc55f40eb04f 1050 Attention_Cmd();
mridup 0:dc55f40eb04f 1051 /* Set the SSID : AT+S.SSIDTXT=<SSID>*/
mridup 0:dc55f40eb04f 1052 status = SET_SSID((char*)ssid);
mridup 0:dc55f40eb04f 1053 if(status != WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 1054 return WiFi_SSID_ERROR;
mridup 0:dc55f40eb04f 1055
mridup 0:dc55f40eb04f 1056 /* Set the network privacy mode : AT+S.SCFG=wifi_priv_mode,0*/
mridup 0:dc55f40eb04f 1057 status = SET_Configuration_Value(WIFI_PRIV_MODE, priv_mode);
mridup 0:dc55f40eb04f 1058 if(status != WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 1059 return WiFi_CONFIG_ERROR;
mridup 0:dc55f40eb04f 1060
mridup 0:dc55f40eb04f 1061
mridup 0:dc55f40eb04f 1062 /* Set the network mode (1 = STA, 2 = IBSS, 3 = MiniAP) :: AT+S.SCFG=wifi_mode,2*/
mridup 0:dc55f40eb04f 1063 status = SET_Configuration_Value(WIFI_MODE, WiFi_IBSS_MODE);
mridup 0:dc55f40eb04f 1064 if(status != WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 1065 return WiFi_CONFIG_ERROR;
mridup 0:dc55f40eb04f 1066
mridup 0:dc55f40eb04f 1067 /* Set IP address */
mridup 0:dc55f40eb04f 1068 status = SET_Configuration_Addr(WIFI_IP_ADDRESS, WIFI_IBSS_IP_ADDR);
mridup 0:dc55f40eb04f 1069 if(status != WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 1070 return WiFi_CONFIG_ERROR;
mridup 0:dc55f40eb04f 1071
mridup 0:dc55f40eb04f 1072 /* Set IP default gateway */
mridup 0:dc55f40eb04f 1073 status = SET_Configuration_Addr(WIFI_IP_DEFAULT_GATEWAY, WIFI_IBSS_DEFAULT_GATEWAY);
mridup 0:dc55f40eb04f 1074 if(status != WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 1075 return WiFi_CONFIG_ERROR;
mridup 0:dc55f40eb04f 1076
mridup 0:dc55f40eb04f 1077
mridup 0:dc55f40eb04f 1078 /* Set IP DNS */
mridup 0:dc55f40eb04f 1079 status = SET_Configuration_Addr(WIFI_IP_DNS, WIFI_IBSS_IP_DNS_ADDR);
mridup 0:dc55f40eb04f 1080 if(status != WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 1081 return WiFi_CONFIG_ERROR;
mridup 0:dc55f40eb04f 1082
mridup 0:dc55f40eb04f 1083 /* Set IP netmask */
mridup 0:dc55f40eb04f 1084 status = SET_Configuration_Addr(WIFI_IP_NETMASK, WIFI_IBSS_IP_MASK);
mridup 0:dc55f40eb04f 1085 if(status != WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 1086 return WiFi_CONFIG_ERROR;
mridup 0:dc55f40eb04f 1087
mridup 0:dc55f40eb04f 1088 /* Turn OFF the DHCP */
mridup 0:dc55f40eb04f 1089 SET_Configuration_Value(IP_USE_DHCP_SERVER, WIFI_IP_USE_DHCP);
mridup 0:dc55f40eb04f 1090 if(status != WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 1091 return WiFi_CONFIG_ERROR;
mridup 0:dc55f40eb04f 1092
mridup 0:dc55f40eb04f 1093 /* Save the settings on the flash memory : AT&W*/
mridup 0:dc55f40eb04f 1094 Save_Current_Setting();
mridup 0:dc55f40eb04f 1095
mridup 0:dc55f40eb04f 1096 /* Soft reset the module */
mridup 0:dc55f40eb04f 1097 SET_Power_State(PowerSave_State);
mridup 0:dc55f40eb04f 1098 return status;
mridup 0:dc55f40eb04f 1099 }
mridup 0:dc55f40eb04f 1100
mridup 0:dc55f40eb04f 1101
mridup 0:dc55f40eb04f 1102 /**
mridup 0:dc55f40eb04f 1103 * @brief wifi_standby
mridup 0:dc55f40eb04f 1104 * Configured WiFi module to enter standby
mridup 0:dc55f40eb04f 1105 * @param arg_standby_time: standby time
mridup 0:dc55f40eb04f 1106 * @retval WiFi_Status_t : status of AT cmd
mridup 0:dc55f40eb04f 1107 */
mridup 0:dc55f40eb04f 1108 WiFi_Status_t wifi_standby(uint8_t arg_standby_time)
mridup 0:dc55f40eb04f 1109 {
mridup 0:dc55f40eb04f 1110 /*
mridup 0:dc55f40eb04f 1111 For Standby, the presence of Jumpers on JP4 and JP3 has the following behaviour:
mridup 0:dc55f40eb04f 1112 JP3 (middle and bottom): prevents standby and immediately wakes-up module
mridup 0:dc55f40eb04f 1113 JP3 (middle and top): no effect on standby
mridup 0:dc55f40eb04f 1114 JP4 (middle and right): prevents wakeup and standby runs forever
mridup 0:dc55f40eb04f 1115 JP4 (middle and left): no effect on standby
mridup 0:dc55f40eb04f 1116 */
mridup 0:dc55f40eb04f 1117
mridup 0:dc55f40eb04f 1118 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 1119
mridup 0:dc55f40eb04f 1120 /*if(arg_standby_time<2)
mridup 0:dc55f40eb04f 1121 return WiFi_NOT_SUPPORTED;*/
mridup 0:dc55f40eb04f 1122
mridup 0:dc55f40eb04f 1123 SET_Configuration_Value(WIFI_SLEEP_ENABLED, 0);
mridup 0:dc55f40eb04f 1124 SET_Configuration_Value(WIFI_STANDBY_ENABLED, 1);
mridup 0:dc55f40eb04f 1125 status = SET_Configuration_Value(WIFI_STANDBY_TIME, arg_standby_time);
mridup 0:dc55f40eb04f 1126
mridup 0:dc55f40eb04f 1127 /* save current setting in flash */
mridup 0:dc55f40eb04f 1128 Save_Current_Setting();
mridup 0:dc55f40eb04f 1129
mridup 0:dc55f40eb04f 1130 /* AT : send AT command */
mridup 0:dc55f40eb04f 1131 sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_POWER_STATE,1); //cfun=4
mridup 0:dc55f40eb04f 1132 WiFi_Module_State = Process_Event; //make sure the WiFi module is in this state to receive WINDS after wakeup
mridup 0:dc55f40eb04f 1133 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 1134
mridup 0:dc55f40eb04f 1135 if(status == WiFi_MODULE_SUCCESS)//if transmit is success, prepare for resume
mridup 0:dc55f40eb04f 1136 {
mridup 0:dc55f40eb04f 1137 /*
mridup 0:dc55f40eb04f 1138 status_flag.AT_Cmd_Processing = WIFI_TRUE;//We do not want the next UART data_byte fetch to be done
mridup 0:dc55f40eb04f 1139 HAL_NVIC_DisableIRQ(USARTx_IRQn);//Disable UART IRQ
mridup 0:dc55f40eb04f 1140 status_flag.Standby_Timer_Running=WIFI_TRUE;
mridup 0:dc55f40eb04f 1141 printf("\r\nGoing into Standby Mode...\r\n");*/
mridup 0:dc55f40eb04f 1142 }
mridup 0:dc55f40eb04f 1143
mridup 0:dc55f40eb04f 1144 return status;
mridup 0:dc55f40eb04f 1145
mridup 0:dc55f40eb04f 1146 }
mridup 0:dc55f40eb04f 1147
mridup 0:dc55f40eb04f 1148 /**
mridup 0:dc55f40eb04f 1149 * @brief wifi_wakeup
mridup 0:dc55f40eb04f 1150 * wakeup the module from sleep by setting the GPIO6 through PC13
mridup 0:dc55f40eb04f 1151 * or allow it to go to sleep
mridup 0:dc55f40eb04f 1152 * Jumper needed on JP4
mridup 0:dc55f40eb04f 1153 * @param wakeup wakeup (WIFI_TRUE) or allow sleep(WIFI_FALSE)
mridup 0:dc55f40eb04f 1154 * @retval WiFi_Status_t : status of function call
mridup 0:dc55f40eb04f 1155 */
mridup 0:dc55f40eb04f 1156 WiFi_Status_t wifi_wakeup(wifi_bool wakeup)
mridup 0:dc55f40eb04f 1157 {
mridup 0:dc55f40eb04f 1158 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 1159
mridup 0:dc55f40eb04f 1160 if(wakeup)
mridup 1:bd9db471d47d 1161 callSpwfSADevice_wakeup(spwf_device_class, 0);
mridup 0:dc55f40eb04f 1162 else
mridup 0:dc55f40eb04f 1163 callSpwfSADevice_wakeup(spwf_device_class, 0);
mridup 0:dc55f40eb04f 1164 wait_ms(100);
mridup 0:dc55f40eb04f 1165 return status;
mridup 0:dc55f40eb04f 1166 }
mridup 0:dc55f40eb04f 1167
mridup 0:dc55f40eb04f 1168
mridup 0:dc55f40eb04f 1169 /**
mridup 0:dc55f40eb04f 1170 * @brief wifi_disconnect
mridup 0:dc55f40eb04f 1171 * disconnect the module from any AP
mridup 0:dc55f40eb04f 1172 * @param None
mridup 0:dc55f40eb04f 1173 * @retval WiFi_Status_t : status of AT cmd
mridup 0:dc55f40eb04f 1174 */
mridup 0:dc55f40eb04f 1175 WiFi_Status_t wifi_disconnect(void)
mridup 0:dc55f40eb04f 1176 {
mridup 0:dc55f40eb04f 1177 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 1178
mridup 5:c83ffd44f40a 1179 //Wait till all queued events are executed
mridup 5:c83ffd44f40a 1180 while(!event_empty(&event_buff));
mridup 5:c83ffd44f40a 1181 Wait_For_Sock_Read_To_Complete();
mridup 5:c83ffd44f40a 1182
mridup 0:dc55f40eb04f 1183 /* Set wifi_mode to idle*/
mridup 0:dc55f40eb04f 1184 status = SET_Configuration_Value(WIFI_MODE, WiFi_IDLE_MODE);
mridup 0:dc55f40eb04f 1185
mridup 0:dc55f40eb04f 1186 /*If module was connected, reset the status*/
mridup 0:dc55f40eb04f 1187 if(wifi_connected == 1)
mridup 0:dc55f40eb04f 1188 {
mridup 0:dc55f40eb04f 1189 wifi_connected = 0;//this will allow the TIM handler to make the callback on connection(WiFiUp)
mridup 0:dc55f40eb04f 1190 }
mridup 0:dc55f40eb04f 1191
mridup 0:dc55f40eb04f 1192 /* save current setting in flash */
mridup 0:dc55f40eb04f 1193 Save_Current_Setting();
mridup 0:dc55f40eb04f 1194
mridup 0:dc55f40eb04f 1195 /* Soft reset the module */
mridup 0:dc55f40eb04f 1196 status = SET_Power_State(PowerSave_State);//CFUN=1
mridup 0:dc55f40eb04f 1197
mridup 0:dc55f40eb04f 1198 return status;
mridup 0:dc55f40eb04f 1199 }
mridup 0:dc55f40eb04f 1200
mridup 0:dc55f40eb04f 1201 /**
mridup 0:dc55f40eb04f 1202 * @brief wifi_enable
mridup 0:dc55f40eb04f 1203 * Enable/Disable the Wi-Fi interface
mridup 0:dc55f40eb04f 1204 * @param enable enable Wi-Fi (WIFI_TRUE) disable Wi-Fi (WIFI_FALSE)
mridup 0:dc55f40eb04f 1205 * @retval WiFi_Status_t : status of AT cmd
mridup 0:dc55f40eb04f 1206 */
mridup 0:dc55f40eb04f 1207 WiFi_Status_t wifi_enable(wifi_bool enable)
mridup 0:dc55f40eb04f 1208 {
mridup 0:dc55f40eb04f 1209 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 1210
mridup 0:dc55f40eb04f 1211 /* Enable or Disable wifi interface*/
mridup 0:dc55f40eb04f 1212 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 1213 sprintf((char*)WiFi_AT_Cmd_Buff,AT_WIFI_ENABLE, enable);
mridup 0:dc55f40eb04f 1214
mridup 0:dc55f40eb04f 1215 /*if(HAL_UART_Transmit(&UartWiFiHandle, (uint8_t *)WiFi_AT_Cmd_Buff, strlen((char*)WiFi_AT_Cmd_Buff),1000)!= HAL_OK)
mridup 0:dc55f40eb04f 1216 {
mridup 0:dc55f40eb04f 1217 Error_Handler();
mridup 0:dc55f40eb04f 1218 #if DEBUG_PRINT
mridup 0:dc55f40eb04f 1219 printf("HAL_UART_Transmit Error");
mridup 0:dc55f40eb04f 1220 #endif
mridup 0:dc55f40eb04f 1221 return WiFi_HAL_UART_ERROR;
mridup 0:dc55f40eb04f 1222 } */
mridup 0:dc55f40eb04f 1223
mridup 0:dc55f40eb04f 1224 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 1225
mridup 0:dc55f40eb04f 1226 //wait for power down/hw started
mridup 0:dc55f40eb04f 1227 if(enable)
mridup 0:dc55f40eb04f 1228 while(status_flag.WiFi_Enabled != WIFI_TRUE)
mridup 0:dc55f40eb04f 1229 {
mridup 0:dc55f40eb04f 1230 asm("NOP");
mridup 0:dc55f40eb04f 1231 }
mridup 0:dc55f40eb04f 1232 else
mridup 0:dc55f40eb04f 1233 while(status_flag.WiFi_Enabled != WIFI_FALSE)
mridup 0:dc55f40eb04f 1234 {
mridup 0:dc55f40eb04f 1235 asm("NOP");
mridup 0:dc55f40eb04f 1236 }
mridup 0:dc55f40eb04f 1237
mridup 0:dc55f40eb04f 1238 return status;
mridup 0:dc55f40eb04f 1239
mridup 0:dc55f40eb04f 1240 }
mridup 0:dc55f40eb04f 1241
mridup 0:dc55f40eb04f 1242
mridup 0:dc55f40eb04f 1243
mridup 0:dc55f40eb04f 1244 /**
mridup 0:dc55f40eb04f 1245 * @brief wifi_restore
mridup 0:dc55f40eb04f 1246 * Restore the Wi-Fi with default values.
mridup 0:dc55f40eb04f 1247 * @param None
mridup 0:dc55f40eb04f 1248 * @retval WiFi_Status_t : status of AT cmd
mridup 0:dc55f40eb04f 1249 */
mridup 0:dc55f40eb04f 1250 WiFi_Status_t wifi_restore()
mridup 0:dc55f40eb04f 1251 {
mridup 0:dc55f40eb04f 1252 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 1253
mridup 0:dc55f40eb04f 1254 /* Restore default setting*/
mridup 0:dc55f40eb04f 1255 Restore_Default_Setting();
mridup 0:dc55f40eb04f 1256
mridup 0:dc55f40eb04f 1257 /* Set wifi_mode to idle*/
mridup 0:dc55f40eb04f 1258 SET_Configuration_Value(WIFI_MODE, WiFi_IDLE_MODE);
mridup 0:dc55f40eb04f 1259
mridup 0:dc55f40eb04f 1260 /* set the local echo */
mridup 0:dc55f40eb04f 1261 SET_Configuration_Value(LOCALECHO1, 0);
mridup 0:dc55f40eb04f 1262
mridup 0:dc55f40eb04f 1263 /* save current setting in flash */
mridup 0:dc55f40eb04f 1264 Save_Current_Setting();
mridup 0:dc55f40eb04f 1265
mridup 0:dc55f40eb04f 1266 /* Soft reset the module */
mridup 0:dc55f40eb04f 1267 status = SET_Power_State(PowerSave_State);//CFUN=1
mridup 0:dc55f40eb04f 1268
mridup 0:dc55f40eb04f 1269 return status;
mridup 0:dc55f40eb04f 1270 }
mridup 0:dc55f40eb04f 1271
mridup 0:dc55f40eb04f 1272 /*GPIO Configuration Functions*/
mridup 0:dc55f40eb04f 1273
mridup 0:dc55f40eb04f 1274 /**
mridup 0:dc55f40eb04f 1275 * @brief wifi_gpio_init
mridup 0:dc55f40eb04f 1276 * Configure a GPIO pin as in or out with IRQ setting
mridup 0:dc55f40eb04f 1277 * @param pin GPIO pin number
mridup 0:dc55f40eb04f 1278 * @param irq configuration of the pin
mridup 0:dc55f40eb04f 1279 * @retval WiFi_Status_t : status of AT cmd
mridup 0:dc55f40eb04f 1280 */
mridup 0:dc55f40eb04f 1281 uint8_t wifi_gpio_init(GpioPin pin, char* dir, char irq)
mridup 0:dc55f40eb04f 1282 {
mridup 0:dc55f40eb04f 1283 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 1284
mridup 0:dc55f40eb04f 1285 /* AT+S.GPIOC=pin,dir,irq */
mridup 0:dc55f40eb04f 1286 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 1287
mridup 0:dc55f40eb04f 1288 memset(WiFi_AT_Cmd_Buff, 0x00, sizeof WiFi_AT_Cmd_Buff);
mridup 0:dc55f40eb04f 1289
mridup 0:dc55f40eb04f 1290 if(irq!=GPIO_Off)
mridup 0:dc55f40eb04f 1291 sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.GPIOC=%d,%s,%c\r", pin, dir, irq);
mridup 0:dc55f40eb04f 1292 else
mridup 0:dc55f40eb04f 1293 sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.GPIOC=%d,%s\r", pin, dir);
mridup 0:dc55f40eb04f 1294
mridup 0:dc55f40eb04f 1295 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 1296 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 1297 {
mridup 0:dc55f40eb04f 1298 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 1299 }
mridup 0:dc55f40eb04f 1300
mridup 0:dc55f40eb04f 1301
mridup 0:dc55f40eb04f 1302 return status;
mridup 0:dc55f40eb04f 1303
mridup 0:dc55f40eb04f 1304 }
mridup 0:dc55f40eb04f 1305
mridup 0:dc55f40eb04f 1306 /**
mridup 0:dc55f40eb04f 1307 * @brief wifi_gpio_read
mridup 0:dc55f40eb04f 1308 * Read the configuration of a GPIO pin
mridup 0:dc55f40eb04f 1309 * @param pin GPIO pin number
mridup 0:dc55f40eb04f 1310 * @param val value returned
mridup 0:dc55f40eb04f 1311 * @param dir configuration direction returned
mridup 0:dc55f40eb04f 1312 * @retval WiFi_Status_t : status of AT cmd
mridup 0:dc55f40eb04f 1313 */
mridup 0:dc55f40eb04f 1314 uint8_t wifi_gpio_read(GpioPin pin, uint8_t *val, uint8_t *dir)
mridup 0:dc55f40eb04f 1315 {
mridup 0:dc55f40eb04f 1316 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 1317
mridup 0:dc55f40eb04f 1318 /* AT+S.GPIOR=pin */
mridup 0:dc55f40eb04f 1319 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 1320
mridup 0:dc55f40eb04f 1321 sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.GPIOR=%d\r", pin);
mridup 0:dc55f40eb04f 1322
mridup 0:dc55f40eb04f 1323 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 1324 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 1325 {
mridup 0:dc55f40eb04f 1326 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 1327 }
mridup 0:dc55f40eb04f 1328 *val = gpio_value;
mridup 0:dc55f40eb04f 1329 *dir = gpio_direc;
mridup 0:dc55f40eb04f 1330
mridup 0:dc55f40eb04f 1331 return status;
mridup 0:dc55f40eb04f 1332 }
mridup 0:dc55f40eb04f 1333
mridup 0:dc55f40eb04f 1334 /**
mridup 0:dc55f40eb04f 1335 * @brief wifi_gpio_write
mridup 0:dc55f40eb04f 1336 * Read the value of a GPIO pin
mridup 0:dc55f40eb04f 1337 * @param pin GPIO pin number
mridup 0:dc55f40eb04f 1338 * @param val value to be configured
mridup 0:dc55f40eb04f 1339 * @retval WiFi_Status_t : status of AT cmd
mridup 0:dc55f40eb04f 1340 */
mridup 0:dc55f40eb04f 1341 uint8_t wifi_gpio_write(GpioPin pin, GpioWriteValue value)
mridup 0:dc55f40eb04f 1342 {
mridup 0:dc55f40eb04f 1343 WiFi_Status_t status = WiFi_MODULE_SUCCESS;
mridup 0:dc55f40eb04f 1344
mridup 0:dc55f40eb04f 1345 /* AT+S.GPIOW=pin,value */
mridup 0:dc55f40eb04f 1346 Reset_AT_CMD_Buffer();
mridup 0:dc55f40eb04f 1347
mridup 0:dc55f40eb04f 1348 sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.GPIOW=%d,%d\r", pin, value);
mridup 0:dc55f40eb04f 1349
mridup 0:dc55f40eb04f 1350 status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff));
mridup 0:dc55f40eb04f 1351 if(status == WiFi_MODULE_SUCCESS)
mridup 0:dc55f40eb04f 1352 {
mridup 0:dc55f40eb04f 1353 status = USART_Receive_AT_Resp(Process_Event);
mridup 0:dc55f40eb04f 1354 }
mridup 0:dc55f40eb04f 1355
mridup 0:dc55f40eb04f 1356 return status;
mridup 0:dc55f40eb04f 1357 }
mridup 0:dc55f40eb04f 1358
mridup 0:dc55f40eb04f 1359 void UART_Configuration(uint32_t baud_rate)
mridup 0:dc55f40eb04f 1360 {
mridup 0:dc55f40eb04f 1361 }
mridup 0:dc55f40eb04f 1362
mridup 0:dc55f40eb04f 1363 #ifdef USART_PRINT_MSG
mridup 0:dc55f40eb04f 1364 void USART_PRINT_MSG_Configuration(uint32_t baud_rate)
mridup 0:dc55f40eb04f 1365 {
mridup 0:dc55f40eb04f 1366 }
mridup 0:dc55f40eb04f 1367 #endif
mridup 0:dc55f40eb04f 1368
mridup 0:dc55f40eb04f 1369 /**
mridup 0:dc55f40eb04f 1370 * @}
mridup 0:dc55f40eb04f 1371 */
mridup 0:dc55f40eb04f 1372
mridup 0:dc55f40eb04f 1373 /**
mridup 0:dc55f40eb04f 1374 * @}
mridup 0:dc55f40eb04f 1375 */
mridup 0:dc55f40eb04f 1376
mridup 0:dc55f40eb04f 1377
mridup 0:dc55f40eb04f 1378 /**
mridup 0:dc55f40eb04f 1379 * @}
mridup 0:dc55f40eb04f 1380 */
mridup 0:dc55f40eb04f 1381
mridup 0:dc55f40eb04f 1382 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
mridup 0:dc55f40eb04f 1383
mridup 0:dc55f40eb04f 1384