In the code for the device side of BLE112 on GitHub, there’s this function I’d like to modify slightly to get just the “beacon” variable (a table) as the final value reported from the function in a way that I can store such outcome into a global variable (let’s say: myBeacons<-{}). How can I do that? Where can I assign the “return” statement of the function to achieve that?
//…
function discover_mode(active = false) {// Setup the scanning in passive mode ble112.gap_set_scan_parameters(75, 50, active ? 1 : 0); // start scanning for peripherals ble112.gap_discover(BLE_GAP_DISCOVER_MODE.GAP_DISCOVER_GENERIC); // Handle incoming scan responses here ble112.on("gap_scan_response", function(event) { // Parse the advertising packet foreach (advdata in event.payload.data) { if (advdata.type == BLE_GAP_AD_TYPES.GAP_AD_TYPE_MANUFACTURER_DATA) { // This is an ibeacon if (advdata.data.slice(0, 4) == "\x4c\x00\x02\x15") { // This is an iBeacon local uuid = advdata.data.slice(4, 20); uuid = parse_uuid(uuid); if (uuid in uuids) { local major = advdata.data.slice(20, 22); major = (major[0] << 8) + (major[1]); local minor = advdata.data.slice(22, 24); minor = (minor[0] << 8) + (minor[1]); local power = advdata.data[24]; local beaconid = format("%s:%d:%d", uuid, major, minor) if (!(beaconid in scans)) { scans[beaconid] <- {}; scans[beaconid].rssi <- {}; scans[beaconid].rssi[address] <- {}; scans[beaconid].rssi[address].time <- time(); scans[beaconid].rssi[address].samples <- 0; scans[beaconid].rssi[address].rssi <- 0.0; } local beacon = scans[beaconid]; beacon.uuid <- uuid; beacon.major <- major; beacon.minor <- minor; beacon.time <- time(); beacon.rssi[address].samples++; beacon.rssi[address].rssi += event.payload.rssi; beacon.rssi[address].rssi /= 2; } } } } })
}
Thanks in advance,
Aquiles