Last week I received my Raspberry Pi and installed Debian wheezy on it. I decided to install NodeJS and mySQL and play a bit. I have written a simple program which queries the pi for its' core temperature and inserts it into a mySQL table.

Installing NodeJS
Installation of Node is quite simple:
view plain print about
1apt-get update
2apt-get upgrade
3apt-get install nodejs npm node-semver

Addendum

The version of node returned is very old (v0.6.19) and the package manager (npm) is also old. I have installed a later version from here and now have 0.10.5 installed and a later version of npm (which is included).

Installing MySql
If you have installed the Debian install from NOOBS on your pi you can just install by:
view plain print about
1sudo apt-get install mysql-server-5.5
If you have installed by another method you may have to expand the file system on your SD card first. Instructions here.

You will also want the mysql connector for node:

view plain print about
1npm install mysql@2.0.0-alpha9
Using node to query pi's temperature

Here is a simple program to store the core temp in a MySql table:

view plain print about
1var mysql = require('mysql');
2var connection = mysql.createConnection({
3 host : 'localhost',
4 user : 'pi',
5 database: 'coretemp',
6 password : 'xxxxx',
7});
8connection.connect();
9 var exec=require('child_process').exec;
10 exec('cat /sys/class/thermal/thermal_zone0/temp',function(err,stdout){
11 var temp=((parseInt(stdout)/1000*1.8)+32).toFixed(2);
12 console.log("The temperature at %s is %s\u00B0 F",new Date(),temp);
13    connection.query('insert into tbl_temp (dt,temp) SELECT now(),? ',[temp], function(err, rows, fields) {
14 if (err) throw err;
15     connection.end();
16 console.log('inserted %s',temp);
17 });
18 });
We use the child_process module to get the temperature and then save it in the database.

My next project will be to attach a thermal probe to the pi and measure the temperature of my smoker so I can be a real couch potato and not go outside and check all the time.

As a side note I put the node program I used for calculating words in words on the pi and it runs fine. See earlier entries.