Hi guys, I’m back with a couple questions. I’ve formatted my particle so that it outputs the cellular signal, but I seem to be having a little trouble getting it to actually add to the spreadsheet. When I put my postman request in, I get these results:
{
"cmd": "VarReturn",
"name": "result",
"result": "{data1: -73 \n data2: 37}",
"coreInfo": {
"last_app": "",
"last_heard": "2016-07-14T13:49:55.945Z",
"connected": true,
"last_handshake_at": "2016-07-14T13:32:05.070Z",
"deviceID": "MY-DEVICE-ID",
"product_id": 10
}
}
And when I run the script, I get these results:
But it doesn;t seem to be updated the spreadsheet at all. Any ideas? My two Codes are pasted below. Thanks so much for all the help:
#include "AssetTracker/AssetTracker.h"
//Device sleep time, minutes between publishes
int delayMinutes = 1;
char resultstr[64];
//AssetTracker
AssetTracker t = AssetTracker();
FuelGauge fuel;
int rssi;
void setup() {
//Begin AssetTracker
t.begin();
//Enable the GPS module
//Takes 1.5s or so because of delays
t.gpsOn();
Particle.variable("result", resultstr);
}
void loop() {
//Need to capture the GPS output every loop
t.updateGPS();
//Read and Publish lat/long
Particle.publish("LatLong", t.readLatLon(), 60, PRIVATE);
//Read and publish battery state
//Formatted "Cell votlage, state of charge %"
Particle.publish("Battery",String(fuel.getVCell()) + String(fuel.getSoC()), 60, PRIVATE);
//Read and Publish cell strength
//Formatted "RSSI (-113dBm to -51dBm), quality (0-49))"
CellularSignal rssi = Cellular.RSSI();
Particle.publish("RSSI", String(rssi), 60, PRIVATE);
snprintf(resultstr, sizeof(resultstr), "{\"Rssi\":%d,\"Qual\":%d,\"data3\":}", rssi.rssi, rssi.qual);
Serial.println(resultstr);
}
And here is my script code:
function collectData() {
var sheet = SpreadsheetApp.getActiveSheet();
var response = UrlFetchApp.fetch("https://api.particle.io/v1/devices/MY-DEVICE-ID/result?access_token=MY-ACCESS-TOKEN");
try {
var response = JSON.parse(response.getContentText()); // parse the JSON the Core API created
var result = unescape(response.result); // you'll need to unescape before your parse as JSON
try {
var p = JSON.parse(result); // parse the JSON you created
var d = new Date(); // time stamps are always good when taking readings
sheet.appendRow([d, p.data1, p.data2]); // append the date, data1, data2 to the sheet
} catch(e)
{
Logger.log("Unable to do second parse");
}
} catch(e)
{
Logger.log("Unable to returned JSON");
}
}