-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
66 lines (51 loc) · 1.21 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var j5 = require( 'johnny-five' ),
board,
narf = require( 'narf' );
board = new j5.Board();
board.on("ready", function() {
var val = 0;
// Set pin 13 to OUTPUT mode
this.pinMode( 13, 1 );
this.pinMode( 12, 1 );
// Mode Table
// INPUT: 0
// OUTPUT: 1
// ANALOG: 2
// PWM: 3
// SERVO: 4
this.digitalWrite( 13, 0 );
this.digitalWrite( 12, 0 );
/* Api functions */
var self = this;
var APIFunctions = {
GET : {
redLedSwitch : function ( data, callback ){
data.url.value = parseInt( data.url.value, 0 );
if( data.url.value === 1 || data.url.value === 0)
{
self.digitalWrite( 13, data.url.value );
}
callback( data.url.value );
},
blueLedSwitch : function ( data, callback ) {
data.url.value = parseInt( data.url.value, 0 );
if( data.url.value === 1 || data.url.value === 0)
{
self.digitalWrite( 12, data.url.value );
}
callback( data.url.value );
}
},
POST : {}
};
console.log(narf);
var hs = new narf.HttpServer( { port : 8080 } ).start();
hs.on( 'port', function( port ){
hs.addAPI( { functions : APIFunctions } );
});
});
narf.setDebug( false );
narf.pageServer( {
port : 8079,
path : __dirname + '/'
});