Author Topic: Moteino + Raspberry pi controlled door lock  (Read 14174 times)

goryri

  • Newbie
  • *
  • Posts: 35
Re: Moteino + Raspberry pi controlled door lock
« Reply #15 on: January 25, 2014, 02:42:20 PM »
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

  • Newbie
  • *
  • Posts: 35
Re: Moteino + Raspberry pi controlled door lock
« Reply #16 on: January 25, 2014, 04:17:53 PM »
Mailbox

goryri

  • Newbie
  • *
  • Posts: 35
Re: Moteino + Raspberry pi controlled door lock
« Reply #17 on: January 26, 2014, 05:48:25 AM »
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?
Code: [Select]

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);
}
« Last Edit: January 26, 2014, 06:23:32 AM by goryri »

goryri

  • Newbie
  • *
  • Posts: 35
Re: Moteino + Raspberry pi controlled door lock
« Reply #18 on: January 26, 2014, 10:27:19 AM »
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/ .
Code: [Select]
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);
}
« Last Edit: January 26, 2014, 12:49:27 PM by goryri »

goryri

  • Newbie
  • *
  • Posts: 35
Re: Moteino + Raspberry pi controlled door lock
« Reply #19 on: January 27, 2014, 08:44:15 AM »
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:

Code: [Select]
<?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:password@domain.com/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
« Last Edit: January 27, 2014, 08:49:18 AM by goryri »

goryri

  • Newbie
  • *
  • Posts: 35
Re: Moteino + Raspberry pi controlled door lock
« Reply #20 on: January 27, 2014, 05:56:13 PM »
Created a blog http://yrielectro.com/ about this project.

goryri

  • Newbie
  • *
  • Posts: 35
Re: Moteino + Raspberry pi controlled door lock
« Reply #21 on: January 28, 2014, 11:01:53 AM »
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:password@domain.com/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              ||
-------------------------------------------------------

Code: [Select]
<?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();
?>
Code: [Select]
  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);
}
« Last Edit: January 28, 2014, 11:54:21 AM by goryri »

goryri

  • Newbie
  • *
  • Posts: 35
Re: Moteino + Raspberry pi controlled door lock
« Reply #22 on: February 06, 2014, 02:47:26 PM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 5934
  • Country: us
    • LowPowerLab
Re: Moteino + Raspberry pi controlled door lock
« Reply #23 on: February 07, 2014, 08:44:58 AM »
That's some serious progress! Keep it coming!

goryri

  • Newbie
  • *
  • Posts: 35
Re: Moteino + Raspberry pi controlled door lock
« Reply #24 on: February 11, 2014, 11:57:50 AM »
New demo
  • 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

  • Administrator
  • Hero Member
  • *****
  • Posts: 5934
  • Country: us
    • LowPowerLab
Re: Moteino + Raspberry pi controlled door lock
« Reply #25 on: February 11, 2014, 12:43:17 PM »
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

  • Newbie
  • *
  • Posts: 35
Re: Moteino + Raspberry pi controlled door lock
« Reply #26 on: February 11, 2014, 02:28:20 PM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 5934
  • Country: us
    • LowPowerLab
Re: Moteino + Raspberry pi controlled door lock
« Reply #27 on: February 11, 2014, 02:52:02 PM »
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

  • Newbie
  • *
  • Posts: 35
Re: Moteino + Raspberry pi controlled door lock
« Reply #28 on: March 07, 2014, 05:14:16 AM »
Hi,
I want to make a update on what im have been working on.

  • Updated on a old project this one
    have made some modifications so its more space inside the box and I can unlock the door remotly whit this using Moteino of cource. 
  • New video
  • Built myself a ShapeOko CNC machine
  • Control safe whit Moteino
  • Control blueray player whit serial port on the raspberry pi
  • voice recognition computer c#
« Last Edit: March 07, 2014, 07:37:16 AM by goryri »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5934
  • Country: us
    • LowPowerLab
Re: Moteino + Raspberry pi controlled door lock
« Reply #29 on: March 07, 2014, 11:35:45 AM »
Quite impressive, excellent work!