Last active
November 11, 2015 09:57
-
-
Save imrehg/415103ab52c1f0d1c513 to your computer and use it in GitHub Desktop.
Telemetry with Arduino Yun
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var autobahn = require('autobahn'); | |
var connection = new autobahn.Connection({ | |
url: 'ws://octv-versus.ddns.net:8080/ws', | |
realm: 'octv1'} | |
); | |
connection.onopen = function (session) { | |
// SUBSCRIBE to a topic and receive events | |
// | |
function telemetry (args) { | |
var msg = args[0]; | |
try { | |
var results = JSON.parse(msg); // can use this object to do stuff | |
console.log("event for 'telemetry.yun1' received: " + msg); | |
} catch(e) { | |
} | |
} | |
session.subscribe('com.octv.telemetry.yun1', telemetry).then( | |
function (sub) { | |
console.log("subscribed to topic 'telemetry.yun1'"); | |
}, | |
function (err) { | |
console.log("failed to subscribed: " + err); | |
} | |
); | |
}; | |
connection.open(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var autobahn = require('autobahn'); | |
var serialport = require("serialport"); | |
var SerialPort = serialport.SerialPort; // localize object constructor | |
var id = 'yun1'; | |
var channel = 'com.octv.telemetry.'+id; | |
var connection = new autobahn.Connection({ | |
url: 'ws://octv-versus.ddns.net:8080/ws', | |
realm: 'octv1' | |
}); | |
var sp = new SerialPort('/dev/ttyATH0', { | |
baudrate: 115200, | |
parser: serialport.parsers.readline("\n") | |
}); | |
var parseTelemetry = function (data) { | |
var parts = data.trim().split(','); | |
var results = {}; | |
if (parts[0] === 'T') { | |
results.timestamp = new Date(); | |
results.type = 'temperature'; | |
results.id = parts[1]; | |
results.readings = {'reading': parseFloat(parts[3]), | |
'coldpoint': parseFloat(parts[2]) | |
}; | |
}; | |
return JSON.stringify(results); | |
}; | |
console.log('starting...'); | |
connection.onopen = function (session) { | |
console.log("Connected to network with Session ID: "+session.id); | |
sp.open(function (error) { | |
if ( error ) { | |
console.log('failed to open: '+error); | |
} else { | |
console.log('open'); | |
sp.on("data", function (data) { | |
var outdata = parseTelemetry(data); | |
if (outdata.length > 0) { | |
console.log("Sending: "+ outdata); | |
session.publish(channel, [outdata]); | |
}; | |
}); | |
} | |
}); | |
}; | |
connection.open(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Overclocker telemetry using Arduino Yun | |
* | |
*/ | |
#include <SPI.h> | |
#include <Adafruit_MAX31855.h> | |
#define CS 10 | |
Adafruit_MAX31855 thermocouple(CS); | |
int led = 13; | |
boolean status = HIGH; | |
void setup() { | |
delay(5000); // for hard boot not to mess with the U-Boot command line (probably) | |
Serial1.begin(115200); | |
while (!Serial1) { | |
// wait for serial port to connect. | |
} | |
pinMode(led, OUTPUT); | |
} | |
void loop() { | |
char buf[64]; | |
double internal_temp = thermocouple.readInternal(); | |
double external_temp = thermocouple.readCelsius(); | |
char str_internal_temp[6]; | |
char str_external_temp[6]; | |
dtostrf(internal_temp, 4, 2, str_internal_temp); | |
char type = 'T'; | |
int sensorID = 1; | |
if (isnan(external_temp)) { // Something wrong with the thermocouple | |
sprintf(buf, "%c,%d,%s,X", type, sensorID, str_internal_temp); | |
} else { | |
dtostrf(external_temp, 4, 2, str_external_temp); | |
sprintf(buf, "%c,%d,%s,%s", type, sensorID, str_internal_temp, str_external_temp); | |
} | |
Serial1.println(buf); | |
digitalWrite(led, status); | |
status = !status; | |
delay(247); // the above code needs about 2.6ms to run, do 4 readings/s | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script>AUTOBAHN_DEBUG = false;</script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<script src="http://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script> | |
<script src="http://rawgit.com/joewalnes/smoothie/master/smoothie.js"></script> | |
<script> | |
var connection = new autobahn.Connection({ | |
url: 'ws://octv-versus.ddns.net:8080/ws', | |
realm: 'octv1'} | |
); | |
var temperature = new TimeSeries(); | |
connection.onopen = function (session) { | |
// SUBSCRIBE to a topic and receive events | |
// | |
function telemetry (args) { | |
var now = new Date(); | |
var msg = args[0]; | |
try { | |
var results = JSON.parse(msg); // can use this object to do stuff | |
$("#temperature").text(results.readings.reading+ '°C'); | |
$("#coldpoint").text(results.readings.coldpoint+ '°C'); | |
temperature.append(new Date().getTime(), results.readings.reading); | |
var timestamp = new Date(results.timestamp); | |
var latency = now - timestamp; | |
console.log(latency); | |
$("#latency").text(latency+ 'ms'); | |
/* console.log("event for 'telemetry.yun1' received: " + msg); */ | |
} catch(e) { | |
} | |
} | |
session.subscribe('com.octv.telemetry.yun1', telemetry).then( | |
function (sub) { | |
console.log("subscribed to topic 'telemetry.yun1'"); | |
}, | |
function (err) { | |
console.log("failed to subscribed: " + err); | |
} | |
); | |
}; | |
connection.open(); | |
function createTimeline() { | |
var chart = new SmoothieChart(); | |
chart.addTimeSeries(temperature, { strokeStyle: 'rgba(0, 255, 0, 1)', fillStyle: 'rgba(0, 255, 0, 0.2)', lineWidth: 4 }); | |
chart.streamTo(document.getElementById("chart"), 500); | |
} | |
</script> | |
</head> | |
<body onload="createTimeline()"> | |
<h1>Arduino Yun Serial to WAMP Bridge Test</h1> | |
<div>Temperature: <span id="temperature"></span></div> | |
<div>Coldpoint: <span id="coldpoint"></span></div> | |
<div>Latency: <span id="latency"></span></div> | |
<canvas id="chart" width="400" height="100" style="border: 1px black solid;"></canvas> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Focused dashboard,!Fine-grained permissions..?Repositoryne..!