Advertisement
Guest User

Untitled

a guest
May 14th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. // Import the interface to Tessel hardware
  2. var tessel = require('tessel');
  3.  
  4. //Install mqtt library using: npm install mqtt
  5. var mqtt = require('mqtt');
  6.  
  7. var client = mqtt.connect({
  8. servers:[{'host':'mqtt.relayr.io'}],
  9. // Add your credentials here.
  10. username: "<my device ID>", // add your own
  11. password: "<my password>", // add your own
  12. clientId: "<my client ID>" // add your own
  13. protocol : 'mqtts'
  14. });
  15.  
  16.  
  17. var fuckingName;
  18. var pin = tessel.port.B.pin[7]; // select pin 7 on port B
  19.  
  20. pin.analogWrite(0.6); // turn pin to 60% of high
  21.  
  22. pin.analogRead(function(error, value) {
  23. // print the pin value to the console
  24. fuckingName = value;
  25. console.log(value);
  26. });
  27.  
  28. // an array of available LEDs
  29. var leds = tessel.led;
  30.  
  31. // ERR - Red
  32. var red = leds[0];
  33.  
  34. // WLAN - Amber
  35. var amber = leds[1];
  36.  
  37. // LED0 - Green
  38. var green = leds[2];
  39.  
  40. // LED1 - Blue
  41. var blue = leds[3];
  42.  
  43. // Green LED
  44. var led = tessel.led[2];
  45.  
  46. /*
  47. * Property: isOn
  48. * Returns: boolean (true or false) if led is on
  49. *
  50. * Checks the led to see if it is on or not.
  51. */
  52. if (led.isOn)
  53. {
  54. console.log('The green LED is currently on.');
  55. }
  56.  
  57.  
  58.  
  59. client.on('connect', function() {
  60.  
  61. //subscribe to commands sent from the dashboard or other clients
  62. client.subscribe("/v1/f7396807-18fc-4205-b055-3a6dda680f77/cmd");
  63.  
  64. client.on('message', function(topic, message) {
  65. });
  66.  
  67. //simple timer to send a message every 1 second
  68. var publisher = setInterval(function(){
  69.  
  70. // publish a message to a topic
  71. var data = JSON.stringify({meaning:"analog0", value:fuckingName});
  72.  
  73. client.publish("/v1/f7396807-18fc-4205-b055-3a6dda680f77/data", data, function() {
  74. });
  75.  
  76. }, 500);
  77.  
  78. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement