Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. var API = require('node-samsung-airconditioner');
  2. var express = require('express');
  3. var app = express();
  4.  
  5. var connecting_to = {};
  6.  
  7. var known_tokens = {};
  8.  
  9. new API().on('discover', function(aircon) {
  10.  
  11. if (connecting_to[aircon.options.ip]) {
  12. return;
  13. }
  14. known_tokens[aircon.options.ip] = '33965903-4482-M849-N716-373832354144';
  15. connecting_to[aircon.options.ip] = true;
  16. aircon.login(known_tokens[aircon.options.ip], function() {
  17. app.get('/on', function (req, res) {
  18. aircon.onoff(true);
  19. res.send('Hello World!');
  20. });
  21. app.get('/off', function (req, res) {
  22. aircon.onoff(false);
  23. res.send('Hello World!');
  24. });
  25.  
  26. app.listen(3000, function () {
  27. console.log('Example app listening on port 3000!');
  28. });
  29. // setTimeout(function() { aircon.onoff(true); },1000);
  30.  
  31. // setTimeout(function() { aircon.onoff(false); }, 5*60 * 1000);
  32. }).on('stateChange', function(state) {
  33. console.log("State changed");
  34. console.log(state);
  35. }).on('loginSuccess', function () {
  36. console.log("HIDSFDs");
  37. aircon.status();
  38. });
  39.  
  40.  
  41. }).on('error', function(err) {
  42. console.log('discovery error: ' + err.message);
  43. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement