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

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


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.


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.

Hi @markp1989,

Good question! I’m hoping to solve this use case with webhooks / callbacks. We have a beta program going currently where the Spark Cloud will make a web request when one of your cores publishes a matching event. Some details here:

I’m hoping to get some time soon to properly release it. :slight_smile:


1 Like

@aguspg Hey I just got a chance to get my SHT15 temp & humidity sensor up and running on Ubidots and I’m very impressed with it. Ubidots provides all the features that I really wanted and it makes it really simple to create graphs that can be embedded and events that can be triggered by any setpoint you want from your sensor data so you get a Email or SMS message once that event is triggered.

I’ll post a review in a separate thread later tonight so others can see how easy it is to make good use of the Spark Core. I wish Ubidots was around when I first started playing with the Spark Core.

Now I just want to be able to do the same thing using the Adafruit FONA so I’m not limited by my WiFi range but by a almost unlimited cellular range.

Pretty excited its so easy to get sensor data out to a webpage to view it in a nice graphing format + the ability to easily create notifications when predefined events are triggered. Its a dream come true.

1 Like

Hi @RWB and @Julian, thank you for your words. They give lots of sense to what we do!

@RWB let us know the link of the new thread once you post it.

@aguspg I haven’t started a thread yet but here are some pictures for now.

I really love how everything is so easy to use, and how easy it is to setup event triggers that actually work. I have a event that sends a email when my garage hits 87F just for testing. Ubidots sends the email instantly and it ends up as a vibration/notification on the Pebble Steel watch on my wrist which is so cool. Up till now I have not came across a platform like yours that lets me easily get this setup.

I also really like how you can easily setup the dashboard with all kinds of different data visualization layout options. This is way better than Xivley, I have tried them both. It even works on my Android Smart phone. I like how the data points on the strictly data point displays will keep auto updating without having to refresh the page.

1 Like

That’s a neat dashboard you made; it even looks better than the one in my account!

Btw we’ll release an Android SDK and sample app very soon, will keep you posted.

The dashboard and how you can easily drag boxed around and resize them is sweet. It makes viewing the data very easy and enjoyable.

Next thing I want to try is to use a temp sensor to measure the temp of a can of Soda so when I throw it in the freezer I can get Ubidots to send me a SMS message to let me know when the pop is almost frozen and ready to drink vs forgetting about it only to find a exploded mess to clean up in the fridge sometimes.

Did you guys order up a FONA board from Adafruit?

Good idea (been there as well).

Sure, we got the FONA and it’s in our backlog of devices to be connected; it’s assigned for the first week of september.

@aguspg Sounds good.

I’m interested in the FONA + Ubidots for a more commercial application. I build portable solar power systems and I am thinking of adding the FONA to these systems so it can send system performance data over the cellular network using the FONA and then to Ubidots where the customers can log in a view the performance of their system over time. It would be a nice feature to remotely monitor these portable power stations and get notifications when certain events happen like a low or full battery, or over temp or under temp conditions.

Lots off cool stuff that can be done, especially with the FONA where you have almost nationwide coverage. Looking forward to doing something cool and new.

1 Like

@RWB Sounds good. Our Enterprise plan allows you to even put your own logo in a Ubidots portal, and create accounts for your customers to login to it.

1 Like

@aguspg. Thanks for informing us of ubidots. I am loving how easy and neat the interface is. I have a small problem though. Should be an easy fix but can’t get my head around it. I am trying to use a Dormant Lab pH sensor on a Spark core, to send pH measurements to ubidots. The code compiles fine, but I don’t see any data posted on ubidots. When I use the sample code “send-value-ubidots” it works fine. The code I am using for http sending to ubidots is:

request.path = "/api/v1.6/variables/"VARIABLE_ID"/values";
request.body = "{\"value\":" + String(avgPHVolts) + "}";

where avgPHVolts is a “double” not an int. If I change it to an int it works fine. How can I change a double to a string so i can send via http? I need to pass on the number rounded to 4 decimal places.

