コード例 #1
0
/******************************************************************************
 * FunctionName : user_esp_platform_check_ip
 * Description  : check whether get ip addr or not
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
v_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_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");

    } 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 *)v_user_esp_platform_check_ip, NULL);
            os_timer_arm(&test_timer, 100, 0);
        }
    }
}
コード例 #2
0
ファイル: user_main.cpp プロジェクト: complynx/esp_shell
static void ICACHE_FLASH_ATTR wifi_check_ip(void *arg)
{
	os_timer_disarm(&WiFiCheck);

	switch(wifi_station_get_connect_status())
	{
		case STATION_GOT_IP:
			struct ip_info LocalIP;
			wifi_get_ip_info(STATION_IF, &LocalIP);
			if(LocalIP.ip.addr != 0) {
				DPRINT("WiFi connected");
				Config::I().errno(ERRNO_OK);

				IoTServer::instance().setIP(LocalIP);
				return;
			}
			break;
		case STATION_WRONG_PASSWORD:
		case STATION_CONNECT_FAIL:
		case STATION_NO_AP_FOUND:
			Config::I().errno(STATION_ERROR_TO_ERRNO(wifi_station_get_connect_status()));
			DPRINT("WiFi error #%d, see <user_interface.h> for info.",wifi_station_get_connect_status());
			break;
		default:
			DPRINT("WiFi connecting...");
	}
	os_timer_setfn(&WiFiCheck, (os_timer_func_t *)wifi_check_ip, NULL);
	os_timer_arm(&WiFiCheck, 1000, 0);
}
コード例 #3
0
void ICACHE_FLASH_ATTR station_connect_status_check_timercb(void* _timer)
{
	ETSTimer* timer = (ETSTimer*)_timer;
	os_printf("wifi_station_dhcpc_status: [%d]\n", wifi_station_dhcpc_status());
    if(wifi_station_dhcpc_status() == DHCP_STOPPED && !wifi_station_dhcpc_start()) {
    	os_printf("wifi_station_dhcpc_start error\n");
    }

    os_printf("wifi station connect status: [%d]\n", wifi_station_get_connect_status());
    if(wifi_station_get_connect_status() == STATION_GOT_IP && client_status != STATUS_CONNECTED) {
    	os_printf("Connected to ROUTER, connecting to cloud\n");
    	connect_to_cloud();
    	client_status = STATUS_CONNECTING;
    }

    //连接成功后停止定时器
    if(client_status == STATUS_CONNECTED) {
    	os_timer_disarm(timer);
    }

    //如果系统模式非station模式,则停止
    if(wifi_get_opmode() != STATION_MODE) {
    	os_timer_disarm(timer);
    }
}
コード例 #4
0
ファイル: user_main.c プロジェクト: Squonk42/nodelua
void ICACHE_FLASH_ATTR user_check_ip(uint8 reset_flag)
{
    struct ip_info ipconfig;

    os_timer_disarm(&check_sta_timer);

    wifi_get_ip_info(STATION_IF, &ipconfig);

    if (wifi_station_get_connect_status() == STATION_GOT_IP && ipconfig.ip.addr != 0)
	{
		fetch_code_from_cloud();
    }
	else
	{
        /* if there are wrong while connecting to some AP, then reset mode */
        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))
		{
			//TODO: reconfig wifi!!!
            //user_esp_platform_reset_mode();
        } else {
            os_timer_setfn(&check_sta_timer, (os_timer_func_t *)user_check_ip, NULL);
            os_timer_arm(&check_sta_timer, 100, 0);
        }
    }
}
コード例 #5
0
ファイル: wifi.c プロジェクト: AxelLin/esp_mqtt
static void ICACHE_FLASH_ATTR wifi_check_ip(void *arg)
{
	struct ip_info ipConfig;

	os_timer_disarm(&WiFiLinker);
	wifi_get_ip_info(STATION_IF, &ipConfig);
	wifiStatus = wifi_station_get_connect_status();
	if (wifiStatus == STATION_GOT_IP && ipConfig.ip.addr != 0)
	{

		os_timer_setfn(&WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);
		os_timer_arm(&WiFiLinker, 2000, 0);


	}
	else
	{
		if(wifi_station_get_connect_status() == STATION_WRONG_PASSWORD)
		{

			INFO("STATION_WRONG_PASSWORD\r\n");
			wifi_station_connect();


		}
		else if(wifi_station_get_connect_status() == STATION_NO_AP_FOUND)
		{

			INFO("STATION_NO_AP_FOUND\r\n");
			wifi_station_connect();


		}
		else if(wifi_station_get_connect_status() == STATION_CONNECT_FAIL)
		{

			INFO("STATION_CONNECT_FAIL\r\n");
			wifi_station_connect();

		}
		else
		{
			INFO("STATION_IDLE\r\n");
		}

		os_timer_setfn(&WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);
		os_timer_arm(&WiFiLinker, 500, 0);
	}
	if(wifiStatus != lastWifiStatus){
		lastWifiStatus = wifiStatus;
		if(wifiCb)
			wifiCb(wifiStatus);
	}
}
コード例 #6
0
ファイル: start_wifi.c プロジェクト: jcloiacon/ESPDrone
 /******************************************************************************
 * FunctionName : user_check_ip
 * Description  : check whether get ip addr or not
 * Parameters	: none
 * Returns	  : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_check_ip(void)
{
	struct ip_info ipconfig;

	//disarm timer first
	os_timer_disarm(&test_timer);

	//get ip info of ESP8266 station
	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");

	  wifi_set_broadcast_if(STATIONAP_MODE); // send UDP broadcast from both station and soft-AP interface

	  user_udp_espconn.type = ESPCONN_UDP;
	  user_udp_espconn.proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp));
	  user_udp_espconn.proto.udp->local_port = 1112;  // set a available  port
	 
	  const char udp_remote_ip[4] = {255, 255, 255, 255}; 
	 
	  os_memcpy(user_udp_espconn.proto.udp->remote_ip, udp_remote_ip, 4); // ESP8266 udp remote IP
	 
	  user_udp_espconn.proto.udp->remote_port = 5556;  // ESP8266 udp remote port
	 
	  espconn_regist_recvcb(&user_udp_espconn, user_udp_recv_cb); // register a udp packet receiving callback
	  espconn_regist_sentcb(&user_udp_espconn, user_udp_sent_cb); // register a udp packet sent callback
	 
	  espconn_create(&user_udp_espconn);	// create udp

	  user_udp_send();	// send udp data

	  os_timer_arm(&send_timer, 40, 0);
	}
	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
	  {	
		//os_printf("still waiting...\n");
		//re-arm timer to check ip
		os_timer_setfn(&test_timer, (os_timer_func_t *)user_check_ip, NULL);
		os_timer_arm(&test_timer, 500, 0);
	}
	}
}
コード例 #7
0
ファイル: user_main.c プロジェクト: mroavi/my-esp
void wifiConnectTimerCb(void *arg)
{
	/* Do we have an IP already? */
	int status = wifi_station_get_connect_status();
	if( status != STATION_GOT_IP)
	{
		/* No, then connect to the WiFi station */
		wifi_station_disconnect();

		os_printf("Trying to connect to %s\n", stconf.ssid );

		/* connect to a WiFi station */
		wifi_station_connect();
	}
	else
	{
		/* yes, then disable the timer WiFi setup timer*/
		os_timer_disarm(&wifi_setup_timer);

		/* enable POST timer in periodic mode */
		os_timer_disarm((ETSTimer*)&post_timer);
		os_timer_setfn((ETSTimer*)&post_timer, (os_timer_func_t *) startHttpRequestTimerCallback, NULL);
		os_timer_arm((ETSTimer*)&post_timer, 10000, 0); // thingspeak needs minimum 15 sec delay between updates
	}
}
コード例 #8
0
ファイル: cgiwifi.c プロジェクト: alonewolfx2/esp-link
//This routine is ran some time after a connection attempt to an access point. If
//the connect succeeds, this gets the module in STA-only mode.
static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
	int x = wifi_station_get_connect_status();
	int m = wifi_get_opmode() & 0x3;
	os_printf("Wifi check: mode=%s status=%d\n", wifiMode[m], x);

	if (x == STATION_GOT_IP) {
		if (m != 1) {
			// We're happily connected, go to STA mode
			os_printf("Wifi got IP. Going into STA mode..\n");
			wifi_set_opmode(1);
			wifi_set_sleep_type(SLEEP_MODE);
			os_timer_arm(&resetTimer, RESET_TIMEOUT, 0);
			//os_timer_disarm(&deepTimer);
			//os_timer_setfn(&deepTimer, deepSleepCb, NULL);
			//os_timer_arm(&deepTimer, 1000, 1);
		}
		log_uart(false);
		// no more resetTimer at this point, gotta use physical reset to recover if in trouble
	} else {
		if (m != 3) {
			os_printf("Wifi connect failed. Going into STA+AP mode..\n");
			wifi_set_opmode(3);
		}
		log_uart(true);
		os_printf("Enabling/continuing uart log\n");
		os_timer_arm(&resetTimer, RESET_TIMEOUT, 0);
	}
}
コード例 #9
0
ファイル: cgiwifi.c プロジェクト: alonewolfx2/esp-link
// print various Wifi information into json buffer
int ICACHE_FLASH_ATTR printWifiInfo(char *buff) {
	int len;

	struct station_config stconf;
	wifi_station_get_config(&stconf);

	uint8_t op = wifi_get_opmode() & 0x3;
	char *mode = wifiMode[op];
	char *status = "unknown";
	int st = wifi_station_get_connect_status();
	if (st > 0 && st < sizeof(connStatuses)) status = connStatuses[st];
	int p = wifi_get_phy_mode();
	char *phy = wifiPhy[p&3];
	char *warn = wifiWarn[op];
	sint8 rssi = wifi_station_get_rssi();
	if (rssi > 0) rssi = 0;
	uint8 mac_addr[6];
	wifi_get_macaddr(0, mac_addr);

	len = os_sprintf(buff,
		"\"mode\": \"%s\", \"ssid\": \"%s\", \"status\": \"%s\", \"phy\": \"%s\", "
		"\"rssi\": \"%ddB\", \"warn\": \"%s\", \"passwd\": \"%s\", "
		"\"mac\":\"%02x:%02x:%02x:%02x:%02x:%02x\"",
		mode, (char*)stconf.ssid, status, phy, rssi, warn, (char*)stconf.password,
		mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);

	struct ip_info info;
	if (wifi_get_ip_info(0, &info)) {
		len += os_sprintf(buff+len, ", \"ip\": \"%d.%d.%d.%d\"",
			(info.ip.addr>>0)&0xff, (info.ip.addr>>8)&0xff,
			(info.ip.addr>>16)&0xff, (info.ip.addr>>24)&0xff);
	} else {
コード例 #10
0
ファイル: v7_esp.c プロジェクト: fast01/smart.js
ICACHE_FLASH_ATTR static v7_val_t Wifi_status(struct v7 *v7, v7_val_t this_obj,
                                              v7_val_t args) {
  uint8 st = wifi_station_get_connect_status();
  const char *msg;

  (void) this_obj;
  (void) args;

  switch (st) {
    case STATION_IDLE:
      msg = "idle";
      break;
    case STATION_CONNECTING:
      msg = "connecting";
      break;
    case STATION_WRONG_PASSWORD:
      msg = "bad pass";
      break;
    case STATION_NO_AP_FOUND:
      msg = "no ap";
      break;
    case STATION_CONNECT_FAIL:
      msg = "connect failed";
      break;
    case STATION_GOT_IP:
      msg = "got ip";
      break;
  }
  return v7_create_string(v7, msg, strlen(msg), 1);
}
コード例 #11
0
ファイル: syslog.c プロジェクト: rbiazotto/esp-link
/******************************************************************************
 * FunctionName : syslog_chk_wifi_stat
 * Description  : check whether get ip addr or not
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
static void ICACHE_FLASH_ATTR syslog_chk_wifi_stat(void)
{
  struct ip_info ipconfig;
  DBG("syslog_chk_wifi_stat: state: %d ", syslogState);

  //disarm timer first
  os_timer_disarm(&wifi_chk_timer);

  //try to get ip info of ESP8266 station
  wifi_get_ip_info(STATION_IF, &ipconfig);
  int wifi_status = wifi_station_get_connect_status();
  if (wifi_status == STATION_GOT_IP && ipconfig.ip.addr != 0)
  {
    if (syslogState == SYSLOG_WAIT) {			// waiting for initialization
      DBG("connected, initializing UDP socket\n");
      syslog_init(flashConfig.syslog_host);
    }
  } else {
    if ((wifi_status == STATION_WRONG_PASSWORD ||
	 wifi_status == STATION_NO_AP_FOUND ||
	 wifi_status == STATION_CONNECT_FAIL)) {
      syslogState = SYSLOG_ERROR;
      os_printf("*** connect failure!!!\n");
    } else {
      DBG("re-arming timer...\n");
      os_timer_setfn(&wifi_chk_timer, (os_timer_func_t *)syslog_chk_wifi_stat, NULL);
      os_timer_arm(&wifi_chk_timer, WIFI_CHK_INTERVAL, 0);
    }
  }
}
コード例 #12
0
ファイル: user_main.c プロジェクト: tsbp/esp_udp_uart
static void ICACHE_FLASH_ATTR wifi_check_ip(void *arg)
{
	os_timer_disarm(&WiFiLinker);
	switch(wifi_station_get_connect_status())
	{
		case STATION_GOT_IP:
			wifi_get_ip_info(STATION_IF, &ipConfig);
			if(ipConfig.ip.addr != 0) {
				connState = WIFI_CONNECTED;
				DHT22_DEBUG("WiFi connected,do something..\r\n");
			} else {
				connState = WIFI_CONNECTING_ERROR;
				DHT22_DEBUG("WiFi connected, ip.addr is null\r\n");
			}
			break;
		case STATION_WRONG_PASSWORD:
			connState = WIFI_CONNECTING_ERROR;
			DHT22_DEBUG("WiFi connecting error, wrong password\r\n");
			break;
		case STATION_NO_AP_FOUND:
			connState = WIFI_CONNECTING_ERROR;
			DHT22_DEBUG("WiFi connecting error, ap not found\r\n");
			break;
		case STATION_CONNECT_FAIL:
			connState = WIFI_CONNECTING_ERROR;
			DHT22_DEBUG("WiFi connecting fail\r\n");
			break;
		default:
			connState = WIFI_CONNECTING;
			DHT22_DEBUG("WiFi connecting...\r\n");
	}
	os_timer_setfn(&WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);
	os_timer_arm(&WiFiLinker, WIFI_CHECK_DELAY, 0);
}
コード例 #13
0
ファイル: user_main.c プロジェクト: donnaware/ESP8266
// ----------------------------------------------------------------------------
static void wifi_check_ip(void *arg)
{
    struct ip_info ipConfig;
    os_timer_disarm(&WiFiLinker);
    switch(wifi_station_get_connect_status()) {
        case STATION_GOT_IP:
            wifi_get_ip_info(STATION_IF, &ipConfig);
            if(ipConfig.ip.addr != 0) {
                connState = WIFI_CONNECTED;
                os_printf("WiFi connected\n");
                return;
            }
            break;
        case STATION_WRONG_PASSWORD:
            connState = WIFI_CONNECTING_ERROR;
            os_printf("WiFi connecting error, wrong password\n");
            break;
        case STATION_NO_AP_FOUND:
            connState = WIFI_CONNECTING_ERROR;
            os_printf("WiFi connecting error, ap not found\n");
            break;
        case STATION_CONNECT_FAIL:
            connState = WIFI_CONNECTING_ERROR;
            os_printf("WiFi connecting fail\n");
            break;
        default:
            connState = WIFI_CONNECTING;
            os_printf("WiFi connecting...\n");
            break;
    }
    os_timer_setfn(&WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);
    os_timer_arm(&WiFiLinker, 1000, 0);
}
コード例 #14
0
ファイル: esp_sj_wifi.c プロジェクト: gas19/mongoose-iot
char *sj_wifi_get_status_str(void) {
  uint8 st = wifi_station_get_connect_status();
  const char *msg = NULL;

  switch (st) {
    case STATION_IDLE:
      msg = "idle";
      break;
    case STATION_CONNECTING:
      msg = "connecting";
      break;
    case STATION_WRONG_PASSWORD:
      msg = "bad pass";
      break;
    case STATION_NO_AP_FOUND:
      msg = "no ap";
      break;
    case STATION_CONNECT_FAIL:
      msg = "connect failed";
      break;
    case STATION_GOT_IP:
      msg = "got ip";
      break;
  }
  if (msg != NULL) return strdup(msg);
  return NULL;
}
コード例 #15
0
static void ICACHE_FLASH_ATTR ost_wifi_setup(os_event_t *events){
	os_printf("WiFi Setup...\n");
	uint8_t stationStatus = wifi_station_get_connect_status();
	//Handle status
	wifi_station_set_auto_connect(TRUE);
	wifi_setup(&ssid,&pass, STATION_MODE);
}
コード例 #16
0
ファイル: cgiwifi.c プロジェクト: mroavi/esp-link
// This routine is ran some time after a connection attempt to an access point. If
// the connect succeeds, this gets the module in STA-only mode. If it fails, it ensures
// that the module is in STA+AP mode so the user has a chance to recover.
static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
  int x = wifi_station_get_connect_status();
  int m = wifi_get_opmode() & 0x3;
  DBG("Wifi check: mode=%s status=%d\n", wifiMode[m], x);

  if (m == 2) return; // 2=AP, in AP-only mode we don't do any auto-switching

  if ( x == STATION_GOT_IP ) {
    // if we got an IP we could switch to STA-only...
    if (m != 1) { // 1=STA
#ifdef CHANGE_TO_STA
      // We're happily connected, go to STA mode
      DBG("Wifi got IP. Going into STA mode..\n");
      wifi_set_opmode(1);
      os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); // check one more time after switching to STA-only
#endif
    }
    log_uart(false);
    // no more resetTimer at this point, gotta use physical reset to recover if in trouble
  } else {
    // we don't have an IP address
    if (m != 3) {
      DBG("Wifi connect failed. Going into STA+AP mode..\n");
      wifi_set_opmode(3);
      wifi_softap_set_config(&apconf);
    }
    log_uart(true);
    DBG("Enabling/continuing uart log\n");
    os_timer_arm(&resetTimer, RESET_TIMEOUT, 0);
  }
}
コード例 #17
0
ファイル: at_wifiCmd.c プロジェクト: GPTO/ESP8266-SSM
/**
  * @brief  Transparent data through ip.
  * @param  arg: no used
  * @retval None
  */
void ICACHE_FLASH_ATTR
at_japChack(void *arg)
{
  static uint8_t chackTime = 0;
  uint8_t japState;

  os_timer_disarm(&at_japDelayChack);
  chackTime++;
  japState = wifi_station_get_connect_status();
  if(japState == STATION_GOT_IP)
  {
    chackTime = 0;
    at_backOk;
    specialAtState = TRUE;
    at_state = at_statIdle;
    return;
  }
  else if(chackTime >= 7)
  {
    wifi_station_disconnect();
    chackTime = 0;
    uart0_sendStr("\r\nFAIL\r\n");
    specialAtState = TRUE;
    at_state = at_statIdle;
    return;
  }
  os_timer_arm(&at_japDelayChack, 2000, 0);

}
コード例 #18
0
ファイル: esp_sj_wifi.c プロジェクト: gas19/mongoose-iot
enum sj_wifi_status sj_wifi_get_status(void) {
  if (wifi_station_get_connect_status() == STATION_GOT_IP) {
    return SJ_WIFI_IP_ACQUIRED;
  } else {
    return SJ_WIFI_DISCONNECTED;
  }
}
コード例 #19
0
int8_t ESP8266WiFiClass::scanNetworks()
{
    if(_useApMode) {
        // turn on AP+STA mode
        mode(WIFI_AP_STA);
    } else {
        // turn on STA mode
        mode(WIFI_STA);
    }

    int status = wifi_station_get_connect_status();
    if (status != STATION_GOT_IP && status != STATION_IDLE)
    {
        disconnect();
    }

    if (ESP8266WiFiClass::_scanResult)
    {
        delete[] reinterpret_cast<bss_info*>(ESP8266WiFiClass::_scanResult);
        ESP8266WiFiClass::_scanResult = 0;
        ESP8266WiFiClass::_scanCount = 0;
    }
    
    struct scan_config config;
    config.ssid = 0;
    config.bssid = 0;
    config.channel = 0;
    config.show_hidden = 0;
    wifi_station_scan(&config, reinterpret_cast<scan_done_cb_t>(&ESP8266WiFiClass::_scanDone));
    esp_yield();
    return ESP8266WiFiClass::_scanCount;
}
コード例 #20
0
void ICACHE_FLASH_ATTR network_check_ip(void) 
{
  
  struct ip_info ipconfig;
  os_timer_disarm(&network_timer);
  
  wifi_get_ip_info(STATION_IF, &ipconfig);
  
  if (wifi_station_get_connect_status() == STATION_GOT_IP && ipconfig.ip.addr != 0) 
  {
   
    //char page_buffer[20];
    //os_sprintf(page_buffer,"IP: %d.%d.%d.%d",IP2STR(&ipconfig.ip));
    //uart0_tx_buffer(page_buffer,strlen(page_buffer));
    
 	  os_timer_disarm(&led_timer);
	  os_timer_setfn(&led_timer, (os_timer_func_t *)LedTimer, NULL);
	  os_timer_arm(&led_timer, 500, 1);
    
    network_start();
  } 
  else 
  {
 	  //uart0_tx_buffer("!!NOIP!!",8); 
 	  
 	  os_timer_disarm(&led_timer);
	  os_timer_setfn(&led_timer, (os_timer_func_t *)LedTimer, NULL);
	  os_timer_arm(&led_timer, 2000, 1);

    os_timer_setfn(&network_timer, (os_timer_func_t *)network_check_ip, NULL);
    os_timer_arm(&network_timer, 1000, 0);
  }
}
コード例 #21
0
ファイル: slave_main.c プロジェクト: eeijcea/ESP8266
/**
  * @brief  Transparent data through ip.
  * @param  arg: no used
  * @retval None
  */
static void ICACHE_FLASH_ATTR
at_japChack(void *arg)
{

  uint8_t japState;
  char temp[32];
  os_printf("Checking if we have ip...\r\n");
  os_timer_disarm(&at_japDelayChack);
  chackTime++;
  japState = wifi_station_get_connect_status();
  if(japState == STATION_GOT_IP)
  {
	os_printf("YEAHHH we have ip...\r\n");
    chackTime = 0;
    connect_attempts = 0;
    if(ip_connected == 0) {
    	initer_slave();
    	ip_connected = 1;
    }
  }
  else if(chackTime >= 10)
  {
	ip_connected = 0;
    wifi_station_disconnect();
    os_sprintf(temp,"+CWJAP:%d\r\n",japState);
    os_printf(temp);
    os_printf("\r\nFAIL\r\n");
    reset_slave();
    return;
  }
  //scan_slave();
  os_timer_arm(&at_japDelayChack, 2000, 0);
  os_printf("ip check done\r\n");
}
コード例 #22
0
iram static void slow_timer_callback(void *arg)
{
	int ix;

	// run background task every ~100 ms = ~10 Hz

	stat_slow_timer++;

	dispatch_post_command(command_task_update_time);

	if(uart_bridge_active)
		dispatch_post_command(command_task_uart_bridge);

	if(display_detected())
		dispatch_post_command(command_task_display_update);

	for(ix = 5; ix > 0; ix--)
		dispatch_post_command(command_task_periodic_i2c_sensors);

	// fallback to config-ap-mode when not connected or no ip within 30 seconds

	if((stat_slow_timer == 300) && (wifi_station_get_connect_status() != STATION_GOT_IP))
		dispatch_post_command(command_task_fallback_wlan);

	dispatch_post_timer(timer_task_io_periodic_slow);
}
コード例 #23
0
static void ICACHE_FLASH_ATTR MQTTLogonTimerCb(void *arg)
{
static int resetCnt=0;

if (allow_mqtt_init)
	{
	if (!logged_on_to_network)
		{
		int x=wifi_station_get_connect_status();
		if (x==STATION_GOT_IP)
			{
			logged_on_to_network = 1;
			if (!logged_on_to_mqtt)
				{
				INFO("\n\rNETWRK OK\n");
				mqtt_init();
				MQTT_Connect(&mqttClient);
				INFO("MQTT OK\r\n");
				logged_on_to_mqtt = 1;
				}
			}
		else
			{
			if (logged_on_to_mqtt) // Disconnect and reconnect later
				{
				MQTT_Disconnect(&mqttClient);
				INFO("Left MQTT\r\n");
				logged_on_to_mqtt = 0;
				}
			}

		}
	}
}
コード例 #24
0
ファイル: app.c プロジェクト: flo90/esp-ginx
static void ICACHE_FLASH_ATTR mqtt_app_timer_cb(void *arg){

	
	struct ip_info ipConfig;
	
	wifi_get_ip_info(STATION_IF, &ipConfig);	
	wifiStatus = wifi_station_get_connect_status();

	//check wifi
	if(wifiStatus != lastWifiStatus){

		lastWifiStatus = wifiStatus;
		
		if(wifiStatus==STATION_GOT_IP && ipConfig.ip.addr != 0){
        	MQTT_DBG("MQTT: Detected wifi network up");
        	MQTT_Connect(&mqtt_client);       
	    }
	    else{
	    	MQTT_DBG("MQTT: Detected wifi network down");
	    	MQTT_Disconnect(&mqtt_client);    
	    }

	}
	    
}
コード例 #25
0
ファイル: cgiwifi.c プロジェクト: seco/esp-link
int ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData) {
  char buff[1024];
  int len;

  if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
  jsonHeader(connData, 200);

  len = os_sprintf(buff, "{");
  len += printWifiInfo(buff+len);
  len += os_sprintf(buff+len, ", ");

  if (wifiReason != 0) {
    len += os_sprintf(buff+len, "\"reason\": \"%s\", ", wifiGetReason());
  }

#if 0
  // commented out 'cause often the client that requested the change can't get a request in to
  // find out that it succeeded. Better to just wait the std 15 seconds...
  int st=wifi_station_get_connect_status();
  if (st == STATION_GOT_IP) {
    if (wifi_get_opmode() != 1) {
      // Reset into AP-only mode sooner.
      os_timer_disarm(&resetTimer);
      os_timer_setfn(&resetTimer, resetTimerCb, NULL);
      os_timer_arm(&resetTimer, 1000, 0);
    }
  }
#endif

  len += os_sprintf(buff+len, "\"x\":0}\n");
  //DBG("  -> %s\n", buff);
  httpdSend(connData, buff, len);
  return HTTPD_CGI_DONE;
}
コード例 #26
0
ファイル: cgiwifi.c プロジェクト: seco/esp-link
// This routine is ran some time after a connection attempt to an access point. If
// the connect succeeds, this gets the module in STA-only mode. If it fails, it ensures
// that the module is in STA+AP mode so the user has a chance to recover.
static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
  int x = wifi_station_get_connect_status();
  int m = wifi_get_opmode() & 0x3;
  DBG("Wifi check: mode=%s status=%d\n", wifiMode[m], x);

  if (x == STATION_GOT_IP) {
    if (m != 1) {
#ifdef CHANGE_TO_STA
      // We're happily connected, go to STA mode
      DBG("Wifi got IP. Going into STA mode..\n");
      wifi_set_opmode(1);
      os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); // check one more time after switching to STA-only
#endif
    }
    log_uart(false);
    // no more resetTimer at this point, gotta use physical reset to recover if in trouble
  } else {
    if (m != 3) {
      DBG("Wifi connect failed. Going into STA+AP mode..\n");
      wifi_set_opmode(3);
    }
    log_uart(true);
    DBG("Enabling/continuing uart log\n");
    os_timer_arm(&resetTimer, RESET_TIMEOUT, 0);
  }
}
コード例 #27
0
LOCAL void ICACHE_FLASH_ATTR wifi_check_ip(void *arg) {
	struct ip_info ipConfig;
	uint8_t wifiStatus = STATION_IDLE;

	os_timer_disarm(&wiFiLinker);

	wifi_get_ip_info(STATION_IF, &ipConfig);

	wifiStatus = wifi_station_get_connect_status();

	if (wifiStatus == STATION_GOT_IP && ipConfig.ip.addr != 0) {

		DEBUG("[NETWORK] Connected to network (IP: "IPSTR")\r\n", IP2STR(&ipConfig.ip));

		os_timer_setfn(&wiFiLinker, (os_timer_func_t *) wifi_check_ip, NULL);
		os_timer_arm(&wiFiLinker, 2000, 0);

	} else {

		if (wifi_station_get_connect_status() == STATION_WRONG_PASSWORD) {
			DEBUG("[NETWORK] error: STATION_WRONG_PASSWORD\r\n");
			station_connect();
		} else if (wifi_station_get_connect_status() == STATION_NO_AP_FOUND) {
			DEBUG("[NETWORK] error: STATION_NO_AP_FOUND\r\n");
			station_connect();
		} else if (wifi_station_get_connect_status() == STATION_CONNECT_FAIL) {
			DEBUG("[NETWORK] error: STATION_CONNECT_FAIL\r\n");
			station_connect();
		} else {
			//DEBUG("[NETWORK] error: STATION_IDLE\r\n");
		}

		if(state == USER_STATION_MODE){
			os_timer_setfn(&wiFiLinker, (os_timer_func_t *) wifi_check_ip, NULL);
			os_timer_arm(&wiFiLinker, 500, 0);
		}

	}

	if (wifiStatus != lastWifiStatus) {

		lastWifiStatus = wifiStatus;
		if (wifiCb)
			wifiCb(wifiStatus);

	}
}
コード例 #28
0
ファイル: cgi_wifi.c プロジェクト: someburner/esp-rfm69
int http_wifi_api_get_status(http_connection *c)
{
    CGI_WIFI_DBG("wifi get_status\n");

    //wait for whole body
    if(c->state <HTTPD_STATE_BODY_END) {
        return HTTPD_CGI_MORE;
    }

    api_cgi_status * status = c->cgi.data;

    //first call, send headers
    if(status==NULL)
    {
        status = (api_cgi_status*)os_malloc(sizeof(api_cgi_status));
        status->state=1;
        c->cgi.data=status;

        http_SET_HEADER(c,HTTP_CONTENT_TYPE,JSON_CONTENT_TYPE);
        http_response_OK(c);

        return HTTPD_CGI_MORE;
    }
    else if(status->state==1)
    {
        wifi_station_get_config(&wifi_status.station_config);
        uint8_t c_status = wifi_station_get_connect_status();

        //return JSON
        cJSON *root = cJSON_CreateObject();
        cJSON_AddBoolToObject(root,"scanning",wifi_status.scanning);
        cJSON_AddStringToObject(root,"ssid",(const char *)wifi_status.station_config.ssid);
        cJSON_AddNumberToObject(root,"mode",wifi_get_opmode());
        cJSON_AddNumberToObject(root,"station_status",c_status);

        //got ip
        if(c_status==5)
        {
            struct ip_info ip;
            wifi_get_ip_info(0x0,&ip);
            char *ip_str = (char*)ipaddr_ntoa(&ip.ip);
            cJSON_AddStringToObject(root,"ip",ip_str);
        }
        else {
            cJSON_AddStringToObject(root,"ip","");
        }

        http_write_json(c,root);
        cJSON_Delete(root);

        status->state=99;
        return HTTPD_CGI_MORE;
    }
    else
    {
        os_free(c->cgi.data);
        return HTTPD_CGI_DONE;
    }
}
コード例 #29
0
ファイル: espconn.c プロジェクト: AbuShaqra/nodemcu-firmware
/******************************************************************************
 * FunctionName : espconn_connect
 * Description  : The function given as the connect
 * Parameters   : espconn -- the espconn used to listen the connection
 * Returns      : none
*******************************************************************************/
sint8 ICACHE_FLASH_ATTR
espconn_connect(struct espconn *espconn)
{
	struct ip_addr ipaddr;
	struct ip_info ipinfo;
	uint8 connect_status = 0;
	sint8 value = ESPCONN_OK;
	espconn_msg *plist = NULL;

    if (espconn == NULL) {
        return ESPCONN_ARG;
    } else if (espconn ->type != ESPCONN_TCP)
    	return ESPCONN_ARG;

    if (wifi_get_opmode() == ESPCONN_STA){
    	wifi_get_ip_info(STA_NETIF,&ipinfo);
    	if (ipinfo.ip.addr == 0){
   	 		return ESPCONN_RTE;
   	 	}
    } else if(wifi_get_opmode() == ESPCONN_AP){
    	wifi_get_ip_info(AP_NETIF,&ipinfo);
    	if (ipinfo.ip.addr == 0){
    		return ESPCONN_RTE;
    	}
    } else if(wifi_get_opmode() == ESPCONN_AP_STA){
    	IP4_ADDR(&ipaddr, espconn->proto.tcp->remote_ip[0],
    	    	    		espconn->proto.tcp->remote_ip[1],
    	    	    		espconn->proto.tcp->remote_ip[2],
    	    	    		espconn->proto.tcp->remote_ip[3]);
    	ipaddr.addr <<= 8;
    	wifi_get_ip_info(AP_NETIF,&ipinfo);
    	ipinfo.ip.addr <<= 8;
    	espconn_printf("softap_addr = %x, remote_addr = %x\n", ipinfo.ip.addr, ipaddr.addr);

    	if (ipaddr.addr != ipinfo.ip.addr){
    		connect_status = wifi_station_get_connect_status();
			if (connect_status == STATION_GOT_IP){
				wifi_get_ip_info(STA_NETIF,&ipinfo);
				if (ipinfo.ip.addr == 0)
					return ESPCONN_RTE;
			} else {
				return connect_status;
			}
    	}
    }

    for (plist = plink_active; plist != NULL; plist = plist->pnext){
    	if (plist->pespconn->type == ESPCONN_TCP){
    		if (espconn->proto.tcp->local_port == plist->pespconn->proto.tcp->local_port){
    			return ESPCONN_ISCONN;
    		}
    	}
    }

    value = espconn_tcp_client(espconn);

    return value;
}
コード例 #30
0
ファイル: user_main.c プロジェクト: hehao3344/mkit
static void ICACHE_FLASH_ATTR led_status_center(void *arg)
{
    os_timer_arm(&status_timer, 2000, 0);
    user_wifi_output(led_status);
    led_status = (0 == led_status) ? 1 : 0;
    os_printf("get status %d \n", smart_config_get_status());

    int status = wifi_station_get_connect_status();
    int smart_status = wifi_station_get_connect_status();

    if ((E_STATUS_LINK_OVER == smart_status) &&
        (status == STATION_GOT_IP))
    {
        os_timer_disarm(&status_timer, 2000, 0);
        flash_param_set_id(CONFIG_DONE_ID);
        schedule_create(0);
    }
}