Skip to content

Instantly share code, notes, and snippets.

@perusio
Created May 15, 2016 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perusio/24ae93fb67d990aa2b13eeaf05a5dacc to your computer and use it in GitHub Desktop.
Save perusio/24ae93fb67d990aa2b13eeaf05a5dacc to your computer and use it in GitHub Desktop.
Better code for the Tessel board
// 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);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment