Code to display multiple RSSI data on web page

To help position my Imps I’d like to display signal strength for multiple access points. The code below is almost working, but after the wifi array is sent to the agent all array indexes are invalid. What did I miss?
Agent:
`
local wifi = {};

http.onrequest(function(request,res){
if (request.body == “”) {
device.send(“getwifi”,0);
res.send(200,
@“


wifi_rssi: " + wifi[0].rssi + wifi[1].rssi +
@”
"

    );
}

});

device.on(“sendwifi”, function(data) {
wifi = data;
});
Device:
local wifi = {};

agent.on(“getwifi”, function(data) {
scanwifi();
agent.send(“sendwifi”, wifi);
});

function scanwifi() {

local scanResults = imp.scanwifinetworks();

foreach (idx,val in scanResults) { 
  if (scanResults[idx].ssid == "my_ssid1" ) {
    server.log("SSID="+ scanResults[idx].ssid +" Ch="+scanResults[idx].channel + " rssi="+scanResults[idx].rssi );
    wifi[0] <- {
      ssid = scanResults[idx].ssid,
      channel = scanResults[idx].channel,
      rssi = scanResults[idx].rssi
    };
  }
  if (scanResults[idx].ssid == "my_ssid2") {
    server.log("SSID="+ scanResults[idx].ssid +" Ch="+scanResults[idx].channel + " rssi="+scanResults[idx].rssi );
    wifi[1] <- {
      ssid = scanResults[idx].ssid,
      channel = scanResults[idx].channel,
      rssi = scanResults[idx].rssi
    };
    
  }
}

}

`