Showing posts with label Raspbian. Show all posts
Showing posts with label Raspbian. Show all posts

Monday, October 5, 2015

How to compile nginx with nginx-rtmp-module

Prepare environment for compile.
$ sudo apt-get update
$ sudo apt-get install libpcre3-dev libatomic-ops-dev libgeoip-dev geoip-bin geoip-database geoip-database-extra libperl-dev libssl-dev libxml2-dev libxslt1-dev

Create directory src

$ mkdir src

Download Nginx (last version)

$ cd src
$ wget http://nginx.org/download/nginx-1.9.5.tar.gz
$ tar -xvzf nginx-1.9.5.tar.gz

Git Clone nginx-rtmp-module

$ git clone https://github.com/arut/nginx-rtmp-module.git


Change current to nginx-1.9.5

$ cd nginx-1.9.5

Run configure

$ ./configure --prefix=/usr/local/nginx --user=www-data --group=www-data --with-select_module --with-poll_module --with-threads --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module  --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-pcre --with-pcre-jit --with-md5-asm --with-sha1-asm --with-libatomic --with-pcre --with-stream --with-stream_ssl_module --with-http_v2_module --add-module=../nginx-rtmp-module

Run make to compile

$ make

Install nginx to /usr/local/nginx

$ sudo make install

Config Nginx on /usr/local/nginx/conf/nginx.conf

$ sudo nano /usr/local/nginx/conf/nginx.conf


Config for streaming server see on nginx-rtmp-module wiki

Web path /usr/local/nginx/html

Start nginx service

$ sudo /usr/local/nginx/sbin/nginx

Stop nginx service

$ sudo /usr/local/nginx/sbin/nginx -s stop


Reference
Nginx

nginx-rtmp-module (source code)

nginx-rtmp-module (wiki)

Streaming with nginx-rtmp-module


Wednesday, September 30, 2015

How to Disable Power Management of rtl8192cu

Fix problem wireless disconnect and go to save mode.

Create file /etc/modprobe.d/8192cu.conf

$ sudo nano /etc/modprobe.d/8192cu.conf

add this line

options 8192cu rtw_power_mgnt=0 rtw_enusbss=0


Restart raspberry pi



Reference :

https://github.com/xbianonpi/xbian/issues/217

https://github.com/pvaret/rtl8192cu-fixes/blob/master/8192cu-disable-power-management.conf

DLNA/UPnP with MiniDLNA

How to build DLNA/UPnP Server on Raspberry PI for use at Home device.
(Example TV, Media player, PS3, Xbox etc.)


Install minidlna package

$ sudo apt-get install minidlna


Add pi user to minidlna group

$ sudo usermod -a -G minidlna pi

Create Directory for store media file

Example:

$ mkdir -p /home/pi/minidlna/music
$ mkdir -p /home/pi/minidlna/pictures
$ mkdir -p /home/pi/minidlna/videos
$ mkdir -p /home/pi/.minidlna

Change Mode of /home/pi/minidlna and /home/pi/.minidlna
$ sudo chmod 777 /home/pi/minidlna
$ sudo chmod 777 /home/pi/.minidlna

Config MiniDLNA

$ sudo nano /etc/minidlna.conf

Modify this file
...
db_dir=/home/pi/.minidlna/data
log_dir=/home/pi/.minidlna/data/log
# * "A" for audio (eg. media_dir=A,/var/lib/minidlna/music)
# * "P" for pictures (eg. media_dir=P,/var/lib/minidlna/pictures)
# * "V" for video (eg. media_dir=V,/var/lib/minidlna/videos)
media_dir=A,/home/pi/minidlna/music
media_dir=P,/home/pi/minidlna/pictures
media_dir=V,/home/pi/minidlna/videos
# Name that the DLNA server presents to clients.
friendly_name=RASPBERRY DLNA
# Automatic discovery of new files in the media_dir directory.
inotify=yes
# Notify interval, in seconds.notify_interval=895...

Restart MiniDLNA Service

$ sudo /etc/init.d/minidlna restart

Or re-indexing all of media files

$ sudo /etc/init.d/minidlan force-reload



Test on Device supported with DLNA/UPnP to play media.




Reference:

Digital Living Network Alliance
https://en.wikipedia.org/wiki/Digital_Living_Network_Alliance

ReadyMedia (MiniDLNA Source Code)
http://sourceforge.net/projects/minidlna/

ReadyMedia (Wiki of Archlinux)
https://wiki.archlinux.org/index.php/ReadyMedia

Saturday, July 18, 2015

VNC Server for Raspberry PI with dispmanx

You can remote console of raspberry pi with dispmanx


Install libvncserver-dev, gcc and g++ version 4.7

$ sudo apt-get install gcc-4.7 g++-4.7 libvncserver-dev

Update alternatives version of gcc and g++

$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6

$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7

Select gcc and g++ version to 4.7 (2)

$ sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/gcc-4.6 60 auto mode
1 /usr/bin/gcc-4.6 60 manual mode
2 /usr/bin/gcc-4.7 40 manual mode

Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/gcc-4.7 to provide /usr/bin/gcc (gcc) in manual mode
See on : https://github.com/Na1w/dispmanx_vnc

Clone source code of dispmanx.
$ git clone https://github.com/Na1w/dispmanx_vnc.git

Compile dispmanx.

$ cd dispmanx_vnc
$ make
After compile finish. It has dispmanx_vncserver file.
Copy this file to execute path. example /bin, /usr/local/bin, etc.


If you want to use X, modprobe  evdev first.

$ sudo modprobe evdev
See on : https://github.com/hanzelpeter/dispmanx_vnc


Start dispmanx vncserver

$ sudo dispmanx_vncserver
*** default port 5900

Stop dispmanx vncserver with Control + C Key.



Start dispmanx vncserver with password

$ sudo dispmanx_vncserver -P [password]

Change port number

$ sudo dispmanx_vncserver -p [port number]


Screen resolution config on /boot/config.txt

Example (1280x1024)
#HDMI force hotplug
hdmi_force_hotplug=1
# Group DMT
hdmi_group=2
# mode 35 - 1280x1024 60Hz
hdmi_mode=35
Reboot after save config.

Reference:

dispmanx_vnc
https://github.com/hanzelpeter/dispmanx_vnc

https://github.com/Na1w/dispmanx_vnc

Raspberry PI Document configuration config.txt
https://www.raspberrypi.org/documentation/configuration/config-txt.md

Thursday, July 16, 2015

How to use VNC Server on Raspberry PI

If you want to remote to Raspbian with X Windows Desktop, you can use vnc server.

Install TightVNC Server.

$ sudo apt-get install tightvncserver

After install finished.

Start vncserver.

$ tightvncserver :<DISPLAY NUMBER>

Example: Start VNC Server on Display number 1 or port 5901 run with pi user.
$ tightvncserver :1

You will require a password to access your desktops.

Password: 
Verify: 

Would you like to enter a view-only password (y/n)? n


New 'X' desktop is raspberrypi:1


Creating default startup script /home/pi/.vnc/xstartup

Starting applications specified in /home/pi/.vnc/xstartup

Log file is /home/pi/.vnc/raspberrypi:1.log

On first time run script. Program will ask password for connect to VNC Server and ask view-only mode for this password.



After run tightvncserver. You can use TightVNC Viewer or VNC Client for remote to server.

Enter IP Address : Display number and Connect


Enter Password and OK

Connected to VNC Server


If you want to change vnc password for remote, use this command.
$ tightvncpasswd
Using password file /home/pi/.vnc/passwd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n

VNC Password File save on /<User Directory>/.vnc/passwd


Stop VNC Server

$ tightvncserver -kill :<DISPLAY NUMBER>

Example : Stop VNC Server Display number 1

$ tightvncserver -kill :1

Screen resolution of VNC.
Start VNC Server with option.

