Complete lightswitch for makerfaire
This commit is contained in:
parent
d382fdd8fa
commit
f1594d2e38
2
dist/index.html
vendored
2
dist/index.html
vendored
|
@ -1,6 +1,6 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>LED Toggle Demo</title>
|
||||
<title>Remote Control Lightswitch</title>
|
||||
<link rel="stylesheet" href="semantic.min.css">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
</head>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "criticaldemo",
|
||||
"name": "lightswitch-server",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
|
@ -23,6 +23,7 @@
|
|||
"react": "^15.6.1",
|
||||
"react-dom": "^15.6.1",
|
||||
"react-fastclick": "^3.0.2",
|
||||
"serialport": "^6.0.4",
|
||||
"socket.io": "^2.0.3"
|
||||
}
|
||||
}
|
||||
|
|
19
server.js
19
server.js
|
@ -1,5 +1,6 @@
|
|||
const express = require('express');
|
||||
const app = express();
|
||||
const SerialPort = require('serialport');
|
||||
|
||||
const server = app.listen(3000, function () {
|
||||
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 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 => {
|
||||
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'))
|
||||
|
@ -18,3 +36,4 @@ io.on('connection', socket => {
|
|||
update(data);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -15,6 +15,10 @@ export default class App extends React.Component {
|
|||
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
document.body.addEventListener('touchmove', function(e){ e.preventDefault(); });
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
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">
|
||||
<img className="ui centered image" src="logo.png" />
|
||||
<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 segment">
|
||||
|
@ -54,10 +57,6 @@ export default class App extends React.Component {
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="ui basic center aligned segment">
|
||||
<p>Created by Tanner Collin <br />
|
||||
tannercollin.com</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user