示例#1
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);
  }
}
示例#2
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);
  }
}
示例#3
0
//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);
	}
}
示例#4
0
int ICACHE_FLASH_ATTR
ajaxLogDbg(HttpdConnData *connData) {
  if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
  char buff[512];
  int len, status = 400;
  len = httpdFindArg(connData->getArgs, "mode", buff, sizeof(buff));
  if (len > 0) {
    int8_t mode = -1;
    if (os_strcmp(buff, "auto") == 0)  mode = LOG_MODE_AUTO;
    if (os_strcmp(buff, "off") == 0)   mode = LOG_MODE_OFF;
    if (os_strcmp(buff, "on0") == 0) mode = LOG_MODE_ON0;
    if (os_strcmp(buff, "on1") == 0) mode = LOG_MODE_ON1;
    if (mode >= 0) {
      flashConfig.log_mode = mode;
      if (mode != LOG_MODE_AUTO) log_uart(mode >= LOG_MODE_ON0);
      status = configSave() ? 200 : 400;
    }
  } else if (connData->requestType == HTTPD_METHOD_GET) {
    status = 200;
  }

  jsonHeader(connData, status);
  os_sprintf(buff, "{\"mode\": \"%s\"}", dbg_mode[flashConfig.log_mode]);
  httpdSend(connData, buff, -1);
  return HTTPD_CGI_DONE;
}