void ICACHE_FLASH_ATTR dhcps_lease_test(void)
{
struct dhcps_lease dhcp_lease;
IP4_ADDR(&dhcp_lease.start_ip, 192, 168, 5, 100);
IP4_ADDR(&dhcp_lease.end_ip, 192, 168, 5, 105);
wifi_softap_set_dhcps_lease(&dhcp_lease) ;
}
void ICACHE_FLASH_ATTR user_init()
{
LOCAL struct espconn esp_conn;
LOCAL esp_tcp esptcp;
uart_init(BIT_RATE_115200, BIT_RATE_115200);
os_delay_us(100);
#ifdef PLATFORM_DEBUG
ets_uart_printf("ESP8266 platform starting...\r\n");
#endif
struct softap_config apConfig;
struct ip_info ipinfo;
char ssid[33];
char password[33];
char macaddress[17];
char info[150];
if(wifi_get_opmode() != SOFTAP_MODE)
{
#ifdef PLATFORM_DEBUG
ets_uart_printf("ESP8266 not in SOFTAP mode, restarting in SOFTAP mode...\r\n");
#endif
wifi_set_opmode(SOFTAP_MODE);
//after esp_iot_sdk_v0.9.2, need not to restart
//system_restart();
}
wifi_get_macaddr(SOFTAP_IF, macaddr);
wifi_softap_get_config(&apConfig);
os_memset(apConfig.ssid, 0, sizeof(apConfig.ssid));
os_sprintf(ssid, "%s", WIFI_APSSID);
os_memcpy(apConfig.ssid, ssid, os_strlen(ssid));
if (wifi_get_opmode() == SOFTAP_MODE)
{
#ifdef WIFI_APWPA
os_memset(apConfig.password, 0, sizeof(apConfig.password));
os_sprintf(password, "%s", WIFI_APPASSWORD);
os_memcpy(apConfig.password, password, os_strlen(password));
apConfig.authmode = AUTH_WPA_WPA2_PSK;
#else
apConfig.authmode = AUTH_OPEN;
#endif
apConfig.channel = 7;
apConfig.max_connection = 255;
apConfig.ssid_hidden = 0;
wifi_softap_set_config(&apConfig);
}
#ifdef PLATFORM_DEBUG
if (wifi_get_opmode() == SOFTAP_MODE)
{
wifi_softap_get_config(&apConfig);
os_sprintf(macaddress, MACSTR, MAC2STR(macaddr));
os_sprintf(info,"OPMODE: %u, SSID: %s, PASSWORD: %s, CHANNEL: %d, AUTHMODE: %d, MACADDRESS: %s\r\n",
wifi_get_opmode(),
apConfig.ssid,
apConfig.password,
apConfig.channel,
apConfig.authmode,
macaddress);
ets_uart_printf(info);
}
#endif
/*
IP4_ADDR(&ipinfo.ip, 192, 168, 4, 1);
IP4_ADDR(&ipinfo.gw, 192, 168, 4, 1);
IP4_ADDR(&ipinfo.netmask, 255, 255, 255, 0);
wifi_set_ip_info(SOFTAP_IF, &ipinfo);
*/
wifi_softap_dhcps_stop();
IP4_ADDR(&ipinfo.ip, 192, 168, 5, 1);
IP4_ADDR(&ipinfo.gw, 192, 168, 5, 1);
IP4_ADDR(&ipinfo.netmask, 255, 255, 255, 0);
wifi_set_ip_info(SOFTAP_IF, &ipinfo);
dhcps_lease_test();
wifi_softap_dhcps_start();
esp_conn.type = ESPCONN_TCP;
esp_conn.state = ESPCONN_NONE;
esp_conn.proto.tcp = &esptcp;
esp_conn.proto.tcp->local_port = 5555;
espconn_regist_connectcb(&esp_conn, at_tcpclient_connect_cb);
espconn_accept(&esp_conn);
WiFiCheckConnInit();
#ifdef PLATFORM_DEBUG
ets_uart_printf("ESP8266 platform started!\r\n");
#endif
}