예제 #1
0
static void __wifi_activated_cb(wifi_error_e result, void *user_data)
{
    OIC_LOG(INFO, LOG_TAG, "__wifi_activated_cb");
    if (result == WIFI_ERROR_NONE)
    {
        OIC_LOG(INFO,LOG_TAG,"#### Success to activate Wi-Fi device!");
    }
    wifi_scan(__scan_request_cb, NULL);

}
예제 #2
0
파일: scan.c 프로젝트: danathughes/esp-idf
void app_main()
{
    // Initialize NVS
    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK( ret );

    wifi_scan();
}
예제 #3
0
int main(int argc, char *argv[])
{
	int rc = inetcfg_init();
	if (rc != EOK) {
		printf("%s: Failed connecting to inetcfg service (%d).\n",
		    NAME, rc);
		return 1;
	}
	
	rc = dhcp_init();
	if (rc != EOK) {
		printf("%s: Failed connecting to dhcp service (%d).\n",
		    NAME, rc);
		return 1;
	}
	
	if (argc == 2) {
		if (!str_cmp(argv[1], "list"))
			return wifi_list();
	} else if (argc > 2) {
		uint32_t index;
		rc = str_uint32_t(argv[2], NULL, 10, false, &index);
		if (rc != EOK) {
			printf("%s: Invalid argument.\n", NAME);
			print_syntax();
			return EINVAL;
		}
		
		if (!str_cmp(argv[1], "scan")) {
			bool now = false;
			if (argc > 3)
				if (!str_cmp(argv[3], "-n"))
					now = true;
			
			return wifi_scan(index, now);
		} else if (!str_cmp(argv[1], "connect")) {
			char *pass = NULL;
			if (argc > 3) {
				if (argc > 4)
					pass = argv[4];
				
				return wifi_connect(index, argv[3], pass);
			}
		} else if (!str_cmp(argv[1], "disconnect"))
			return wifi_disconnect(index);
	}
	
	print_syntax();
	
	return EOK;
}
예제 #4
0
파일: wifi.c 프로젝트: liuhangyu/wifi
int main (int argc, char *argv[])
{
	struct wifi_interface wi;
	if (argc != 3)
		return usage(argv[0]);
	if (wifi_interface(&wi, argv[1]))
		return 2;
	if (!strcmp("scan", argv[2])) {
	  int err = 0;
	  err |= wifi_scan(&wi);
	  print_nodes(&wi);
	  err |= wifi_interface_close(&wi);
	  return err;
	}
	return 0;
}
예제 #5
0
static void ESActivateWifi()
{
    int error_code;
    error_code = wifi_initialize();
    OIC_LOG_V(INFO,LOG_TAG,"#### WIFI INITIALIZED WITH STATUS :%d", error_code);

    error_code = wifi_activate(__wifi_activated_cb, NULL);
    OIC_LOG_V(INFO,LOG_TAG,"#### WIFI ACTIVATED WITH STATUS :%d", error_code);

    bool wifi_activated = false;
    wifi_is_activated(&wifi_activated);
    if (wifi_activated)
    {
        OIC_LOG(INFO,LOG_TAG,"#### Success to get Wi-Fi device state.");
        int scan_result = wifi_scan(__scan_request_cb, NULL);
        OIC_LOG_V(INFO,LOG_TAG,"#### Wifi scan result:%d", scan_result);
    }
    else
    {
        OIC_LOG(ERROR,LOG_TAG, "#### Fail to get Wi-Fi device state.");
    }
}
예제 #6
0
int wifi_scan_networks(rtw_scan_result_handler_t results_handler, void* user_data)
{
	unsigned int max_ap_size = 64;

#if SCAN_USE_SEMAPHORE
	rtw_bool_t result;
	if(NULL == scan_result_handler_ptr.scan_semaphore)
		rtw_init_sema(&scan_result_handler_ptr.scan_semaphore, 1);
	
	scan_result_handler_ptr.scan_start_time = rtw_get_current_time();
	/* Initialise the semaphore that will prevent simultaneous access - cannot be a mutex, since
	* we don't want to allow the same thread to start a new scan */
	result = (rtw_bool_t)rtw_down_timeout_sema(&scan_result_handler_ptr.scan_semaphore, SCAN_LONGEST_WAIT_TIME);
	if ( result != RTW_TRUE )
	{
		/* Return error result, but set the semaphore to work the next time */
		rtw_up_sema(&scan_result_handler_ptr.scan_semaphore);
		return RTW_TIMEOUT;
	}
#else
	if(scan_result_handler_ptr.scan_running){
		int count = 100;
		while(scan_result_handler_ptr.scan_running && count > 0)
		{
			rtw_msleep_os(20);
			count --;
		}
		if(count == 0){
			printf("\n\r[%d]WiFi: Scan is running. Wait 2s timeout.", rtw_get_current_time());
			return RTW_TIMEOUT;
		}
	}
	scan_result_handler_ptr.scan_start_time = rtw_get_current_time();
	scan_result_handler_ptr.scan_running = 1;
#endif

	scan_result_handler_ptr.gscan_result_handler = results_handler;
	
	scan_result_handler_ptr.max_ap_size = max_ap_size;
	scan_result_handler_ptr.ap_details = (rtw_scan_result_t*)rtw_zmalloc(max_ap_size*sizeof(rtw_scan_result_t));
	if(scan_result_handler_ptr.ap_details == NULL){
		goto error_with_result_ptr;
	}
	rtw_memset(scan_result_handler_ptr.ap_details, 0, max_ap_size*sizeof(rtw_scan_result_t));

	scan_result_handler_ptr.pap_details = (rtw_scan_result_t**)rtw_zmalloc(max_ap_size*sizeof(rtw_scan_result_t*));
	if(scan_result_handler_ptr.pap_details == NULL)
		return RTW_ERROR;
	rtw_memset(scan_result_handler_ptr.pap_details, 0, max_ap_size);
	
	scan_result_handler_ptr.scan_cnt = 0;

	scan_result_handler_ptr.scan_complete = RTW_FALSE;
	scan_result_handler_ptr.user_data = user_data;

	if (wifi_scan( RTW_SCAN_COMMAMD<<4 | RTW_SCAN_TYPE_ACTIVE, RTW_BSS_TYPE_ANY, NULL) != RTW_SUCCESS)
	{
		goto error_with_result_ptr;
	}

	return RTW_SUCCESS;

error_with_result_ptr:
	rtw_free((u8*)scan_result_handler_ptr.pap_details);
	scan_result_handler_ptr.pap_details = NULL;
	return RTW_ERROR;
}
예제 #7
0
int wifi_scan_networks_with_ssid(rtw_scan_result_handler_t results_handler, void* user_data, char* ssid, int ssid_len){
	int scan_cnt = 0, add_cnt = 0;
	scan_buf_arg scan_buf;
	int ret;

	scan_buf.buf_len = *((int*)user_data);
	scan_buf.buf = (char*)pvPortMalloc(scan_buf.buf_len);
	if(!scan_buf.buf){
		printf("\n\rERROR: Can't malloc memory");
		return RTW_NOMEM;
	}
	//set ssid
	memset(scan_buf.buf, 0, scan_buf.buf_len);
	if(ssid && ssid_len > 0 && ssid_len <= 32){
		memcpy(scan_buf.buf, &ssid_len, sizeof(int));
		memcpy(scan_buf.buf+sizeof(int), ssid, ssid_len);
	}
	//Scan channel	
	if(scan_cnt = (wifi_scan(RTW_SCAN_TYPE_ACTIVE, RTW_BSS_TYPE_ANY, &scan_buf)) < 0){
		printf("\n\rERROR: wifi scan failed");
		ret = RTW_ERROR;
	}else{
		int plen = 0;
		while(plen < scan_buf.buf_len){
			int len, rssi, ssid_len, i;
			u8 wps_password_id, security_mode;
			char *mac, *ssid;
			//u8 *security_mode;
			printf("\n\r");
			// len
			len = (int)*(scan_buf.buf + plen);
			printf("len = %d, ", len);
			// check end
			if(len == 0) break;
			// mac
			mac = scan_buf.buf + plen + 1;
			printf("mac = ");
			for(i=0; i<6; i++)
				printf("%02x,", *(u8*)(mac+i));
			// rssi
			memcpy(&rssi, (scan_buf.buf + plen + 1 + 6), sizeof(int));
			printf(" rssi = %d, ", rssi);
			// security_mode
			security_mode = *(scan_buf.buf + plen + 1 + 6 + 4);
				switch (security_mode) {
			case IW_ENCODE_ALG_NONE:
				printf("sec = open    , ");
				break;
			case IW_ENCODE_ALG_WEP:
				printf("sec = wep     , ");
				break;
			case IW_ENCODE_ALG_CCMP:
				printf("sec = wpa/wpa2, ");
				break;
			}
			// password id
			wps_password_id = *(scan_buf.buf + plen + 1 + 6 + 4 + 1);
			printf("wps password id = %d, ", wps_password_id);
			
			printf("channel = %d ", *(scan_buf.buf + plen + 1 + 6 + 4 + 1 + 1));
			// ssid
			ssid_len = len - 1 - 6 - 4 - 1 - 1 - 1;
			ssid = scan_buf.buf + plen + 1 + 6 + 4 + 1 + 1 + 1;
			printf("ssid = ");
			for(i=0; i<ssid_len; i++)
				printf("%c", *(ssid+i));
			plen += len;
			add_cnt++;
		}

		printf("\n\rwifi_scan: add count = %d, scan count = %d", add_cnt, scan_cnt);
		ret = RTW_SUCCESS;
	}

	if(scan_buf.buf)
	    vPortFree(scan_buf.buf);
	
	return ret;
}
int main()
{
  wifi_start(31, 30, 115200, WX_ALL_COM);
  wifi_setBuffer(str, sizeof(str));

  int tcpHandle = wifi_connect("api.openweathermap.org", 80);
  
  print("tcpHandle = %d\r", tcpHandle);
  
  pause(2000);
  
  // IMPORTANT: Replace YourKeyYourKey... with the API key you 
  // obtain from openweathermap.com when you create a free 
  // account. 

  char request[] = 
  "GET /data/2.5/weather?zip=95677,us"\
  "&appid=YourKeyYourKeyYourKeyYourKeyYour"\
  " HTTP/1.1\r\n"\
  "Host: api.openweathermap.org\r\n"\
  "Connection: keep-alive\r\n"\
  "Accept: *" "/" "*\r\n\r\n";

  int size = strlen(request);
  
  print("GET req size: %d\r", size);
  
  pause(2000);

  wifi_print(TCP, tcpHandle, "%s", request);
  event = wifi_event;
  
  pause(2000);
  size = strlen(str);
  print("size = %d", size);
  
  pause(2000);
  wifi_scan(TCP, tcpHandle, "%s", str); 
  for(int n = 0; n < sizeof(str); n++)
  {
    if(str[n] <= 'z' && str[n] >= ' ')
    {
      print("%c", str[n]);
    }      
    else if(str[n] == 0)
    {
      print("[%d]", str[n]);
      break;
    }      
    else if(str[n] == '\n')
    {
      print("\r", str[n]);
    }      
    else
    {
      print("[%d]", str[n]);
    }      
  }
  char *loc = strstr(str, "temp");
  print("\rloc = %d\r", loc);
  float temp = 0;
  sscan(loc+5, "%f", &temp);
  float degC = temp -273.15;
  print("temp = %6.2f deg C\r", degC); 
  float degF = degC * 9.0 / 5.0 + 32.0;
  print("temp = %6.2f deg C\r", degF); 
}