/* The example of esp-free-rtos
*
* This sample code is in the public domain.
*/
#include <stdlib.h>
#include <string.h>
#include "espressif/esp_common.h"
#include "espressif/user_interface.h"
#include "esp/uart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "esp8266.h"
#include "lwip/err.h"
#include "lwip/sockets.h"
#include "lwip/sys.h"
#include "lwip/netdb.h"
#include "lwip/dns.h"
int TaskIsAlive = 1;
// WiFi Task
void task1(void *pvParameters)
{
TickType_t nowTick;
nowTick = xTaskGetTickCount();
printf("[%s:%d] Start\n",pcTaskGetName(0),nowTick);
/* Wait until we have joined AP and are assigned an
IP */
int wifiStatus;
while (1) {
wifiStatus =
sdk_wifi_station_get_connect_status();
nowTick = xTaskGetTickCount();
printf("[%s:%d]
wifiStatus=%d\n",pcTaskGetName(0),nowTick,wifiStatus);
//if
(sdk_wifi_station_get_connect_status() == STATION_GOT_IP)
break;
if (wifiStatus == STATION_GOT_IP)
break;
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
printf("[%s:%d] Connected to
AP\n",pcTaskGetName(0),nowTick);
uint8_t hwaddr[6];
if (sdk_wifi_get_macaddr(STATION_IF, hwaddr)) {
/*
#define MAC2STR(a) (a)[0], (a)[1],
(a)[2], (a)[3], (a)[4], (a)[5]
#define MACSTR
"%02x:%02x:%02x:%02x:%02x:%02x"
*/
printf("[%s] MAC
address="MACSTR"\n",pcTaskGetName(0),MAC2STR(hwaddr));
}
struct ip_info info;
if (sdk_wifi_get_ip_info(STATION_IF, &info)) {
/*
#define IP2STR(ipaddr)
ip4_addr1_16(ipaddr), \
ip4_addr2_16(ipaddr), \
ip4_addr3_16(ipaddr), \
ip4_addr4_16(ipaddr)
#define IPSTR "%d.%d.%d.%d"
*/
printf("[%s] IP
address="IPSTR"\n",pcTaskGetName(0),IP2STR(&info.ip));
printf("[%s]
Netmask="IPSTR"\n",pcTaskGetName(0),IP2STR(&info.netmask));
printf("[%s]
Gateway="IPSTR"\n",pcTaskGetName(0),IP2STR(&info.gw));
}
TaskIsAlive = 0;
vTaskDelete( NULL );
}
// Dummy Task
void task2(void *pvParameters)
{
TickType_t nowTick;
nowTick = xTaskGetTickCount();
printf("[%s:%d] Start\n",pcTaskGetName(0),nowTick);
while(TaskIsAlive) {
nowTick = xTaskGetTickCount();
printf("[%s:%d]
Running...\n",pcTaskGetName(0),nowTick);
vTaskDelay(100/portTICK_PERIOD_MS);
}
vTaskDelete( NULL );
}
void user_init(void)
{
uart_set_baud(0, 115200);
printf("SDK version:%s\n",
sdk_system_get_sdk_version());
printf("pcTaskGetName=%s\n",pcTaskGetName(0));
char ssid[] = "Your_SSID";
char password[] = "Your_PASSWORD";
struct sdk_station_config _station_info;
struct ip_info static_ip_info;
memset(&static_ip_info, 0,
sizeof(static_ip_info));
strcpy((char *)_station_info.ssid, ssid);
strcpy((char *)_station_info.password, password);
_station_info.bssid_set = 0;
IP4_ADDR(&static_ip_info.ip, 192, 168, 10, 70);
IP4_ADDR(&static_ip_info.gw, 192, 168, 10, 1);
IP4_ADDR(&static_ip_info.netmask, 255, 255,
255, 0);
sdk_wifi_station_dhcpc_stop();
//vTaskDelay(50);
//Must call sdk_wifi_set_opmode before
sdk_wifi_station_set_config
sdk_wifi_set_opmode(STATION_MODE);
sdk_wifi_set_ip_info(STATION_IF,
&static_ip_info);
sdk_wifi_station_set_config(&_station_info);
//sdk_wifi_station_connect();
xTaskCreate(task1, "task1", 384, NULL, 2,
NULL);
xTaskCreate(task2, "task2", 256, NULL, 2, NULL);
}
|