add more nodejs instrumentation
This commit is contained in:
parent
e79c419e40
commit
060e0caa44
38
index.html
38
index.html
|
@ -3,13 +3,45 @@
|
||||||
<script src="/socket.io/socket.io.js"></script>
|
<script src="/socket.io/socket.io.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var socket = io();
|
var socket = io();
|
||||||
console.log("loaded socketio");
|
// console.log("loaded socketio");
|
||||||
|
|
||||||
|
// connect to socketio
|
||||||
socket.on('connect', function(){
|
socket.on('connect', function(){
|
||||||
socket.send('hi');
|
// send connect message
|
||||||
|
socket.send('hi '+window.location);
|
||||||
|
});
|
||||||
|
window.onload = function(){
|
||||||
|
cons = document.getElementById("console");
|
||||||
|
// handle user input
|
||||||
|
cons.onsubmit = function(){
|
||||||
|
inp = document.getElementById("input")
|
||||||
|
scr = document.getElementById("screen")
|
||||||
|
// send input to socketio
|
||||||
|
socket.emit('data',inp.value);
|
||||||
|
// console.log(inp.value);
|
||||||
|
scr.value += "> "+inp.value+"\r";
|
||||||
|
scr.scrollTop = scr.scrollHeight;
|
||||||
|
inp.value = "";
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
scr = document.getElementById("screen")
|
||||||
|
scr.value = ""; // reset input onload
|
||||||
|
// log data from socket
|
||||||
socket.on('data', function(data){
|
socket.on('data', function(data){
|
||||||
console.log(data);
|
// console.log(data);
|
||||||
|
scr.value += "< "+data+"\r";
|
||||||
|
scr.scrollTop = scr.scrollHeight;
|
||||||
});
|
});
|
||||||
|
// log connect messages
|
||||||
|
socket.on('message', function(data){
|
||||||
|
console.log('message',window.location,data);
|
||||||
});
|
});
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
<form id="console">
|
||||||
|
<textarea cols=80 rows=20 id="screen"></textarea><br/>
|
||||||
|
<input id="input" type="text" />
|
||||||
|
<input id="submit" type="button" value="Submit" />
|
||||||
|
</form>
|
||||||
</html>
|
</html>
|
17
serial.js
17
serial.js
|
@ -14,7 +14,7 @@ server.listen(8080);
|
||||||
// open the serial port. Change the name to the name of your port, just like in Processing and Arduino:
|
// open the serial port. Change the name to the name of your port, just like in Processing and Arduino:
|
||||||
const port = new SerialPort("/dev/ttyUSB0", { baudRate: 9600 });
|
const port = new SerialPort("/dev/ttyUSB0", { baudRate: 9600 });
|
||||||
|
|
||||||
const parser = new Readline({ delimiter: '\r' });
|
const parser = new Readline({ delimiter: '\r\n' });
|
||||||
port.pipe(parser)
|
port.pipe(parser)
|
||||||
|
|
||||||
// respond to web GET requests with the index.html page:
|
// respond to web GET requests with the index.html page:
|
||||||
|
@ -27,9 +27,18 @@ parser.on('data', line => console.log(`> ${line}`))
|
||||||
|
|
||||||
// listen for new socket.io connections:
|
// listen for new socket.io connections:
|
||||||
io.on('connection', function (socket) {
|
io.on('connection', function (socket) {
|
||||||
parser.on('data', line => socket.emit('data', line))
|
// get data from serial and send it to socket
|
||||||
|
parser.on('data', line => {
|
||||||
|
socket.emit('data', line)
|
||||||
|
});
|
||||||
|
// get data from socket and send it to serial
|
||||||
|
socket.on('data', function (data) {
|
||||||
|
console.log('data', socket.conn.remoteAddress, data)
|
||||||
|
port.write(data+"\r") // we need to end each command with a CR
|
||||||
|
});
|
||||||
|
// send and log connect messages
|
||||||
|
socket.volatile.emit('message', "hi "+socket.conn.remoteAddress);
|
||||||
socket.on('message', function (data) {
|
socket.on('message', function (data) {
|
||||||
console.log(data)
|
console.log('message',socket.conn.remoteAddress,data)
|
||||||
port.write(data+'\r')
|
|
||||||
});
|
});
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user