Moteino + Raspberry pi controlled door lock

Started by goryri, January 17, 2014, 07:49:51 AM

goryri

Yes got it working!  :)

Added this to shutdowncheck:
gpio export 28 output
gpio export 30 output

npm install wiring-pi

then I could control the relay this way:
var wpi = require('wiring-pi');
wpi.wiringPiSetupSys();
wpi.digitalWrite(28, wpi.HIGH);
wpi.digitalWrite(30, wpi.HIGH);

goryri


goryri

#17
sudo apt-get install libasound2-dev
npm install lame
npm install speaker
npm install wiring-pi

this is the command I use to kill gateway.js  ps aux | grep "gateway.js" | grep -v grep | awk '{print $2}' | xargs kill -9

I have some problem whit the code the mp3 file is only playing 1,5 time when it should be playing 5 times. Anyone that gets why? http://www.youtube.com/watch?v=d3zGCdISbkk
var lame = require('lame'), Speaker = require('speaker'), fs = require('fs'), var wpi = require('wiring-pi');
wpi.wiringPiSetupSys();

playSong('alarm.mp3',5, 10000);

function playSong(song,repeat,timout) {
        writeHigh();
		console.log("MUSIC START");
		var $stream = fs.createReadStream(song).pipe(new lame.Decoder).pipe(new Speaker);
		var i = 0;
		
		function repeat()
		{
			$stream = fs.createReadStream(song).pipe(new lame.Decoder).pipe(new Speaker);
			i++; 
		}
		
	    $stream.on('error', function(err){
		  // handle playback error
		  console.log(err);
		  writeLow();
		});
		
		setTimeout(function() {
			$stream.end();
			writeLow();
		}, timout);

		$stream.on('close', function()
		{ 
			if (i < repeat) 
			{
				console.log("MUSIC REPEAT");
				repeat();
			}
			else
			{
				writeLow();
			}
		});
}

function writeHigh(){
		console.log("RELAY ON");
		wpi.digitalWrite(28, wpi.HIGH);
		wpi.digitalWrite(30, wpi.HIGH);
}

function writeLow(){
		console.log("RELAY OFF");
		wpi.digitalWrite(28, wpi.LOW);
		wpi.digitalWrite(30, wpi.LOW);
}

goryri

#18
Now do I have a way of controlling my cube whit node.js. But I having bad experience whit it. If i use sleep do i block execution of all javascript! node.js server processes seem to freeze up for a long time (seconds) from time to time and I had to restart raspberry pi serveral times. Since the cube is only on when my pc is on will I write a udp server in c# where I write effects and send it to the cube.    I followed this guide for making the cube http://www.instructables.com/id/Led-Cube-8x8x8/ .
var serialport = require("serialport");
var serialcube = new serialport.SerialPort("/dev/ttyUSB0", { baudrate : 38400, parser: serialport.parsers.readline("\n") });

function createArray(length) {
    var arr = new Array(length || 0),
        i = length;

    if (arguments.length > 1) {
        var args = Array.prototype.slice.call(arguments, 1);
        while(i--) arr[length-1 - i] = createArray.apply(this, args);
    }
    return arr;
}

var data = createArray(8, 8);
fill(0x00);


function myFunction()
{
	setvoxel(0, 0, 0);
	cube_push();
}

function setvoxel(x, y, z)
{
	if (inrange(x,y,z))
		data[z][y] |= (1 << x);
}

function clrvoxel(x, y, z)
{
	if (inrange(x,y,z))
		data[z][y] &= ~(1 << x);
}

function fill (pattern)
{
	var z;
	var y;
	for (z=0;z<8;z++)
	{
		for (y=0;y<8;y++)
		{
			data[z][y] = pattern;
		}
	}
}

function inrange(x, y, z)
{
	if (x >= 0 && x < 8 && y >= 0 && y < 8 && z >= 0 && z < 8)
	{
		return true;
	} else
	{
		// One of the coordinates was outside the cube.
		return false;
	}
}

function cube_push()
{
	var i = 0;
	var buffer = new Array();
	buffer[i] = 0xff;
	i += 1;
	buffer[i] = 0x0;
	i += 1;

	for (var x = 0; x < 8; x++)
	{
		for (var y = 0; y < 8; y++)
		{
			buffer[i++] = data[y][x];
			if (data[y][x] == 0xff)
			{
				buffer[i++] = data[y][x];
			}
		}
	}
	serialcube.write(buffer, 0, i);
}

goryri

#19
Today have im been working whit getting tasker to work whit node.js.
I started whit downloaded lib folder from https://github.com/Wisembly/elephant.io to /var/www/default
sudo apt-get install php5-curl

