Created
March 24, 2016 06:22
-
-
Save mako34/c9d89f3617173676a486 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var mqtt = require('mqtt'); | |
| var client = mqtt.connect('mqtt://test.mosquitto.org'); | |
| var led_blue; | |
| client.on('connect', function () { | |
| console.log('state'); | |
| client.subscribe('tito'); | |
| // client.publish('sensor', 'Hello mqtt'); | |
| }); | |
| var five = require("johnny-five"); | |
| var pcDuino = require("pcduino-io"); | |
| var board = new five.Board({ | |
| io: new pcDuino() | |
| }); | |
| board.on("ready", function() { | |
| led_blue = new five.Led(12); | |
| led_green = new five.Led(11); | |
| led_red = new five.Led(10); | |
| // led_blue.blink(); | |
| client.publish('tito', 'readys'); | |
| var slider = new five.Sensor("A0"); //flood sensor | |
| slider.scale([0 , 255]).on("slide", function () { | |
| console.log("slide", this.value); | |
| client.publish('sensor', this.value.toString()); | |
| if (this.value === 0) {led_red.on()} | |
| else {led_red.off()}; | |
| }); | |
| }); | |
| client.on('message', function (topic, message) { | |
| // message is Buffer | |
| console.log(message.toString()); | |
| console.log(topic.toString()); | |
| // client.end(); | |
| // led_blue.toggle(); | |
| if(message.toString()=='blue'){ | |
| led_blue.toggle(); | |
| } | |
| if(message.toString()=='green'){ | |
| led_green.toggle(); | |
| } | |
| if(message.toString()=='red'){ | |
| led_red.toggle(); | |
| } | |
| }); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "pcduino-io-2", | |
| "version": "0.0.0", | |
| "description": "", | |
| "main": "index.js", | |
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| }, | |
| "author": "MK", | |
| "license": "ISC", | |
| "dependencies": { | |
| "pcduino-io": "~0.3.0", | |
| "mqtt": "~1.7.4", | |
| "johnny-five": "~0.9.34" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment