Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
/*JSON{
  "type"     : "staticmethod",
  "class"    : "ESP8266WiFi",
  "name"     : "getAccessPoints",
  "generate" : "jswrap_ESP8266WiFi_getAccessPoints",
  "params"   : [
    ["callback","JsVar","Function to call back when access points retrieved."]
  ]
}*/
void jswrap_ESP8266WiFi_getAccessPoints(
    JsVar *callback //!< Function to call back when access points retrieved.
  ) {
  os_printf("> ESP8266WiFi_getAccessPoints\n");
  if (callback == NULL || !jsvIsFunction(callback)) {
      jsExceptionHere(JSET_ERROR, "No callback.");
    return;
  }

  // If we had saved a previous scan callback function, release it.
  if (g_jsScanCallback != NULL) {
    jsvUnLock(g_jsScanCallback);
  }

  // Save the callback for the scan in the global variable called jsScanCallback.
  g_jsScanCallback = jsvLockAgainSafe(callback);

  // Ask the ESP8266 to perform a network scan after first entering
  // station mode.  The network scan will eventually result in a callback
  // being executed (scanCB) which will contain the results.

  // Ensure we are in station mode
  wifi_set_opmode_current(STATION_MODE);

  // Request a scan of the network calling "scanCB" on completion
  wifi_station_scan(NULL, scanCB);

  os_printf("< ESP8266WiFi_getAccessPoints\n");
}
Ejemplo n.º 3
0
bool ICACHE_FLASH_ATTR wifi_scan_start() {
	if (!wifi_scan_in_progress) {
		wifi_scan_in_progress = wifi_station_scan(NULL, wifi_scan_done);
		return wifi_scan_in_progress;
	}
	return true;
}
Ejemplo n.º 4
0
void scanner(void *arg)
{
    if (scan_complete)
    {
        scan_complete = false;
        wifi_station_scan(NULL,scan_done);
    }
}
Ejemplo n.º 5
0
void StationClass::onSystemReady()
{
	if (runScan)
	{
		wifi_station_scan(NULL, staticScanCompleted);
		runScan = false;
	}
}
Ejemplo n.º 6
0
void ICACHE_FLASH_ATTR dhserial_commands_scan(const char *args) {
	static struct scan_config config = {0, 0, 0, 1};
	if(wifi_station_scan(&config, scan_done_cb)) {
		uart_send_line("Scanning...");
		mIsCommandWorking = 1;
		dhserial_set_mode(SM_OUTPUT_MODE, 0, 0);
	} else {
		uart_send_line("Failed to start scan.");
	}
}
Ejemplo n.º 7
0
//Routine to start a WiFi access point scan.
static void ICACHE_FLASH_ATTR wifiStartScan() {
	int x;
	cgiWifiAps.scanInProgress=1;
	x=wifi_station_get_connect_status();
	if (x!=STATION_GOT_IP) {
		//Unit probably is trying to connect to a bogus AP. This messes up scanning. Stop that.
		os_printf("STA status = %d. Disconnecting STA...\n", x);
		wifi_station_disconnect();
	}
	wifi_station_scan(NULL, wifiScanDoneCb);
}
Ejemplo n.º 8
0
/**
  * @brief  Execution commad of list wifi aps.
  * @param  id: commad id number
  * @retval None
  */
void ICACHE_FLASH_ATTR
at_exeCmdCwlap(uint8_t id)//need add mode chack
{
  if(at_wifiMode == SOFTAP_MODE)
  {
    at_backError;
    return;
  }
  wifi_station_scan(scan_done);
  specialAtState = FALSE;
}
Ejemplo n.º 9
0
void ICACHE_FLASH_ATTR setup_ap() {
    setup_ap_ip();

    // Set STATION+AP mode
    wifi_set_opmode(STATIONAP_MODE);

    // Store MAC address
    wifi_get_macaddr(SOFTAP_IF, macaddr);
    char macstr[255];
    os_sprintf(macstr, MACSTR, MAC2STR(macaddr));
    //ets_uart_printf("Got mac addr %s\r\n", macstr);

    // Set AP info
    char ssid[32];
    os_sprintf(ssid, "Maia Setup 0x%x", DEVICE_ID);
    char password[64] = "heyamaia";

    // Create config struct
    struct softap_config apConfig;
    wifi_softap_get_config(&apConfig);

    // Set SSID in struct
    os_memset(apConfig.ssid, 0, sizeof(apConfig.ssid));
    os_memcpy(apConfig.ssid, ssid, os_strlen(ssid));

    // Set Password in struct
    os_memset(apConfig.password, 0, sizeof(apConfig.password));
    os_memcpy(apConfig.password, password, os_strlen(password));

    // Set AP options
    apConfig.authmode = AUTH_WPA_WPA2_PSK;
    apConfig.channel = 7;
    apConfig.ssid_hidden = 0;
    apConfig.ssid_len = 0;
    apConfig.max_connection = 255;

    // Use config struct
    wifi_softap_set_config(&apConfig);
    //print("Set AP info");

    /* char info[1024]; */
    /* 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, */
    /*         macstr); */
    //ets_uart_printf(info);

    wifi_station_scan(NULL, wifi_scan_done);
    mode = MODE_AP;
}
Ejemplo n.º 10
0
 // returns access point list
 WiFi::APInfo* STC_FLASHMEM WiFi::getAPList(uint32_t* count, bool rescan)
 {
     if (rescan)
     {
         if (getMode() == AccessPoint)
             setMode(ClientAndAccessPoint);
         wifi_station_scan(NULL, scanDoneCB);
         getAPInfo()->receive();	// wait for completion
     }
     APInfo* infos;
     getAPInfo(&infos, count);
     return infos;
 }
Ejemplo n.º 11
0
// returns access point list
WiFi::APInfo *STC_FLASHMEM WiFi::getAPList(uint32_t *count, bool rescan, bool canRetry) {
  if (rescan) {
    if (getMode() == AccessPoint)
      setMode(ClientAndAccessPoint);
    wifi_station_scan(NULL, scanDoneCB);
    getAPInfo()->receive(); // wait for completion
  }
  APInfo *infos;
  getAPInfo(&infos, count);
  if (*count == 0 && canRetry) {
    // retry
    return getAPList(count, true, false); // canRetry = false, no more retry to avoid infinite recursive calls
  }
  return infos;
}
Ejemplo n.º 12
0
int8_t ESP8266WiFiClass::scanNetworks(bool async)
{
    if(ESP8266WiFiClass::_scanStarted) {
        return WIFI_SCAN_RUNNING;
    }

    ESP8266WiFiClass::_scanAsync = async;

    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();
    }

    scanDelete();

    struct scan_config config;
    config.ssid = 0;
    config.bssid = 0;
    config.channel = 0;
    config.show_hidden = 0;
    if(wifi_station_scan(&config, reinterpret_cast<scan_done_cb_t>(&ESP8266WiFiClass::_scanDone))) {
        ESP8266WiFiClass::_scanComplete = false;
        ESP8266WiFiClass::_scanStarted = true;

        if(ESP8266WiFiClass::_scanAsync) {
            delay(0); // time for the OS to trigger the scan
            return WIFI_SCAN_RUNNING;
        }

        esp_yield();
        return ESP8266WiFiClass::_scanCount;
    } else {
        return WIFI_SCAN_FAILD;
    }

}
Ejemplo n.º 13
0
bool StationClass::startScan(ScanCompletedDelegate scanCompleted)
{
	scanCompletedCallback = scanCompleted;
	if (!scanCompleted) return false;

	bool res = wifi_station_scan(NULL, staticScanCompleted);
	if (!res)
	{
		if (!System.isReady())
		{
			// It's OK, queue this task
			runScan = true;
			return true;
		}
		debugf("startScan failed");
	}
	return res;
}
Ejemplo n.º 14
0
//Routine to start a WiFi access point scan.
static void ICACHE_FLASH_ATTR wifiStartScan() {
//	int x;
	if (cgiWifiAps.scanInProgress) return;
    if (newModeData.inProgress) {
        if (newModeData.newMode == STATIONAP_MODE)
            newModeData.needScan = 1;
        else
            httpd_printf("Must be in STA+AP mode to start AP scan: mode=%d\n", newModeData.newMode);
    }
    else {
        if (wifi_get_opmode() == STATIONAP_MODE) {
            httpd_printf("Starting scan...\n");
	        wifi_station_scan(NULL, wifiScanDoneCb);
 	        cgiWifiAps.scanInProgress=1;
        }
        else
            httpd_printf("Must be in STA+AP mode to start AP scan: mode=%d\n", wifi_get_opmode());
    }
}
Ejemplo n.º 15
0
void on_mqtt_data(uint32_t *args, const char *topic, uint32_t topic_len,
		  const char *data, uint32_t data_len)
{
	char cmd[256];

	if (data_len < sizeof(cmd)) {
		os_memcpy(cmd, data, data_len);
		cmd[data_len] = '\0';

		/* echo back the message */
		dmesg(cmd);

		if (strcmp("SCAN", cmd) == 0) {
			wifi_station_scan(NULL, on_scan_ready);
		} else if (strcmp("ADC_READ", cmd) == 0) {
			uint16 adc_in = system_adc_read();
			dmesg("adc_in=%hu", (unsigned short)adc_in);
		}
	}
}
Ejemplo n.º 16
0
static void ICACHE_FLASH_ATTR setModeCb(void *arg) {
    if (!newModeData.inProgress) return;
    switch (newModeData.newMode) {
    case STATION_MODE:
    case SOFTAP_MODE:
    case STATIONAP_MODE:
httpd_printf("setModeCb: %d\n", newModeData.newMode);
        wifi_set_opmode(newModeData.newMode);
        break;
    default:
        httpd_printf("setModeCb: invalid mode %d\n", newModeData.newMode);
        break;
    }
    if (newModeData.needScan) {
        httpd_printf("Starting deferred scan...\n");
        wifi_station_scan(NULL, wifiScanDoneCb);
        cgiWifiAps.scanInProgress=1;
    }
    newModeData.inProgress = 0;
}
Ejemplo n.º 17
0
static int wifi_station_listap( lua_State* L )
{
  if(wifi_get_opmode() == SOFTAP_MODE)
  {
    return luaL_error( L, "Can't list ap in SOFTAP mode" );
  }
  gL = L;
  // luaL_checkanyfunction(L, 1);
  if (lua_type(L, 1) == LUA_TFUNCTION || lua_type(L, 1) == LUA_TLIGHTFUNCTION){
    lua_pushvalue(L, 1);  // copy argument (func) to the top of stack
    if(wifi_scan_succeed != LUA_NOREF)
      luaL_unref(L, LUA_REGISTRYINDEX, wifi_scan_succeed);
    wifi_scan_succeed = luaL_ref(L, LUA_REGISTRYINDEX);
    wifi_station_scan(NULL,wifi_scan_done);
  } else {
    if(wifi_scan_succeed != LUA_NOREF)
      luaL_unref(L, LUA_REGISTRYINDEX, wifi_scan_succeed);
    wifi_scan_succeed = LUA_NOREF;
  }
}
irom static app_action_t application_function_wlan_scan(const string_t *src, string_t *dst)
{
	if(wlan_scan_state != ws_inactive)
	{
		string_cat(dst, "wlan-scan: already scanning\n");
		return(app_action_error);
	}

#if IMAGE_OTA == 1
	if(ota_active())
	{
		string_cat(dst, "wlan-scan: ota active\n");
		return(app_action_error);
	}
#endif

	wlan_scan_state = ws_scanning;
	wifi_station_scan(0, wlan_scan_done_callback);
	string_cat(dst, "wlan scan started, use wlan-list to retrieve the results\n");

	return(app_action_normal);
}
Ejemplo n.º 19
0
static void ICACHE_FLASH_ATTR ost_wifi_scan(os_event_t *events){
	os_printf("WiFi Scan...\n");
	os_delay_us(10000);
	wifi_promiscuous_enable(0);
	wifi_station_scan(NULL, wifiScan_cb);
}
Ejemplo n.º 20
0
int http_wifi_api_scan(http_connection *c)
{
    //wait for whole body
    if(c->state <HTTPD_STATE_BODY_END) {
        return HTTPD_CGI_MORE;
    }

    api_cgi_scan_status * status = c->cgi.data;
    //first call, create status
    if(status==NULL)
    {
        //create status
        status = (api_cgi_scan_status*)os_malloc(sizeof(api_cgi_scan_status));
        status->state=1;
        status->ap_index=0;
        c->cgi.data=status;

        //if not already scanning, request scan
        if(!wifi_status.scanning)
        {
            // CGI_WIFI_DBG("Starting scan\n");
            wifi_station_scan(NULL,http_wifi_api_scan_callback);
            wifi_status.scanning=1;
        }

        //write headers
        http_SET_HEADER(c,HTTP_CONTENT_TYPE,JSON_CONTENT_TYPE);
        http_response_OK(c);

        //set state to 1 - waiting
        status->state=1;

        return HTTPD_CGI_MORE;
    }
    else
    {
        if (wifi_status.scanning)
        {
            // CGI_WIFI_DBG("Waiting scan done\n");

            //set timer to check again
            os_timer_disarm(&status->timer);
            os_timer_setfn(&status->timer, (os_timer_func_t *)http_execute_cgi, c);
            os_timer_arm(&status->timer, 500, 0);

            return HTTPD_CGI_MORE;
        }
        else if (status->state==1)
        {
            //clear timer
            os_timer_disarm(&status->timer);

            CGI_WIFI_DBG("Scan complete %d\n",status->ap_index);

            //create json
            cJSON *root = cJSON_CreateObject();
            cJSON_AddNumberToObject(root,"ap_count",wifi_status.scan_result.ap_count);

            cJSON * array;
            cJSON * item;
            cJSON_AddItemToObject(root, "ap", array = cJSON_CreateArray());

            int i;
            for(i=0; i< wifi_status.scan_result.ap_count; i++)
            {
                cJSON_AddItemToArray(array,item=cJSON_CreateObject());
                cJSON_AddStringToObject(item,"ssid",(const char *)wifi_status.scan_result.ap[i]->ssid);
                cJSON_AddNumberToObject(item,"rssi",wifi_status.scan_result.ap[i]->rssi);
                cJSON_AddNumberToObject(item,"enc",wifi_status.scan_result.ap[i]->enc);
                cJSON_AddNumberToObject(item,"channel",wifi_status.scan_result.ap[i]->channel);
            }

            http_write_json(c,root);

            //delete json struct
            cJSON_Delete(root);

            status->state=99;
            return HTTPD_CGI_MORE;
        }
        else  //free resources
        {
            CGI_WIFI_DBG("Freeing alloced memory\n");
            os_free(c->cgi.data);

            return HTTPD_CGI_DONE;
        }
    }
}
Ejemplo n.º 21
0
int ICACHE_FLASH_ATTR http_wifi_api_scan(http_connection *c) {
		
	NODE_DBG("http_wifi_api_scan");

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


	api_cgi_scan_status * status = c->cgi.data;
	if(status==NULL){ //first call, create status

		//create status
		status = (api_cgi_scan_status*)os_malloc(sizeof(api_cgi_scan_status));
		status->state=1;
		status->ap_index=0;
		c->cgi.data=status;

		if(!wifi_status.scanning){
			//if not already scanning, request scan

			NODE_DBG("Starting scan");

			wifi_station_scan(NULL,http_wifi_api_scan_callback);

			wifi_status.scanning=1;

		}

		//write headers
		http_SET_HEADER(c,HTTP_CONTENT_TYPE,JSON_CONTENT_TYPE);	
		http_response_OK(c);			

		//set state to 1 - waiting
		status->state=1;
		
		return HTTPD_CGI_MORE;

	}
	else{		

		if(wifi_status.scanning){
			NODE_DBG("Waiting scan done");

			//set timer to check again
			os_timer_disarm(&status->timer);
			os_timer_setfn(&status->timer, http_execute_cgi, c);
			os_timer_arm(&status->timer, 500, 0);

			return HTTPD_CGI_MORE;
		}			
		else if(status->state==1){	
			
			//clear timer
			os_timer_disarm(&status->timer);

			NODE_DBG("Scan complete %d",status->ap_index);

			//create json
			cJSON *root = cJSON_CreateObject();
			cJSON_AddNumberToObject(root,"ap_count",wifi_status.scan_result.ap_count);

			cJSON * array;
			cJSON * item;
			cJSON_AddItemToObject(root, "ap", array = cJSON_CreateArray());


			//check max count on query string
			char *query=http_url_get_query_param(c,"max");
			int max = INT_MAX;
			if(query!=NULL)		
				max = atoi(query);

			int i;
			for(i=0;i< wifi_status.scan_result.ap_count && i<max;i++){

				cJSON_AddItemToArray(array,item=cJSON_CreateObject());
				cJSON_AddStringToObject(item,"ssid",(const char *)wifi_status.scan_result.ap[i]->ssid);
				cJSON_AddNumberToObject(item,"rssi",wifi_status.scan_result.ap[i]->rssi);
				cJSON_AddNumberToObject(item,"enc",wifi_status.scan_result.ap[i]->enc);
				cJSON_AddNumberToObject(item,"channel",wifi_status.scan_result.ap[i]->channel);

			}

			http_write_json(c,root);	

			//delete json struct
			cJSON_Delete(root);

			status->state=99; 		
			return HTTPD_CGI_MORE;
						
			
		}
		else{ //free resources

			NODE_DBG("Freeing alloced memory");
			os_free(c->cgi.data); 		

			return HTTPD_CGI_DONE;
		}

	}

}
Ejemplo n.º 22
0
void ICACHE_FLASH_ATTR
at_setupCmdCwlap(uint8_t id, char *pPara)
{
  struct scan_config config;
  int8_t len;
  char ssid[32];
  char bssidT[18];
  char bssid[6];
  uint8_t channel;
  uint8_t i;

  pPara++;
//  os_printf("%x\r\n",*pPara);////
//  os_bzero(ssid, 32);

  len = at_dataStrCpy(ssid, pPara, 32);
//  os_printf("%d\r\n",len);////

  if(len == -1)
  {
    at_backError;
//    uart0_sendStr(at_backTeError"11\r\n");
    return;
  }
  if(len == 0)
  {
    config.ssid = NULL;
  }
  else
  {
    config.ssid = ssid;
  }
  pPara += (len+3);
//  os_printf("%x\r\n",*pPara);/////
  len = at_dataStrCpy(bssidT, pPara, 18);
//  os_printf("%d\r\n",len);////
  if(len == -1)
  {
    at_backError;
  //    uart0_sendStr(at_backTeError"11\r\n");
    return;
  }
  if(len == 0)
  {
    config.bssid = NULL;
  }
  else
  {
    if(os_str2macaddr(bssid, bssidT) == 0)
    {
      at_backError;
      return;
    }
    config.bssid = bssid;
  }
//  if(*pPara == ',')
//  {
//    config.bssid = NULL;
//  }
//  else
//  {
//    os_memcpy(bssidT,pPara,17);
//    bssidT[17] = '\0';
//    os_str2macaddr(bssid, bssidT);
//    config.bssid = bssid;
//  }
  pPara += (len+3);
  config.channel = atoi(pPara);

//  os_printf("%s,%s,%d\r\n",
//            config.ssid,
//            config.bssid,
//            config.channel);
  if(wifi_station_scan(&config, scan_done))
  {
    specialAtState = FALSE;
  }
  else
  {
    at_backError;
  }
}
Ejemplo n.º 23
0
static void scan() {
	os_timer_setfn(&scanTimer, (os_timer_func_t *)scan, NULL);
	wifi_station_scan(NULL, scan_done_slave);
}
Ejemplo n.º 24
0
//Routine to start a WiFi access point scan.
static void ICACHE_FLASH_ATTR wifiStartScan() {
//	int x;
	if (cgiWifiAps.scanInProgress) return;
	cgiWifiAps.scanInProgress=1;
	wifi_station_scan(NULL, wifiScanDoneCb);
}
Ejemplo n.º 25
0
static void ICACHE_FLASH_ATTR scanStartCb(void *arg) {
  DBG("Starting a scan\n");
  wifi_station_scan(NULL, wifiScanDoneCb);
}
Ejemplo n.º 26
0
/**
  * wifi.sta.listap()
  * Description:
  * 	scan and get ap list as a lua table into callback function.
  * Syntax:
  * 	wifi.sta.getap(function(table))
  * 	wifi.sta.getap(format, function(table))
  * 	wifi.sta.getap(cfg, function(table))
  * 	wifi.sta.getap(cfg, format, function(table))
  * Parameters:
  * 	cfg: table that contains scan configuration
  * 	Format:Select output table format.
  * 		0 for the old format (SSID : Authmode, RSSI, BSSID, Channel) (Default)
  * 		1 for the new format (BSSID : SSID, RSSI, Authmode, Channel)
  * 	function(table): a callback function to receive ap table when scan is done
			this function receive a table, the key is the ssid,
			value is other info in format: authmode,rssi,bssid,channel
  * Returns:
  * 	nil
  *
  * Example:
  	  --original function left intact to preserve backward compatibility
  	  wifi.sta.getap(function(T) for k,v in pairs(T) do print(k..":"..v) end end)

  	  --if no scan configuration is desired cfg can be set to nil or previous example can be used
  	  wifi.sta.getap(nil, function(T) for k,v in pairs(T) do print(k..":"..v) end end)

  	  --scan configuration
  	  scan_cfg={}
	  scan_cfg.ssid="myssid"  			 --if set to nil, ssid is not filtered
	  scan_cfg.bssid="AA:AA:AA:AA:AA:AA" --if set to nil, MAC address is not filtered
	  scan_cfg.channel=0  				 --if set to nil, channel will default to 0(scans all channels), if set scan will be faster
	  scan_cfg.show_hidden=1			 --if set to nil, show_hidden will default to 0
  	  wifi.sta.getap(scan_cfg, function(T) for k,v in pairs(T) do print(k..":"..v) end end)

  */
