Example: Logging and graphing data from your Spark Core using Google

@mdfast1 @Dave Thanks for the update! Yes, it works much better now.

1 Like

thanks! It does work much better!! :slight_smile:

Thanks to the help from @binaryfrost and @bko, here is some working code for a temperature/humidity control utilizing the honeywell hih-8120 with a web interface to set the values and data logging to google. Feedback is welcome! https://github.com/wildhans1/web_temp_humidity_control

2 Likes

This was working great last week. I have the google trigger set to every minute:

Today the timing is erratic. Notice the time stamps here:

Sometimes the data comes more often than each minute, and most of time there are 3-5 minute dead periods between data. Any ideas? The code is identical to the github link in the post above this. Thanks!

So I know we are looking at possibly increasing the 1 minute timer on sheets internally, I would suspect bandwidth issues. Looking at your data itā€™s not really changing in ~ 1 hour. Do you really need to ping it every 1 minute? Think of the bandwidth.

What do you see if you switch to 5minute timer? Dead on timing?

Hi @mdfast1, the appliance that this thing is controlling is unplugged. Iā€™m just running the Core and a sensor. When turned on, the system changes quite rapidly (full range swing in ~2 minutes) so even 1 minute intervals are pretty slow. Iā€™m trying 5 minute intervals as you suggested- Iā€™ll post back. thanks!

Hmm. Now it doesnā€™t appear to be working at all. It just works once when I hit ā€œrunā€ and then not again. Is anyone else having issues? Thanks

Hi @wildhans1,

I think the problem we saw earlier is that Google is really cautious when hitting other servers for this kind of request. If your core is offline, then Google is getting a bunch of ā€˜timeoutā€™ errors, because we canā€™t see your core. Google sees this as a ā€œoh dang, this server is super busy, Iā€™d better ease upā€, and slows down your requests. (I think)

Thanks!
David

Has anyone figured out how to use the Gauge Chart with a spreadsheet that adds data to the last row? The gauge wants to pull from a single row only and I havenā€™t figured out how to use a formula in the gauge or a script that maybe always copies the last row to row 1 or to another spreadsheet so I can use a gauge and always display the last data. I am using Temboo to collect the data and add rows. Works good for a chart but not a gauge.

Try:

sheet.clear();

before

sheet.appendRow

but wonā€™t that just clear the whole sheet? I want to keep the history but show a gauge of the last sample. I think it can be done with a google script or trigger but this is all new to me. Or a script or formula that will copy the contents of the last row to a new sheet or area of the spreadsheet that the gauge can then act on.

Yep it would. If you want to keep the data I would do something like having two sheets (tabs), one for storing data and one for your most up to data for the gauge.

So load data into your main sheet sheet 0

// The code below will make the first sheet active in the active workbook
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.setActiveSheet(ss.getSheets()[0]);
ss.appendRow

Then load up sheet 1:

// The code below will make the Second sheet active in the active workbook
ss.setActiveSheet(ss.getSheets()[1]);
ss.clear();
ss.appendRow
2 Likes

Hi @RWB and all,

Perhaps Ubidots can help you graph your data in different ways. You just need to add an HTTP library to your app and a few lines of code where you actually push the sensor data to Ubidots API:

request.path = "/api/v1.6/variables/"VARIABLE_ID"/values";
request.body = "{\"value\":" + String(lightLevel) + "}";
http.post(request, response, headers);

After your data reaches Ubidots, you can create line charts, scatter plots, gauges, maps, etc.

Hereā€™s the full tutorial about it. Any feedback/contribution is welcome!

1 Like

@aguspg Hey I checked out Ubidots and it looks very promising. Iā€™m going to try to get the tutorial example up and running and then begin tying out different sensors and play with the data graphing and especially the SMS and Email notifications which are the features I really really wanted to use vs just the graphing.

Thanks so much for letting everybody know about this service. Iā€™ll post some pictures of what I have setup once its up and running! :smiley:

Sure! look forward to hear about your results. --AgustĆ­n

Hey @aguspg would you be willing to do a guide on how to integrate Adafruits new FONA cellular module with Ubidots if I sent you a Fona? I have a few extra units Iā€™m not using and I would like to use Ubidots with Fonaā€™s cellular data output stream.

Hi @RWB that would be awesome! weā€™re very interested. Letā€™s exchange an email about it, my address: agustin at ubidots.com

Does anyone here know of a way to get the core to ā€œpushā€ data a Google spread sheet rather than having Google poll the spark core API?

I am making a temperature + motion(presence) data logger and I want to keep the spark in deep sleep for as long as possible to make the battery life acceptable, using Spark.variable seems to cause issues with this setup. Having the core push the new data to the Google server would make things a lot simpler.

I already have a small web server available on the public net, so one way I am thinking of doing this is having the spark core push the data to this server and then having the google script poll the 3rd party server, it seems a little bit clunky. Iā€™m not familiar enough with the Google Docs APIs to know if there is any functions that could be called directly from the core for sending new data. lack of https support may make this hard. I will do some research to see if I can find anything, but it would be helpful to know if anyone has already done something similar.

1 Like

@aguspg,

Thanks for suggesting Ubidots. I have it running my thermocouple data and it is brilliant. Good clear graphs or guages and events that can trigger SMS or email at preset values.

Brill.

Thank you.

Thanks for the great ā€œHow toā€. Being a beginner with Google Script, Iā€™m wonder if its possible to get it to call a function on the spark to set one of the digital I/O ports to high. Iā€™d like to have it flip on my sensors, wait a second then poll the sensors, wait another second and then set the I/O to low, which would flip a relay off. Iā€™ve looked at the spark examples for turning an led on and off, but they use Curl to do this, Iā€™m not sure how to get a Google script to accomplish this.

Thanks in advance.