$ tightvncserver -geometry <width>x<height> -depth <color depth>

Example

$ tightvncserver -geometry 1280x720 -depth 16 :1

Reference :

TightVNC
http://tightvnc.org/


Tuesday, July 7, 2015

How to use DS3231 I2C Real Time Clock



Before use DS3231 I2C Real Time Clock. Enable I2C Interface.

On new kernel use Device Tree Overlays.

Edit on /boot/config.txt.

add new line

device_tree_param=i2c1=on
dtoverlay=i2c-rtc,ds3231

Reference : https://github.com/raspberrypi/firmware/tree/master/boot/overlays

Edit on /etc/modprobe.d/raspi-blacklist.conf

add # (comment) on line "blacklist i2c-bcm2708"

#blacklist i2c-bcm2708

Reboot Raspberry PI

sudo shutdown -r now

Re-Check I2C Interface software

$ dmesg | grep i2c
[    5.505513] bcm2708_i2c 20804000.i2c: BSC1 Controller at 0x20804000 (irq 79) (baudrate 100000)
[   11.969815] i2c /dev entries driver

$ lsmod
i2c_bcm2708             6244  0

If you found, software is enabled.


Install DS3231 I2C RTC to Raspberry PI



Test to get time from RTC Module.

$ sudo hwclock -r 
Tue 07 Jul 2015 05:20:09 PM ICT  -0.397656 seconds 

If you want to current time of Raspberry PI to RTC Module.

$ sudo hwclock -w

If you want to set time of RTC Module to Raspberry PI.

$ sudo hwclock -s

You can set time of RTC Module to Raspberry PI on startup.

Edit on file /etc/rc.local
Add line

/sbin/hwclock -s

before line "exit 0"


Reference :
Device Tree overlays of Raspberry PI Firmware
https://github.com/raspberrypi/firmware/tree/master/boot/overlays
Adding a hardware clock to Raspberry Pi (DS3231)
http://www.drewkeller.com/blog/adding-hardware-clock-raspberry-pi-ds3231
Adding a DS3231 Real Time Clock To The Raspberry Pi
http://www.raspberrypi-spy.co.uk/2015/05/adding-a-ds3231-real-time-clock-to-the-raspberry-pi/
Using an I2C Real Time Clock (RTC) with a Raspberry Pi
https://nicegear.co.nz/blog/using-an-i2c-real-time-clock-rtc-with-a-raspberry-pi/

How to use RFID-RC522 on Raspbian



Before use RFID-RC522. Enable SPI Interface (Update 2018-09-28)

