process.on('SIGINT', function() {
    clearInterval(iv);
    led.write(0);
    process.exit();
});
示例#2
0
    winston.level = 'debug';
}
if (argv.vv) {
    winston.level = 'silly';
}
var gpioPin = argv.p || 6;
winston.info("GPIO Pin Number " + gpioPin);
var noisebridge = new detection.Bathroom();
noisebridge.isOn(true);
winston.debug(noisebridge.currentSession);
noisebridge.isOn(false);
winston.debug(noisebridge.currentSession);
setTimeout(function () { winston.debug('Past Sessions: ', noisebridge.pastSessions.map(getIDofElement)); }, noisebridge.minTimeGap + 500);
setTimeout(function () { winston.debug('Session IDs in DB: ', noisebridge.sessionDB.find().map(getIDofElement)); }, noisebridge.minTimeGap + 500);
if (!argv.g) {
    var switchGPIO = new mraa.Gpio(gpioPin);
    switchGPIO.dir(mraa.DIR_IN);
    pollSwitch();
}
else {
    winston.info('Skipping GPIO');
}
function pollSwitch() {
    var status = switchGPIO.read();
    winston.debug('status: ', status);
    noisebridge.isOn(status == true);
    if (noisebridge.inUse()) {
        winston.debug('Current Session ID: ' + noisebridge.currentSession.id);
    }
    else {
        winston.debug('No Current Session');
	function() {
 		d4.write(state?0:1); //if state is true then write a '1' (high) otherwise write a '0' (low)
 		state = !state; //invert the ledState
	}
示例#4
0
 * TMP36 temperature sensor connected to analog input A0.
 *
 * Copyright (c) 2019 Losant IoT, Inc. All rights reserved.
 * https://www.losant.com
 */

 /* eslint no-console: "off"*/

var mraa = require('mraa');
var Device = require('losant-mqtt').Device;

// Reading temperature from analog input.
var temp = new mraa.Aio(0);

// Blinking an LED everytime temperature is read.
var led = new mraa.Gpio(7);
led.dir(mraa.DIR_OUT);

// Construct a device instance.
var device = new Device({
  id: 'my-device-id',
  key: 'my-access-key',
  secret: 'my-access-secret'
});

// Connect device to Losant.
device.connect();

// Attach event listener for commands.
device.on('command', function(command) {
  console.log(command.name);
// Reference http://www.instructables.com/id/Intel-IoT-Edison-web-controlled-LED/step3/The-nodejs-part/

var mraa = require('mraa');
var led = new mraa.Gpio(12); // Setup IO
var http = require('http');
var url = require('url');
var greenBean = require("green-bean");
var doorState = 0

led.dir(mraa.DIR_OUT); // Output

function UpdateLed()
{
   led.write(doorState);
}

function SaveDoorState(value)
{
   doorState = value['doorState'];
}

greenBean.connect("refrigerator", function(refrigerator)
   {
      refrigerator.doorState.read(function (value)
         {
            console.log("door state is:", value);
            SaveDoorState(value);
            UpdateLed();
         });

      refrigerator.doorState.subscribe(function (value)
示例#6
0
文件: isr.js 项目: KurtE/mraa
setInterval(function() {
    // It's important to refer to our GPIO context here,
    // otherwise it will be garbage-collected
    console.log("Waiting for an interrupt at GPIO pin " + pin.getPin() + "...");
}, 10000);
 var blinkingOff = setInterval(function () {
     pushButtonLight.write(0);
 }, 250);
示例#8
0
 
// Telegram Bot API module
// https://www.npmjs.com/package/telegram-bot-api
var telegram = require('telegram-bot-api');
var api = new telegram({
	token: 'YOUR_TOKEN',
	updates: {
		enabled: true,
		get_interval: 1000
	}
});

var m = require('mraa'); //require mraa
console.log('MRAA Version: ' + m.getVersion()); //write the mraa version to the console

var myLed = new m.Gpio(13); //LED hooked up to digital pin 13 (or built in pin on Galileo Gen1 & Gen2)
myLed.dir(m.DIR_OUT); //set the gpio direction to output

var analogPin0 = new m.Aio(0); //setup access analog input Analog pin #0 (A0)
var analogValue=0,counter=0;

// Global variables used in program
var chatId;
var chatName;

  
// When someone send message to bot this event runs to get message.
api.on('message', function(message)
{
	chatId = message.chat.id;			// To reply we need sender id
	chatName = message.chat.first_name;	// Sender first name
示例#9
0
api.on('message', function(message)
{
	chatId = message.chat.id;			// To reply we need sender id
	chatName = message.chat.first_name;	// Sender first name
	var command="";
	var txt="";
	var commandType=false;
	
	// It'd be good to check received message type here
	// And react accordingly
	// We consider that only text messages can be received here
	//if(message.chat.id == "82112412")
	//{	
		message.text = message.text.toLowerCase();	// Firs convert message to lower case.
	//	Check the message to get command
		if(message.text.indexOf("help")>-1)
		{
			txt="\n\rAvailabe commands\n\r" +
			"Get location\n\r" +
			"Get temperature\n\r" +
			"Get plate number\n\r" +
			"Take a photo\n\r" +
			"Led on(test)\n\r" +
			"Led off(test)\n\r";
			console.log("Availabe commands asked");	
			commandType=true;
		}
		else if(message.text.indexOf("led on")>-1)
		{
			myLed.write(1);
			txt="\n\rLED is on!";
			console.log("LED is on!");	
			commandType=true;
		}	
		else if(message.text.indexOf("led off")>-1)
		{
			myLed.write(0)
			txt="\n\rLED is off!";
			console.log("LED is off!");
			commandType=true;
		}
		else if(message.text.indexOf("temp")>-1
		|| message.text.indexOf("temperature")>-1)
		{
			for(i=0;i<10;i++)
			{
				analogValue = analogValue + analogPin0.read(); //read the value of the analog pin
			}
			analogValue = analogValue / 10;
			var resistance=(1023-analogValue)*10000/analogValue; 
			var temperature=1/(Math.log(resistance/10000)/3975+1/298.15)-273.15;
			temperature = Math.round(temperature * 10) / 10;
			txt="\n\rTemperature is "+temperature + '\xB0' + "C";
			console.log("Temperature is "+temperature + '\xB0' + "C");
			commandType=true;
			analogValue = 0;
		}
		else if(message.text.indexOf("plate number")>-1)
		{
			txt="\n\rTruck plate number is B-TR-3427";
			console.log("Trcuk plate number is B-TR-3427");
			commandType=true;
		}
		else if(message.text.indexOf("pic")>-1
		|| message.text.indexOf("picture")>-1
		|| message.text.indexOf("photo")>-1)
		{
			api.sendPhoto({
				chat_id: chatId,
				caption: "Truck Camera",
				// you can also send file_id here as string (as described in telegram bot api documentation)
				photo: "/home/erhan/TruckBot/nodejs/truckcam.jpeg"
				}, function(err, data)
				{	if(err)
					console.log(err);
				});
			txt="\n\rPicture taken";
			console.log("Picture taken");
			commandType=true;
		}
		else if(message.text.indexOf("loc")>-1
		|| message.text.indexOf("location")>-1)
		{
			api.sendLocation({
				chat_id: chatId,
				latitude: 52.505582,
				longitude: 13.393242,
				}, function(err, data)
				{	if(err)
					console.log(err);
				});
			txt="\n\rTruck location";
			console.log("Truck location");
			commandType=true;
		}
		else	// Unknown message
		{
			txt="\n\rUnknown Command";
			commandType=true;
		}
//////////////////////////////////////////////////

		if(commandType)
		{
			api.sendMessage({
				chat_id: chatId,
				text: chatName+":"+txt
			}, function(err, message)
			{
				if(err)console.log(err);
				console.log(message);		// More info about message packet
				console.log(chatName+":"+txt);
			});
		}
	//}
	/*
	else
	{
		api.sendMessage({
				chat_id: chatId,
				text: chatName+":Please get lost!"
			}, function(err, message)
			{
				if(err)console.log(err);
				console.log(message);		// More info about message packet
				console.log(chatName+":Tried to acces to system!");
			});
	}
	*/
});
示例#10
0
    init: function() {
        var config = require('./config'),
            bson = require('bson'),
            mongoose = require('mongoose'),
            Statistics = require('./Statistics'),
            mraa = require("mraa"),
            jsupm_i2clcd = require('jsupm_i2clcd');

        // connect to external database
        mongoose.connect(config.db);

        // temperature sensor on Analog 0
        var temperatureSensor = new mraa.Aio(0);

        // sound sensor on Analog 1
        var soundSensor = new mraa.Aio(1);

        // light sensor on Analog 2
        var lightSensor = new mraa.Aio(2);

        // button on Digital 4
        var button = new mraa.Gpio(4);

        // set to read
        button.dir(mraa.DIR_IN);

        //Initialize Jhd1313m1 at 0x62 (RGB_ADDRESS) and 0x3E (LCD_ADDRESS)
        var LCD = new jsupm_i2clcd.Jhd1313m1 (6, 0x3E, 0x62);

        // turn off brightness
        LCD.setColor(0,0,0);

        // start
        main();
        highlight();

        function main() {
            'use strict';

            setInterval(function () {
                var temperature = getCelsius(temperatureSensor.read()),
                    darkness    = getDarknessCoefficient(lightSensor.read()),
                    noise       = soundSensor.read();

                // save to database
                sendValues(temperature, noise, darkness);

                LCD.setCursor(0,0);
                LCD.write('T:' + temperature);

                LCD.setCursor(1,0);
                LCD.write('S:' + noise);

                LCD.setCursor(1,9);
                LCD.write('L:' + darkness);
            }, 60000);
        }

        /**
         * Highlight LCD on pressing button, and keep lights for 2 sec
         */
        function highlight() {
            var timeout, state = true;
            setInterval(function () {
                // check if button is pressed
                if(button.read() !== 1)
                    return;

                // highlight
                (state) ? LCD.setColor(4,55,21) : LCD.setColor(21,74,7);

                // remove previous timeout
                clearTimeout(timeout);
                // set new timeout
                timeout = setTimeout(function() {
                    state = !state;
                    LCD.setColor(0,0,0);
                }, 2000);

            }, 400);
        }

        /**
         * Transform temperature sensor value to celsius temperature
         *
         * @param value
         * @returns {float}
         */
        function getCelsius(value) {
            // Shifting bits to get value between 0 to 1023 (10 bits)
            if (value > 1024)
                value = value >> 2; //Shift 'a' right two bits

            // get the resistance of the sensor
            var resistance = (1023 - value) * 10000 / value;
            // convert to temperature via datasheet
            return 1 / (Math.log(resistance / 10000) / 3975 + 1 / 298.15) - 273.15;
        }

        /**
         * Get coefficient of darkness from converted from sensor value
         *
         * @param value
         * @returns {float}
         */
        function getDarknessCoefficient(value) {
            return (1023-value)*10/value;
        }

        /**
         * Send values to external database
         *
         * @param {float}   temperature
         * @param {int}     noise
         * @param {float}   light
         */
        function sendValues(temperature, noise, light) {
            Statistics.create({
                temperature: temperature,
                noise: noise,
                light: light,
                date: Date.now()
            });
        }
    }
示例#11
0
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
// Leave the above lines for propper jshinting
//Type Node.js Here :)

var mraa = require('mraa'); 
var request = require('request');

var myOnboardLedRed = new mraa.Gpio(4);
myOnboardLedRed.dir(mraa.DIR_OUT);

var myOnboardSound = new mraa.Gpio(8);
myOnboardSound.dir(mraa.DIR_OUT);

var myOnboardLedBlue = new mraa.Gpio(3);
myOnboardLedBlue.dir(mraa.DIR_OUT); 






//function periodicActivity()
//{
//  myOnboardLedRed.write(ledState? 1:0);//if ledState is true then write a '1' (high) otherwise write a '0' (low)
//  myOnboardLedBlue.write(ledState? 1:0);
//  myOnboardSound.write(ledState? 1:0);    
//  ledState = !ledState; //invert the ledState
//  setTimeout(periodicActivity,1000); //call the indicated function after 1 second (1000 milliseconds)  
//    
//}
示例#12
0
var mraa = require('mraa');
var ultrasonic = require('jsupm_groveultrasonic');

var buzzer = new mraa.Gpio(2);
buzzer.dir(mraa.DIR_OUT);

var redlight = new mraa.Gpio(3);
redlight.dir(mraa.DIR_OUT);

//var greenlight = new mraa.Gpio(4);
//greenlight.dir(mraa.DIR_OUT);

//var trig = new mraa.Gpio(1);
//trig.dir(mraa.DIR_OUT);

//var echo = new mraa.Gpio(0);
//echo.dir(mraa.DIR_IN);

//var sensor = new sensor(trig, echo);
var sensor = new ultrasonic.GroveUltraSonic(0);

setInterval(sense, 500);

function sense(){
  var travelTime = sensor.getDistance();
  var distance = (travelTime / 29 / 2 / 100).toFixed(3);
  console.log("distance: " + distance + " [m]");
  
  //Cases
  if (distance < .3){
示例#13
0
var m = require('mraa');
var pin = new m.Gpio(13);
pin.dir(m.DIR_OUT);
pin.write(0);
console.log(pin);
iv = setInterval(function () {
    led.write(led.read() ^ 1);
}, 200);
示例#15
0
/*
 * Author: Dan Yocom <*****@*****.**>
 * Copyright (c) 2014 Intel Corporation.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

var m = require('mraa'); //require mraa
console.log('MRAA Version: ' + m.getVersion()); //write the mraa version to the console

var myDigitalPin = new m.Gpio(5); //setup digital read on pin 5
myDigitalPin.dir(m.DIR_OUT); //set the gpio direction to output
myDigitalPin.write(1); //set the digital pin to high (1)
示例#16
0
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
// Leave the above lines for propper jshinting
//Type Node.js Here :)


var mraa= require('mraa'); //Include MRAAlibrary
var mqtt=require('mqtt');

// Find MRAA pin mappings at https://learn.sparkfun.com/tutorials/sparkfun-inventors-kit-for-edison-experiment-guide/appendix-e-mraa-pin-table

var led1= new mraa.Gpio(33);  //LED - Green Led - GP48
var led2 = new mraa.Gpio(48); // Arduino - BLUE led - GP15
var led3 = new mraa.Gpio(32); // RED led - RPI - GP46

led1.dir(mraa.DIR_OUT);
led2.dir(mraa.DIR_OUT);
led3.dir(mraa.DIR_OUT);

//Clear all LEDs
led1.write(0);
led2.write(0);
led3.write(0);

var client = mqtt.connect({host:'172.20.10.7', port:'1883',  protocolId: 'MQIsdp', protocolVersion: 3, keepalive: 60, clientId:'mqtt_edison'});

client.on('connect', function () {
    console.log('connected')
  client.subscribe({'lightStatus': 2,'Status/Arduino': 2,'Status/RPi':2});
});
示例#17
0
文件: isr.js 项目: KurtE/mraa
#!/usr/bin/env node

"use strict";

const mraa = require('mraa');

function hello() {
    console.log("HELLO!!!!");
}

let pin = new mraa.Gpio(14);
pin.isr(mraa.EDGE_BOTH, hello);

setInterval(function() {
    // It's important to refer to our GPIO context here,
    // otherwise it will be garbage-collected
    console.log("Waiting for an interrupt at GPIO pin " + pin.getPin() + "...");
}, 10000);
示例#18
0
//Reference http://codefoster.com/edison-setup
var mraa = require('mraa'); //create a reference to the built-in mraa library (which provides easy access to hardware capabilities)
var led = new mraa.Gpio(13); //setup a variable for pin 13 which also happens to be an LED on the board (how convenient)
led.dir(mraa.DIR_OUT); //tell pin 13 that it should act as an output pin for now
var state = 0; //create a variable for saving the state of the LED
var blink = function() { state = (state==1?0:1); led.write(state); setTimeout(blink,500); } //create a function that changes the state, waits 500ms, and then calls itself
blink() //start blinking
 var blinkingOn = setInterval(function () {
     pushButtonLight.write(1);
 }, 200);
示例#20
0
var blink = function() { state = (state==1?0:1); led.write(state); setTimeout(blink,500); } //create a function that changes the state, waits 500ms, and then calls itself
//-----------------------------------------------------------------------------------------------------------
function setupMonitoring() {
    initWebService();
    logger("App mode: " + appMode);

//------------------ initialize power booster to OFF
    powerBoost = new mraa.Gpio(voltageBoostPin);
    powerBoost.dir(mraa.DIR_OUT);
    powerBoost.write(0);

    touchSensor = new touchSensorDriver.MPR121(touchSensorDriver.MPR121_I2C_BUS, touchSensorDriver.MPR121_DEFAULT_I2C_ADDR);

    if (touchSensorWorks()) {
        logger("TOUCH SENSOR OK");
        initTouchSensor();

    }
    else {
        logger(" !!!!!!!!!!!!!!!!!! NO TOUCH SENSOR !!!!!!!!!!!!!!!!");
    }


    gyroAccelCompass = new IMUClass.LSM9DS0();

    if (gyroAccelCompass.readReg(IMUClass.LSM9DS0.DEV_GYRO, IMUClass.LSM9DS0.REG_WHO_AM_I_G) != 255) {
        logger("MOTION SENSOR OK");
        gyroAccelCompass.init();                          // Initialize the device with default values
        setupGyroscope();
        setupAccelerometer();


        gyrocsopeInterrupt = new mraa.Gpio(GyroscopeInterruptPin);
        gyrocsopeInterrupt.dir(mraa.DIR_IN);

        horizontalPositionInterrupt = new mraa.Gpio(horizontalPositionInterruptPin);
        horizontalPositionInterrupt.dir(mraa.DIR_IN);


        var moduleTransportationInterrupt = new mraa.Gpio(moduleIsBeingTransportedInterruptPin);
        moduleTransportationInterrupt.dir(mraa.DIR_IN);


        gyrocsopeInterrupt.isr(mraa.EDGE_BOTH, gyroInterruptCallBack);
        horizontalPositionInterrupt.isr(mraa.EDGE_BOTH, horizontalPositionCallBack);
        moduleTransportationInterrupt.isr(mraa.EDGE_BOTH, moduleTransportationCallBack);

    }
    else {
        logger(" !!!!!!!!!!!!!!!!!! NO MOTION SENSOR !!!!!!!!!!!!!!!!");
        IMUSensorIsDamaged = true;
    }

    showHardwareStateOnButton();
    logger("The system will be idled for " + (delayBeforeActivatingAllSensors/60000) + " minutes to allow mounting of the unit...");
    setTimeout(function(){
        appState = "active";
        logger("Application now running will all sensors activated");
    }, delayBeforeActivatingAllSensors );

}
var mraa = require ('mraa');
var LCD  = require ('jsupm_i2clcd');
var mathjs = require ('mathjs');
var moment = require('moment-timezone');

var temperatureSensor = new mraa.Aio(0);
var lightSensor = new mraa.Aio(1);
var soundSensor = new mraa.Aio(2);
var airQualitySensor = new mraa.Aio(3);

var touchSensor = new mraa.Gpio(2);
var buzzer = new mraa.Gpio(3);
var LED = new mraa.Gpio(4);
var switchButton = new mraa.Gpio(5);
var POT = new mraa.Gpio(5);

touchSensor.dir(mraa.DIR_IN);
buzzer.dir(mraa.DIR_OUT);
LED.dir(mraa.DIR_OUT);
switchButton.dir(mraa.DIR_OUT);
POT.dir(mraa.DIR_IN);

var tempPinValue, lightPinValue, soundPinValue, airQualityPinValue;
var tempValue, lightValue, soundValue, airQualityValue;
var lcdMessage_temp = "Temperature Sense";
var lcdMessage_light = "Light Sense";
var lcdMessage_sound = "Sound Level Sense";
var lcdMessage_airQuality = "Air Quality Sense";

var myLCD = new LCD.Jhd1313m1(0, 0x3E, 0x62);
示例#23
0
 setTimeout(function() { led.write(0); }, 500);
function loop() {
	/* Started Reading Sensor Data	*/
	tempPinValue = temperatureSensor.read();
	tempValue = getTemperature(tempPinValue);
	lightPinValue  = lightSensor.read();
	lightValue = Math.round( lightPinValue/1023*100);
	soundPinValue = soundSensor.read();
	soundValue = Math.round( soundPinValue/1023*100);
	airQualityPinValue = airQualitySensor.read();
	airQualityValue = Math.round( airQualityPinValue/1023*100);
	
	var touchVal = String(touchSensor.read());
	/* Finished Reading Sensor Data	*/
	
	lcdMessage_temp = "Temp. is @ "+tempValue;
	lcdMessage_light = "Light is @ "+lightValue+" %";
	var lcdMessage_sound = "Sound is @"+soundValue+" %";
	var lcdMessage_airQuality = "AirQlty @ "+airQualityValue+" %";

	myLCD.setCursor(0,0);
	myLCD.write(lcdMessage_temp);
	myLCD.setCursor(1,0);
	myLCD.write(lcdMessage_light);
	
	/*	Process Touch Sensor Data	*/
	if(touchVal == '1') {
		LED.write(1);
		buzzer.write(1);
		while(String(touchSensor.read()) == '1') {
			myLCD.setCursor(0,0);
			myLCD.write("Touch Detected:)");
			myLCD.setCursor(1,0);
			myLCD.write(getTime());
		}
	}
	if(touchVal == '0') {
		buzzer.write(0);
	}
	
	/*	Process Light Sensor Data	*/
	if(lightValue > 10) {
		LED.write(0);
	}
	if(lightValue < 10) {
		LED.write(1);
	}
	
	/*	Process Sound Sensor Data	*/
	if(soundPinValue > 200) {
		if(soundPinValue > 450) {
			console.log('Clapping! Sound Level @ '+soundPinValue+" at "+getTime());
		}
		else if(soundPinValue > 350) {
			console.log('Talking/Singing! Sound Level @ '+soundPinValue+" at "+getTime());
		}
		//else
			//console.log('Fan! Normal Sound Level @ '+soundPinValue+" at "+getTime());
	}
	else if(soundPinValue < 200) {
		//Normal Value @HomeAlone
		//console.log('Sound Level @ '+soundPinValue);
	}
	
	/*	Process Air Quality Sensor Data	*/
	if(airQualityPinValue > 150) {
		if(airQualityPinValue > 500) {
			console.log('Critical Condition!!  Air Quality Level @ '+airQualityPinValue+" at "+getTime());
		}
		else if(airQualityPinValue > 350) {
			console.log('Warning! High CO2 Content!  Air Quality Level @ '+airQualityPinValue+" at "+getTime());
		}
		else
			console.log('Moderate CO2 Content! Air Quality Level @ '+airQualityPinValue+" at "+getTime());
	}
	else if(airQualityPinValue < 150) {
		//Normal Value @Home
		//console.log('Air Quality Level @ '+airQualityPinValue);
	}
	
	//console.log('Sound Level @ '+soundPinValue+'	Air Quality Level @ '+airQualityPinValue+" at "+getTime());
	
	setTimeout(loop,100);
}
function UpdateLed()
{
   led.write(doorState);
}
示例#26
0
// The program is using the `twilio` module
// to make the remote calls to Twilio service
// to send SMS alerts
var twilio = require("twilio")(config.TWILIO_ACCT_SID,
                               config.TWILIO_AUTH_TOKEN);

// Used to store the schedule for turning on/off the
// watering system, as well as store moisture data
var SCHEDULE = {},
    MOISTURE = [],
    intervals = [];

// Initialize the hardware devices
var moisture = new (require("jsupm_grovemoisture").GroveMoisture)(0),
    flow = new (require("jsupm_grovewfs").GroveWFS)(2),
    pump = new mraa.Gpio(4);

// Set GPIO direction to output
pump.dir(mraa.DIR_OUT);

// Set up 0-23 hour schedules
for (var i = 0; i < 24; i++) {
  SCHEDULE[i] = { on: false, off: false };
}

// Helper function to convert a value to an integer
function toInt(h) { return +h; }

// Display and then store record in the remote datastore
// of each time a watering system event has occurred
function log(event) {
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/   

var allthingstalk = require('allthingstalk');
var mraa = require('mraa'); //Wrapper for GPIO Pins

var a0 = new mraa.Aio(0); //setup access analog input Analog pin #0 (A0)
var d4 = new mraa.Gpio(4); //LED hooked up to digital pin 4 

d4.dir(mraa.DIR_OUT); //set the gpio direction to output
var state = false; //Boolean to hold the state of Led

allthingstalk.credentials = require('./credentials');

// Set up the Potentiometer Sensor
allthingstalk.addAsset(
	"0",
	"Thermo-reactor turbine speed controller",
	"Controls the main turbine of the nuclear reactor, using a good ol' potentiometer",
	"int",
	function(){
    	console.log("Turbine potentiometer controller enrolled")
	}
led_pins.forEach(function (pinNumber) {
  var pin = new mraa.Gpio(pinNumber); 
  pin.dir(mraa.DIR_OUT); 
  pin.write(1);
});
示例#29
0
var twitter = require('twitter');
var fs = require('fs');

var mraa = require('mraa');
var pin13 = new mraa.Gpio(13);
pin13.dir(mraa.DIR_OUT);


var client = new twitter({
    consumer_key: 'VeuGh3jZBd14iDv1kAEsqF1Id',
    consumer_secret: 'mHv0OmxDSELIVocu18Mj3LlAAoaBzLqoA5N3uSXgqcrruO3rQS',
    access_token_key: '4075978940-M2RsGnrYkb7X4tJIyxVGJMSQdMROtNd4NodybOF',
    access_token_secret: 'F5rZqpMc2wr5n7tzd8CkRTRdFCfhjxJIhP5ESbi2fmfLX'
});

var content = fs.readFileSync('index.jpg');

client.post('media/upload', { media: content }, function(error, data, response) {
    if (!error) {
        console.log("Hey got some media riding on you");
        console.log(data);
        var mediaIdStr = data.media_id_string;
        var params = { status: 'Go here!!!', media_ids: mediaIdStr };

        client.post('statuses/update', params, function(error, data, response) {
            if (!error) {
                console.log("tweet madi again");
                for (var i = 0; i < 3; i++) {
                    pin13.write(1);
                    pin13.write(0);
                }
示例#30
0
var mraa = require('mraa');
var pin13 = new mraa.Gpio(13);
pin13.dir(mraa.DIR_OUT);
pin13.write(1);