Json no longer able to decode

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.

What do you see if you server.log(response.body) just before the jsondecode line?


It returns the table with the json I expected to get.

{ "accuracy" : 122, "location" : { "lat" : 0.000000, "lng" : 0.000000 }, "status" : "OK" }
(I changed lat and lng to zeroes)

Problem found… Someone used all allowed requests to the api from the electric imp servers. Tested the returned data on another system.