static int wifi_station_listap( lua_State* L )
{
  if(wifi_get_opmode() == SOFTAP_MODE)
  {
    return luaL_error( L, "Can't list ap in SOFTAP mode" );
  }
  gL = L;
  struct scan_config scan_cfg;
  getap_output_format=0;

  if (lua_type(L, 1)==LUA_TTABLE)
  {
	  char ssid[32];
	  char bssid[6];
	  uint8 channel=0;
	  uint8 show_hidden=0;
	  size_t len;

	  lua_getfield(L, 1, "ssid");
	  if (!lua_isnil(L, -1)){  /* found? */
	    if( lua_isstring(L, -1) )   // deal with the ssid string
	    {
	      const char *ssidstr = luaL_checklstring( L, -1, &len );
	      if(len>32)
	        return luaL_error( L, "ssid:<32" );
	      c_memset(ssid, 0, 32);
	      c_memcpy(ssid, ssidstr, len);
	      scan_cfg.ssid=ssid;
	      NODE_DBG(scan_cfg.ssid);
	      NODE_DBG("\n");
	    }
	    else
	      return luaL_error( L, "wrong arg type" );
	  }
	  else
		  scan_cfg.ssid=NULL;

	  lua_getfield(L, 1, "bssid");
	  if (!lua_isnil(L, -1)){  /* found? */
	    if( lua_isstring(L, -1) )   // deal with the ssid string
	    {
	      const char *macaddr = luaL_checklstring( L, -1, &len );
	      if(len!=17)
	        return luaL_error( L, "bssid: FF:FF:FF:FF:FF:FF" );
	      c_memset(bssid, 0, 6);
	      os_str2macaddr(bssid, macaddr);
	      scan_cfg.bssid=bssid;
	      NODE_DBG(MACSTR, MAC2STR(scan_cfg.bssid));
	      NODE_DBG("\n");

	    }
	    else
	      return luaL_error( L, "wrong arg type" );
	  }
	  else
		  scan_cfg.bssid=NULL;


	  lua_getfield(L, 1, "channel");
	  if (!lua_isnil(L, -1)){  /* found? */
	    if( lua_isnumber(L, -1) )   // deal with the ssid string
	    {
	      channel = luaL_checknumber( L, -1);
	      if(!(channel>=0 && channel<=13))
	        return luaL_error( L, "channel: 0 or 1-13" );
	      scan_cfg.channel=channel;
	      NODE_DBG("%d\n", scan_cfg.channel);
	    }
	    else
	      return luaL_error( L, "wrong arg type" );
	  }
	  else
		  scan_cfg.channel=0;

	  lua_getfield(L, 1, "show_hidden");
	  if (!lua_isnil(L, -1)){  /* found? */
	    if( lua_isnumber(L, -1) )   // deal with the ssid string
	    {
	      show_hidden = luaL_checknumber( L, -1);
	      if(show_hidden!=0 && show_hidden!=1)
	        return luaL_error( L, "show_hidden: 0 or 1" );
	      scan_cfg.show_hidden=show_hidden;
	      NODE_DBG("%d\n", scan_cfg.show_hidden);

	    }
	    else
	      return luaL_error( L, "wrong arg type" );
	  }
	  else
		  scan_cfg.show_hidden=0;
	  if (lua_type(L, 2) == LUA_TFUNCTION || lua_type(L, 2) == LUA_TLIGHTFUNCTION)
	  {
		  lua_pushnil(L);
		  lua_insert(L, 2);
	  }
	  lua_pop(L, -4);
  }
  else  if (lua_type(L, 1) == LUA_TNUMBER)
  {
	  lua_pushnil(L);
	  lua_insert(L, 1);
  }
  else  if (lua_type(L, 1) == LUA_TFUNCTION || lua_type(L, 1) == LUA_TLIGHTFUNCTION)
  {
	  lua_pushnil(L);
	  lua_insert(L, 1);
	  lua_pushnil(L);
	  lua_insert(L, 1);
  }
  else if(lua_isnil(L, 1))
  {
	  if (lua_type(L, 2) == LUA_TFUNCTION || lua_type(L, 2) == LUA_TLIGHTFUNCTION)
	  {
		  lua_pushnil(L);
		  lua_insert(L, 2);
	  }
  }
  else
  {
	  return luaL_error( L, "wrong arg type" );
  }


  if (lua_type(L, 2) == LUA_TNUMBER) //this section changes the output format
    {
	  getap_output_format=luaL_checkinteger( L, 2 );
	  if ( getap_output_format != 0 && getap_output_format != 1)
		  return luaL_error( L, "wrong arg type" );
    }
  NODE_DBG("Use alternate output format: %d\n", getap_output_format);
  if (lua_type(L, 3) == LUA_TFUNCTION || lua_type(L, 3) == LUA_TLIGHTFUNCTION)
  {
    lua_pushvalue(L, 3);  // copy argument (func) to the top of stack
    if(wifi_scan_succeed != LUA_NOREF)
      luaL_unref(L, LUA_REGISTRYINDEX, wifi_scan_succeed);
    wifi_scan_succeed = luaL_ref(L, LUA_REGISTRYINDEX);
    if (lua_type(L, 1)==LUA_TTABLE)
    {
    	wifi_station_scan(&scan_cfg,wifi_scan_done);
    }
    else
    {
    	wifi_station_scan(NULL,wifi_scan_done);
    }
  }
  else
  {
    if(wifi_scan_succeed != LUA_NOREF)
      luaL_unref(L, LUA_REGISTRYINDEX, wifi_scan_succeed);
    wifi_scan_succeed = LUA_NOREF;
  }
}
Ejemplo n.º 27
0
// ----------------------------------------------------------------------------
// Routine to start a WiFi access point scan.
// ----------------------------------------------------------------------------
static void ICACHE_FLASH_ATTR logwifiaps(void)
{
    if(scanInProgress) return;               // if we called it before, then dont do that until it is done
    scanInProgress = 1;                      // Set the flag to make sure we dont call it twice
    wifi_station_scan(NULL, wifiSendCb);     // kicks things off, when done, the Cb function is called
}