Exemplo n.º 1
0
void StationClass::staticScanCompleted(void *arg, STATUS status)
{
	BssList list;
	if (status == OK)
	{
		if (WifiStation.scanCompletedCallback )
		{
			bss_info *cur = (bss_info*)arg;

			while (cur != NULL)
			{
				list.add(BssInfo(cur));
				cur = cur->next.stqe_next;
			}
			WifiStation.scanCompletedCallback(true, list);
		}

		debugf("scan completed: %d found", list.count());
	}
	else
	{
		debugf("scan failed %d", status);
		if (WifiStation.scanCompletedCallback )
			WifiStation.scanCompletedCallback(false, list);
	}
}
Exemplo n.º 2
0
void networkScanCompleted(bool succeeded, BssList list) {
	if (succeeded) {
		for (int i = 0; i < list.count(); i++)
			if (!list[i].hidden && list[i].ssid.length() > 0)
				networks.add(list[i]);
		scanStatus = 2;
	}
	networks.sort([](const BssInfo& a, const BssInfo& b){ return b.rssi - a.rssi; } );
}
Exemplo n.º 3
0
void onAjaxNetworkList(HttpRequest &request, HttpResponse &response)
{
	JsonObjectStream* stream = new JsonObjectStream();
	JsonObject& json = stream->getRoot();

	json["status"] = (bool)true;

	bool connected = WifiStation.isConnected();
	json["connected"] = connected;
	if (connected)
	{
		currentNetwork = WifiStation.getSSID();
		json["network"] = currentNetwork.c_str();
	}

	JsonArray& netlist = json.createNestedArray("available");
	for (int i = 0; i < networks.count(); i++)
	{
		//if (networks[i].hidden) continue;
		JsonObject &item = netlist.createNestedObject();
		//debugf("%s %s", test.c_str(), networks[i].ssid.c_str());
		item.add("id", (int)networks[i].getHashId());
		item.add("title", networks[i].ssid.c_str());
		item.add("signal", networks[i].rssi);
		item.add("encryption", networks[i].getAuthorizationMethodName());
	}

	response.setAllowCrossDomainOrigin("*");
	response.sendJsonObject(stream);
}
Exemplo n.º 4
0
void onAjaxNetworkList(HttpRequest &request, HttpResponse &response)
{
	JsonObjectStream* stream = new JsonObjectStream();
	JsonObject& json = stream->getRoot();

	json["status"] = (bool)true;

	bool connected = WifiStation.isConnected();
	json["connected"] = connected;
	if (connected)
	{
		// Copy full string to JSON buffer memory
		json["network"]= WifiStation.getSSID();
	}

	JsonArray& netlist = json.createNestedArray("available");
	for (int i = 0; i < networks.count(); i++)
	{
		if (networks[i].hidden) continue;
		JsonObject &item = netlist.createNestedObject();
		item["id"] = (int)networks[i].getHashId();
		// Copy full string to JSON buffer memory
		item["title"] = networks[i].ssid;
		item["signal"] = networks[i].rssi;
		item["encryption"] = networks[i].getAuthorizationMethodName();
	}

	response.setAllowCrossDomainOrigin("*");
	response.sendJsonObject(stream);
}
Exemplo n.º 5
0
void sendWiFiAPListToPeer(CAbstractPeer* peer, BssList& list)
{
	size_t sizePkt = m_snprintf(g_devScrapBuffer, sizeof(g_devScrapBuffer),
						"%d;%d;", cwReportWiFiList, list.count());

	for (int i = 0; i < list.count(); i++)
	{
		sizePkt += m_snprintf(g_devScrapBuffer + sizePkt,
							(uint32_t)(sizeof(g_devScrapBuffer) - sizePkt),
							"%s;%02x:%02x:%02x:%02x:%02x:%02x;%s;%d;%d;%d;",
							list[i].ssid.c_str(),
							list[i].bssid[0], list[i].bssid[1], list[i].bssid[2],
							list[i].bssid[3], list[i].bssid[4], list[i].bssid[5],
							list[i].getAuthorizationMethodName(), list[i].channel,
							list[i].rssi, list[i].hidden ? 1:0);
	}

	LOG_I("wifi list:%s", g_devScrapBuffer);
	peer->sendToPeer((const char*)g_devScrapBuffer, sizePkt);
}
void AppWIFI::scanCompleted(bool succeeded, BssList list) {
	debugapp("AppWIFI::scanCompleted");
	if (succeeded)
	{
		_networks.clear();
		for (int i = 0; i < list.count(); i++)
			if (!list[i].hidden && list[i].ssid.length() > 0)
				_networks.add(list[i]);
	}
	_networks.sort([](const BssInfo& a, const BssInfo& b){ return b.rssi - a.rssi; } );
	_scanning = false;
}
// Will be called when WiFi station network scan was completed
void listNetworks(bool succeeded, BssList list)
{
	if (!succeeded)
	{
		Serial.println("Failed to scan networks");
		return;
	}

	Serial.print("Found ");
	Serial.print(list.count());
	Serial.println(" networks.");

	for (int i = 0; i < list.count(); i++)
	{
		Serial.print(list[i].ssid);
		if (list[i].ssid.startsWith(NETWORK_PREFIX)) {
			Serial.print(" -> XIAOYI");
			WifiStation.config(list[i].ssid, WIFI_PWD);
		}
		Serial.println();
	}
}
Exemplo n.º 8
0
void web_cb_scan_status(HttpRequest &request, HttpResponse &response) {
	JsonObjectStream* stream = new JsonObjectStream();
	JsonObject& json = stream->getRoot();
	JsonArray& netlist = json.createNestedArray("available");
	for (int i = 0; i < networks.count(); i++) {
		JsonObject &item = netlist.createNestedObject();
		item.add("id", (int)networks[i].getHashId());
		item.add("title", networks[i].ssid.c_str());
		item.add("signal", networks[i].rssi);
		item.add("encryption", networks[i].getAuthorizationMethodName());
	}

	response.setAllowCrossDomainOrigin("*");
	response.sendJsonObject(stream);
}