Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Thursday, July 14, 2016

Live streaming video from the Raspberry Pi with Camera v2

Just got my Raspberry Pi Camera v2, cannot wait to unbox and play with it.


I didn't get a good case to fit in the camera module, but it works.  :)


First of all you can start by taking a picture to make sure your camera is working fine:

raspistill -o image.jpg

To capture your first video, you can use the command raspivid:

raspivid -o video.h264

The video is in raw h.264 format.  It is fine to be played back by my omxplayer on the Raspberry, however if you want most of the other video players to play it, it will be better to convert the file into mp4.

sudo apt-get install gpac
MP4Box -fps 30 -add video.h264 video.mp4

For some application such as "motion", the motion detection and video streaming applications, it needs to recognised the video device as /dev/video0.  It is not the case by default for the Pi Camera.

To enable that, you need to run:

sudo modprobe bcm2835-v4l2

You can also put this command in /etc/rc.local so that the next reboot it will run automatically.

Motion is an open source motion detection and surveillance software which can help you to convert your Raspberry Pi into a home surveillance camera.  To start with, you can get the motion package:

sudo apt-get install motion

A few parameters under motion.conf that you can change, such as:

daemon on

which makes the motion run in background when you start the motion server.

You can also change the resolution in the conf file:
width 1280
height 720

change the following parameter to off so that you can access from host other than localhost:
stream_localhost off
webcontrol_localhost off

You can now access the stream via http::8081


And you will get a bunch of files in your home directory, make sure you have enough storage, if not probably you might need to do it off box to a NAS or whatever it is.  These files are created when motion is detected.



These are the links that I've used to aid my setup, listing all here for your reference:
http://www.instructables.com/id/Raspberry-Pi-as-low-cost-HD-surveillance-camera/?ALLSTEPS
http://www.makeuseof.com/tag/raspberry-pi-camera-module/
http://www.raspberrypi-spy.co.uk/2013/05/capturing-hd-video-with-the-pi-camera-module/

Sunday, July 10, 2016

Using Web and Cisco Spark to control a Lego EV3 Robot


I have bought the Lego Mindstorms EV3 robot for more than 2 years, however I didn't spend any time on it until recently.  My daughter was sick and she has to stay at home, to keep her busy I built the EV3 together with her and we had run some pre-set missions to make the robot move and did some simple tasks.  It works great, except that I have to use the Mindstorm software to program it.


There is also another iPhone app to give you basic control of your robot, however it only accepts bluetooth connection, which makes me a lot less flexible compare with Wifi.




I have done some googling and find this post:
http://programmablebrick.blogspot.hk/2014/11/seanbot-ev3-robot-controlled-via-web.html

It looks interesting to me and I would want to make it my first EV3 project.  This is what I've done:

1. Get an microSD card.  So happen I've found one old 2GB card at home and I've used that for this project.  Flash it with the ev3dev OS following the instruction in this page, it is based on Debian Linux:
http://www.ev3dev.org/docs/getting-started/

2. Putting the microSD card into my EV3 and power it on.  It will not affect your original firmware in EV3, it is just like dual booting another OS.




3. Setting up the wireless network.  I've bought a wireless USB dongle from a local computer store, and it is less than US$9.  It works like a charm.  I did purposely pick one without 802.11ac, older model, claim to have Linux support.  Just bet on it, provided that it is so cheap.


4. Plug that into the USB port of EV3.  Use the screen on EV3 to choose my home wifi network, and entered the WPA PSK.  It is now connected, and able to access the Internet.


5. SSH to the box.  Use apt-get to get the packages, make sure you did a apt-get upgrade and update before you download the other packages.


sudo apt-get update; sudo apt-get upgrade
sudo apt-get install apache2 libapache2-mod-php5 unzip

6. Download the files in zip in this github project -  https://github.com/dwalton76/LegoEV3D4.  Unzip and copy these contents into your apache document root, in my case it is /var/www/html.  I download it to my Mac and then scp to the EV3, unzip it then copy it to the document root.

7. Install the python-ev3 on EV3 - https://github.com/topikachu/python-ev3.  My version of python is 2.7, therefore these are the commands that I've issued to my EV3.

Python 2.7

apt-get update
apt-get install virtualenv virtualenvwrapper python-setuptools python-smbus python-pil
source /etc/bash_completion.d/virtualenvwrapper
mkvirtualenv ev3_py27 --python=/usr/bin/python2.7 --system-site-packages
workon ev3_py27
easy_install -U python-ev3
type deactive to exit

8. Download the python-ev3 project in zip file - https://github.com/topikachu/python-ev3.  Similar to step 6, copy the content to the EV3.  In python-ev3, there is a ev3 folder.  Make sure this folder is copied to /var/www/html.  You will need to make sure you do this otherwise your LegoR2D2.py will not work.

9. Some python libraries dependencies need to be resolved, and this is what I've done:
easy_install web.py

10.  Start your apache using the command /etc/init.d/apache2 start.  Run the LegoR2D2 python scripts with sudo.  tcp/8080 will be listened after you run the script.


11. Launch your web browser.  I have tried Chrome and Firefox, for some reasons it only works on my Firefox, probably it is something specific to my laptop.  By the way this is what you will see:



12.  Click on the arrows to move your robot!  Is that it?  No!  How about we using a Cisco Spark Chatbot to control the EV3?











Tuesday, January 7, 2014

Shell script to update device user association in batch

Referring to my previous post:
http://pandaeatsbamboo.blogspot.hk/2014/01/associate-existing-phones-to-users-with.html

I have created a shell script that allow us to update the owner ID to phone in batch.


bulk-update.sh, change with your UCM ip address and credential in the curl statement.

#!/bin/sh

for i in `less user-phone-list.txt`
        do 
                #echo $i
                username=`echo $i | cut -d ',' -f1`
                devicename=`echo $i | cut -d ',' -f2`
                 

cat <<EOF1 >$username.xml

    <soapenv:Header/>

    <soapenv:Body>

        <ns:executeSQLUpdate sequence="?">

EOF1

                echo "<sql>update Device set fkenduser = ( select pkid from EndUser where userid = '$username')  where name = '$devicename'</sql>" >>$username.xml

cat <<EOF2 >>$username.xml
        </ns:executeSQLUpdate>

    </soapenv:Body>

</soapenv:Envelope>
EOF2

        curl -k -u administrator:ccievoice -H "Content-type: text/xml;" -H "SOAPAction: CUCM:DB ver=8.5" -d @$username.xml https://10.1.90.11:8443/axl/
        
        done


user-phone-list.txt, file contains username and device name pair with comma as delimiter, put them in the same directory as the script.

dannywon,SEPAABBAABBAABB
briacho,SEP00077DDFFB7E


Monday, December 28, 2009

Script to turn off PoE power using Energywise

My environment: Cisco 3560E

Besides shutting down the switchport, you can turn off the PoE power via the Energywise command.  Before you run this script, setup your energywise domain with the command “energywise domain panda security shared-secret eatsbamboo”

#!/usr/bin/expect

set timeout 5
log_user 1
set hostlist "pandasw01"
set prompt "pandasw01"
foreach host $hostlist {
#set prompt [append $host "#"]
set promptcfg [append $prompt "(config)#"]
spawn telnet $host
expect $prompt
send "conf t\r"
expect $promptcfg
send "int range fa0/1 - 23\r"
expect $promptcfg
send "energywise level 0\r"
expect $promptcfg
send "end\r"
expect $prompt
send "exit\r"
}

Script to Turn off Cisco Autonomous Access Point radio interface

My environment: Cisco 861W

You can turn off the radio interface of the autonomous AP when you don’t use it to save power.

#!/usr/bin/expect

set timeout 5
log_user 1
set hostlist "pandaap01"
foreach host $hostlist {
set prompt [append $host "#"]
set promptcfg [append $prompt "(config)#"]
spawn telnet $host
expect $prompt
send "conf t\r"
expect $promptcfg
send "int dot11radio0\r"
expect $promptcfg
send "shut\r"
expect $promptcfg
send "end\r"
}

Tuesday, December 15, 2009

CIFS Mounted Drive for Apache

My environment: Apache 2.2.9 on Fedora Core 10 x86_64

Although it is not a good idea to do something like this, I’ve come across a case that I need to mount a CIFS drive and serve the content inside for an apache web server on Linux.  After some googling, the trick to make this work is to turn off a parameter called EnableSendfile in httpd.conf

#
# EnableSendfile: Control whether the sendfile kernel support is
# used to deliver files (assuming that the OS supports it).
# The default is on; turn this off if you serve from NFS-mounted
# filesystems.  Please see
#
http://httpd.apache.org/docs/2.2/mod/core.html#enablesendfile
#
EnableSendfile off

Sunday, December 6, 2009

IPv6 PTR Record configuration in BIND

My environment: RedHat Fedora Core 12 x86_64

BIND version: bind-9.6.1-11.P1.fc12.x86_64

Let’s see an example how to configure IPv6 reverse lookup record in BIND.

Forward Lookup:

www   AAAA   2001:123:45:678:20c:29ff:fe6a:7f93

It just like normal IPv4 host record, except it is a “AAAA” record instead of an “A” record.

Reverse Lookup zone configuration in named.conf:

zone "8.7.6.0.5.4.0.0.3.2.1.0.1.0.0.2.ip6.arpa" {
        type master;
        file "2001.123.45.678-db";
};

The name of the zone is the reverse of the /64 prefix 2001:123:45:678::/64

In the reverse lookup zone file, the PTR record is:

3.9.f.7.a.6.e.f.f.f.9.2.c.0.2.0   IN   PTR   www

The PTR record is the reverse of the host portion of the IPv6 address.

Try a dig -x 2001:123:45:678:20c:29ff:fe6a:7f93 and see if the BIND server replies with the reverse lookup record correctly.

Friday, August 14, 2009

802.1q configuration on Linux

My environment: RH FC8 x86_64

1. Make sure the 802.1q module is added to the kernel 

modprobe 8021q

2. Add a subinterface.  In this example 170 is the 802.1q VLAN ID.

vconfig add eth0 170

3. Create the NIC configuration file

/etc/sysconfig/network-scripts/ifcfg-eth0.170

DEVICE=eth0.170
BOOTPROTO=none
IPADDR=192.168.170.1
NETMASK=255.255.255.0

4. Restart the network service

/etc/init.d/network restart

Tuesday, August 4, 2009

Configuring IPv6 address on Linux

My environment: RH FC8 x86_64

To enable IPv6 globally, modify the file

# vi /etc/sysconfig/network

And append the following:

NETWORKING_IPV6=yes

Then change the NIC config file

# vi /etc/sysconfig/network-scripts/ifcfg-eth0

And append the following IPv6 parameters:

IPV6INIT=yes
IPV6ADDR=<IPv6-IP-Address>
IPV6_DEFAULTGW=<IPv6-IP-Gateway-Address>

If you want to acquire the IPv6 address via DHCPv6 server, first make sure you have the DHCPv6 client installed:

# rpm –q dhcpv6-client

then modifiy the NIC config file and append the following parameters:

# vi /etc/sysconfig/network-scripts/ifcfg-eth0

IPV6INIT=yes
DHCPV6C=yes

Edit the main DHCPv6 client config file

# cp /usr/share/doc/dhcpv6-client-*/dhcp6c.conf /etc/
# vi /etc/dhcp6c.conf

interface eth0 {
    send rapid-commit;
    request domain-name-servers;
};

Restart the network service

# /etc/init.d/network restart

Then check your eth0 configuration to make sure you get the ipv6 address:

# ifconfig eth0

Monday, August 3, 2009

Configuring Windows 2003 Server DNS in IPv6 environment

My environment: Windows 2003 Server Enterprise edition

You can configure your Windows 2K3 server to listen over IPv6, what you need to do is to enable it through command prompt:

dnscmd /config /EnableIPv6 1

Then restart your DNS service.

To add an IPv6 host record, you’ll need to add an “AAAA” record instead of an “A” host record like you did in IPv4.

Right click on your domain name in the forward lookup zones, choose “Other New Records”

image

Add a new AAAA record:

image

image

To check if it is working, you can either using nslookup on Windows or dig on Linux:

dig -6 ad-v6.ucdemo.com @c0:a8:a::c8 AAAA

image

nslookup –q=AAAA ad-v6.ucdemo.com

image

Monday, July 27, 2009

Enable RH FC 10 root login

My environment: RH FC 10 x86_64

Although it is not recommended to login GNOME GUI as root, sometimes you just need to do it.  Firstly, type the following in your terminal prompt:

1. su

2. Enter your root password
3. vi /etc/pam.d/gdm

and comment the following line:

# auth required pam_succeed_if.so user != root quiet

Sunday, July 19, 2009

Getting Flash Player to work on 64-bit Linux

My environment: RH FC8 x86_64
Flash Player version: 10.0.22.87
Firefox version: 3.0.9

Adobe has released an alpha version of flash player on 64-bit Linux and to get this working on your 64-bit Linux box, go to Adobe site to download the shared object library:

http://labs.adobe.com/downloads/flashplayer10.html

Untar the file then you will get the flash player .so file:
libflashplayer.so

Copy it to ~/.mozilla/plugins, if the folder doesn't exist, create the folder by yourselves. Restart the browser then you are now able to view Flash content via your firefox on your 64-bit Linux box.

Monday, July 13, 2009

Clear the route cache on your Linux box

My environment: RH FC8 x86_64

Routing cache is a hash table in the kernel which contains recently used routes.  I have had a problem about traceroute on my Linux box after changing the default route, it still redirecting the packets to the old default gateway.  So what I have done is to remove the route cache.

To show the route cache:

ip route show cache

To clear the route cache:

ip route flush cache

Slow Performance when query MySQL Database

My environment: RH FC8 X86_64

MySQL server version: mysql-server-5.0.45-6.fc8

Just hit a problem that takes me several hours to get it solve.  The symptom is extremely slow performance when connecting the database remotely either via JDBC connection from my JSP page or using MySQL front GUI.

After hours and hours of troubleshooting, I’ve found out the MySQL server need some sort of DNS lookup when an external client attempts to connect to it, and in my demo environment unfortunately the name server is down.

The trick is to comment the name server entry in /etc/resolv.conf.  After I did that, it resumes to normal!

Thursday, June 4, 2009

Pktgen – a tool to generate packets at very high speed in the kernel

My environment: RedHat Fedora Core 8 x86_64

Firstly check if your pktgen is running:

[root@pandaeatsbamboo pktgen]# ps -e | grep pktgen
8913 ?        00:01:55 kpktgend_0
8914 ?        00:01:55 kpktgend_1
8915 ?        00:00:01 kpktgend_2
8916 ?        00:00:01 kpktgend_3


I have a quad-core AMD CPU therefore you will see 4 processes there.  Pktgen creates 1 thread per CPU.

If you can’t see that, try to:
modprobe pktgen

I have 2 NIC card, eth0 and eth1, here is my sample shell script to kick start the pktgen:

#! /bin/sh



 



#modprobe pktgen



 



 



function pgset() {



    local result



 



    echo $1 > $PGDEV



 



    result=`cat $PGDEV | fgrep "Result: OK:"`



    if [ "$result" = "" ]; then



         cat $PGDEV | fgrep Result:



    fi



}



 



function pg() {



    echo inject > $PGDEV



    cat $PGDEV



}



 



# Config Start Here -----------------------------------------------------------



 



 



# thread config



# Each CPU has own thread. Two CPU exammple. We add eth1, eth2 respectivly.



 



PGDEV=/proc/net/pktgen/kpktgend_0



  echo "Removing all devices"



 pgset "rem_device_all"



  echo "Adding eth0"



 pgset "add_device eth0"



  echo "Setting max_before_softirq 10000"



 pgset "max_before_softirq 10000"



 



PGDEV=/proc/net/pktgen/kpktgend_1



  echo "Removing all devices"



 pgset "rem_device_all"



  echo "Adding eth1"



 pgset "add_device eth1"



  echo "Setting max_before_softirq 10000"



 pgset "max_before_softirq 10000"



 



 



# device config



# delay 0 means maximum speed.



 



CLONE_SKB="clone_skb 1000000"



# NIC adds 4 bytes CRC



PKT_SIZE="pkt_size 60"



 



# COUNT 0 means forever



#COUNT="count 0"



COUNT="count 10000000"



DELAY="delay 0"



 



PGDEV=/proc/net/pktgen/eth0



  echo "Configuring $PGDEV"



 pgset "$COUNT"



 pgset "$CLONE_SKB"



 pgset "$PKT_SIZE"



 pgset "$DELAY"



 pgset "dst 168.106.1.248"



 pgset "dst_mac  00:24:51:13:06:41"



 



PGDEV=/proc/net/pktgen/eth1



  echo "Configuring $PGDEV"



 pgset "$COUNT"



 pgset "$CLONE_SKB"



 pgset "$PKT_SIZE"



 pgset "$DELAY"



 pgset "dst 192.168.10.1"



 pgset "dst_mac  00:24:51:13:06:43"



 



# Time to run



PGDEV=/proc/net/pktgen/pgctrl



 



 echo "Running... ctrl^C to stop"



 pgset "start"



 echo "Done"




To view the statistics, check the files in /proc/net/pktgen/ethX





[root@pandaeatsbamboo pktgen]# less /proc/net/pktgen/eth0



Params: count 10000000  min_pkt_size: 60  max_pkt_size: 60



     frags: 0  delay: 0  clone_skb: 1000000  ifname: eth0



     flows: 0 flowlen: 0



     queue_map_min: 0  queue_map_max: 0



     dst_min: 168.106.1.248  dst_max:



     src_min:   src_max:



     src_mac: 00:1f:d0:50:19:6d dst_mac: 00:24:51:13:06:41



     udp_src_min: 9  udp_src_max: 9  udp_dst_min: 9  udp_dst_max: 9



     src_mac_count: 0  dst_mac_count: 0



     Flags:



Current:



     pkts-sofar: 10000000  errors: 0



     started: 1244025262231283us  stopped: 1244025310237392us idle: 11640574us



     seq_num: 10000001  cur_dst_mac_offset: 0  cur_src_mac_offset: 0



     cur_saddr: 0xfa016aa8  cur_daddr: 0xf8016aa8



     cur_udp_dst: 9  cur_udp_src: 9



     cur_queue_map: 0



     flows: 0



Result: OK: 48006109(c36365535+d11640574) usec, 10000000 (60byte,0frags)



  208306pps 99Mb/sec (99986880bps) errors: 0




To learn more you can visit here:



http://www.linuxfoundation.org/en/Net:Pktgen

Wednesday, April 29, 2009

Playing ASF on Linux

My environment: RH FC 10 x86_64

To play asf file on linux, you can use VLC as your media player. To install VLC by yum:

1. rpm -ivh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm

2. yum install vlc

Tuesday, April 28, 2009

Network backup with Rsync

My environment: RH FC8 x86_64
Rsync Version: rsync-2.6.9-3.2.fc8

 

1. Enable rsync server in xinetd:

vi /etc/xinetd.d/rsync

disable = no

2. Start xinetd on server side

3. Generate password-less inter-host key for SSH connection between rsync server and client.  Follow the tutorial here.

4. Run this on rsync server:

rsync -ave ssh --numeric-ids rsync-client-hostname:/files-to-be-backup /backup-location-on-server

Thursday, April 9, 2009

Create public folder on samba

My environment: Samba 3.0.28 on RH FC8

Nothing better than learn by example, let see the following 2 examples on /etc/samba/smb.conf to create a writable and read-only share

Writable share - A publicly accessible directory, but read only, except for people in software group

[software]
comment = Software Share
path = /media/disk/software
public = yes
writable = yes
printable = no
browseable = yes
write list = +software

A read-only share

[VM]
comment = VM
path = /media/disk/VM
public = yes
writable = no
printable = no
browseable = yes

Start your samba server in 5 mins

My environment: Samba 3.0.28 on RH FC8

Again it’s time for our quick and dirty series – the samba episode.  Let's create a samba share in 5 mins!

1. Make sure you have samba server installed.  If not, yum –y install samba-common. 
2. Add your existing users to samba, say I have an user pandaeatsbamboo already in the system:
smbpasswd -a pandaeatsbamboo
3. Restart your samba server:

/etc/init.d/smb restart

4. Access your share via UNC path, \\192.168.1.10 and you’ll see your home folder as a shared folder.

Friday, April 3, 2009

Basic Text-to-Speech example with Festival

My environment: Festival 1.9.6 on RH FC8

A simple example on Festival TTS

echo “I love to visit this blog and I’m going to visit it everyday” | text2wave -o pandaeatsbamboo.wav