iowfehu;gdbjwHJAOPIHO?L
Fork of X_NUCLEO_IDW01M1 by
Spwf/wifi_interface.c@6:e7a3fca2df10, 2016-05-09 (annotated)
- Committer:
- mridup
- Date:
- Mon May 09 10:38:22 2016 +0000
- Revision:
- 6:e7a3fca2df10
- Parent:
- 5:c83ffd44f40a
- Child:
- 7:0fdd186a7d90
Socket Server support.
Who changed what in which revision?
User | Revision | Line number | New 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>© 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 | 0:dc55f40eb04f | 615 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 616 | |
mridup | 0:dc55f40eb04f | 617 | /* AT+S.SOCKD=portNo,t<cr> */ |
mridup | 0:dc55f40eb04f | 618 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_SERVER_SOCKET_OPEN,(int)port_number,protocol); |
mridup | 0:dc55f40eb04f | 619 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 620 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 621 | { |
mridup | 0:dc55f40eb04f | 622 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 623 | } |
mridup | 0:dc55f40eb04f | 624 | return status; |
mridup | 0:dc55f40eb04f | 625 | } |
mridup | 0:dc55f40eb04f | 626 | |
mridup | 0:dc55f40eb04f | 627 | |
mridup | 0:dc55f40eb04f | 628 | |
mridup | 0:dc55f40eb04f | 629 | /** |
mridup | 0:dc55f40eb04f | 630 | * @brief Server Socket Close |
mridup | 0:dc55f40eb04f | 631 | * Close a Server socket |
mridup | 0:dc55f40eb04f | 632 | * @param None |
mridup | 0:dc55f40eb04f | 633 | * @retval WiFi_Status_t : return status of server socket request |
mridup | 0:dc55f40eb04f | 634 | */ |
mridup | 0:dc55f40eb04f | 635 | WiFi_Status_t wifi_socket_server_close() |
mridup | 0:dc55f40eb04f | 636 | { |
mridup | 0:dc55f40eb04f | 637 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 638 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 639 | |
mridup | 0:dc55f40eb04f | 640 | /* AT+S.SOCKD=portNo,t<cr> */ |
mridup | 0:dc55f40eb04f | 641 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_SERVER_SOCKET_CLOSE); |
mridup | 0:dc55f40eb04f | 642 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 643 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 644 | { |
mridup | 0:dc55f40eb04f | 645 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 646 | } |
mridup | 0:dc55f40eb04f | 647 | |
mridup | 0:dc55f40eb04f | 648 | return status; |
mridup | 0:dc55f40eb04f | 649 | } |
mridup | 0:dc55f40eb04f | 650 | |
mridup | 0:dc55f40eb04f | 651 | |
mridup | 0:dc55f40eb04f | 652 | /** |
mridup | 0:dc55f40eb04f | 653 | * @brief wait_for_command_mode |
mridup | 0:dc55f40eb04f | 654 | * Waits till we are in command mode |
mridup | 0:dc55f40eb04f | 655 | * @param None |
mridup | 0:dc55f40eb04f | 656 | * @retval None |
mridup | 0:dc55f40eb04f | 657 | */ |
mridup | 0:dc55f40eb04f | 658 | void wait_for_command_mode(void) |
mridup | 0:dc55f40eb04f | 659 | { |
mridup | 0:dc55f40eb04f | 660 | while(!status_flag.command_mode) |
mridup | 0:dc55f40eb04f | 661 | { |
mridup | 0:dc55f40eb04f | 662 | //Make sure we are in command mode, ideally we should do this in every User API? |
mridup | 0:dc55f40eb04f | 663 | asm("NOP"); |
mridup | 0:dc55f40eb04f | 664 | } |
mridup | 0:dc55f40eb04f | 665 | } |
mridup | 0:dc55f40eb04f | 666 | |
mridup | 0:dc55f40eb04f | 667 | |
mridup | 0:dc55f40eb04f | 668 | /** |
mridup | 0:dc55f40eb04f | 669 | * @brief wifi_file_delete |
mridup | 0:dc55f40eb04f | 670 | * Delete a file |
mridup | 0:dc55f40eb04f | 671 | * @param pFileName : File Name to be deleted |
mridup | 0:dc55f40eb04f | 672 | * @retval WiFi_Status_t : return status of delete file request |
mridup | 0:dc55f40eb04f | 673 | */ |
mridup | 0:dc55f40eb04f | 674 | WiFi_Status_t wifi_file_delete(char * pFileName) |
mridup | 0:dc55f40eb04f | 675 | { |
mridup | 0:dc55f40eb04f | 676 | /* AT+S.FSD: delete an existing file */ |
mridup | 0:dc55f40eb04f | 677 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 678 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 679 | /* AT+S.FSL */ |
mridup | 0:dc55f40eb04f | 680 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_DELETE_FILE,pFileName); |
mridup | 0:dc55f40eb04f | 681 | |
mridup | 0:dc55f40eb04f | 682 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 683 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 684 | { |
mridup | 0:dc55f40eb04f | 685 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 686 | } |
mridup | 0:dc55f40eb04f | 687 | return status; |
mridup | 0:dc55f40eb04f | 688 | } |
mridup | 0:dc55f40eb04f | 689 | |
mridup | 0:dc55f40eb04f | 690 | /** |
mridup | 0:dc55f40eb04f | 691 | * @brief wifi_file_list |
mridup | 0:dc55f40eb04f | 692 | * List existing filename |
mridup | 0:dc55f40eb04f | 693 | * @param None |
mridup | 0:dc55f40eb04f | 694 | * @retval WiFi_Status_t : return status of AT cmd request |
mridup | 0:dc55f40eb04f | 695 | */ |
mridup | 0:dc55f40eb04f | 696 | |
mridup | 0:dc55f40eb04f | 697 | WiFi_Status_t wifi_file_list() |
mridup | 0:dc55f40eb04f | 698 | { |
mridup | 0:dc55f40eb04f | 699 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 700 | Queue_Wifi_File_Event(NULL,NULL,0); |
mridup | 0:dc55f40eb04f | 701 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 702 | return status; |
mridup | 0:dc55f40eb04f | 703 | } |
mridup | 0:dc55f40eb04f | 704 | |
mridup | 0:dc55f40eb04f | 705 | /** |
mridup | 0:dc55f40eb04f | 706 | * @brief wifi_file_show |
mridup | 0:dc55f40eb04f | 707 | * Print the contents of an existing file |
mridup | 0:dc55f40eb04f | 708 | * @param pFileName : pinter of file name |
mridup | 0:dc55f40eb04f | 709 | * @retval WiFi_Status_t : return status of AT cmd request |
mridup | 0:dc55f40eb04f | 710 | */ |
mridup | 0:dc55f40eb04f | 711 | |
mridup | 0:dc55f40eb04f | 712 | WiFi_Status_t wifi_file_show(uint8_t * pFileName) |
mridup | 0:dc55f40eb04f | 713 | { |
mridup | 0:dc55f40eb04f | 714 | if(pFileName==NULL) |
mridup | 0:dc55f40eb04f | 715 | return WiFi_MODULE_ERROR; |
mridup | 0:dc55f40eb04f | 716 | |
mridup | 0:dc55f40eb04f | 717 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 718 | Queue_Wifi_File_Event(NULL,pFileName,0); |
mridup | 0:dc55f40eb04f | 719 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 720 | return status; |
mridup | 0:dc55f40eb04f | 721 | } |
mridup | 0:dc55f40eb04f | 722 | |
mridup | 0:dc55f40eb04f | 723 | /** |
mridup | 0:dc55f40eb04f | 724 | * @brief wifi_file_create |
mridup | 0:dc55f40eb04f | 725 | * Create file for HTTP server |
mridup | 0:dc55f40eb04f | 726 | * @param pFileName : pointer of file name to be created |
mridup | 0:dc55f40eb04f | 727 | * alength : length of file |
mridup | 0:dc55f40eb04f | 728 | * @retval WiFi_Status_t : return status of AT cmd request |
mridup | 0:dc55f40eb04f | 729 | */ |
mridup | 0:dc55f40eb04f | 730 | |
mridup | 0:dc55f40eb04f | 731 | WiFi_Status_t wifi_file_create(char *pFileName, uint16_t alength, char * pUserFileBuff) |
mridup | 0:dc55f40eb04f | 732 | { |
mridup | 0:dc55f40eb04f | 733 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 734 | |
mridup | 0:dc55f40eb04f | 735 | if(alength >1024) |
mridup | 0:dc55f40eb04f | 736 | return WiFi_AT_FILE_LENGTH_ERROR; |
mridup | 0:dc55f40eb04f | 737 | |
mridup | 0:dc55f40eb04f | 738 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 739 | |
mridup | 0:dc55f40eb04f | 740 | /* AT+S.FSC=/index.html */ |
mridup | 0:dc55f40eb04f | 741 | sprintf((char*)WiFi_AT_Cmd_Buff, AT_CREATE_NEW_HTML_FILE, pFileName, alength); |
mridup | 0:dc55f40eb04f | 742 | |
mridup | 0:dc55f40eb04f | 743 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 744 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 745 | { |
mridup | 0:dc55f40eb04f | 746 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 747 | int len = strlen(pUserFileBuff); |
mridup | 0:dc55f40eb04f | 748 | |
mridup | 0:dc55f40eb04f | 749 | if(len >= 1024) |
mridup | 0:dc55f40eb04f | 750 | return WiFi_AT_FILE_LENGTH_ERROR; |
mridup | 0:dc55f40eb04f | 751 | |
mridup | 0:dc55f40eb04f | 752 | /* AT+S.FSA=/index.html */ |
mridup | 0:dc55f40eb04f | 753 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_APPEND_FILE,pFileName,len); |
mridup | 0:dc55f40eb04f | 754 | |
mridup | 0:dc55f40eb04f | 755 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 756 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 757 | { |
mridup | 0:dc55f40eb04f | 758 | memset(WiFi_AT_Cmd_Buff, 0x00, sizeof WiFi_AT_Cmd_Buff); |
mridup | 0:dc55f40eb04f | 759 | memcpy((char*)(char*)WiFi_AT_Cmd_Buff, (char*) pUserFileBuff,len); |
mridup | 0:dc55f40eb04f | 760 | WiFi_AT_Cmd_Buff[len+1]='\r'; |
mridup | 0:dc55f40eb04f | 761 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 762 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 763 | { |
mridup | 0:dc55f40eb04f | 764 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 765 | } |
mridup | 0:dc55f40eb04f | 766 | } |
mridup | 0:dc55f40eb04f | 767 | } |
mridup | 0:dc55f40eb04f | 768 | return status; |
mridup | 0:dc55f40eb04f | 769 | } |
mridup | 0:dc55f40eb04f | 770 | |
mridup | 0:dc55f40eb04f | 771 | /** |
mridup | 0:dc55f40eb04f | 772 | * @brief wifi_http_get |
mridup | 0:dc55f40eb04f | 773 | * Issue an HTTP GET of the given path to the specified host |
mridup | 0:dc55f40eb04f | 774 | * @param None |
mridup | 0:dc55f40eb04f | 775 | * @retval WiFi_Status_t : return status of AT cmd response |
mridup | 0:dc55f40eb04f | 776 | */ |
mridup | 0:dc55f40eb04f | 777 | |
mridup | 0:dc55f40eb04f | 778 | WiFi_Status_t wifi_http_get(uint8_t * hostname, uint8_t * path, uint32_t port_number) |
mridup | 0:dc55f40eb04f | 779 | { |
mridup | 0:dc55f40eb04f | 780 | if(hostname == NULL || path == NULL) |
mridup | 0:dc55f40eb04f | 781 | return WiFi_MODULE_ERROR; |
mridup | 0:dc55f40eb04f | 782 | |
mridup | 0:dc55f40eb04f | 783 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 784 | |
mridup | 0:dc55f40eb04f | 785 | while(status_flag.sock_read_ongoing || WIND64_count!= 0); //wait till any pending data is read |
mridup | 0:dc55f40eb04f | 786 | { |
mridup | 0:dc55f40eb04f | 787 | asm("NOP"); |
mridup | 0:dc55f40eb04f | 788 | } |
mridup | 0:dc55f40eb04f | 789 | |
mridup | 0:dc55f40eb04f | 790 | // AT+S.HTTPGET=host.example.com,/index.html, port_number<cr> |
mridup | 0:dc55f40eb04f | 791 | //Queue the http-get command |
mridup | 0:dc55f40eb04f | 792 | Queue_Http_Event(hostname, path, port_number,NULL); |
mridup | 0:dc55f40eb04f | 793 | |
mridup | 0:dc55f40eb04f | 794 | //Make the user wait anyway |
mridup | 0:dc55f40eb04f | 795 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 796 | |
mridup | 0:dc55f40eb04f | 797 | return status; |
mridup | 0:dc55f40eb04f | 798 | |
mridup | 0:dc55f40eb04f | 799 | } |
mridup | 0:dc55f40eb04f | 800 | |
mridup | 0:dc55f40eb04f | 801 | /** |
mridup | 0:dc55f40eb04f | 802 | * @brief wifi_http_post |
mridup | 0:dc55f40eb04f | 803 | * Issue an HTTP GET of the given path to the specified host |
mridup | 0:dc55f40eb04f | 804 | * @param None |
mridup | 0:dc55f40eb04f | 805 | * @retval WiFi_Status_t : status of Http Post Request |
mridup | 0:dc55f40eb04f | 806 | */ |
mridup | 0:dc55f40eb04f | 807 | |
mridup | 0:dc55f40eb04f | 808 | WiFi_Status_t wifi_http_post(uint8_t * pURL_path) |
mridup | 0:dc55f40eb04f | 809 | { |
mridup | 0:dc55f40eb04f | 810 | if(pURL_path == NULL) |
mridup | 0:dc55f40eb04f | 811 | return WiFi_MODULE_ERROR; |
mridup | 0:dc55f40eb04f | 812 | |
mridup | 0:dc55f40eb04f | 813 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 814 | |
mridup | 0:dc55f40eb04f | 815 | while(status_flag.sock_read_ongoing || WIND64_count!= 0);//wait till any pending data is read |
mridup | 0:dc55f40eb04f | 816 | { |
mridup | 0:dc55f40eb04f | 817 | asm("NOP"); |
mridup | 0:dc55f40eb04f | 818 | } |
mridup | 0:dc55f40eb04f | 819 | |
mridup | 0:dc55f40eb04f | 820 | // AT+S.HTTPPOST = posttestserver.com,/post.php,name=demo&email=mymail&subject=subj&body=message<cr> |
mridup | 0:dc55f40eb04f | 821 | Queue_Http_Event(NULL,NULL,0,pURL_path); |
mridup | 0:dc55f40eb04f | 822 | |
mridup | 0:dc55f40eb04f | 823 | //Make the user wait anyway |
mridup | 0:dc55f40eb04f | 824 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 825 | return status; |
mridup | 0:dc55f40eb04f | 826 | } |
mridup | 0:dc55f40eb04f | 827 | |
mridup | 0:dc55f40eb04f | 828 | /** |
mridup | 0:dc55f40eb04f | 829 | * @brief wifi_file_image_create |
mridup | 0:dc55f40eb04f | 830 | * Downloads an updated file system via a single HTTP GET request to the |
mridup | 0:dc55f40eb04f | 831 | * named host and path. |
mridup | 0:dc55f40eb04f | 832 | * @param None |
mridup | 0:dc55f40eb04f | 833 | * @retval WiFi_Status_t |
mridup | 0:dc55f40eb04f | 834 | */ |
mridup | 0:dc55f40eb04f | 835 | WiFi_Status_t wifi_file_image_create(uint8_t * pHostName, uint8_t * pFileName, uint32_t port_number) |
mridup | 0:dc55f40eb04f | 836 | { |
mridup | 0:dc55f40eb04f | 837 | if(pHostName == NULL || pFileName == NULL || port_number ==0) |
mridup | 0:dc55f40eb04f | 838 | return WiFi_MODULE_ERROR; |
mridup | 0:dc55f40eb04f | 839 | |
mridup | 0:dc55f40eb04f | 840 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 841 | Queue_Wifi_File_Event(pHostName,pFileName,port_number); |
mridup | 0:dc55f40eb04f | 842 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 843 | |
mridup | 0:dc55f40eb04f | 844 | /* Soft reset the module */ |
mridup | 0:dc55f40eb04f | 845 | SET_Power_State(PowerSave_State); |
mridup | 0:dc55f40eb04f | 846 | return status; |
mridup | 0:dc55f40eb04f | 847 | } |
mridup | 0:dc55f40eb04f | 848 | |
mridup | 0:dc55f40eb04f | 849 | /** |
mridup | 0:dc55f40eb04f | 850 | * @brief wifi_file_erase_external_flash |
mridup | 0:dc55f40eb04f | 851 | * This API allows to erase the content of the external flash |
mridup | 0:dc55f40eb04f | 852 | * @param None |
mridup | 0:dc55f40eb04f | 853 | * @retval WiFi_Status_t |
mridup | 0:dc55f40eb04f | 854 | */ |
mridup | 0:dc55f40eb04f | 855 | WiFi_Status_t wifi_file_erase_external_flash() |
mridup | 0:dc55f40eb04f | 856 | { |
mridup | 0:dc55f40eb04f | 857 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 858 | |
mridup | 0:dc55f40eb04f | 859 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 860 | ResetBuffer(); |
mridup | 0:dc55f40eb04f | 861 | |
mridup | 0:dc55f40eb04f | 862 | /* AT+S.HTTPDFSERASE */ |
mridup | 0:dc55f40eb04f | 863 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_ERASE_FLASH_MEMORY); |
mridup | 0:dc55f40eb04f | 864 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 865 | |
mridup | 0:dc55f40eb04f | 866 | /* Soft reset the module */ |
mridup | 0:dc55f40eb04f | 867 | SET_Power_State(PowerSave_State); |
mridup | 0:dc55f40eb04f | 868 | |
mridup | 0:dc55f40eb04f | 869 | return status; |
mridup | 0:dc55f40eb04f | 870 | } |
mridup | 0:dc55f40eb04f | 871 | |
mridup | 0:dc55f40eb04f | 872 | /** |
mridup | 0:dc55f40eb04f | 873 | * @brief wifi_fw_update |
mridup | 0:dc55f40eb04f | 874 | * Issue an HTTP GET of the given path to the specified host and get the firmware updated |
mridup | 0:dc55f40eb04f | 875 | * @param None |
mridup | 0:dc55f40eb04f | 876 | * @retval None |
mridup | 0:dc55f40eb04f | 877 | */ |
mridup | 0:dc55f40eb04f | 878 | WiFi_Status_t wifi_fw_update(uint8_t * hostname, uint8_t * filename_path, uint32_t port_number) |
mridup | 0:dc55f40eb04f | 879 | { |
mridup | 0:dc55f40eb04f | 880 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 881 | Queue_Wifi_FW_Update_Event(hostname,filename_path,port_number); |
mridup | 0:dc55f40eb04f | 882 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 883 | /* Soft reset the module */ |
mridup | 0:dc55f40eb04f | 884 | SET_Power_State(PowerSave_State); |
mridup | 0:dc55f40eb04f | 885 | return status; |
mridup | 0:dc55f40eb04f | 886 | } |
mridup | 0:dc55f40eb04f | 887 | |
mridup | 0:dc55f40eb04f | 888 | /** |
mridup | 0:dc55f40eb04f | 889 | * @brief wifi_network_scan |
mridup | 0:dc55f40eb04f | 890 | * Performs an immediate scan for available network |
mridup | 0:dc55f40eb04f | 891 | * @param None |
mridup | 0:dc55f40eb04f | 892 | * @retval WiFi_Status_t : WiFi status error |
mridup | 0:dc55f40eb04f | 893 | */ |
mridup | 0:dc55f40eb04f | 894 | WiFi_Status_t wifi_network_scan(wifi_scan *scan_result, uint16_t max_scan_number) |
mridup | 0:dc55f40eb04f | 895 | { |
mridup | 0:dc55f40eb04f | 896 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 897 | wifi_scanned_list = scan_result; |
mridup | 0:dc55f40eb04f | 898 | if(max_scan_number>MAX_WIFI_SCAN_NETWORK) |
mridup | 0:dc55f40eb04f | 899 | return WiFi_NOT_SUPPORTED; |
mridup | 0:dc55f40eb04f | 900 | user_scan_number = max_scan_number; |
mridup | 0:dc55f40eb04f | 901 | |
mridup | 0:dc55f40eb04f | 902 | if(status_flag.Scan_Ongoing) |
mridup | 0:dc55f40eb04f | 903 | { |
mridup | 0:dc55f40eb04f | 904 | return WiFi_AT_CMD_BUSY; |
mridup | 0:dc55f40eb04f | 905 | } |
mridup | 0:dc55f40eb04f | 906 | |
mridup | 0:dc55f40eb04f | 907 | status_flag.Scan_Ongoing = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 908 | |
mridup | 0:dc55f40eb04f | 909 | #if 0 //TBD |
mridup | 0:dc55f40eb04f | 910 | if(WiFi_Param.WiFi_Module_State == WiFi_MiniAP_MODE) |
mridup | 0:dc55f40eb04f | 911 | return WiFi_NOT_SUPPORTED; |
mridup | 0:dc55f40eb04f | 912 | #endif |
mridup | 0:dc55f40eb04f | 913 | |
mridup | 0:dc55f40eb04f | 914 | /* AT+S.SCAN: performs an immediate scan for available networks */ |
mridup | 0:dc55f40eb04f | 915 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 916 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_WiFi_SCAN); |
mridup | 0:dc55f40eb04f | 917 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 918 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 919 | { |
mridup | 0:dc55f40eb04f | 920 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 921 | } |
mridup | 0:dc55f40eb04f | 922 | |
mridup | 0:dc55f40eb04f | 923 | /*At this point we have WiFi_Scan_Buffer filled with RSSI and SSID values*/ |
mridup | 0:dc55f40eb04f | 924 | return status; |
mridup | 0:dc55f40eb04f | 925 | } |
mridup | 0:dc55f40eb04f | 926 | |
mridup | 0:dc55f40eb04f | 927 | /** |
mridup | 0:dc55f40eb04f | 928 | * @brief Set_MiniAP_Mode |
mridup | 0:dc55f40eb04f | 929 | * Configure Wi-Fi module in AP mode. |
mridup | 0:dc55f40eb04f | 930 | MiniAP is always configured in open mode (WEP not supported) |
mridup | 0:dc55f40eb04f | 931 | * @param None |
mridup | 0:dc55f40eb04f | 932 | * @retval WiFi_Status_t : status of AT cmd |
mridup | 0:dc55f40eb04f | 933 | */ |
mridup | 0:dc55f40eb04f | 934 | WiFi_Status_t wifi_ap_start(uint8_t * ssid, uint8_t channel_num) |
mridup | 0:dc55f40eb04f | 935 | { |
mridup | 0:dc55f40eb04f | 936 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 937 | |
mridup | 0:dc55f40eb04f | 938 | /* Set the SSID : AT+S.SSIDTXT=<SSID>*/ |
mridup | 0:dc55f40eb04f | 939 | //if(ssid) |
mridup | 0:dc55f40eb04f | 940 | status = SET_SSID((char*)ssid); |
mridup | 0:dc55f40eb04f | 941 | |
mridup | 0:dc55f40eb04f | 942 | |
mridup | 0:dc55f40eb04f | 943 | if(status != WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 944 | return WiFi_SSID_ERROR; |
mridup | 0:dc55f40eb04f | 945 | |
mridup | 0:dc55f40eb04f | 946 | /* Set the network privacy mode : AT+S.SCFG=wifi_priv_mode,0*/ |
mridup | 0:dc55f40eb04f | 947 | status = SET_Configuration_Value(WIFI_PRIV_MODE, None); |
mridup | 0:dc55f40eb04f | 948 | if(status != WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 949 | return WiFi_CONFIG_ERROR; |
mridup | 0:dc55f40eb04f | 950 | |
mridup | 0:dc55f40eb04f | 951 | /* Set the network mode (1 = STA, 2 = IBSS, 3 = MiniAP) :: AT+S.SCFG=wifi_mode,3*/ |
mridup | 0:dc55f40eb04f | 952 | status = SET_Configuration_Value(WIFI_MODE, WiFi_MiniAP_MODE); |
mridup | 0:dc55f40eb04f | 953 | if(status != WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 954 | return WiFi_CONFIG_ERROR; |
mridup | 0:dc55f40eb04f | 955 | |
mridup | 0:dc55f40eb04f | 956 | /* Set the channel number */ |
mridup | 0:dc55f40eb04f | 957 | status = SET_Configuration_Value(WIFI_CHANNEL_NUMBER, channel_num); |
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 | /* Save the settings on the flash memory : AT&W*/ |
mridup | 0:dc55f40eb04f | 962 | Save_Current_Setting(); |
mridup | 0:dc55f40eb04f | 963 | |
mridup | 0:dc55f40eb04f | 964 | status_flag.WiFi_Configuration_Done = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 965 | WiFi_Module_State = Process_Event; |
mridup | 0:dc55f40eb04f | 966 | |
mridup | 0:dc55f40eb04f | 967 | /* Soft reset the module */ |
mridup | 0:dc55f40eb04f | 968 | SET_Power_State(PowerSave_State); |
mridup | 0:dc55f40eb04f | 969 | |
mridup | 0:dc55f40eb04f | 970 | return status; |
mridup | 0:dc55f40eb04f | 971 | } |
mridup | 0:dc55f40eb04f | 972 | |
mridup | 0:dc55f40eb04f | 973 | |
mridup | 0:dc55f40eb04f | 974 | /** |
mridup | 0:dc55f40eb04f | 975 | * @brief SET_WiFi_STA_Mode |
mridup | 0:dc55f40eb04f | 976 | * Configure Wi-Fi module in STA mode |
mridup | 0:dc55f40eb04f | 977 | * @param SSID : SSID name |
mridup | 0:dc55f40eb04f | 978 | * @param sec_key : security key |
mridup | 0:dc55f40eb04f | 979 | * @param priv_mode : network privecy mode |
mridup | 0:dc55f40eb04f | 980 | * @retval WiFi_Status_t : status of AT cmd |
mridup | 0:dc55f40eb04f | 981 | */ |
mridup | 0:dc55f40eb04f | 982 | WiFi_Status_t wifi_connect(char * ssid, char * sec_key, WiFi_Priv_Mode priv_mode) |
mridup | 0:dc55f40eb04f | 983 | { |
mridup | 0:dc55f40eb04f | 984 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 985 | if(status_flag.AT_Cmd_Ongoing == WIFI_FALSE) |
mridup | 0:dc55f40eb04f | 986 | status_flag.AT_Cmd_Ongoing = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 987 | else |
mridup | 0:dc55f40eb04f | 988 | { |
mridup | 0:dc55f40eb04f | 989 | return WiFi_AT_CMD_BUSY; |
mridup | 0:dc55f40eb04f | 990 | } |
mridup | 0:dc55f40eb04f | 991 | |
mridup | 0:dc55f40eb04f | 992 | if(sec_key) { |
mridup | 0:dc55f40eb04f | 993 | status = SET_WiFi_SecKey((char*)sec_key); |
mridup | 0:dc55f40eb04f | 994 | if(status != WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 995 | return WiFi_SecKey_ERROR; |
mridup | 0:dc55f40eb04f | 996 | } |
mridup | 0:dc55f40eb04f | 997 | |
mridup | 0:dc55f40eb04f | 998 | /* Set the SSID : AT+S.SSIDTXT=<SSID>*/ |
mridup | 0:dc55f40eb04f | 999 | |
mridup | 0:dc55f40eb04f | 1000 | status = SET_SSID((char*)ssid); |
mridup | 0:dc55f40eb04f | 1001 | |
mridup | 0:dc55f40eb04f | 1002 | if(status != WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 1003 | return WiFi_SSID_ERROR; |
mridup | 0:dc55f40eb04f | 1004 | |
mridup | 0:dc55f40eb04f | 1005 | /* Set the network privacy mode : AT+S.SCFG=wifi_priv_mode,2*/ |
mridup | 0:dc55f40eb04f | 1006 | status = SET_Configuration_Value(WIFI_PRIV_MODE, priv_mode); |
mridup | 0:dc55f40eb04f | 1007 | if(status != WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 1008 | return WiFi_CONFIG_ERROR; |
mridup | 0:dc55f40eb04f | 1009 | |
mridup | 0:dc55f40eb04f | 1010 | /* Set the network mode (1 = STA, 2 = IBSS, 3 = MiniAP) :: AT+S.SCFG=wifi_mode,1*/ |
mridup | 0:dc55f40eb04f | 1011 | status = SET_Configuration_Value(WIFI_MODE, WiFi_STA_MODE); |
mridup | 0:dc55f40eb04f | 1012 | if(status != WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 1013 | return WiFi_CONFIG_ERROR; |
mridup | 0:dc55f40eb04f | 1014 | |
mridup | 0:dc55f40eb04f | 1015 | /* Save the settings on the flash memory : AT&W*/ |
mridup | 0:dc55f40eb04f | 1016 | Save_Current_Setting(); |
mridup | 0:dc55f40eb04f | 1017 | |
mridup | 0:dc55f40eb04f | 1018 | status_flag.WiFi_Configuration_Done = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1019 | //WiFi_Module_State = WiFi_Process_Event; |
mridup | 0:dc55f40eb04f | 1020 | |
mridup | 0:dc55f40eb04f | 1021 | /* Soft reset the module */ |
mridup | 0:dc55f40eb04f | 1022 | SET_Power_State(PowerSave_State); |
mridup | 0:dc55f40eb04f | 1023 | |
mridup | 0:dc55f40eb04f | 1024 | status_flag.AT_Cmd_Ongoing = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1025 | |
mridup | 0:dc55f40eb04f | 1026 | return status; |
mridup | 0:dc55f40eb04f | 1027 | } |
mridup | 0:dc55f40eb04f | 1028 | |
mridup | 0:dc55f40eb04f | 1029 | /** |
mridup | 0:dc55f40eb04f | 1030 | * @brief SET_WiFi_IBSS_Mode |
mridup | 0:dc55f40eb04f | 1031 | * Configure Wi-Fi module in IBSS mode |
mridup | 0:dc55f40eb04f | 1032 | * @param SSID : SSID name |
mridup | 0:dc55f40eb04f | 1033 | * @param priv_mode : network privecy mode |
mridup | 0:dc55f40eb04f | 1034 | * @retval WiFi_Status_t : status of AT cmd |
mridup | 0:dc55f40eb04f | 1035 | */ |
mridup | 0:dc55f40eb04f | 1036 | WiFi_Status_t wifi_adhoc_create(uint8_t * ssid, WiFi_Priv_Mode priv_mode) |
mridup | 0:dc55f40eb04f | 1037 | { |
mridup | 0:dc55f40eb04f | 1038 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 1039 | |
mridup | 0:dc55f40eb04f | 1040 | Attention_Cmd(); |
mridup | 0:dc55f40eb04f | 1041 | /* Set the SSID : AT+S.SSIDTXT=<SSID>*/ |
mridup | 0:dc55f40eb04f | 1042 | status = SET_SSID((char*)ssid); |
mridup | 0:dc55f40eb04f | 1043 | if(status != WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 1044 | return WiFi_SSID_ERROR; |
mridup | 0:dc55f40eb04f | 1045 | |
mridup | 0:dc55f40eb04f | 1046 | /* Set the network privacy mode : AT+S.SCFG=wifi_priv_mode,0*/ |
mridup | 0:dc55f40eb04f | 1047 | status = SET_Configuration_Value(WIFI_PRIV_MODE, priv_mode); |
mridup | 0:dc55f40eb04f | 1048 | if(status != WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 1049 | return WiFi_CONFIG_ERROR; |
mridup | 0:dc55f40eb04f | 1050 | |
mridup | 0:dc55f40eb04f | 1051 | |
mridup | 0:dc55f40eb04f | 1052 | /* Set the network mode (1 = STA, 2 = IBSS, 3 = MiniAP) :: AT+S.SCFG=wifi_mode,2*/ |
mridup | 0:dc55f40eb04f | 1053 | status = SET_Configuration_Value(WIFI_MODE, WiFi_IBSS_MODE); |
mridup | 0:dc55f40eb04f | 1054 | if(status != WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 1055 | return WiFi_CONFIG_ERROR; |
mridup | 0:dc55f40eb04f | 1056 | |
mridup | 0:dc55f40eb04f | 1057 | /* Set IP address */ |
mridup | 0:dc55f40eb04f | 1058 | status = SET_Configuration_Addr(WIFI_IP_ADDRESS, WIFI_IBSS_IP_ADDR); |
mridup | 0:dc55f40eb04f | 1059 | if(status != WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 1060 | return WiFi_CONFIG_ERROR; |
mridup | 0:dc55f40eb04f | 1061 | |
mridup | 0:dc55f40eb04f | 1062 | /* Set IP default gateway */ |
mridup | 0:dc55f40eb04f | 1063 | status = SET_Configuration_Addr(WIFI_IP_DEFAULT_GATEWAY, WIFI_IBSS_DEFAULT_GATEWAY); |
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 | |
mridup | 0:dc55f40eb04f | 1068 | /* Set IP DNS */ |
mridup | 0:dc55f40eb04f | 1069 | status = SET_Configuration_Addr(WIFI_IP_DNS, WIFI_IBSS_IP_DNS_ADDR); |
mridup | 0:dc55f40eb04f | 1070 | if(status != WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 1071 | return WiFi_CONFIG_ERROR; |
mridup | 0:dc55f40eb04f | 1072 | |
mridup | 0:dc55f40eb04f | 1073 | /* Set IP netmask */ |
mridup | 0:dc55f40eb04f | 1074 | status = SET_Configuration_Addr(WIFI_IP_NETMASK, WIFI_IBSS_IP_MASK); |
mridup | 0:dc55f40eb04f | 1075 | if(status != WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 1076 | return WiFi_CONFIG_ERROR; |
mridup | 0:dc55f40eb04f | 1077 | |
mridup | 0:dc55f40eb04f | 1078 | /* Turn OFF the DHCP */ |
mridup | 0:dc55f40eb04f | 1079 | SET_Configuration_Value(IP_USE_DHCP_SERVER, WIFI_IP_USE_DHCP); |
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 | /* Save the settings on the flash memory : AT&W*/ |
mridup | 0:dc55f40eb04f | 1084 | Save_Current_Setting(); |
mridup | 0:dc55f40eb04f | 1085 | |
mridup | 0:dc55f40eb04f | 1086 | /* Soft reset the module */ |
mridup | 0:dc55f40eb04f | 1087 | SET_Power_State(PowerSave_State); |
mridup | 0:dc55f40eb04f | 1088 | return status; |
mridup | 0:dc55f40eb04f | 1089 | } |
mridup | 0:dc55f40eb04f | 1090 | |
mridup | 0:dc55f40eb04f | 1091 | |
mridup | 0:dc55f40eb04f | 1092 | /** |
mridup | 0:dc55f40eb04f | 1093 | * @brief wifi_standby |
mridup | 0:dc55f40eb04f | 1094 | * Configured WiFi module to enter standby |
mridup | 0:dc55f40eb04f | 1095 | * @param arg_standby_time: standby time |
mridup | 0:dc55f40eb04f | 1096 | * @retval WiFi_Status_t : status of AT cmd |
mridup | 0:dc55f40eb04f | 1097 | */ |
mridup | 0:dc55f40eb04f | 1098 | WiFi_Status_t wifi_standby(uint8_t arg_standby_time) |
mridup | 0:dc55f40eb04f | 1099 | { |
mridup | 0:dc55f40eb04f | 1100 | /* |
mridup | 0:dc55f40eb04f | 1101 | For Standby, the presence of Jumpers on JP4 and JP3 has the following behaviour: |
mridup | 0:dc55f40eb04f | 1102 | JP3 (middle and bottom): prevents standby and immediately wakes-up module |
mridup | 0:dc55f40eb04f | 1103 | JP3 (middle and top): no effect on standby |
mridup | 0:dc55f40eb04f | 1104 | JP4 (middle and right): prevents wakeup and standby runs forever |
mridup | 0:dc55f40eb04f | 1105 | JP4 (middle and left): no effect on standby |
mridup | 0:dc55f40eb04f | 1106 | */ |
mridup | 0:dc55f40eb04f | 1107 | |
mridup | 0:dc55f40eb04f | 1108 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 1109 | |
mridup | 0:dc55f40eb04f | 1110 | /*if(arg_standby_time<2) |
mridup | 0:dc55f40eb04f | 1111 | return WiFi_NOT_SUPPORTED;*/ |
mridup | 0:dc55f40eb04f | 1112 | |
mridup | 0:dc55f40eb04f | 1113 | SET_Configuration_Value(WIFI_SLEEP_ENABLED, 0); |
mridup | 0:dc55f40eb04f | 1114 | SET_Configuration_Value(WIFI_STANDBY_ENABLED, 1); |
mridup | 0:dc55f40eb04f | 1115 | status = SET_Configuration_Value(WIFI_STANDBY_TIME, arg_standby_time); |
mridup | 0:dc55f40eb04f | 1116 | |
mridup | 0:dc55f40eb04f | 1117 | /* save current setting in flash */ |
mridup | 0:dc55f40eb04f | 1118 | Save_Current_Setting(); |
mridup | 0:dc55f40eb04f | 1119 | |
mridup | 0:dc55f40eb04f | 1120 | /* AT : send AT command */ |
mridup | 0:dc55f40eb04f | 1121 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_POWER_STATE,1); //cfun=4 |
mridup | 0:dc55f40eb04f | 1122 | WiFi_Module_State = Process_Event; //make sure the WiFi module is in this state to receive WINDS after wakeup |
mridup | 0:dc55f40eb04f | 1123 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 1124 | |
mridup | 0:dc55f40eb04f | 1125 | if(status == WiFi_MODULE_SUCCESS)//if transmit is success, prepare for resume |
mridup | 0:dc55f40eb04f | 1126 | { |
mridup | 0:dc55f40eb04f | 1127 | /* |
mridup | 0:dc55f40eb04f | 1128 | status_flag.AT_Cmd_Processing = WIFI_TRUE;//We do not want the next UART data_byte fetch to be done |
mridup | 0:dc55f40eb04f | 1129 | HAL_NVIC_DisableIRQ(USARTx_IRQn);//Disable UART IRQ |
mridup | 0:dc55f40eb04f | 1130 | status_flag.Standby_Timer_Running=WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1131 | printf("\r\nGoing into Standby Mode...\r\n");*/ |
mridup | 0:dc55f40eb04f | 1132 | } |
mridup | 0:dc55f40eb04f | 1133 | |
mridup | 0:dc55f40eb04f | 1134 | return status; |
mridup | 0:dc55f40eb04f | 1135 | |
mridup | 0:dc55f40eb04f | 1136 | } |
mridup | 0:dc55f40eb04f | 1137 | |
mridup | 0:dc55f40eb04f | 1138 | /** |
mridup | 0:dc55f40eb04f | 1139 | * @brief wifi_wakeup |
mridup | 0:dc55f40eb04f | 1140 | * wakeup the module from sleep by setting the GPIO6 through PC13 |
mridup | 0:dc55f40eb04f | 1141 | * or allow it to go to sleep |
mridup | 0:dc55f40eb04f | 1142 | * Jumper needed on JP4 |
mridup | 0:dc55f40eb04f | 1143 | * @param wakeup wakeup (WIFI_TRUE) or allow sleep(WIFI_FALSE) |
mridup | 0:dc55f40eb04f | 1144 | * @retval WiFi_Status_t : status of function call |
mridup | 0:dc55f40eb04f | 1145 | */ |
mridup | 0:dc55f40eb04f | 1146 | WiFi_Status_t wifi_wakeup(wifi_bool wakeup) |
mridup | 0:dc55f40eb04f | 1147 | { |
mridup | 0:dc55f40eb04f | 1148 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 1149 | |
mridup | 0:dc55f40eb04f | 1150 | if(wakeup) |
mridup | 1:bd9db471d47d | 1151 | callSpwfSADevice_wakeup(spwf_device_class, 0); |
mridup | 0:dc55f40eb04f | 1152 | else |
mridup | 0:dc55f40eb04f | 1153 | callSpwfSADevice_wakeup(spwf_device_class, 0); |
mridup | 0:dc55f40eb04f | 1154 | wait_ms(100); |
mridup | 0:dc55f40eb04f | 1155 | return status; |
mridup | 0:dc55f40eb04f | 1156 | } |
mridup | 0:dc55f40eb04f | 1157 | |
mridup | 0:dc55f40eb04f | 1158 | |
mridup | 0:dc55f40eb04f | 1159 | /** |
mridup | 0:dc55f40eb04f | 1160 | * @brief wifi_disconnect |
mridup | 0:dc55f40eb04f | 1161 | * disconnect the module from any AP |
mridup | 0:dc55f40eb04f | 1162 | * @param None |
mridup | 0:dc55f40eb04f | 1163 | * @retval WiFi_Status_t : status of AT cmd |
mridup | 0:dc55f40eb04f | 1164 | */ |
mridup | 0:dc55f40eb04f | 1165 | WiFi_Status_t wifi_disconnect(void) |
mridup | 0:dc55f40eb04f | 1166 | { |
mridup | 0:dc55f40eb04f | 1167 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 1168 | |
mridup | 5:c83ffd44f40a | 1169 | //Wait till all queued events are executed |
mridup | 5:c83ffd44f40a | 1170 | while(!event_empty(&event_buff)); |
mridup | 5:c83ffd44f40a | 1171 | Wait_For_Sock_Read_To_Complete(); |
mridup | 5:c83ffd44f40a | 1172 | |
mridup | 0:dc55f40eb04f | 1173 | /* Set wifi_mode to idle*/ |
mridup | 0:dc55f40eb04f | 1174 | status = SET_Configuration_Value(WIFI_MODE, WiFi_IDLE_MODE); |
mridup | 0:dc55f40eb04f | 1175 | |
mridup | 0:dc55f40eb04f | 1176 | /*If module was connected, reset the status*/ |
mridup | 0:dc55f40eb04f | 1177 | if(wifi_connected == 1) |
mridup | 0:dc55f40eb04f | 1178 | { |
mridup | 0:dc55f40eb04f | 1179 | wifi_connected = 0;//this will allow the TIM handler to make the callback on connection(WiFiUp) |
mridup | 0:dc55f40eb04f | 1180 | } |
mridup | 0:dc55f40eb04f | 1181 | |
mridup | 0:dc55f40eb04f | 1182 | /* save current setting in flash */ |
mridup | 0:dc55f40eb04f | 1183 | Save_Current_Setting(); |
mridup | 0:dc55f40eb04f | 1184 | |
mridup | 0:dc55f40eb04f | 1185 | /* Soft reset the module */ |
mridup | 0:dc55f40eb04f | 1186 | status = SET_Power_State(PowerSave_State);//CFUN=1 |
mridup | 0:dc55f40eb04f | 1187 | |
mridup | 0:dc55f40eb04f | 1188 | return status; |
mridup | 0:dc55f40eb04f | 1189 | } |
mridup | 0:dc55f40eb04f | 1190 | |
mridup | 0:dc55f40eb04f | 1191 | /** |
mridup | 0:dc55f40eb04f | 1192 | * @brief wifi_enable |
mridup | 0:dc55f40eb04f | 1193 | * Enable/Disable the Wi-Fi interface |
mridup | 0:dc55f40eb04f | 1194 | * @param enable enable Wi-Fi (WIFI_TRUE) disable Wi-Fi (WIFI_FALSE) |
mridup | 0:dc55f40eb04f | 1195 | * @retval WiFi_Status_t : status of AT cmd |
mridup | 0:dc55f40eb04f | 1196 | */ |
mridup | 0:dc55f40eb04f | 1197 | WiFi_Status_t wifi_enable(wifi_bool enable) |
mridup | 0:dc55f40eb04f | 1198 | { |
mridup | 0:dc55f40eb04f | 1199 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 1200 | |
mridup | 0:dc55f40eb04f | 1201 | /* Enable or Disable wifi interface*/ |
mridup | 0:dc55f40eb04f | 1202 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 1203 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_WIFI_ENABLE, enable); |
mridup | 0:dc55f40eb04f | 1204 | |
mridup | 0:dc55f40eb04f | 1205 | /*if(HAL_UART_Transmit(&UartWiFiHandle, (uint8_t *)WiFi_AT_Cmd_Buff, strlen((char*)WiFi_AT_Cmd_Buff),1000)!= HAL_OK) |
mridup | 0:dc55f40eb04f | 1206 | { |
mridup | 0:dc55f40eb04f | 1207 | Error_Handler(); |
mridup | 0:dc55f40eb04f | 1208 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 1209 | printf("HAL_UART_Transmit Error"); |
mridup | 0:dc55f40eb04f | 1210 | #endif |
mridup | 0:dc55f40eb04f | 1211 | return WiFi_HAL_UART_ERROR; |
mridup | 0:dc55f40eb04f | 1212 | } */ |
mridup | 0:dc55f40eb04f | 1213 | |
mridup | 0:dc55f40eb04f | 1214 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 1215 | |
mridup | 0:dc55f40eb04f | 1216 | //wait for power down/hw started |
mridup | 0:dc55f40eb04f | 1217 | if(enable) |
mridup | 0:dc55f40eb04f | 1218 | while(status_flag.WiFi_Enabled != WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 1219 | { |
mridup | 0:dc55f40eb04f | 1220 | asm("NOP"); |
mridup | 0:dc55f40eb04f | 1221 | } |
mridup | 0:dc55f40eb04f | 1222 | else |
mridup | 0:dc55f40eb04f | 1223 | while(status_flag.WiFi_Enabled != WIFI_FALSE) |
mridup | 0:dc55f40eb04f | 1224 | { |
mridup | 0:dc55f40eb04f | 1225 | asm("NOP"); |
mridup | 0:dc55f40eb04f | 1226 | } |
mridup | 0:dc55f40eb04f | 1227 | |
mridup | 0:dc55f40eb04f | 1228 | return status; |
mridup | 0:dc55f40eb04f | 1229 | |
mridup | 0:dc55f40eb04f | 1230 | } |
mridup | 0:dc55f40eb04f | 1231 | |
mridup | 0:dc55f40eb04f | 1232 | |
mridup | 0:dc55f40eb04f | 1233 | |
mridup | 0:dc55f40eb04f | 1234 | /** |
mridup | 0:dc55f40eb04f | 1235 | * @brief wifi_restore |
mridup | 0:dc55f40eb04f | 1236 | * Restore the Wi-Fi with default values. |
mridup | 0:dc55f40eb04f | 1237 | * @param None |
mridup | 0:dc55f40eb04f | 1238 | * @retval WiFi_Status_t : status of AT cmd |
mridup | 0:dc55f40eb04f | 1239 | */ |
mridup | 0:dc55f40eb04f | 1240 | WiFi_Status_t wifi_restore() |
mridup | 0:dc55f40eb04f | 1241 | { |
mridup | 0:dc55f40eb04f | 1242 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 1243 | |
mridup | 0:dc55f40eb04f | 1244 | /* Restore default setting*/ |
mridup | 0:dc55f40eb04f | 1245 | Restore_Default_Setting(); |
mridup | 0:dc55f40eb04f | 1246 | |
mridup | 0:dc55f40eb04f | 1247 | /* Set wifi_mode to idle*/ |
mridup | 0:dc55f40eb04f | 1248 | SET_Configuration_Value(WIFI_MODE, WiFi_IDLE_MODE); |
mridup | 0:dc55f40eb04f | 1249 | |
mridup | 0:dc55f40eb04f | 1250 | /* set the local echo */ |
mridup | 0:dc55f40eb04f | 1251 | SET_Configuration_Value(LOCALECHO1, 0); |
mridup | 0:dc55f40eb04f | 1252 | |
mridup | 0:dc55f40eb04f | 1253 | /* save current setting in flash */ |
mridup | 0:dc55f40eb04f | 1254 | Save_Current_Setting(); |
mridup | 0:dc55f40eb04f | 1255 | |
mridup | 0:dc55f40eb04f | 1256 | /* Soft reset the module */ |
mridup | 0:dc55f40eb04f | 1257 | status = SET_Power_State(PowerSave_State);//CFUN=1 |
mridup | 0:dc55f40eb04f | 1258 | |
mridup | 0:dc55f40eb04f | 1259 | return status; |
mridup | 0:dc55f40eb04f | 1260 | } |
mridup | 0:dc55f40eb04f | 1261 | |
mridup | 0:dc55f40eb04f | 1262 | /*GPIO Configuration Functions*/ |
mridup | 0:dc55f40eb04f | 1263 | |
mridup | 0:dc55f40eb04f | 1264 | /** |
mridup | 0:dc55f40eb04f | 1265 | * @brief wifi_gpio_init |
mridup | 0:dc55f40eb04f | 1266 | * Configure a GPIO pin as in or out with IRQ setting |
mridup | 0:dc55f40eb04f | 1267 | * @param pin GPIO pin number |
mridup | 0:dc55f40eb04f | 1268 | * @param irq configuration of the pin |
mridup | 0:dc55f40eb04f | 1269 | * @retval WiFi_Status_t : status of AT cmd |
mridup | 0:dc55f40eb04f | 1270 | */ |
mridup | 0:dc55f40eb04f | 1271 | uint8_t wifi_gpio_init(GpioPin pin, char* dir, char irq) |
mridup | 0:dc55f40eb04f | 1272 | { |
mridup | 0:dc55f40eb04f | 1273 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 1274 | |
mridup | 0:dc55f40eb04f | 1275 | /* AT+S.GPIOC=pin,dir,irq */ |
mridup | 0:dc55f40eb04f | 1276 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 1277 | |
mridup | 0:dc55f40eb04f | 1278 | memset(WiFi_AT_Cmd_Buff, 0x00, sizeof WiFi_AT_Cmd_Buff); |
mridup | 0:dc55f40eb04f | 1279 | |
mridup | 0:dc55f40eb04f | 1280 | if(irq!=GPIO_Off) |
mridup | 0:dc55f40eb04f | 1281 | sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.GPIOC=%d,%s,%c\r", pin, dir, irq); |
mridup | 0:dc55f40eb04f | 1282 | else |
mridup | 0:dc55f40eb04f | 1283 | sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.GPIOC=%d,%s\r", pin, dir); |
mridup | 0:dc55f40eb04f | 1284 | |
mridup | 0:dc55f40eb04f | 1285 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 1286 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 1287 | { |
mridup | 0:dc55f40eb04f | 1288 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 1289 | } |
mridup | 0:dc55f40eb04f | 1290 | |
mridup | 0:dc55f40eb04f | 1291 | |
mridup | 0:dc55f40eb04f | 1292 | return status; |
mridup | 0:dc55f40eb04f | 1293 | |
mridup | 0:dc55f40eb04f | 1294 | } |
mridup | 0:dc55f40eb04f | 1295 | |
mridup | 0:dc55f40eb04f | 1296 | /** |
mridup | 0:dc55f40eb04f | 1297 | * @brief wifi_gpio_read |
mridup | 0:dc55f40eb04f | 1298 | * Read the configuration of a GPIO pin |
mridup | 0:dc55f40eb04f | 1299 | * @param pin GPIO pin number |
mridup | 0:dc55f40eb04f | 1300 | * @param val value returned |
mridup | 0:dc55f40eb04f | 1301 | * @param dir configuration direction returned |
mridup | 0:dc55f40eb04f | 1302 | * @retval WiFi_Status_t : status of AT cmd |
mridup | 0:dc55f40eb04f | 1303 | */ |
mridup | 0:dc55f40eb04f | 1304 | uint8_t wifi_gpio_read(GpioPin pin, uint8_t *val, uint8_t *dir) |
mridup | 0:dc55f40eb04f | 1305 | { |
mridup | 0:dc55f40eb04f | 1306 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 1307 | |
mridup | 0:dc55f40eb04f | 1308 | /* AT+S.GPIOR=pin */ |
mridup | 0:dc55f40eb04f | 1309 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 1310 | |
mridup | 0:dc55f40eb04f | 1311 | sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.GPIOR=%d\r", pin); |
mridup | 0:dc55f40eb04f | 1312 | |
mridup | 0:dc55f40eb04f | 1313 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 1314 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 1315 | { |
mridup | 0:dc55f40eb04f | 1316 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 1317 | } |
mridup | 0:dc55f40eb04f | 1318 | *val = gpio_value; |
mridup | 0:dc55f40eb04f | 1319 | *dir = gpio_direc; |
mridup | 0:dc55f40eb04f | 1320 | |
mridup | 0:dc55f40eb04f | 1321 | return status; |
mridup | 0:dc55f40eb04f | 1322 | } |
mridup | 0:dc55f40eb04f | 1323 | |
mridup | 0:dc55f40eb04f | 1324 | /** |
mridup | 0:dc55f40eb04f | 1325 | * @brief wifi_gpio_write |
mridup | 0:dc55f40eb04f | 1326 | * Read the value of a GPIO pin |
mridup | 0:dc55f40eb04f | 1327 | * @param pin GPIO pin number |
mridup | 0:dc55f40eb04f | 1328 | * @param val value to be configured |
mridup | 0:dc55f40eb04f | 1329 | * @retval WiFi_Status_t : status of AT cmd |
mridup | 0:dc55f40eb04f | 1330 | */ |
mridup | 0:dc55f40eb04f | 1331 | uint8_t wifi_gpio_write(GpioPin pin, GpioWriteValue value) |
mridup | 0:dc55f40eb04f | 1332 | { |
mridup | 0:dc55f40eb04f | 1333 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 1334 | |
mridup | 0:dc55f40eb04f | 1335 | /* AT+S.GPIOW=pin,value */ |
mridup | 0:dc55f40eb04f | 1336 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 1337 | |
mridup | 0:dc55f40eb04f | 1338 | sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.GPIOW=%d,%d\r", pin, value); |
mridup | 0:dc55f40eb04f | 1339 | |
mridup | 0:dc55f40eb04f | 1340 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 1341 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 1342 | { |
mridup | 0:dc55f40eb04f | 1343 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 1344 | } |
mridup | 0:dc55f40eb04f | 1345 | |
mridup | 0:dc55f40eb04f | 1346 | return status; |
mridup | 0:dc55f40eb04f | 1347 | } |
mridup | 0:dc55f40eb04f | 1348 | |
mridup | 0:dc55f40eb04f | 1349 | void UART_Configuration(uint32_t baud_rate) |
mridup | 0:dc55f40eb04f | 1350 | { |
mridup | 0:dc55f40eb04f | 1351 | } |
mridup | 0:dc55f40eb04f | 1352 | |
mridup | 0:dc55f40eb04f | 1353 | #ifdef USART_PRINT_MSG |
mridup | 0:dc55f40eb04f | 1354 | void USART_PRINT_MSG_Configuration(uint32_t baud_rate) |
mridup | 0:dc55f40eb04f | 1355 | { |
mridup | 0:dc55f40eb04f | 1356 | } |
mridup | 0:dc55f40eb04f | 1357 | #endif |
mridup | 0:dc55f40eb04f | 1358 | |
mridup | 0:dc55f40eb04f | 1359 | /** |
mridup | 0:dc55f40eb04f | 1360 | * @} |
mridup | 0:dc55f40eb04f | 1361 | */ |
mridup | 0:dc55f40eb04f | 1362 | |
mridup | 0:dc55f40eb04f | 1363 | /** |
mridup | 0:dc55f40eb04f | 1364 | * @} |
mridup | 0:dc55f40eb04f | 1365 | */ |
mridup | 0:dc55f40eb04f | 1366 | |
mridup | 0:dc55f40eb04f | 1367 | |
mridup | 0:dc55f40eb04f | 1368 | /** |
mridup | 0:dc55f40eb04f | 1369 | * @} |
mridup | 0:dc55f40eb04f | 1370 | */ |
mridup | 0:dc55f40eb04f | 1371 | |
mridup | 0:dc55f40eb04f | 1372 | /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/ |
mridup | 0:dc55f40eb04f | 1373 | |
mridup | 0:dc55f40eb04f | 1374 |