Difference between revisions of "EBC Exercise 31 Pushing Data to the Cloud"

From eLinux.org
Jump to: navigation, search
(Initial Page)
 
m (Gathering the Data)
Line 4: Line 4:
  
 
== Gathering the Data ==
 
== Gathering the Data ==
 +
Here's a simple program for ready temperatures from some TMP101 sensors.
 +
 +
#!/usr/bin/env node
 +
// Reads the tmp101 temperature sensor.
 +
 +
var i2c = require('i2c-bus');
 +
var bus = 2;
 +
var tmp101 = [0x48, 0x49, 0x4a];
 +
var time = 1000;    // Time between readings
 +
 +
var sensor = i2c.openSync(bus);
 +
 +
var temp = [];
 +
 +
for(var i=0; i<tmp101.length; i++) {
 +
    temp[i] = sensor.readByteSync(tmp101[i], 0x0);
 +
    console.log("temp: %dC, %dF (0x%s)", temp[i], temp[i]*9/5+32, tmp101[i].toString(16));
 +
}
 +
 +
== Create a Data Stream on Phant ==
 +
Next go to [https://data.sparkfun.com/ https://data.sparkfun.com/] and click on '''CREATE''' on the top right.  On the next page fill in the fields.  I used:
 +
Title: Three TMP101's
 +
Description: Playing with phant and logging TMP101's.
 +
Fields: temp0 temp1 temp2
 +
Tags: temp
 +
Location: Terre Haute, IN, United States
 +
The only part the really matters is '''Fields''', since that impact our code.
 +
 +
Click '''Save'''.
 +
 +
The next page has information about Public and Private Keys, but the most important part is to click '''Download your keys as a JSON file.'''  Move the downloaded file to the folder where  your code is and rename it '''keys_tmp101.json'''.
 +
  
 
{{YoderFoot}}
 
{{YoderFoot}}

Revision as of 16:31, 22 September 2016

thumb‎ Embedded Linux Class by Mark A. Yoder


Now that you are able to gather data on the Bone it would be nice to store it some place in the "Cloud". In this exercise we'll show how to push data to Sparkfun's Phant, and then later pull it from Phant and plot it with Plotly.

Gathering the Data

Here's a simple program for ready temperatures from some TMP101 sensors.

#!/usr/bin/env node
// Reads the tmp101 temperature sensor.

var i2c = require('i2c-bus');
var bus = 2;
var tmp101 = [0x48, 0x49, 0x4a];
var time = 1000;    // Time between readings

var sensor = i2c.openSync(bus); 

var temp = [];

for(var i=0; i<tmp101.length; i++) {
    temp[i] = sensor.readByteSync(tmp101[i], 0x0);
    console.log("temp: %dC, %dF (0x%s)", temp[i], temp[i]*9/5+32, tmp101[i].toString(16));
}

Create a Data Stream on Phant

Next go to https://data.sparkfun.com/ and click on CREATE on the top right. On the next page fill in the fields. I used:

Title: Three TMP101's
Description: Playing with phant and logging TMP101's.
Fields: temp0 temp1 temp2
Tags: temp
Location: Terre Haute, IN, United States

The only part the really matters is Fields, since that impact our code.

Click Save.

The next page has information about Public and Private Keys, but the most important part is to click Download your keys as a JSON file. Move the downloaded file to the folder where your code is and rename it keys_tmp101.json.




thumb‎ Embedded Linux Class by Mark A. Yoder