コード例 #1
0
ファイル: WIFI.cpp プロジェクト: Pfannex/ESP8266_Basic
//...............................................................................
//  WiFi start connection
//...............................................................................
void WIFI::start() {
  staMode     = ffs.cfg.readItem("wifi"); // off, dhcp, manual
  apMode      = ffs.cfg.readItem("ap");   // on, off, auto

  logging.info("MAC address: "+macAddress());

  // some workaround for WiFi.status() showing disconnect although WiFi
  // is connected
  WiFi.disconnect(true);
  WiFi.persistent(false);
  //ESP.eraseConfig();
  WiFi.mode(WIFI_OFF);

  if (staMode=="off" and apMode=="off"){
    logging.info("WiFi staMode=off and apMode=off -> no WiFi functions available!");
  } else if (apMode=="on") {
    logging.info("WiFi apMode=on -> starting AP");
    startAP(true);
  } else if (staMode=="off" and apMode=="auto") {
    logging.info("WiFi staMode=off and apMode=auto -> starting AP");
    startAP(true);

  } else {  //staMode dhcp or auto
    startSTA();
  }
}
コード例 #2
0
ファイル: WIFI.cpp プロジェクト: Pfannex/ESP8266_Basic
String WIFI::get(Topic &topic) {
  if (topic.itemIs(3, "macAddress")) {
    return macAddress();
  } else if (topic.itemIs(3, "scanResult")){
    return scanResult();
  } else {
    return TOPIC_NO;
  }
}
コード例 #3
0
ファイル: toolkit_windows.cpp プロジェクト: public0821/npg
std::vector<ifi_info> SocketToolkit::ifiInfo(int family, int doaliases)
{
	std::vector<ifi_info> ifi_infos;

	char errbuf[PCAP_ERRBUF_SIZE];
	pcap_if_t *alldevs = NULL;

	/* get all device */
	if (pcap_findalldevs(&alldevs, errbuf) == -1)
	{
		LOG_ERROR(QObject::tr( "Error in pcap_findalldevs: %1").arg( errbuf));
		return ifi_infos;
	}
	if (alldevs == NULL)
	{
		LOG_ERROR("No interfaces found! Make sure WinPcap is installed.");
		return ifi_infos;
	}

	pcap_if_t *device = NULL;
	for (device = alldevs; device; device = device->next)
	{
		struct ifi_info ifi;
		strncpy(ifi.ifi_name, device->name, sizeof(ifi.ifi_name));
		pcap_addr_t *local_address;
		//get ip address and netmask
		for (local_address = device->addresses; local_address != NULL; local_address = local_address->next)
		{
			if (local_address->addr->sa_family != AF_INET)
			{
				continue;
			}
			ifi.ifi_addr = *(local_address->addr);
			struct sockaddr_in * sin = (struct sockaddr_in *) &(ifi.ifi_addr);
			int ret = macAddress(inet_ntoa(sin->sin_addr), ifi.ifi_haddr);
			if(-1 != ret)
			{
				ifi_infos.push_back(ifi);
			}
			break;
		}
	}

	pcap_freealldevs(alldevs);

	return ifi_infos;
}
コード例 #4
0
void processSamples(int nSamples, IPOD_SAMPLE *samples)
{
#ifdef VERBOSE
	PRINT_ERR("Processing %d samples\n", nSamples);
#endif
	//for each of the samples
	for(int sam = 0; sam < nSamples; sam++)
	{
		int nAPs = samples[sam].nAPs;
#ifdef VERBOSE
        PRINT_ERR("Sample %d contains %d APs\n",sam+1,nAPs);
#endif
		float lat, lon;
		//lat long sample was taken at
		lat = samples[sam].lat;
		lon = samples[sam].lon;
#ifdef VERBOSE
        PRINT_ERR("Latitude: %f Longitude: %f\n",lat,lon);
#endif
		//convenience pointer to beginning of APs
		APINFO *apIter = samples[sam].APs;

		//for each ap
		for(int ap = 0; ap < nAPs; ap++)
		{
			//c++ string for MAC because they're awesome
			std::string macAddress(apIter[ap].mac);
			sample_info s;
			s.latitude = lat;
			s.longitude = lon;
			s.rssi = apIter[ap].rssi;
#ifdef VERBOSE
        PRINT_ERR("MAC Address: %s RSSI: %d \n",macAddress.c_str(),s.rssi);
#endif
			samplesSoFar[macAddress].push_back(s);
		}
	}
	//iterate through the map
	//construct 
	std::map<std::string,std::vector<sample_info> >::iterator it = samplesSoFar.begin();
	for(; it != samplesSoFar.end(); it++)
	{
		//number of processed samples
		int nProc = it->second.size();
		//set a threshold that 10+ samples must be present before trilateration can occur
		if(nProc >= 10)
		{
			std::vector<float> lats;
			std::vector<float> lons;
			std::vector<int32_t> rssis;
			
			std::vector<sample_info>::iterator sInfoIter = it->second.begin();
			for(; sInfoIter != it->second.end(); sInfoIter++)
			{
				lats.push_back(sInfoIter->latitude);
				lons.push_back(sInfoIter->longitude);
				rssis.push_back(sInfoIter->rssi);
			}
			//generate a position for this WAP
			if(generateWAPPosition(lats,lons,rssis,it->first));
				it->second.clear();
		}
	}
}