Zoran RoncevicMonica Houston
Published © GPL3+

Intel Edison CPU monitoring with Artik Cloud

Tutorial for creating Artik Cloud device (Intel Edison) and monitoring CPU cores temperature.

AdvancedProtip30 minutes1,038
Intel Edison CPU monitoring with Artik Cloud

Things used in this project

Software apps and online services

ARTIK Cloud for IoT
Samsung ARTIK Cloud for IoT

Story

Read more

Code

main.js

JavaScript
NodeJS app for sending data to Artik Cloud
var mqtt = require('mqtt');
var fs = require('fs');

var fbuff = '';
var temp1 = 0;
var temp2 = 0;

var fcore1 = "/sys/devices/virtual/thermal/thermal_zone3/temp";
var fcore2 = "/sys/devices/virtual/thermal/thermal_zone4/temp";

var ID = '<Device ID here>';

var PROTOCOL = 'mqtts';
var BROKER ='api.artik.cloud';
var PORT = 8883;

//Create the url string
var URL = PROTOCOL + '://' + BROKER;
URL += ':' + PORT;

var AUTHMETHOD = ID;
var AUTHTOKEN = '<Device Token Here>';

var requireds = { username: AUTHMETHOD, password: AUTHTOKEN };
var mqttConfig = { 'url': URL, 'requireds': requireds };

var client;
client = mqtt.connect(mqttConfig.url, mqttConfig.requireds);
var TOPIC = '/v1.1/messages/'+ID;

client.on('connect', function () {
    console.log('connect');
    setInterval(function () {
        getTemp1();
        getTemp2();
        //client.publish(TOPIC, '{"Core1Temp":'+temp1+',"Core2Temp":'+temp2+'}');
    }, 10*1000);//Keeps publishing every 10000 milliseconds.    
});

function getTemp1(){
	var s = '';
	var t = 0;
            
	fs.readFile(fcore1,function(err,data){
		fbuff = data;
		s = fbuff.toString();
		t = parseFloat(s);
		temp1 = t / 1000;
        client.publish(TOPIC, '{"Core1Temp":'+temp1+'}');        
	});
}

function getTemp2(){
    var s = '';
	var t = 0;
	fs.readFile(fcore2,function(err,data){
		fbuff = data;
		s = fbuff.toString();
		t = parseFloat(s);
		temp2 = t / 1000;
        client.publish(TOPIC, '{"Core2Temp":'+temp2+'}');            
	});
}

package.json

JSON
Package JSON file for NodeJS application
{
  "name": "EdisonToArtik",
  "description": "",
  "version": "0.0.0",
  "main": "main.js",
  "engines": {
    "node": ">=4.0.0"
  },
  "dependencies": {
      "mqtt" : "*"
  }
}

Credits

Zoran Roncevic

Zoran Roncevic

19 projects • 127 followers
Hackster Live ambassador in Serbia. Organizer of Maker NS community.
Monica Houston

Monica Houston

75 projects • 451 followers
I don't live on a boat anymore.

Comments