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

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:

Thanks,
David

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

2 Likes

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:

//Variables
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(RESSET, INPUT_PULLUP);
    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
}
else

{ //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)
        {
           LID1count++; 
           
        }    
        
    }
    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)
        {
           LID2count++;
          
        }    
        
    }
    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)
        {
           LID3count++; 
           
        }    
        
    }
    
}
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

Is anyone else still having issues with time triggered events on Google App Scripts. Mine worked flawlessly for a few days and now fail 90% of the time for no apparent reason. Iā€™m having the same issue as everyone else.

Did yā€™all just give up on GAS entirely because of this issue?

Dave

Switch over to www.Ubidots.com

Search this forum for that and you will find setup code. Its way better than Google App Scripts.

Ubidots looks cool ā€“ Iā€™ll have to investigate them. But for an alternate solution: if you run your own server, use a PHP script to write a CSV. Iā€™ve done my kegerator monitor, solar panel monitor and a couple temperature monitors using this method. All you have to do is:

  • Set up a TCP connection using Sparkā€™s TCPClient library (debugging thread here)
  • make a getrequest() with your data in the URL: "/postdata.php?user=0001&data=%2.2f", data
  • in the PHP script, append the data from the URL into a CSV file.

I think it is a super simple solution. Not secure or scalable, but for my solo purposes it works really well. I can send data as quickly as the core connection will load the ~2kb php script (translation: pretty fast).

B

For me, time-triggered GASā€™s ran well for several months, but mostly fail as of a few weeks ago. Iā€™m giving up on these for now. -D

Hi Kareem, guess this is a way old post now - but Iā€™m really keen on finding a way to have my Spark Core POST data to Google sheets, triggered by an event on the Core side. In simple terms, if a sensor detects a certain spread in data it sends a POST to update a spreadsheet of the values (as variables).