Created
May 3, 2018 01:41
-
-
Save cpq/31ed976d9947d978f0c9ac8466f440cd to your computer and use it in GitHub Desktop.
ble beacon logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doPost(e) { | |
try { | |
var obj = JSON.parse(e.postData.contents); | |
var doc = SpreadsheetApp.getActiveSpreadsheet(); | |
var name = obj.id || 'DATA'; | |
var sheet = doc.getSheetByName(name); | |
if (!sheet) { | |
doc.insertSheet(name); | |
sheet = doc.getSheetByName(name); | |
range = sheet.getRange("H1:Z1"); | |
sheet.deleteColumns(8, range.getNumColumns()); | |
if (obj.names) sheet.appendRow(obj.names); | |
} | |
var points = obj.points || []; | |
for (var i = 0; i < points.length; i++) { | |
sheet.appendRow(points[i]); | |
} | |
return ContentService // return json success results | |
.createTextOutput(JSON.stringify({"result": "success", obj: obj})) | |
.setMimeType(ContentService.MimeType.JSON); | |
} catch (error) { // if error return this | |
return ContentService | |
.createTextOutput(JSON.stringify({"result": "error", "error": error})) | |
.setMimeType(ContentService.MimeType.JSON); | |
} | |
} | |
var eirtypes = { | |
'01': 'flags', | |
'02': 'incomplete_uuid16', | |
'03': 'complete_uuid16', | |
'04': 'incomplete_uuid32', | |
'05': 'complete_uuid32', | |
'06': 'incomplete_uuid128', | |
'07': 'complete_uuid128', | |
'08': 'short_name', | |
'09': 'full_name', | |
'0a': 'tx_power', | |
'10': 'id', | |
'18': 'random_addr', | |
'19': 'appearance', | |
'25': 'url', | |
'ff': 'specific_data', | |
}; | |
function ad(s) { | |
//Logger.log(Object.getOwnPropertyNames(Array.prototype)) | |
var i, a1 = [], a = [], out = []; | |
for (i = 0; i < s.length; i+= 2) a1.push(s.substr(i, 2)); | |
for (i = 0; i < a1.length; i++) a.push(parseInt(a1[i], 16)); | |
for (i = 0; i < a.length && a[i] != 0; i += 1 + a[i]) { | |
var type = a1[i + 1], len = a[i]; | |
out = out.concat(['Type: ', type, ' (', eirtypes[type] || '?', '), ']); | |
out.push(a1.slice(i + 2, i + 2 + len - 1).join('')); | |
out.push('\n'); | |
} | |
return out.join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment