I show how to collect detailed CAN bus data from a Tesla Model S, and display it in the car's own web browser!
Complete Raspberry Pi with CAN bus shield and 12V buck converter: http://copperhilltech.com/raspberry-pi-3-system-with-can-bus-interface/
Tesla diagnostic connector: https://www.panjo.com/buy/tesla-diagnostic-cable-for-ms-mx-sept-2015-and-up-bare-wire-version-308125
RPi CAN bus tutorial: http://www.cowfishstudios.com/blog/canned-pi-part1
Get node.js installed on the RPi: http://thisdavej.com/beginners-guide-to-installing-node-js-on-a-raspberry-pi/
I used socket.io, which is a module that installs into node.js: https://www.npmjs.com/package/socket.io
Diagnostic connector pinout (scroll through the images):
http://store.evtv.me/proddetail.php?prod=TeslaCANKit
Tesla CAN bus reverse engineering: https://skie.net/skynet/downloads
Basic sequence to setup the server on the Pi:
sudo ip link set can0 type can bitrate 500000 listen-only on
sudo ip link set can0 up
candump -cae can0,0:0,#FFFFFFFF
candump -cae can0,0:0,#FFFFFFFF | grep 106 | awk -Winteractive '{ print $10}' | node app.js
I will post the node.js code on my blog:
Support Applied Science on Patreon:
https://www.patreon.com/AppliedScience
app.js:
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
pipedata = '';
rl.on('line', function(line){
console.log(line);
pipedata = line;
});
var http = require('http'),
fs = require('fs'),
// NEVER use a Sync function except at start-up!
index = fs.readFileSync(__dirname + '/index.html');
// Send index.html to all requests
var app = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(index);
});
// Socket.io server listens to our app
var io = require('socket.io').listen(app);
// Send current time to all connected clients
function sendTime() {
// io.emit('time', { time: new Date().toJSON() });
io.emit('time', pipedata);
}
// Send current time every 10 secs
setInterval(sendTime, 100);
// Emit welcome message on connection
io.on('connection', function(socket) {
// Use socket to communicate with this particular client only, sending it it's own id
socket.emit('welcome', { message: 'Welcome!', id: socket.id });
socket.on('i am client', console.log);
});
app.listen(8080);
index.html:
<!doctype html>
<html>
<head>
<script src='/socket.io/socket.io.js'></script>
<script>
var socket = io();
socket.on('welcome', function(data) {
addMessage(data.message);
// Respond with a message including this clients' id sent from the server
socket.emit('i am client', {data: 'foo!', id: data.id});
});
socket.on('time', function(data) {
addMessage(data);
});
socket.on('error', console.error.bind(console));
socket.on('message', console.log.bind(console));
function addMessage(message) {
// var text = document.createTextNode(message);
document.getElementById('messages').textContent = message;
// el = document.createElement('li'),
// messages = document.getElementById('messages');
// el.appendChild(text);
// messages.appendChild(el);
}
</script>
<style>
p.sansserif { font-family: Arial, Helvtica, sans-serif; font-size:300%;}
</style>
</head>
<body>
<p class = "sansserif" id='messages'>Hello</p>
</body>
</html>