I found some code here on the forum a while ago that used a google api to determine the position of the imp from the surrounding wifi networks.
So far I haven’t used it for anything real, but today I noticed it no longer could find the coordinates in the json reply from google.
`function addColons(bssid)
{
local result = bssid.slice(0, 2);
for (local i = 2; i < 12; i += 2)
{
result += ":" + bssid.slice(i, (i + 2));
}
return result;
}
device.on(“location”, function (location)
{
local url = “https://maps.googleapis.com/maps/api/browserlocation/json?browser=electric-imp&sensor=false”;
foreach (network in location)
{
url += ("&wifi=mac:" + addColons(network.bssid) + "|ss:" + network.rssi);
}
local request = http.get(url);
local response = request.sendsync();
if (response.statuscode == 200)
{
local data = http.jsondecode(response.body);
server.log("http://maps.google.com/maps?q=loc:" + data.location.lat + "," + data.location.lng);
}
});`
The error it returns is
2014-08-30 13:25:39 UTC+2 [Agent] ERROR: the index 'location' does not exist 2014-08-30 13:25:39 UTC+2 [Agent] ERROR: at unknown:28
where line 28 is where it returns the http://maps.google.com/maps… url.
I don’t think I touched the code since I tried it successfully last time…?
To trigger the function the device sends a
agent.send("location", imp.scanwifinetworks());
to the agent.