Complete lightswitch for makerfaire

This commit is contained in:
Tanner Collin 2018-02-04 15:39:12 -07:00
parent d382fdd8fa
commit f1594d2e38
4 changed files with 26 additions and 7 deletions

2
dist/index.html vendored
View File

@ -1,6 +1,6 @@
<html> <html>
<head> <head>
<title>LED Toggle Demo</title> <title>Remote Control Lightswitch</title>
<link rel="stylesheet" href="semantic.min.css"> <link rel="stylesheet" href="semantic.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head> </head>

View File

@ -1,5 +1,5 @@
{ {
"name": "criticaldemo", "name": "lightswitch-server",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
@ -23,6 +23,7 @@
"react": "^15.6.1", "react": "^15.6.1",
"react-dom": "^15.6.1", "react-dom": "^15.6.1",
"react-fastclick": "^3.0.2", "react-fastclick": "^3.0.2",
"serialport": "^6.0.4",
"socket.io": "^2.0.3" "socket.io": "^2.0.3"
} }
} }

View File

@ -1,5 +1,6 @@
const express = require('express'); const express = require('express');
const app = express(); const app = express();
const SerialPort = require('serialport');
const server = app.listen(3000, function () { const server = app.listen(3000, function () {
console.log('Example app listening on port 3000!'); console.log('Example app listening on port 3000!');
@ -7,8 +8,25 @@ const server = app.listen(3000, function () {
const io = require('socket.io').listen(server); const io = require('socket.io').listen(server);
const port = new SerialPort('/dev/rfcomm0');
port.on('error', function(err) {
console.log('Error: ', err.message);
port.close();
})
port.on('close', function(err) {
setTimeout(function() {
port.open();
}, 2000);
});
const update = data => { const update = data => {
console.log('recieved ' + data); console.log('recieved ' + data);
port.write(data, function(err) {
if (err) {
return console.log('Error on write: ', err.message);
}
console.log('message written');
});
} }
app.use('/', express.static('dist')) app.use('/', express.static('dist'))
@ -18,3 +36,4 @@ io.on('connection', socket => {
update(data); update(data);
}); });
}); });

View File

@ -15,6 +15,10 @@ export default class App extends React.Component {
} }
componentWillMount() {
document.body.addEventListener('touchmove', function(e){ e.preventDefault(); });
}
componentWillUnmount() { componentWillUnmount() {
this.setState({socket: this.state.socket.removeAllListeners()}); this.setState({socket: this.state.socket.removeAllListeners()});
} }
@ -43,7 +47,6 @@ export default class App extends React.Component {
<div className="ui basic center aligned segment"> <div className="ui basic center aligned segment">
<img className="ui centered image" src="logo.png" /> <img className="ui centered image" src="logo.png" />
<h3 className="ui header">Remote Control Lightswitch</h3> <h3 className="ui header">Remote Control Lightswitch</h3>
<p>Press the buttons to control the light.</p>
<div className="ui compact raised segments"> <div className="ui compact raised segments">
<div className="ui segment"> <div className="ui segment">
@ -54,10 +57,6 @@ export default class App extends React.Component {
</div> </div>
</div> </div>
</div> </div>
<div className="ui basic center aligned segment">
<p>Created by Tanner Collin <br />
tannercollin.com</p>
</div>
</div> </div>
); );
} }