michael@0: /*jslint node:true,vars:true, unparam:true */ michael@0: /*jshint unused:true */ michael@0: michael@0: michael@0: /* michael@0: 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. michael@0: michael@0: MRAA - Low Level Skeleton Library for Communication on GNU/Linux platforms michael@0: 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. michael@0: michael@0: Steps for installing MRAA & UPM Library on Intel IoT Platform with IoTDevKit Linux* image michael@0: Using a ssh client: michael@0: 1. echo "src maa-upm http://iotdk.intel.com/repos/1.1/intelgalactic" > /etc/opkg/intel-iotdk.conf michael@0: 2. opkg update michael@0: 3. opkg upgrade michael@0: michael@0: Article: https://software.intel.com/en-us/html5/articles/iot-touch-notifier-nodejs-and-html5-samples michael@0: */ michael@0: michael@0: //MRAA Library was installed on the board directly through ssh session michael@0: var mraa = require("mraa"); michael@0: var mqtt = require("mqtt"); michael@0: var http = require("http"); michael@0: michael@0: function setOpenhabState(txtNewState) { michael@0: http.get("http://192.168.42.245:8080/CMD?door_bell="+txtNewState); michael@0: } michael@0: michael@0: //GROVE Kit Shield D6 --> GPIO6 michael@0: //GROVE Kit Shield D2 --> GPIO2 michael@0: function startSensorWatch(socket) { michael@0: 'use strict'; michael@0: var touch_sensor_value = 0, last_t_sensor_value; michael@0: var mqtcli = mqtt.connect('mqtt://raspeinz.local/'); michael@0: michael@0: //Touch Sensor connected to D2 connector michael@0: var digital_pin_D2 = new mraa.Gpio(2); michael@0: digital_pin_D2.dir(mraa.DIR_IN); michael@0: michael@0: //Buzzer connected to D6 connector michael@0: var digital_pin_D6 = new mraa.Gpio(6); michael@0: digital_pin_D6.dir(mraa.DIR_OUT); michael@0: michael@0: digital_pin_D6.write(0); michael@0: michael@0: setInterval(function () { michael@0: touch_sensor_value = digital_pin_D2.read(); michael@0: if (touch_sensor_value === 1 && last_t_sensor_value === 0) { michael@0: console.log("Buzz ON!!!"); michael@0: socket.emit('message', "present"); michael@0: mqtcli.publish('door', 'ding'); michael@0: //mqtcli.end(); // end connection michael@0: // FUR ULRICH! //http.get("http://ulno.local:8080/CMD?door_bell=ON"); michael@0: digital_pin_D6.write(touch_sensor_value); michael@0: } else if (touch_sensor_value === 0 && last_t_sensor_value === 1) { michael@0: console.log("Buzz OFF!!!"); michael@0: //socket.emit('message', "absent"); michael@0: mqtcli.publish('door', 'dong'); michael@0: // FUR ULRICH! //http.get("http://ulno.local:8080/CMD?door_bell=OFF"); michael@0: digital_pin_D6.write(touch_sensor_value); michael@0: } michael@0: last_t_sensor_value = touch_sensor_value; michael@0: }, 500); michael@0: } michael@0: michael@0: //Create Socket.io server michael@0: //var http = require('http'); // See top requires michael@0: var app = http.createServer(function (req, res) { michael@0: 'use strict'; michael@0: res.writeHead(200, {'Content-Type': 'text/plain'}); michael@0: res.end('