Any help is appreciated. Once I have it working I will be sharing my project. I know a lot of people who are currently on arduino may be interested in using spark.io as an aquarium monitor.

@aguspg @furam28 Guys I’ve been using Ubidots for temp/humidity live view and logging & as a wireless touch less temp sensor setup to track temps of various objects for various different situations with email alerts triggered by certain temps and Ubidots works perfectly every time all the time. I can’t recommend them enough, especially since its free for most uses.

Good luck @furam28


Hi @furam28,

Nice to hear you’re using Ubidots! Indeed, the API accepts string values, so it’s weird you’re not being able to parse it with the String() function.

I found this thread that suggest exactly what you’re doing. Will try it in my Spark and come back. Have you tried a float? Look forward to see your project working.

@aguspg. Thanks for the quick response. I look forward to hearing back from you once you try it out. I tried float too but didn’t work. From my readings (correct me if I am wrong), the String() function doesn’t take double or float: http://arduino.cc/en/Reference/StringConstructor.

Hi @furam28,

Sorry for the not so quick response… I was able to put my hands on the Spark only until now.

Here’s how I parsed a double to a String:

double num=117.443354;
char resultstr[64];
sprintf(resultstr, "{\"value\": %.15f}", num); 
request.body = resultstr

%.15f tells the function sprintf to parse a float with 15 decimal places (which is a double). Also, we had to use a char because the sprintf function was not getting float to string.

This exactly what I need! But I’m having some trouble getting this going. (Could be that this is first time I’ve ever done anything like this). IWhen you say “I used JSON to format the data from my :spark: Core, so that it was already in a format that’s easily parse-able by the Google Apps Script.”, does that mean there is more in the sketch that what is shown here to get the data into a readable format? I copied and pasted the function collectdata into my google drive (replacing my device id and access code and got the following message:
Request failed for https://api.spark.io/v1/devices/53ff6b066678505517491467/result?access_token=1bcef321b85b25c974c125a3beeeba89fc02bfcf returned code 404. Truncated server response: { “ok”: false, “error”: “Variable not found” } (use muteHttpExceptions option to examine full response) (line 4, file “Code”)

Here is my sketch:

char resultstr[64];

const int RESSET = D7;
const int LID1 = D6;
const int LID2 = D5;
const int LID3 = D4;
int LID1count = 0;
int LID2count = 0;
int LID3count = 0;
int resetstate;
int LID1state;
int LID2state;
int LID3state;

void setup() //routine runs only once upon reset, this is your setup
{//Initialize pins as inputs
    pinMode(LID1, INPUT_PULLUP);
    pinMode(LID2, INPUT_PULLUP);
    pinMode(LID3, INPUT_PULLUP);
    Spark.variable("Results",&resultstr, STRING);

void loop() //put your main code here, to run repeatedly
    //read the state of the pins
resetstate = digitalRead(RESSET);
LID1state = digitalRead(LID1);
LID2state = digitalRead(LID2);
LID3state = digitalRead(LID3);

if (resetstate == LOW)
    LID1count = 0;
    LID2count = 0;
    LID3count = 0;
    delay(1000); // wait for a second

{ //check to see if reset button is being pushed
    if(LID1state == LOW)
    { //checks to see if LID1 pushbutton is being held low
        delay(5000); //waits 5 seconds to see if lid stays open
        if(LID1state == LOW)
    if(LID2state == LOW)
    { //checks to see if LID1 pushbutton is being held low
        delay(5000); //waits 5 seconds to see if lid stays open
        if(LID2state == LOW)
    if(LID3state == LOW)
    { //checks to see if LID1 pushbutton is being held low
        delay(5000); //waits 5 seconds to see if lid stays open
        if(LID3state == LOW)
sprintf(resultstr, "{\"LID1count\":%d,\"LID2count\":%d, \"LID3count\":%d}", LID1count, LID2count, LID3count); 
delay(1000);//wait a second

I’ve edited your post to properly format the code. Please check out this post, so you know how to do this yourself in the future. Thanks in advance! ~Jordy