#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "user_interface.h"
#include "mem.h"
#include "uart.h"
#define user_procTaskPrio 0
#define user_procTaskQueueLen 1
os_event_t user_procTaskQueue[user_procTaskQueueLen];
static void user_procTask(os_event_t *events);
static volatile os_timer_t some_timer;
int get_stations(void);
void some_timerfunc(void *arg)
{
//Do blinky stuff
if (GPIO_REG_READ(GPIO_OUT_ADDRESS) & BIT13)
{
//Set GPIO2 to LOW
// gpio_output_set(0, BIT2, BIT2, 0);
GPIO_OUTPUT_SET(12, 0);
}
else
{
//Set GPIO2 to HIGH
// gpio_output_set(BIT2, 0, BIT2, 0);
GPIO_OUTPUT_SET(12, 1);
}
get_stations();
os_printf("LED flush,in task\n");
}
//Do nothing function
static void ICACHE_FLASH_ATTR
user_procTask(os_event_t *events)
{
os_delay_us(10);
}
//return : 0-success,other-fail
int ap_setup(void)
{
struct ip_info info;
struct softap_config config;
struct dhcps_lease dhcp_lease;
if (!wifi_set_opmode_current(SOFTAP_MODE)) return -1; //Set softAP mode
os_memcpy(config.ssid, "configmode", 10);
os_memcpy(config.password, "12345678", 8);
config.ssid_len=os_strlen(config.ssid);
config.channel=11;
config.authmode=AUTH_WPA2_PSK;
config.ssid_hidden=0;
config.max_connection=4; //max 4
config.beacon_interval=100;
if (!wifi_softap_set_config_current(&config)) return -2;
wifi_softap_dhcps_stop();
IP4_ADDR(&info.ip, 192, 168, 1, 1);
IP4_ADDR(&info.gw, 192, 168, 1, 1);
IP4_ADDR(&info.netmask, 255, 255, 255, 0);
if (!wifi_set_ip_info(SOFTAP_IF, &info)) return -4;
const char* start_ip = "192.168.1.2";
const char* end_ip = "192.168.1.102";
dhcp_lease.start_ip.addr = ipaddr_addr(start_ip);
dhcp_lease.end_ip.addr = ipaddr_addr(end_ip);
if (!wifi_softap_set_dhcps_lease(&dhcp_lease)) os_printf("wifi_softap_set_dhcps_lease fail\n"); //return -3;
if (!wifi_softap_dhcps_start()) return -5;
wifi_status_led_install(13, PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13); //GPIO13 is status of WIFI
return 0; //success
}
//get station info in AP mode
//return stations
int get_stations(void)
{
int i=0;
struct station_info * station = wifi_softap_get_station_info();
struct station_info * next_station;
while(station)
{
os_printf("bssid : %02x:%02x:%02x:%02x:%02x:%02x, ip : %d.%d.%d.%d\n", MAC2STR(station->bssid), IP2STR(&station->ip));
next_station = STAILQ_NEXT(station, next);
os_free(station); // Free it directly
station = next_station;
i++;
}
return i;
}
//Init function
void ICACHE_FLASH_ATTR
user_init()
{
int i;
wifi_set_opmode(SOFTAP_MODE); //Set softAP mode
// Initialize the GPIO subsystem.
gpio_init();
uart_init(115200, 115200);
uart0_sendStr("system start,in uart0\r\n");
uart1_sendStr_no_wait("system start,in uart1\r\n");
if ((i=ap_setup())) os_printf("start AP mode fail,error code %d\n", i);
os_printf("chip id 0x%x\n", system_get_chip_id() );
os_printf("CPU frequency %dMHz\n", system_get_cpu_freq() );
os_printf("flash id 0x%x, flash map %d\n", spi_flash_get_id(), system_get_flash_size_map());
os_delay_us(50000); //30ms,wait print finish
//os_printf("power valtage is %d/1024V, system meminfo:\n", system_get_vdd33() );
system_print_meminfo();
//Set GPIO2 to output mode
// PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
//Set GPIO12 to output mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO12);
//Set GPIO2 low
// gpio_output_set(0, BIT2, BIT2, 0);
//Disarm timer
os_timer_disarm(&some_timer);
//Setup timer
os_timer_setfn(&some_timer, (os_timer_func_t *)some_timerfunc, NULL);
//Arm the timer
//&some_timer is the pointer
//1000 is the fire time in ms
//0 for once and 1 for repeating
os_timer_arm(&some_timer, 1000, 1);
//Start os task
system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
}Statistics: Posted by zhongjru — Wed Oct 28, 2015 8:05 pm
]]>