File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+
3
+ /* Before running:
4
+ npm install telnet-client
5
+ */
6
+
7
+ var exec = require ( 'child_process' ) . exec ;
8
+ var telnet = require ( 'telnet-client' ) ;
9
+
10
+ var me = 'my_username' ;
11
+
12
+ exec ( "who" , function ( error , stdout , stderr ) {
13
+
14
+ // Exit if no sessions with my username are found
15
+ if ( stdout . indexOf ( me ) == - 1 )
16
+ process . exit ( /*1*/ ) ;
17
+
18
+ var coffee_machine_ip = 'xxx.xxx.xxx.xxx' ;
19
+ var password = 'xxxx' ;
20
+ var con = new telnet ( ) ;
21
+
22
+ con . on ( 'ready' , function ( prompt ) {
23
+ con . exec ( 'Password: ' + password , function ( error , res ) {
24
+
25
+ // Brew Coffee!
26
+ con . exec ( 'sys brew' , function ( error , res ) {
27
+
28
+ // Wait for 24s
29
+ setTimeout ( function ( ) {
30
+
31
+ // Pour Coffee!
32
+ con . exec ( 'sys pour' , function ( error , res ) {
33
+ con . end ( ) ;
34
+ } ) ;
35
+ } , 24000 ) ;
36
+ } ) ;
37
+ } ) ;
38
+ } ) ;
39
+
40
+ con . connect ( { host : coffee_machine_ip } ) ;
41
+ } ) ;
You can’t perform that action at this time.
0 commit comments