1
#include <ichnaea/client.h>
3
#include <com/ubuntu/location/connectivity/manager.h>
5
#include <core/dbus/macros.h>
6
#include <core/dbus/object.h>
7
#include <core/dbus/signal.h>
9
#include <core/net/http/client.h>
14
namespace connectivity = com::ubuntu::location::connectivity;
18
auto manager = connectivity::platform_default_manager();
19
auto http_client = core::net::http::make_client();
21
std::thread worker1{[http_client]() {http_client->run();}};
23
auto client = std::make_shared<ichnaea::Client>("test", http_client);
25
manager->wireless_network_scan_finished().connect([manager, client]
27
std::cout << "Wireless network scan finished" << std::endl;
29
std::vector<connectivity::WirelessNetwork::Ptr> wifis;
31
manager->enumerate_visible_wireless_networks([&wifis](const connectivity::WirelessNetwork::Ptr& wifi)
33
wifis.push_back(wifi);
36
ichnaea::geolocate::Parameters params;
37
params.consider_ip = true;
39
for (auto wifi : wifis)
41
ichnaea::WifiAccessPoint ap;
42
ap.bssid = wifi->bssid().get();
43
ap.ssid = wifi->ssid().get();
44
ap.frequency = wifi->frequency().get();
45
ap.signal_strength = wifi->signal_strength().get();
47
params.wifi_access_points.insert(ap);
52
client->geolocate(params, [client, params](const ichnaea::Response<ichnaea::geolocate::Result>& response)
54
if (not response.is_error())
56
std::cout << "Submitting to the service again." << std::endl;
57
ichnaea::geosubmit::Parameters submission;
58
ichnaea::geosubmit::Report report;
59
report.timestamp = std::chrono::system_clock::now();
60
report.position.latitude = response.result().location.lat;
61
report.position.longitude = response.result().location.lon;
62
report.position.accuracy = response.result().accuracy;
63
report.wifi_access_points = params.wifi_access_points;
64
submission.reports.push_back(report);
66
client->geosubmit(submission, [](const ichnaea::Response<ichnaea::geosubmit::Result>& response)
68
if (not response.is_error())
69
std::cout << "Successfully submitted to service." << std::endl;
71
std::cout << "Error submitting to service: " << response.error() << std::endl;
76
std::cout << "Error querying service for location: " << response.error() << std::endl;
80
client->region(params, [](const ichnaea::Response<ichnaea::region::Result>& response)
82
if (not response.is_error())
83
std::cout << response.result().country_code << ", " << response.result().country_name << std::endl;
85
std::cout << "Error querying service for region information: " << response.error() << std::endl;
88
catch (const std::exception& e)
90
std::cout << e.what() << std::endl;
96
manager->request_scan_for_wireless_networks();
97
std::this_thread::sleep_for(std::chrono::seconds{15});