diff -r 000000000000 -r e8ccd40d0ef6 Touchiot/main.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Touchiot/main.js Thu Jun 04 14:50:33 2015 +0200 @@ -0,0 +1,91 @@ +/*jslint node:true,vars:true, unparam:true */ +/*jshint unused:true */ + + +/* +The Touch Notifier Node.js sample application distributed within Intel® XDK IoT Edition under the IoT with Node.js Projects project creation option showcases how to read digital data from a Grover Starter Kit Plus – IoT Intel® Edition Touch Sensor, start a web server and communicate wirelessly using WebSockets. + +MRAA - Low Level Skeleton Library for Communication on GNU/Linux platforms +Library in C/C++ to interface with Galileo & other Intel platforms, in a structured and sane API with port nanmes/numbering that match boards & with bindings to javascript & python. + +Steps for installing MRAA & UPM Library on Intel IoT Platform with IoTDevKit Linux* image +Using a ssh client: +1. echo "src maa-upm http://iotdk.intel.com/repos/1.1/intelgalactic" > /etc/opkg/intel-iotdk.conf +2. opkg update +3. opkg upgrade + +Article: https://software.intel.com/en-us/html5/articles/iot-touch-notifier-nodejs-and-html5-samples +*/ + +//MRAA Library was installed on the board directly through ssh session +var mraa = require("mraa"); +var mqtt = require("mqtt"); +var http = require("http"); + +function setOpenhabState(txtNewState) { + http.get("http://192.168.42.245:8080/CMD?door_bell="+txtNewState); +} + +//GROVE Kit Shield D6 --> GPIO6 +//GROVE Kit Shield D2 --> GPIO2 +function startSensorWatch(socket) { + 'use strict'; + var touch_sensor_value = 0, last_t_sensor_value; + var mqtcli = mqtt.connect('mqtt://raspeinz.local/'); + + //Touch Sensor connected to D2 connector + var digital_pin_D2 = new mraa.Gpio(2); + digital_pin_D2.dir(mraa.DIR_IN); + + //Buzzer connected to D6 connector + var digital_pin_D6 = new mraa.Gpio(6); + digital_pin_D6.dir(mraa.DIR_OUT); + + digital_pin_D6.write(0); + + setInterval(function () { + touch_sensor_value = digital_pin_D2.read(); + if (touch_sensor_value === 1 && last_t_sensor_value === 0) { + console.log("Buzz ON!!!"); + socket.emit('message', "present"); + mqtcli.publish('door', 'ding'); + //mqtcli.end(); // end connection +// FUR ULRICH! //http.get("http://ulno.local:8080/CMD?door_bell=ON"); + digital_pin_D6.write(touch_sensor_value); + } else if (touch_sensor_value === 0 && last_t_sensor_value === 1) { + console.log("Buzz OFF!!!"); + //socket.emit('message', "absent"); + mqtcli.publish('door', 'dong'); +// FUR ULRICH! //http.get("http://ulno.local:8080/CMD?door_bell=OFF"); + digital_pin_D6.write(touch_sensor_value); + } + last_t_sensor_value = touch_sensor_value; + }, 500); +} + +//Create Socket.io server +//var http = require('http'); // See top requires +var app = http.createServer(function (req, res) { + 'use strict'; + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.end('