Current kernel in document (Raspbian GNU/Linux 9 Kernel Version 4.14.70-v7+ #1144)

Enable SPI Interface
- Use command
$ sudo raspi-config
select menu
5 Interfacing Options -> SPI -> Yes -> OK -> Finish
Or

- Edit on /boot/config.txt.

change this line

dtparam=spi=on


Edit on /etc/modprobe.d/raspi-blacklist.conf

add # (comment) on line "blacklist spi-bcm2708"

#blacklist spi-bcm2708

Reboot Raspberry PI

sudo shutdown -r now

Re-Check SPI Interface software

$ dmesg | grep spi
[    5.408904] bcm2708_spi 20204000.spi: master is unqueued, this is deprecated
[    5.659213] bcm2708_spi 20204000.spi: SPI Controller at 0x20204000 (irq 80)

$ lsmod | grep spi
spidev                 16384  0
spi_bcm2835            16384  0


If you found, software is enabled.

Install Software for use RFID-RC522
Install python-dev

sudo apt-get install python-dev

Install SPI-Py (Hardware SPI as a C Extension for Python)

git clone https://github.com/lthiery/SPI-Py.git
cd SPI-Py
sudo python setup.py install

Install MFRC522-python

git clone https://github.com/mxgxw/MFRC522-python.git 
cd MFRC522-python 

Install Python RC522 library

$ git clone https://github.com/ondryaso/pi-rc522.git
$ cd pi-rc522
$ sudo python setup.py install


Install Pins between Raspberry PI and RFID-RC522

RFID-RC522 Pin
 Raspberry PI Pin
Raspberry PI Pin name
SDA
  24
    GPIO8
SCK
  23
    GPIO11
MOSI
  19
    GPIO10
MISO
  21
    GPIO9
IRQ
  18
    GPIO24
GND
  Any
    Any Ground
RST
  22
    GPIO25
3.3V
  1
    3V3

You can test read card.

$ cd examples
$ python Read.py
Starting

If touch the card, it will display.

Detected: 10
Card read UID: XX,XX,XX,XX
Setting tag
Selecting UID [XX, XX, XX, XX, XX]

Authorizing
Changing used auth key to [XX, XX, XX, XX, XX, XX] using method B

Reading
Calling card_auth on UID [XX, XX, XX, XX, XX]
S1B0: [0, 0, 105, 36, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Deauthorizing
Changing auth key and method to None
^C
Ctrl+C captured, ending read.

And test write card.

$ python KeyChange.py
Starting

Detected: 10
Card read UID: XX,XX,XX,XX
Setting tag
Selecting UID [XX, XX, XX, XX, XX]

Authorizing
Changing used auth key to [255, 255, 255, 255, 255, 255] using method A

Writing modified bytes
Calling card_auth on UID [XX, XX, XX, XX, XX]
Changing pos 2 with current value 0 to 105
Changing pos 3 with current value 0 to 36
Changing pos 4 with current value 0 to 64
Writing [0, 0, 105, 36, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] to S1B0
Not calling card_auth - already authed
S1B0: [0, 0, 105, 36, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Calling card_auth on UID [XX, XX, XX, XX, XX]
Changing pos 0 with current value 0 to 18
Changing pos 1 with current value 0 to 52
Changing pos 2 with current value 0 to 86
Changing pos 3 with current value 0 to 120
Changing pos 4 with current value 0 to 150
Changing pos 5 with current value 0 to 146
Changing pos 6 with current value 255 to 15
Changing pos 7 with current value 7 to 7
Changing pos 8 with current value 128 to 143
Changing pos 9 with current value 105 to 105
Changing pos 10 with current value 255 to 116
Changing pos 11 with current value 255 to 0
Changing pos 12 with current value 255 to 82
Changing pos 13 with current value 255 to 53
Changing pos 14 with current value 255 to 0
Changing pos 15 with current value 255 to 255
Writing [18, 52, 86, 120, 150, 146, 15, 7, 143, 105, 116, 0, 82, 53, 0, 255] to S1B3
Changing auth key and method to None
Stopping crypto1

You can learning python code for use RFID read and write data.



Python RC522 library : https://github.com/ondryaso/pi-rc522



Example Project for use NFC and Raspberry PI


  • Attendance system using Raspberry Pi and NFC Tag reader by Yim

http://www.instructables.com/id/Attendance-system-using-Raspberry-Pi-and-NFC-Tag-r/


Reference : 

Device Tree overlays of Raspberry PI Firmware
MIFARE (MFRC522) datasheet

Sunday, November 10, 2013

Geniatech DVB-T2 Stick T220 for Raspbian

Linux kernel 3.14 and later is support Geniatech DVB-T2 Stick T220 Driver.

Current version of Raspbian support it.

Raspberry PI kernel source code
https://github.com/raspberrypi/linux

Below for old kernel.

I try to find driver for Geniatech DVB-T2 Stick T220 on Raspbian. http://www.geniatech.com/pa/t220.asp
On product website. It's not have driver for linux.
I found driver on this website.
Source Driver from CrazyCat https://bitbucket.org/CrazyCat/s2-liplianin-v39
I test compile and install modules.
Now It's work for me.

And I try change some code on file dw2102.c for raspberry pi kernel code for t220 driver.
Raspberry PI Kernel source https://github.com/raspberrypi/linux and recompile for test it.
Now It's work for me.
I upload source code and kernel module for this developer and product user on below link.

T220 Driver Kernel Module (New) (Update 2013/11/08)
How to install driver new module (I compile on kernel 3.6.11)
  1. backup original driver (/lib/modules/3.6.11+/kernel/drivers/media/dvb/dvb-usb/dvb-usb-dw2102.ko)
  2. backup original driver (/lib/modules/3.6.11+/kernel/drivers/media/dvb/frontends/cxd2820r.ko)
  3. backup original driver (/lib/modules/3.6.11+/kernel/drivers/media/common/tuners/tda18271.ko) 
  4. extract t220_new_modules.zip (I will found cxd2820r.ko, tda18271.ko and dvb-usb-dw2102.ko)
  5. sudo rm -f /lib/modules/3.6.11+/kernel/drivers/media/dvb/dvb-usb/dvb-usb-dw2102.ko 
  6. sudo rm -f /lib/modules/3.6.11+/kernel/drivers/media/dvb/frontends/cxd2820r.ko 
  7. sudo rm -f /lib/modules/3.6.11+/kernel/drivers/media/common/tuners/tda18271.ko 
  8. sudo install -c -D -m 644 -c dvb-usb-dw2102.ko /lib/modules/3.6.11+/kernel/drivers/media/dvb/dvb-usb/ 
  9. sudo install -c -D -m 644 -c cxd2820r.ko /lib/modules/3.6.11+/kernel/drivers/media/dvb/frontends/ 
  10. sudo install -c -D -m 644 -c tda18271.ko /lib/modules/3.6.11+/kernel/drivers/media/common/tuners/ 
  11. sudo /sbin/depmod -a
T220 Driver Kernel Module (Old)
How to install driver module (I compile on kernel 3.6.11)
  1. backup original driver (/lib/modules/3.6.11+/kernel/drivers/media/dvb/dvb-usb/dvb-usb-dw2102.ko) 
  2. extract dw2102.zip (I will found dw2102.c and dvb-usb-dw2102.ko) 
  3. sudo rm -f /lib/modules/3.6.11+/kernel/drivers/media/dvb/dvb-usb/dvb-usb-dw2102.ko 
  4. sudo install -c -D -m 644 -c dvb-usb-dw2102.ko /lib/modules/3.6.11+/kernel/drivers/media/dvb/dvb-usb/ 
  5. sudo /sbin/depmod -a
Now it's complete for install module.
For compile kernel module replace dw2102.c replace on <kernel path>/drivers/media/dvb/dvb-usb/dw2102.c

Automount NTFS Filesystem with usbmount on plug-in USB Storage Devices

First step. Install usbmount package on Raspbian with below command
sudo apt-get -y install usbmount fuse ntfs-3g
After install usbmount package.
Problem about default configure of usbmount.
It cannot automount NTFS Filesystem.
Modify configure of usbmount for mount NTFS Filesystem on /etc/usbmount/usbmount.conf with Editor. 

Find this line
FILESYSTEMS="vfat ext2 ext3 ext4 hfsplus"
Change to
FILESYSTEMS="vfat ext2 ext3 ext4 hfsplus ntfs fuseblk"
And Restart OS for force take effect.
sudo shutdown -r now
Finish Step.
Test plug-in USB Storage Devices with NTFS Filesystem.
It can automount on /media/usb0
For change default path of automount usb devices (/media/usb<number>)
Modify /etc/usbmount/usbmount.conf with Editor again.

Find this line
MOUNTPOINTS="/media/usb0 /media/usb1 /media/usb2 /media/usb3 /media/usb4 /media/usb5 /media/usb6 /media/usb7"
It can change to other location, if you want.
Sequence of mountpoint left to right.

device 1 -> /media/usb0
device 2 -> /media/usb1
...

If it don't umounted usb device and unplug it, mountpoint is not umount.
It cannot use this mountpoint on other device.
Please umount mountpoint before unplug usb device.