Jerry_k
Posts: 31
Joined: Wed Oct 10, 2012 7:20 pm

Home automation

Sun May 26, 2013 2:06 pm

Sorry for stupid question, but I try make home automation system with PN532 (only ordered, waitng for it).. I'm prepairing it for "plug&play"..

Alredy done:
Installed Gpio, Python, Sqlite3, Libnfc - configured and build..

I have only one question.. how to prepair sql table?
I want use this python program:
https://github.com/xillwillx/RFPiD/blob/master/rfid.py

I could create "sqlite3 DoorDatabase.db" but what to do next? how to name colums - I know ho name it (http://www.raspberrypiblog.com/2012/11/ ... on-pi.html), but don't know exactly name..

know somebody read it from rfid.py ? which one is first col, which second, naming etc?


And one more question.. could I run more python programs at the same time on one raspi?
one for door locking and another for pir sensors and lighting?

Thank you!

Jerry_k
Posts: 31
Joined: Wed Oct 10, 2012 7:20 pm

Re: Home automation

Mon May 27, 2013 9:31 am

okay, on second question solution found:
http://www.raspberrypi.org/phpBB3/viewt ... 7&p=241110
simple add &..

still looking solution for first question - how to make a database... (If no solution found until I receive HW, post will be deleted and card will be probably added directly into python script)

User avatar
rpdom
Posts: 17174
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Home automation

Mon May 27, 2013 10:54 am

I don't know Python, I usually program in PHP, Perl or bash, but I've scanned through the source you linked to and it seems to contain two simple tables.

The first is called "rfid" and has three columns called "card", "name" and "lastentry". I suspect these will all be text fields.

The second table is called "rejects" and has columns called "rejectedcard" and "whenrejected". Probably both text fields again.

It would have helped if the author of that code had included a bit more info :(

Jerry_k
Posts: 31
Joined: Wed Oct 10, 2012 7:20 pm

Re: Home automation

Tue May 28, 2013 6:03 pm

Thank you very much!

I had one more issue with module serial for python3 but I solved this by:
"sudo apt-get install python-serial python3-serial"

before I try only "sudo apt-get install python3-serial" and this was not working..

now there is another error for this serial because I have no HW right now, but I'm thinking about change from USB -> UART.. I'm totally noob, then if I solve this, I post a reply for other noobs, if you have idea try to post :) TY
Error:
File "rfid.py", line 18, in <module>
ser = serial.Serial(rfid_reader, timeout=1)
File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 260, in __init__
self.open()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 276, in open
raise SerialException("could not open port %s: %s" % (self._port, msg))
serial.serialutil.SerialException: could not open port /dev/ttyUSB0: [Errno 2] No such file or directory: '/dev/ttyUSB0'

Jerry_k
Posts: 31
Joined: Wed Oct 10, 2012 7:20 pm

Re: Home automation

Wed May 29, 2013 7:57 pm

Okay, usb -> uart solved from this link:

http://learn.adafruit.com/adafruit-nfc- ... ing-it-out

on screenshot is ttyAMA0 probably now it could working.
changed (rfid_reader = "/dev/ttyAMA0") in rfid.py..

Errors (probably by previous use and not freeing ports)

rfid.py:10: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(TRANSISTOR, GPIO.OUT)
rfid.py:11: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(BLUE_LED, GPIO.OUT)
rfid.py:12: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(GREEN_LED, GPIO.OUT)
rfid.py:13: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(RED_LED, GPIO.OUT)
Connected to RFID reader on: /dev/ttyAMA0

It write connected (part of rfid.py code), but I'm thinking its only waiting for reader.. I think it is ready to connect, do you think too?

PS to all: sorry for my english.. If somebody wants my rfid.py or something another.. I could send..

Jerry_k
Posts: 31
Joined: Wed Oct 10, 2012 7:20 pm

Re: Home automation

Thu Jun 13, 2013 10:10 am

Okey, after some time I received PN532 reader (mini version - which was not plug&play :shock: ), I had an issue with "No NFC device found" and after half day I found a solution and I solder some connectors to empty pins and connect it- now it working with libnfc with "sudo ./nfc-poll"..

my python is not working right now probably because this is wrong:
import serial, time, sys
ser = serial.Serial(rfid_reader, timeout=1)

code is read from print "Card Scanned. Tag ID:", rfid_data

but rfid_data = ser.readline().strip() - this is not working..

can you help me what "serial" really means and how to change it to something another? I'm using UART if its helpful..

Thank you!
Attachments
PN532 NFC-0.jpg
pins to connect for UART/HSU
PN532 NFC-0.jpg (17.76 KiB) Viewed 5737 times

Jerry_k
Posts: 31
Joined: Wed Oct 10, 2012 7:20 pm

Re: Home automation

Thu Jun 13, 2013 11:13 pm

back again..
I found this problem may be caused by "sleep" and "wake-up" conditions..

i think, there is way to send data to serial port from python in binary.. I need send 55 55 00 00 00 (from http://www.adafruit.com/forums/viewtopi ... 9&p=143292 somewhere in half page)

I found solution here http://www.linuxquestions.org/questions ... ng-708935/ - "ECHO" function

or here http://ubuntuforums.org/showthread.php?t=829416

but nothing working.. I do:
tty=serial.Serial("/dev/ttyAMA0", 115200)
output = '5555000000'
output = '5555000000' + chr(0x08) + chr(0x11)
tty.write(output)

Can you help me what is wrong?
PS: (as I say before I'm absolutely lame (or n00b like you calling it), please dont laught on my tries, I do my best)

SteveSpencer
Posts: 357
Joined: Thu Mar 28, 2013 9:19 am
Location: Nottingham, UK

Re: Home automation

Fri Jun 14, 2013 7:59 am

If you need to send the byte sequence 55 55 00 00 00
then you could try something like

output = chr(0x55) + chr(0x55) + chr(0) + chr(0) + chr(0) + chr(0x08) + chr(0x11)
tty.write(output)

I don't "do" Python, so I don't know how it will react to trying to put NUL characters into a string.
If it doesn't like it, you could try the individual characters.

As I say, I know nothing of this Python, but this might help you :)

Steve
Steve S
No, I can't think of anything funny that won't offend someone if they want it to...

PiGraham
Posts: 3939
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Home automation

Fri Jun 14, 2013 8:48 am

I haven't tried this, but the documentation says you can send a byte array:
write(data)
Parameters:

data – Data to send.

Returns:

Number of bytes written.
Raises SerialTimeoutException:


In case a write timeout is configured for the port and the time is exceeded.

Write the string data to the port.

Changed in version 2.5: Accepts instances of bytes and bytearray when available (Python 2.6 and newer) and str otherwise.

Jerry_k
Posts: 31
Joined: Wed Oct 10, 2012 7:20 pm

Re: Home automation

Sat Jun 15, 2013 8:03 pm

Thank you very much guys!!!

i have some bad news and some good..

bad news: not working..

good news: i found a source which is (probably) succesfully working - https://github.com/2m/zbap

but there is one more problem :D i don't know how to read it.. :D I'll try to ask for more how to connect to python, and i hope this will be useful to others too :)

Jerry_k
Posts: 31
Joined: Wed Oct 10, 2012 7:20 pm

Re: Home automation

Sat Jun 22, 2013 6:38 pm

more than 2000 views but no solution.. :?

okay.. I think about another way..

./nfc-poll return card number.. is possible put any data into nfc-poll.c and open gpio port for a few second??

something like this, but it's not working..
#include <time.h>
if (res > 0) {
echo 11 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio11/direction
echo 1 > /sys/class/gpio/gpio11/value
sleep(1000);
echo 0 > /sys/class/gpio/gpio11/value
echo 11 > /sys/class/gpio/unexport

print_nfc_target ( nt, verbose ); - this is working

Jerry_k
Posts: 31
Joined: Wed Oct 10, 2012 7:20 pm

Re: Home automation

Sat Jun 22, 2013 8:40 pm

sorry my mistake.. i must build it before use :/

now its working.. it open GPIO port with script:
#include <bcm2835.h>
#define PIN RPI_GPIO_P1_23
!bcm2835_init();
bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);
{
bcm2835_gpio_write(PIN, HIGH);
bcm2835_delay(1000);
bcm2835_gpio_write(PIN, LOW);
}
bcm2835_close();

last what i want is check if card UID is "in code" or "in database" and return TRUE = gpio open, FALSE = no gpio change..

Jerry_k
Posts: 31
Joined: Wed Oct 10, 2012 7:20 pm

Re: Home automation

Sun Jun 23, 2013 10:59 am

I want check card ID with if statement, like:
if ((nt.nti.nai.abtUid) == (0xbed9264b)) {

but...
With nfc-poll:
printf(" UID (NFCID%c): ");
print_hex(nt.nti.nai.abtUid, 4);
value return every time:
UID (NFCID): 21 d5 6f e8

but when I try:
printf( "The value is 0x%08x\n", nt.nti.nai.abtUid );
values are changed every time:
0xbeef164b
0xbecf564b
etc..

is possible fix it? or.. is here another way to check card ID with if statement?

I alredy try if (print_hex(nt.nti.nai.abtUid, 4)==0x21, 0xd5, 0x6f, 0xe8) {
but i receive error:
quick_start_example1.c:82:3: error: void value not ignored as it ought to be

dshakey
Posts: 2
Joined: Wed May 14, 2014 10:02 am

Re: Home automation

Mon May 26, 2014 6:30 pm

how you getting on with this project? i am just about to start the same thing.
what code did you use to interface with the NFC card?

i have ITEAD but its uses C++ i am looking for something in python.

Return to “Automation, sensing and robotics”