Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Import the interface to Tessel hardware
- var tessel = require('tessel');
- //Install mqtt library using: npm install mqtt
- var mqtt = require('mqtt');
- var client = mqtt.connect({
- servers:[{'host':'mqtt.relayr.io'}],
- // Add your credentials here.
- username: "<my device ID>", // add your own
- password: "<my password>", // add your own
- clientId: "<my client ID>" // add your own
- protocol : 'mqtts'
- });
- var fuckingName;
- var pin = tessel.port.B.pin[7]; // select pin 7 on port B
- pin.analogWrite(0.6); // turn pin to 60% of high
- pin.analogRead(function(error, value) {
- // print the pin value to the console
- fuckingName = value;
- console.log(value);
- });
- // an array of available LEDs
- var leds = tessel.led;
- // ERR - Red
- var red = leds[0];
- // WLAN - Amber
- var amber = leds[1];
- // LED0 - Green
- var green = leds[2];
- // LED1 - Blue
- var blue = leds[3];
- // Green LED
- var led = tessel.led[2];
- /*
- * Property: isOn
- * Returns: boolean (true or false) if led is on
- *
- * Checks the led to see if it is on or not.
- */
- if (led.isOn)
- {
- console.log('The green LED is currently on.');
- }
- client.on('connect', function() {
- //subscribe to commands sent from the dashboard or other clients
- client.subscribe("/v1/f7396807-18fc-4205-b055-3a6dda680f77/cmd");
- client.on('message', function(topic, message) {
- });
- //simple timer to send a message every 1 second
- var publisher = setInterval(function(){
- // publish a message to a topic
- var data = JSON.stringify({meaning:"analog0", value:fuckingName});
- client.publish("/v1/f7396807-18fc-4205-b055-3a6dda680f77/data", data, function() {
- });
- }, 500);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement