Permalink
Browse files

Make the gate open for real

  • Loading branch information...
jbpros committed Feb 29, 2012
1 parent b8290c2 commit f54bde66301b61e3df67b3adfe20f1dba587e9e9
Showing with 19 additions and 6 deletions.
  1. +1 −1 index.html
  2. +18 −5 server.js
View
@@ -45,7 +45,7 @@
<div id="myNav">
<nav>
<p id="wrapOpen">
- <a id="open" href="#">
+ <a id="open" href="/open">
<span>Open Sesame</span>
</a>
</p>
View
@@ -1,5 +1,6 @@
var url = require('url');
var connect = require('connect');
+var parsers = require('serialport').parsers;
var SerialPort = require('serialport').SerialPort;
var port = process.env.PORT || 2847;
@@ -26,12 +27,16 @@ server.use(function(req, res, next){
/////////////////////
+function init(callback) {
+ getSerialPort(callback);
+}
+
function getSerialPort(callback) {
var error = void(0);
try {
- serialPort = serialPort || new SerialPort(serialDevice);
+ serialPort = serialPort || new SerialPort(serialDevice, {baudrate: 9600});
} catch (err) {
- error = "Could not open port";
+ error = "Could not open serial port";
}
callback(error, serialPort);
};
@@ -41,11 +46,19 @@ function openGate(callback) {
if (err) {
callback(err);
} else {
- serialPort.write(1);
+ console.log("Opening gate...");
+ serialPort.write('1');

This comment has been minimized.

Show comment Hide comment
@cimm

cimm Feb 29, 2012

Member

Open Sesame!

@cimm

cimm Feb 29, 2012

Member

Open Sesame!

This comment has been minimized.

Show comment Hide comment
@jbpros

jbpros Feb 29, 2012

Owner

This comment has been minimized.

Show comment Hide comment
@cimm

cimm Feb 29, 2012

Member

Haha, sorry, that wasn't a request, it was just me yelling from excitement. Open Sesame! :D

@cimm

cimm Feb 29, 2012

Member

Haha, sorry, that wasn't a request, it was just me yelling from excitement. Open Sesame! :D

callback();
}
});
};
-server.listen(port);
-console.log('Accepting connection on port '+port+'...');
+init(function(err) {
+ if (err) {
+ throw new Error(err);
+ } else {
+ server.listen(port);
+ console.log('Accepting connection on port '+port+'...');
+ }
+});
+

0 comments on commit f54bde6

Please sign in to comment.