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


#122

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


#123

@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.


#124

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.


#125

@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.


#126

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.


#127

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?


#128

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.


Best framework for data logging
#129

@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.


#130

@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.


#131

@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.


#132

@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


#133

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.


#134

@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.


#135

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.


#136

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


#137

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


Since the Cloud update on 3/23/2015 I'm getting intermittent failures communicating with the cloud
#138

Switch over to www.Ubidots.com

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


#139

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


#140

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


#141

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).