Statistics: Posted by greatz.yu — Sun Nov 27, 2016 7:36 pm
Statistics: Posted by ESP_Rubin — Thu Jul 14, 2016 5:43 pm
Code:
#include "ets_sys.h"
#include "osapi.h"
#include "mem.h"
#include "user_interface.h"
#include "espconn.h"
LOCAL os_timer_t test_timer;
/******************************************************************************
* FunctionName : user_esp_platform_check_ip
* Description : check whether get ip addr or not
* Parameters : none
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_esp_platform_check_ip(void)
{
struct ip_info ipconfig;
//disarm timer first
os_timer_disarm(&test_timer);
//get ip info of ESP8266 station
wifi_station_set_hostname("rubin_8266_test");
wifi_get_ip_info(STATION_IF, &ipconfig);
if (wifi_station_get_connect_status() == STATION_GOT_IP && ipconfig.ip.addr != 0) {
os_printf("got ip !!! \r\n");
if(wifi_set_sleep_type(1))
os_printf("sleep success\n");
else
os_printf("sleep fail\n");
} else {
if ((wifi_station_get_connect_status() == STATION_WRONG_PASSWORD ||
wifi_station_get_connect_status() == STATION_NO_AP_FOUND ||
wifi_station_get_connect_status() == STATION_CONNECT_FAIL)) {
os_printf("connect fail !!! \r\n");
} else {
//re-arm timer to check ip
os_timer_setfn(&test_timer, (os_timer_func_t *)user_esp_platform_check_ip, NULL);
os_timer_arm(&test_timer, 100, 0);
}
}
}
/******************************************************************************
* FunctionName : user_set_station_config
* Description : set the router info which ESP8266 station will connect to
* Parameters : none
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_set_station_config(void)
{
// Wifi configuration
char ssid[32] = "LB_LINK_V5";
char password[64] = "";
struct station_config stationConf;
os_memset(stationConf.ssid, 0, 32);
os_memset(stationConf.password, 0, 64);
//need not mac address
stationConf.bssid_set = 0;
//Set ap settings
os_memcpy(&stationConf.ssid, ssid, 32);
os_memcpy(&stationConf.password, password, 64);
wifi_station_set_config(&stationConf);
//set a timer to check whether got ip from router succeed or not.
os_timer_disarm(&test_timer);
os_timer_setfn(&test_timer, (os_timer_func_t *)user_esp_platform_check_ip, NULL);
os_timer_arm(&test_timer, 100, 0);
}
/******************************************************************************
* FunctionName : user_init
* Description : entry of user application, init user function here
* Parameters : none
* Returns : none
*******************************************************************************/
void user_init(void)
{
os_printf("SDK version:%s\n", system_get_sdk_version());
//Set softAP + station mode
wifi_set_opmode(STATION_MODE);
// ESP8266 connect to router.
user_set_station_config();
// wifi_set_sleep_type(1);
}
Statistics: Posted by greatz.yu — Thu Jul 14, 2016 4:47 pm
Code:
#include "ets_sys.h"
#include "osapi.h"
#include "mem.h"
#include "user_interface.h"
#include "espconn.h"
LOCAL os_timer_t test_timer;
/******************************************************************************
* FunctionName : user_esp_platform_check_ip
* Description : check whether get ip addr or not
* Parameters : none
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_esp_platform_check_ip(void)
{
struct ip_info ipconfig;
//disarm timer first
os_timer_disarm(&test_timer);
//get ip info of ESP8266 station
wifi_station_set_hostname("rubin_8266_test");
wifi_get_ip_info(STATION_IF, &ipconfig);
if (wifi_station_get_connect_status() == STATION_GOT_IP && ipconfig.ip.addr != 0) {
os_printf("got ip !!! \r\n");
if(wifi_set_sleep_type(1))
os_printf("sleep success\n");
else
os_printf("sleep fail\n");
} else {
if ((wifi_station_get_connect_status() == STATION_WRONG_PASSWORD ||
wifi_station_get_connect_status() == STATION_NO_AP_FOUND ||
wifi_station_get_connect_status() == STATION_CONNECT_FAIL)) {
os_printf("connect fail !!! \r\n");
} else {
//re-arm timer to check ip
os_timer_setfn(&test_timer, (os_timer_func_t *)user_esp_platform_check_ip, NULL);
os_timer_arm(&test_timer, 100, 0);
}
}
}
/******************************************************************************
* FunctionName : user_set_station_config
* Description : set the router info which ESP8266 station will connect to
* Parameters : none
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_set_station_config(void)
{
// Wifi configuration
char ssid[32] = "LB_LINK_V5";
char password[64] = "";
struct station_config stationConf;
os_memset(stationConf.ssid, 0, 32);
os_memset(stationConf.password, 0, 64);
//need not mac address
stationConf.bssid_set = 0;
//Set ap settings
os_memcpy(&stationConf.ssid, ssid, 32);
os_memcpy(&stationConf.password, password, 64);
wifi_station_set_config(&stationConf);
//set a timer to check whether got ip from router succeed or not.
os_timer_disarm(&test_timer);
os_timer_setfn(&test_timer, (os_timer_func_t *)user_esp_platform_check_ip, NULL);
os_timer_arm(&test_timer, 100, 0);
}
/******************************************************************************
* FunctionName : user_init
* Description : entry of user application, init user function here
* Parameters : none
* Returns : none
*******************************************************************************/
void user_init(void)
{
os_printf("SDK version:%s\n", system_get_sdk_version());
//Set softAP + station mode
wifi_set_opmode(STATION_MODE);
// ESP8266 connect to router.
user_set_station_config();
// wifi_set_sleep_type(1);
}
Statistics: Posted by ESP_Rubin — Thu Jul 14, 2016 2:46 pm
Code:
void fpm_wakup_cb_func1(void)
{
wifi_fpm_close();
wifi_set_opmode(STATION_MODE);
//wifi_set_sleep_type(LIGHT_SLEEP_T);
{
struct station_config *config = (struct station_config *)zalloc(sizeof(struct station_config));
sprintf(config->ssid, "xxx");
sprintf(config->password, "xxxx");
/* need to sure that you are in station mode first,
* otherwise it will be failed. */
wifi_station_set_config(config);
free(config);
}
wifi_station_connect();
sleeping();
//wifi_set_sleep_type(LIGHT_SLEEP_T);
}
void sleeping(void)
{
wifi_station_disconnect();
if(wifi_set_opmode(NULL_MODE)){os_printf("Set Null Mode OK\n");}
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
wifi_fpm_open();
wifi_fpm_set_wakeup_cb(fpm_wakup_cb_func1);
os_printf("SUP: %d \n",wifi_fpm_do_sleep(10*1000*1000));
}
void user_init(void)
{
sleeping();
}
Statistics: Posted by greatz.yu — Wed Jul 13, 2016 5:10 pm
Code:
void fpm_wakup_cb_func1(void)
{
wifi_fpm_close();
wifi_set_opmode(STATION_MODE);
//wifi_set_sleep_type(LIGHT_SLEEP_T);
{
struct station_config *config = (struct station_config *)zalloc(sizeof(struct station_config));
sprintf(config->ssid, "xxx");
sprintf(config->password, "xxxx");
/* need to sure that you are in station mode first,
* otherwise it will be failed. */
wifi_station_set_config(config);
free(config);
}
wifi_station_connect();
sleeping();
//wifi_set_sleep_type(LIGHT_SLEEP_T);
}
void sleeping(void)
{
wifi_station_disconnect();
if(wifi_set_opmode(NULL_MODE)){os_printf("Set Null Mode OK\n");}
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
wifi_fpm_open();
wifi_fpm_set_wakeup_cb(fpm_wakup_cb_func1);
os_printf("SUP: %d \n",wifi_fpm_do_sleep(10*1000*1000));
}
void user_init(void)
{
sleeping();
}
Statistics: Posted by ESP_Rubin — Wed Jul 13, 2016 2:24 pm
Statistics: Posted by greatz.yu — Tue Jul 12, 2016 8:11 pm
Statistics: Posted by ESP_Rubin — Tue Jul 12, 2016 5:15 pm
Statistics: Posted by greatz.yu — Tue Jul 12, 2016 5:05 pm
Statistics: Posted by ESP_Rubin — Tue Jul 12, 2016 4:46 pm
Code:
void fpm_wakup_cb_func1(void)
{
wifi_fpm_close();
wifi_set_opmode(STATION_MODE);
wifi_set_sleep_type(LIGHT_SLEEP_T);
{
struct station_config *config = (struct station_config *)zalloc(sizeof(struct station_config));
sprintf(config->ssid, "xxx");
sprintf(config->password, "xxxx");
/* need to sure that you are in station mode first,
* otherwise it will be failed. */
wifi_station_set_config(config);
free(config);
}
wifi_station_connect();
//wifi_set_sleep_type(LIGHT_SLEEP_T);
}
void user_init(void)
{
wifi_station_disconnect();
wifi_set_opmode(NULL_MODE);
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
wifi_fpm_open();
wifi_fpm_set_wakeup_cb(fpm_wakup_cb_func1);
wifi_fpm_do_sleep(10000*1000);
}
Statistics: Posted by greatz.yu — Tue Jul 12, 2016 4:09 pm