Monday, May 22, 2017

Arduino Yun Command

CLI

If you are using Windows, you must install a terminal emulator, PuTTY.
  1. Download and install it by default settings
  2. Run the program
  3. Then give the IP address of Arduino
  4. A command prompt will appear
  5. Give value root for login as 
  6. If you don't change the password then give default password - aarduino

SD Card

  1. Format the SD card as FAT32 file system
  2. Plug in with Arduino
  3. For creating mount point
    • mkdir -p /mnt/sda
    • mount  /dev/sda /mnt/sda
  4. For accessing the SD card
    • cd /mnt/sda
  5. To see all file in SD card
    • ls -all
If the file system of SD card would become read only:
mount -o remount,rw /mnt/sda

USB Webcam

Configure Webcam

Check if USB camera is detected:
dmesg | tail -n3
Run following command after opening CLI. At first you need to update opkg.
opkg update
Install kmod-video-uvc
opkg install kmod-video-uvc
Sometimes kmod-video-uvc does not install for it's dependencies. Then you need to run following command to full fill it's dependencies before installing it.
opkg install usbutils
opkg install kmod-usb-core kmod-usb2 kmod-video-core
opkg install kmod-video-uvc
Run following command to complete the process
opkg install python-openssl
opkg install fswebcam
opkg install mjpg-streamer

Test Webcam

Verify if your USB webcam is detected as video device: 
ls /dev/video*
To capture a picture and stored it to SD card memory:
cd /mnt/sda
fswebcam test.png
Image will flicker sometime due to camera resolution. You have to specify resolution by -r:
fswebcam test.png -r 280x175
You can skip frame by -s:
fswebcam test.png -r 280x175 -S 2

Start Video Streaming

Check if mjpg-streamer is running on 8080 
netstat -an | grep 8080
ps | grep mjpg_streamer
If it is not running yet, you can run it manually by a simple command
mjpg_streamer -i "input_uvc.so" -o "output_http.so"
Sometimes this will show error for mismatching with camera resolution. For that situation you need to specify the resolution.
mjpg_streamer -i "input_uvc.so -y -n -f 30 -r 280x175" -o "output_http.so -p 8080 -n -w /www/webcam"
After that you will see the output in following URL.
http://192.168.xxx.xxx:8080/?action=snapshot
http://192.168.xxx.xxx:8080/?action=stream
http://192.168.xxx.xxx:8080/stream.html
Use following command to enable auto start of the service.
/etc/init.d/mjpg-streamer enable 
Use following command to manually stop the service.
killall mjpg_streamer
Use ps command to verify if the process has been run:
ps | grep mjpg 
Note 1: 192.168.xxx.xxx is an IP address of Arduino Yun.
Note 2: Video will flicker sometimes due to camera resolution.  You need to specify it by camera resolution.

Video Streaming on Youtube

  1. Download Wirecast
  2. Install and open Wirecast
  3. Click "+" on any layer (bottom of the window)
  4. Click on Web Display...
  5. Fillup field
    • Address: http://192.168.xxx.xxx:8080/?action=stream
    • Width: your_desired_width
    • Height: your_desired_height
  6. Select any shot of any layer by clicking it
  7. Then press "->" button to stream it
  8. Menu bar => Output => Output Settings [shortcut key: ctrl + y]
  9. Select YouTube from Destination dropdown
  10. Authenticate yourself
  11. Start broadcasting by pressing Stream button (top of the window)


Recording Video from Streaming URL

At first you need ffmpeg library:
opkg update
opkg install ffmpeg
Then run following command to record video for 5 seconds:
ffmpeg -f mjpeg -r 5 -i "http://192.168.xxx.xxx:8080/?action=stream" -t 5 video.avi
You can also capture image via ffmpeg:
ffmpeg -f video4linux2 -i "http://192.168.xxx.xxx:8080/?action=stream" -vframes 1 test_ffmpeg.jpeg
or
ffmpeg -f video4linux2 -i /dev/video0 -vframes 1 test_ffmpeg.jpeg
Note: Make confirm that server is running before capture image or record video.

Thanks to

Basic Linux Command

# show file/folder attribute
$ ls -l

# change file attribute
# 777 => 111,111,111 => rwx,rwx,rwx
# 531 => 101,011,001 => r-x,-wx,--x
$ chmod 777 file_or_folder_name


# see recent mounted drives
$ df
# human readable format
$ df -h


# mount a drive
# first create a mouning point folder, then mount
$ mkdir /media/folder_name
$ sudo mount -t auto /dev/sda6 /media/folder_name # or other name


# unmount a drive
$ sudo umount -t  auto /dev/sda6

# display currently active processes.
$ ps


# dispaly all running processes.
$ top

# get pid of a process
$ pidof process_name

# kill process
$ pkill mysqld
$ kill -SIGTERM pid