sudo nano /etc/php5/fpm/php.ini

Added extension=curl.so after Dynamic Extensions.

Saved and restarted php:  sudo service php5-fpm restart

Created a new php file client.php and added this code:

<?php
require( __DIR__ . '/lib/ElephantIO/Client.php');
use ElephantIO\Client as ElephantIOClient;

$elephant = new ElephantIOClient('http://localhost:8080', 'socket.io', 1, false, true, true);

$elephant->init();
$elephant->emit('DORSTS', 'got status?');
$elephant->close();
?>


Then set Tasker to run a shell script like this:
curl https://username:[email protected]/client.php --insecure
The key here is the "--insecure" flag which tells cURL to ignore the SSL certificate warning.

Then i used Trigger to write to nfc tag that triggers the task when I scan it whit my phone. Demo http://www.youtube.com/watch?v=gBh8OC36KYs

goryri


goryri

#21
I have connected gpio pins to the buttons on the 8x8x8 led cube so that I can start rs232 mode, reset and start animations on the cube from internet.

nano shutdowncheck


gpio export 2  output
gpio export 29 output
gpio export 31 output

gpio -g write 29 1
gpio -g write 31 1
gpio -g write 2  1

http://www.youtube.com/watch?v=ocUBnr-OMKc

curl https://username:[email protected]/client.php?cmd=MAIN_BTN --insecure
-------------------------------------------------------
BUTTON       ||  Port      || Pin nr    ||  GPIO pin   ||
-------------------------------------------------------
MAIN_BTN    || PINB4    ||    5       ||  29            ||
RS232_BTN  || PIND5    ||   19      ||  31            ||
RESET_BTN  || RESET    ||    9       ||  2              ||
-------------------------------------------------------

<?php
require( __DIR__ . '/lib/ElephantIO/Client.php');
use ElephantIO\Client as ElephantIOClient;
$elephant = new ElephantIOClient('http://localhost:8080', 'socket.io', 1, false, true, true);
$elephant->init();
$elephant->emit($_GET["cmd"], $_GET["cmd"]);
$elephant->close();
?>

  socket.on('MAIN_BTN', function (data) {
    console.log(data.toString());
	Pressbutton('RESET_BTN', 100);
	setTimeout(function() {
		Pressbutton('MAIN_BTN', 100);
	}, 200);
  });
  
   socket.on('RS232_BTN', function (data) {
    console.log(data.toString());
	Pressbutton('RESET_BTN', 100);
	setTimeout(function() {
		Pressbutton('RS232_BTN', 100);
	}, 200);
  });
 
  socket.on('RESET_BTN', function (data) {
	console.log(data.toString());
	Pressbutton('RESET_BTN', 100);
  });
  
  function Pressbutton(btname, delay)
{
	switch (btname)
	{
		case 'MAIN_BTN':
				wpi.digitalWrite(29, wpi.LOW);
				break;
		case 'RS232_BTN':
				wpi.digitalWrite(31, wpi.LOW);
				break;
		case 'RESET_BTN':
				wpi.digitalWrite(2, wpi.LOW);
				break;
	}
	
	setTimeout(function() {
		wpi.digitalWrite(29, wpi.HIGH);
		wpi.digitalWrite(31, wpi.HIGH);
		wpi.digitalWrite(2,  wpi.HIGH);
	}, delay);
}

goryri

Have made some progress now. Have added

  • Wake on lan
  • SMS notification using wavecom modem
  • Projector power on/off
  • and much more..
demo: www.youtube.com/watch?v=sXgScbBoOZ4

Felix

That's some serious progress! Keep it coming!

goryri

New demo http://www.youtube.com/watch?v=_esg_ueAh-g

  • have added rgb led
  • Autovoice voice recognition that trigger task in tasker
  • Pushover notifications send from node.js
  • SpeakMe pro reads notifications from pushover 

Felix

Goran, nice work. If you would be able to put all the info together in a writeup on your blog, with perhaps a more complete video, I would be glad to post it on the LowPowerLab blog. It looks like a great project so it would make a great entry on the hackaday.com website as well, but they do like to see a nice writeup with details and good pictures...

goryri

Tank you! Im gone make a writeup soon but I have some parts that I wants to finish first.

  • Control safe whit Moteino
  • Control blueray player whit serial port on the raspberry pi
  • remote shutdown compute C# r
  • 8x8x8 led cube animation when received mail C#
  • voice recognition computer c#

Felix

Awesome, take your time, there's no rush.
If your automation consists of multiple parts you might want to break it into multiple writeups so users have an easier time digesting it all.

goryri

#28
Hi,
I want to make a update on what im have been working on.


Felix