mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-08-06 15:15:15 +08:00
feat(example): Clean up the code in example
This commit is contained in:
@ -46,12 +46,15 @@ uint32_t user_rf_cal_sector_set(void)
|
||||
case FLASH_SIZE_32M_MAP_1024_1024:
|
||||
rf_cal_sec = 1024 - 5;
|
||||
break;
|
||||
|
||||
case FLASH_SIZE_64M_MAP_1024_1024:
|
||||
rf_cal_sec = 2048 - 5;
|
||||
break;
|
||||
|
||||
case FLASH_SIZE_128M_MAP_1024_1024:
|
||||
rf_cal_sec = 4096 - 5;
|
||||
break;
|
||||
|
||||
default:
|
||||
rf_cal_sec = 0;
|
||||
break;
|
||||
@ -70,4 +73,3 @@ void user_init(void)
|
||||
{
|
||||
printf("SDK version:%s\n", system_get_sdk_version());
|
||||
}
|
||||
|
||||
|
@ -325,12 +325,14 @@ void user_init()
|
||||
{
|
||||
wifi_set_opmode(STATION_MODE);
|
||||
|
||||
{
|
||||
// set AP parameter
|
||||
struct station_config config;
|
||||
bzero(&config, sizeof(struct station_config));
|
||||
sprintf((char*)config.ssid, CONFIG_WIFI_SSID);
|
||||
sprintf((char*)config.password, CONFIG_WIFI_PASSWORD);
|
||||
wifi_station_set_config(&config);
|
||||
}
|
||||
|
||||
wifi_set_event_handler_cb(wifi_event_handler_cb);
|
||||
}
|
||||
|
@ -314,12 +314,14 @@ void user_init(void)
|
||||
{
|
||||
wifi_set_opmode(STATION_MODE);
|
||||
|
||||
{
|
||||
// set AP parameter
|
||||
struct station_config config;
|
||||
bzero(&config, sizeof(struct station_config));
|
||||
sprintf((char*)config.ssid, CONFIG_WIFI_SSID);
|
||||
sprintf((char*)config.password, CONFIG_WIFI_PASSWORD);
|
||||
wifi_station_set_config(&config);
|
||||
}
|
||||
|
||||
wifi_set_event_handler_cb(wifi_event_handler_cb);
|
||||
wifi_set_sleep_type(0);
|
||||
|
@ -158,12 +158,15 @@ uint32_t user_rf_cal_sector_set(void)
|
||||
case FLASH_SIZE_32M_MAP_1024_1024:
|
||||
rf_cal_sec = 1024 - 5;
|
||||
break;
|
||||
|
||||
case FLASH_SIZE_64M_MAP_1024_1024:
|
||||
rf_cal_sec = 2048 - 5;
|
||||
break;
|
||||
|
||||
case FLASH_SIZE_128M_MAP_1024_1024:
|
||||
rf_cal_sec = 4096 - 5;
|
||||
break;
|
||||
|
||||
default:
|
||||
rf_cal_sec = 0;
|
||||
break;
|
||||
@ -208,13 +211,13 @@ void user_init(void)
|
||||
printf("SDK version:%s %d\n", system_get_sdk_version(), system_get_free_heap_size());
|
||||
wifi_set_opmode(STATION_MODE);
|
||||
|
||||
{
|
||||
struct station_config config;
|
||||
bzero(&config, sizeof(struct station_config));
|
||||
sprintf((char*)config.ssid, SSID);
|
||||
sprintf((char*)config.password, PASSWORD);
|
||||
wifi_station_set_config(&config);
|
||||
}
|
||||
|
||||
wifi_set_event_handler_cb(wifi_event_handler_cb);
|
||||
|
||||
wifi_station_connect();
|
||||
}
|
||||
|
@ -334,11 +334,14 @@ void user_init(void)
|
||||
printf("SDK version:%s %d\n", system_get_sdk_version(), system_get_free_heap_size());
|
||||
wifi_set_opmode(STATION_MODE);
|
||||
|
||||
{
|
||||
// set AP parameter
|
||||
struct station_config config;
|
||||
bzero(&config, sizeof(struct station_config));
|
||||
sprintf((char*)config.ssid, CONFIG_WIFI_SSID);
|
||||
sprintf((char*)config.password, CONFIG_WIFI_PASSWORD);
|
||||
wifi_station_set_config(&config);
|
||||
}
|
||||
|
||||
wifi_set_event_handler_cb(wifi_event_handler_cb);
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
|
||||
#include "openssl_demo.h"
|
||||
#include "openssl/ssl.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
@ -67,6 +66,7 @@ static void openssl_demo_thread(void *p)
|
||||
do {
|
||||
ret = netconn_gethostbyname(OPENSSL_DEMO_TARGET_NAME, &target_ip);
|
||||
} while (ret);
|
||||
|
||||
printf("get target IP is %d.%d.%d.%d\n", (unsigned char)((target_ip.u_addr.ip4.addr & 0x000000ff) >> 0),
|
||||
(unsigned char)((target_ip.u_addr.ip4.addr & 0x0000ff00) >> 8),
|
||||
(unsigned char)((target_ip.u_addr.ip4.addr & 0x00ff0000) >> 16),
|
||||
@ -74,27 +74,33 @@ static void openssl_demo_thread(void *p)
|
||||
|
||||
printf("create SSL context ......");
|
||||
ctx = SSL_CTX_new(TLSv1_1_client_method());
|
||||
|
||||
if (!ctx) {
|
||||
printf("failed\n");
|
||||
goto failed1;
|
||||
}
|
||||
|
||||
printf("OK\n");
|
||||
|
||||
printf("set SSL context read buffer size ......");
|
||||
SSL_CTX_set_default_read_buffer_len(ctx, OPENSSL_DEMO_FRAGMENT_SIZE);
|
||||
ret = 0;
|
||||
|
||||
if (ret) {
|
||||
printf("failed, return %d\n", ret);
|
||||
goto failed2;
|
||||
}
|
||||
|
||||
printf("OK\n");
|
||||
|
||||
printf("create socket ......");
|
||||
socket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
if (socket < 0) {
|
||||
printf("failed\n");
|
||||
goto failed3;
|
||||
}
|
||||
|
||||
printf("OK\n");
|
||||
|
||||
printf("bind socket ......");
|
||||
@ -103,10 +109,12 @@ static void openssl_demo_thread(void *p)
|
||||
sock_addr.sin_addr.s_addr = 0;
|
||||
sock_addr.sin_port = htons(OPENSSL_DEMO_LOCAL_TCP_PORT);
|
||||
ret = bind(socket, (struct sockaddr*)&sock_addr, sizeof(sock_addr));
|
||||
|
||||
if (ret) {
|
||||
printf("failed\n");
|
||||
goto failed4;
|
||||
}
|
||||
|
||||
printf("OK\n");
|
||||
|
||||
printf("socket connect to remote ......");
|
||||
@ -115,46 +123,57 @@ static void openssl_demo_thread(void *p)
|
||||
sock_addr.sin_addr.s_addr = target_ip.u_addr.ip4.addr;
|
||||
sock_addr.sin_port = htons(OPENSSL_DEMO_TARGET_TCP_PORT);
|
||||
ret = connect(socket, (struct sockaddr*)&sock_addr, sizeof(sock_addr));
|
||||
|
||||
if (ret) {
|
||||
printf("failed\n");
|
||||
goto failed5;
|
||||
}
|
||||
|
||||
printf("OK\n");
|
||||
|
||||
printf("create SSL ......");
|
||||
ssl = SSL_new(ctx);
|
||||
|
||||
if (!ssl) {
|
||||
printf("failed\n");
|
||||
goto failed6;
|
||||
}
|
||||
|
||||
printf("OK\n");
|
||||
|
||||
SSL_set_fd(ssl, socket);
|
||||
|
||||
printf("SSL connected to %s port %d ......", OPENSSL_DEMO_TARGET_NAME, OPENSSL_DEMO_TARGET_TCP_PORT);
|
||||
ret = SSL_connect(ssl);
|
||||
|
||||
if (!ret) {
|
||||
printf("failed, return [-0x%x]\n", -ret);
|
||||
goto failed7;
|
||||
}
|
||||
|
||||
printf("OK\n");
|
||||
|
||||
printf("send request to %s port %d ......", OPENSSL_DEMO_TARGET_NAME, OPENSSL_DEMO_TARGET_TCP_PORT);
|
||||
ret = SSL_write(ssl, send_data, send_bytes);
|
||||
|
||||
if (ret <= 0) {
|
||||
printf("failed, return [-0x%x]\n", -ret);
|
||||
goto failed8;
|
||||
}
|
||||
|
||||
printf("OK\n\n");
|
||||
|
||||
do {
|
||||
ret = SSL_read(ssl, recv_buf, OPENSSL_DEMO_RECV_BUF_LEN - 1);
|
||||
|
||||
if (ret <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
recv_bytes += ret;
|
||||
printf("%s", recv_buf);
|
||||
} while (1);
|
||||
|
||||
printf("read %d bytes data from %s ......\n", recv_bytes, OPENSSL_DEMO_TARGET_NAME);
|
||||
|
||||
failed8:
|
||||
@ -186,6 +205,7 @@ void user_conn_init(void)
|
||||
NULL,
|
||||
OPENSSL_DEMO_THREAD_PRORIOTY,
|
||||
&openssl_handle);
|
||||
|
||||
if (ret != pdPASS) {
|
||||
printf("create thread %s failed\n", OPENSSL_DEMO_THREAD_NAME);
|
||||
return ;
|
||||
@ -227,12 +247,15 @@ uint32_t user_rf_cal_sector_set(void)
|
||||
case FLASH_SIZE_32M_MAP_1024_1024:
|
||||
rf_cal_sec = 1024 - 5;
|
||||
break;
|
||||
|
||||
case FLASH_SIZE_64M_MAP_1024_1024:
|
||||
rf_cal_sec = 2048 - 5;
|
||||
break;
|
||||
|
||||
case FLASH_SIZE_128M_MAP_1024_1024:
|
||||
rf_cal_sec = 4096 - 5;
|
||||
break;
|
||||
|
||||
default:
|
||||
rf_cal_sec = 0;
|
||||
break;
|
||||
@ -269,12 +292,14 @@ void user_init(void)
|
||||
printf("SDK version:%s %d\n", system_get_sdk_version(), system_get_free_heap_size());
|
||||
wifi_set_opmode(STATION_MODE);
|
||||
|
||||
{
|
||||
// set AP parameter
|
||||
struct station_config config;
|
||||
bzero(&config, sizeof(struct station_config));
|
||||
sprintf((char*)config.ssid, SSID);
|
||||
sprintf((char*)config.password, PASSWORD);
|
||||
wifi_station_set_config(&config);
|
||||
}
|
||||
|
||||
wifi_set_event_handler_cb(wifi_event_handler_cb);
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
/*
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#ifndef _OPENSSL_DEMO_H_
|
||||
#define _OPENSSL_DEMO_H_
|
||||
|
||||
void user_conn_init(void);
|
||||
|
||||
#endif
|
@ -9,8 +9,6 @@
|
||||
#ifndef __USER_CONFIG_H__
|
||||
#define __USER_CONFIG_H__
|
||||
|
||||
#include "openssl_demo.h"
|
||||
|
||||
#define SSID "UTT-750"
|
||||
#define PASSWORD "espressif"
|
||||
|
||||
|
@ -328,11 +328,14 @@ void user_init(void)
|
||||
printf("SDK version:%s %d\n", system_get_sdk_version(), system_get_free_heap_size());
|
||||
wifi_set_opmode(STATION_MODE);
|
||||
|
||||
{
|
||||
// set AP parameter
|
||||
struct station_config config;
|
||||
bzero(&config, sizeof(struct station_config));
|
||||
sprintf((char*)config.ssid, CONFIG_WIFI_SSID);
|
||||
sprintf((char*)config.password, CONFIG_WIFI_PASSWORD);
|
||||
wifi_station_set_config(&config);
|
||||
}
|
||||
|
||||
wifi_set_event_handler_cb(wifi_event_handler_cb);
|
||||
}
|
||||
|
@ -7,11 +7,14 @@
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "esp_spiffs.h"
|
||||
#include "esp_ssc.h"
|
||||
#include "esp_system.h"
|
||||
|
||||
#include "testrunner.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "spiffs_test_params.h"
|
||||
|
||||
enum {
|
||||
@ -95,12 +98,15 @@ uint32_t user_rf_cal_sector_set(void)
|
||||
case FLASH_SIZE_32M_MAP_1024_1024:
|
||||
rf_cal_sec = 1024 - 5;
|
||||
break;
|
||||
|
||||
case FLASH_SIZE_64M_MAP_1024_1024:
|
||||
rf_cal_sec = 2048 - 5;
|
||||
break;
|
||||
|
||||
case FLASH_SIZE_128M_MAP_1024_1024:
|
||||
rf_cal_sec = 4096 - 5;
|
||||
break;
|
||||
|
||||
default:
|
||||
rf_cal_sec = 0;
|
||||
break;
|
||||
|
@ -29,12 +29,11 @@ static esp_udp ssdp_udp;
|
||||
static struct espconn pssdpudpconn;
|
||||
static os_timer_t ssdp_time_serv;
|
||||
|
||||
uint8 lan_buf[200];
|
||||
uint16 lan_buf_len;
|
||||
uint8 udp_sent_cnt = 0;
|
||||
uint8_t lan_buf[200];
|
||||
uint16_t lan_buf_len;
|
||||
uint8_t udp_sent_cnt = 0;
|
||||
|
||||
const airkiss_config_t akconf =
|
||||
{
|
||||
const airkiss_config_t akconf = {
|
||||
(airkiss_memset_fn)& memset,
|
||||
(airkiss_memcpy_fn)& memcpy,
|
||||
(airkiss_memcmp_fn)& memcmp,
|
||||
@ -43,7 +42,7 @@ const airkiss_config_t akconf =
|
||||
|
||||
static void airkiss_wifilan_time_callback(void)
|
||||
{
|
||||
uint16 i;
|
||||
uint16_t i;
|
||||
airkiss_lan_ret_t ret;
|
||||
|
||||
if ((udp_sent_cnt++) > 30) {
|
||||
@ -60,21 +59,24 @@ static void airkiss_wifilan_time_callback(void)
|
||||
lan_buf_len = sizeof(lan_buf);
|
||||
ret = airkiss_lan_pack(AIRKISS_LAN_SSDP_NOTIFY_CMD,
|
||||
DEVICE_TYPE, DEVICE_ID, 0, 0, lan_buf, &lan_buf_len, &akconf);
|
||||
|
||||
if (ret != AIRKISS_LAN_PAKE_READY) {
|
||||
printf("Pack lan packet error!");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = espconn_sendto(&pssdpudpconn, lan_buf, lan_buf_len);
|
||||
|
||||
if (ret != 0) {
|
||||
printf("UDP send error!");
|
||||
}
|
||||
|
||||
printf("Finish send notify!\n");
|
||||
}
|
||||
|
||||
static void airkiss_wifilan_recv_callbk(void* arg, char* pdata, unsigned short len)
|
||||
{
|
||||
uint16 i;
|
||||
uint16_t i;
|
||||
remot_info* pcon_info = NULL;
|
||||
|
||||
airkiss_lan_ret_t ret = airkiss_lan_recv(pdata, len, &akconf);
|
||||
@ -101,16 +103,21 @@ static void airkiss_wifilan_recv_callbk(void *arg, char *pdata, unsigned short l
|
||||
}
|
||||
|
||||
printf("\r\n\r\n");
|
||||
for (i=0; i<lan_buf_len; i++)
|
||||
|
||||
for (i = 0; i < lan_buf_len; i++) {
|
||||
printf("%c", lan_buf[i]);
|
||||
}
|
||||
|
||||
printf("\r\n\r\n");
|
||||
|
||||
packret = espconn_sendto(&pssdpudpconn, lan_buf, lan_buf_len);
|
||||
|
||||
if (packret != 0) {
|
||||
printf("LAN UDP Send err!");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Pack is not ssdq req!%d\r\n", ret);
|
||||
break;
|
||||
@ -137,18 +144,23 @@ void smartconfig_done(sc_status status, void *pdata)
|
||||
case SC_STATUS_WAIT:
|
||||
printf("SC_STATUS_WAIT\n");
|
||||
break;
|
||||
|
||||
case SC_STATUS_FIND_CHANNEL:
|
||||
printf("SC_STATUS_FIND_CHANNEL\n");
|
||||
break;
|
||||
|
||||
case SC_STATUS_GETTING_SSID_PSWD:
|
||||
printf("SC_STATUS_GETTING_SSID_PSWD\n");
|
||||
sc_type* type = pdata;
|
||||
|
||||
if (*type == SC_TYPE_ESPTOUCH) {
|
||||
printf("SC_TYPE:SC_TYPE_ESPTOUCH\n");
|
||||
} else {
|
||||
printf("SC_TYPE:SC_TYPE_AIRKISS\n");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SC_STATUS_LINK:
|
||||
printf("SC_STATUS_LINK\n");
|
||||
struct station_config* sta_conf = pdata;
|
||||
@ -157,8 +169,10 @@ void smartconfig_done(sc_status status, void *pdata)
|
||||
wifi_station_disconnect();
|
||||
wifi_station_connect();
|
||||
break;
|
||||
|
||||
case SC_STATUS_LINK_OVER:
|
||||
printf("SC_STATUS_LINK_OVER\n");
|
||||
|
||||
if (pdata != NULL) {
|
||||
//SC_TYPE_ESPTOUCH
|
||||
uint8 phone_ip[4] = {0};
|
||||
@ -169,6 +183,7 @@ void smartconfig_done(sc_status status, void *pdata)
|
||||
//SC_TYPE_AIRKISS - support airkiss v2.0
|
||||
airkiss_start_discover();
|
||||
}
|
||||
|
||||
smartconfig_stop();
|
||||
break;
|
||||
}
|
||||
@ -194,10 +209,10 @@ void smartconfig_task(void *pvParameters)
|
||||
* Parameters : none
|
||||
* Returns : rf cal sector
|
||||
*******************************************************************************/
|
||||
uint32 user_rf_cal_sector_set(void)
|
||||
uint32_t user_rf_cal_sector_set(void)
|
||||
{
|
||||
flash_size_map size_map = system_get_flash_size_map();
|
||||
uint32 rf_cal_sec = 0;
|
||||
uint32_t rf_cal_sec = 0;
|
||||
|
||||
switch (size_map) {
|
||||
case FLASH_SIZE_4M_MAP_256_256:
|
||||
@ -217,12 +232,15 @@ uint32 user_rf_cal_sector_set(void)
|
||||
case FLASH_SIZE_32M_MAP_1024_1024:
|
||||
rf_cal_sec = 1024 - 5;
|
||||
break;
|
||||
|
||||
case FLASH_SIZE_64M_MAP_1024_1024:
|
||||
rf_cal_sec = 2048 - 5;
|
||||
break;
|
||||
|
||||
case FLASH_SIZE_128M_MAP_1024_1024:
|
||||
rf_cal_sec = 4096 - 5;
|
||||
break;
|
||||
|
||||
default:
|
||||
rf_cal_sec = 0;
|
||||
break;
|
||||
|
@ -36,6 +36,7 @@ volatile bool wifi_station_is_connected = false;
|
||||
void wifi_event_handler_cb(System_Event_t* event)
|
||||
{
|
||||
static bool station_was_connected = false;
|
||||
|
||||
if (event == NULL) {
|
||||
return;
|
||||
}
|
||||
@ -46,81 +47,106 @@ void wifi_event_handler_cb(System_Event_t *event)
|
||||
case EVENT_STAMODE_DISCONNECTED:
|
||||
wifi_station_is_connected = false;
|
||||
Event_StaMode_Disconnected_t* ev = (Event_StaMode_Disconnected_t*)&event->event_info;
|
||||
|
||||
if (on_station_disconnect) {
|
||||
on_station_disconnect(ev->reason);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case EVENT_STAMODE_CONNECTED:
|
||||
if (wifi_station_static_ip) {
|
||||
wifi_station_is_connected = true;
|
||||
|
||||
if (!station_was_connected) {
|
||||
station_was_connected = true;
|
||||
|
||||
if (on_station_first_connect) {
|
||||
on_station_first_connect();
|
||||
}
|
||||
}
|
||||
|
||||
if (on_station_connect) {
|
||||
on_station_connect();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case EVENT_STAMODE_DHCP_TIMEOUT:
|
||||
if (wifi_station_is_connected) {
|
||||
wifi_station_is_connected = false;
|
||||
|
||||
if (on_station_disconnect) {
|
||||
on_station_disconnect(REASON_UNSPECIFIED);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case EVENT_STAMODE_GOT_IP:
|
||||
wifi_station_is_connected = true;
|
||||
|
||||
if (!station_was_connected) {
|
||||
station_was_connected = true;
|
||||
|
||||
if (on_station_first_connect) {
|
||||
on_station_first_connect();
|
||||
}
|
||||
}
|
||||
|
||||
if (on_station_connect) {
|
||||
on_station_connect();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case EVENT_SOFTAPMODE_STACONNECTED:
|
||||
if (on_client_connect) {
|
||||
on_client_connect();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case EVENT_SOFTAPMODE_STADISCONNECTED:
|
||||
if (on_client_disconnect) {
|
||||
on_client_disconnect();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void set_on_station_first_connect(wifi_state_cb_t cb){
|
||||
void set_on_station_first_connect(wifi_state_cb_t cb)
|
||||
{
|
||||
on_station_first_connect = cb;
|
||||
}
|
||||
|
||||
void set_on_station_connect(wifi_state_cb_t cb){
|
||||
void set_on_station_connect(wifi_state_cb_t cb)
|
||||
{
|
||||
on_station_connect = cb;
|
||||
}
|
||||
|
||||
void set_on_station_disconnect(wifi_disco_cb_t cb){
|
||||
void set_on_station_disconnect(wifi_disco_cb_t cb)
|
||||
{
|
||||
on_station_disconnect = cb;
|
||||
}
|
||||
|
||||
void set_on_client_connect(wifi_state_cb_t cb){
|
||||
void set_on_client_connect(wifi_state_cb_t cb)
|
||||
{
|
||||
on_client_connect = cb;
|
||||
}
|
||||
|
||||
void set_on_client_disconnect(wifi_state_cb_t cb){
|
||||
void set_on_client_disconnect(wifi_state_cb_t cb)
|
||||
{
|
||||
on_client_disconnect = cb;
|
||||
}
|
||||
|
||||
bool wifi_set_mode(WIFI_MODE mode){
|
||||
bool wifi_set_mode(WIFI_MODE mode)
|
||||
{
|
||||
if (!mode) {
|
||||
bool s = wifi_set_opmode(mode);
|
||||
wifi_fpm_open();
|
||||
@ -128,36 +154,47 @@ bool wifi_set_mode(WIFI_MODE mode){
|
||||
wifi_fpm_do_sleep(0xFFFFFFFF);
|
||||
return s;
|
||||
}
|
||||
|
||||
wifi_fpm_close();
|
||||
return wifi_set_opmode(mode);
|
||||
}
|
||||
|
||||
WIFI_MODE init_esp_wifi(){
|
||||
WIFI_MODE init_esp_wifi(void)
|
||||
{
|
||||
wifi_set_event_handler_cb(wifi_event_handler_cb);
|
||||
WIFI_MODE mode = wifi_get_opmode_default();
|
||||
wifi_set_mode(mode);
|
||||
return mode;
|
||||
}
|
||||
|
||||
bool start_wifi_station(const char * ssid, const char * pass){
|
||||
bool start_wifi_station(const char* ssid, const char* pass)
|
||||
{
|
||||
WIFI_MODE mode = wifi_get_opmode();
|
||||
|
||||
if ((mode & STATION_MODE) == 0) {
|
||||
mode |= STATION_MODE;
|
||||
|
||||
if (!wifi_set_mode(mode)) {
|
||||
printf("Failed to enable Station mode!\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ssid) {
|
||||
printf("No SSID Given. Will connect to the station saved in flash\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
struct station_config config;
|
||||
|
||||
memset((void*)&config, 0, sizeof(struct station_config));
|
||||
|
||||
strcpy((char*)config.ssid, ssid);
|
||||
|
||||
if (pass) {
|
||||
strcpy((char*)config.password, pass);
|
||||
}
|
||||
|
||||
if (!wifi_station_set_config(&config)) {
|
||||
printf("Failed to set Station config!\n");
|
||||
return false;
|
||||
@ -165,70 +202,92 @@ bool start_wifi_station(const char * ssid, const char * pass){
|
||||
|
||||
if (!wifi_station_dhcpc_status()) {
|
||||
printf("DHCP is not started. Starting it...\n");
|
||||
|
||||
if (!wifi_station_dhcpc_start()) {
|
||||
printf("DHCP start failed!\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return wifi_station_connect();
|
||||
}
|
||||
|
||||
bool stop_wifi_station(){
|
||||
bool stop_wifi_station(void)
|
||||
{
|
||||
WIFI_MODE mode = wifi_get_opmode();
|
||||
mode &= ~STATION_MODE;
|
||||
|
||||
if (!wifi_set_mode(mode)) {
|
||||
printf("Failed to disable Station mode!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool start_wifi_ap(const char * ssid, const char * pass){
|
||||
bool start_wifi_ap(const char* ssid, const char* pass)
|
||||
{
|
||||
WIFI_MODE mode = wifi_get_opmode();
|
||||
|
||||
if ((mode & SOFTAP_MODE) == 0) {
|
||||
mode |= SOFTAP_MODE;
|
||||
|
||||
if (!wifi_set_mode(mode)) {
|
||||
printf("Failed to enable AP mode!\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ssid) {
|
||||
printf("No SSID Given. Will start the AP saved in flash\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
struct softap_config config;
|
||||
|
||||
bzero(&config, sizeof(struct softap_config));
|
||||
|
||||
sprintf((char*)config.ssid, ssid);
|
||||
|
||||
if (pass) {
|
||||
sprintf((char*)config.password, pass);
|
||||
}
|
||||
|
||||
return wifi_softap_set_config(&config);
|
||||
}
|
||||
|
||||
bool stop_wifi_ap(){
|
||||
bool stop_wifi_ap(void)
|
||||
{
|
||||
WIFI_MODE mode = wifi_get_opmode();
|
||||
mode &= ~SOFTAP_MODE;
|
||||
|
||||
if (!wifi_set_mode(mode)) {
|
||||
printf("Failed to disable AP mode!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wifi_station_connected(){
|
||||
bool wifi_station_connected(void)
|
||||
{
|
||||
if (!wifi_station_is_connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
WIFI_MODE mode = wifi_get_opmode();
|
||||
|
||||
if ((mode & STATION_MODE) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
STATION_STATUS wifistate = wifi_station_get_connect_status();
|
||||
wifi_station_is_connected = (wifistate == STATION_GOT_IP || (wifi_station_static_ip && wifistate == STATION_CONNECTING));
|
||||
return wifi_station_is_connected;
|
||||
}
|
||||
|
||||
bool wifi_ap_enabled(){
|
||||
bool wifi_ap_enabled(void)
|
||||
{
|
||||
return !!(wifi_get_opmode() & SOFTAP_MODE);
|
||||
}
|
||||
|
||||
@ -269,12 +328,15 @@ uint32_t user_rf_cal_sector_set(void)
|
||||
case FLASH_SIZE_32M_MAP_1024_1024:
|
||||
rf_cal_sec = 1024 - 5;
|
||||
break;
|
||||
|
||||
case FLASH_SIZE_64M_MAP_1024_1024:
|
||||
rf_cal_sec = 2048 - 5;
|
||||
break;
|
||||
|
||||
case FLASH_SIZE_128M_MAP_1024_1024:
|
||||
rf_cal_sec = 4096 - 5;
|
||||
break;
|
||||
|
||||
default:
|
||||
rf_cal_sec = 0;
|
||||
break;
|
||||
@ -286,6 +348,7 @@ uint32_t user_rf_cal_sector_set(void)
|
||||
static void wait_for_connection_ready(uint8_t flag)
|
||||
{
|
||||
os_timer_disarm(&timer);
|
||||
|
||||
if (wifi_station_connected()) {
|
||||
printf("connected\n");
|
||||
} else {
|
||||
@ -295,13 +358,15 @@ static void wait_for_connection_ready(uint8_t flag)
|
||||
}
|
||||
}
|
||||
|
||||
static void on_wifi_connect(){
|
||||
static void on_wifi_connect(void)
|
||||
{
|
||||
os_timer_disarm(&timer);
|
||||
os_timer_setfn(&timer, (os_timer_func_t*)wait_for_connection_ready, NULL);
|
||||
os_timer_arm(&timer, 100, 0);
|
||||
}
|
||||
|
||||
static void on_wifi_disconnect(uint8_t reason){
|
||||
static void on_wifi_disconnect(uint8_t reason)
|
||||
{
|
||||
printf("disconnect %d\n", reason);
|
||||
}
|
||||
|
||||
|
@ -21,11 +21,13 @@
|
||||
static void user_wps_status_cb(int status)
|
||||
{
|
||||
printf("scan status %d\n", status);
|
||||
|
||||
switch (status) {
|
||||
case WPS_CB_ST_SUCCESS:
|
||||
wifi_wps_disable();
|
||||
wifi_station_connect();
|
||||
break;
|
||||
|
||||
case WPS_CB_ST_FAILED:
|
||||
case WPS_CB_ST_TIMEOUT:
|
||||
wifi_wps_start();
|
||||
@ -76,12 +78,15 @@ uint32_t user_rf_cal_sector_set(void)
|
||||
case FLASH_SIZE_32M_MAP_1024_1024:
|
||||
rf_cal_sec = 1024 - 5;
|
||||
break;
|
||||
|
||||
case FLASH_SIZE_64M_MAP_1024_1024:
|
||||
rf_cal_sec = 2048 - 5;
|
||||
break;
|
||||
|
||||
case FLASH_SIZE_128M_MAP_1024_1024:
|
||||
rf_cal_sec = 4096 - 5;
|
||||
break;
|
||||
|
||||
default:
|
||||
rf_cal_sec = 0;
|
||||
break;
|
||||
@ -89,16 +94,15 @@ uint32_t user_rf_cal_sector_set(void)
|
||||
|
||||
return rf_cal_sec;
|
||||
}
|
||||
|
||||
static void wps_task(void* pvParameters)
|
||||
{
|
||||
wifi_set_opmode(STATION_MODE);
|
||||
user_wps_start();
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void user_init(void)
|
||||
{
|
||||
|
||||
xTaskCreate(wps_task, "wps_task", 1024, NULL, 4, NULL);
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user