33
1032 Practical Linux System Administration Final Report Group 8 - <100212067> 1

1032 practical linux system administration

  • Upload
    noel-ng

  • View
    77

  • Download
    2

Embed Size (px)

Citation preview

Page 1: 1032 practical linux system administration

1032Practical Linux System Administration

Final ReportGroup 8 - 吳 芷 恩 <100212067>

1

Page 2: 1032 practical linux system administration

題目

2

Page 3: 1032 practical linux system administration

題目發想緣起

3

Page 4: 1032 practical linux system administration

實作所需材料

4

材料 取得來源 價格

Raspberry Pi BlueT $--

Logitech Webcam C310 PChome $699

Servo motor SG90 Ruten $48

Stepper motor 28BYJ-48-5V Ruten $50

ULN2003 Driver Board Ruten $27

Dupont Line Ruten $20

Steel wire Hardware store $5

Mouse toy DAISO $39

Page 5: 1032 practical linux system administration

★ Web server - LAMP

★ Automatically send ip to Email - Postfix

運用與課程內容中相關的技巧

5

Page 6: 1032 practical linux system administration

★ Stepper motor○ software: Pi4J http://pi4j.com/○ code:https://github.com/Pi4J/pi4j/blob/master/pi4j-

example/src/main/java/StepperMotorGpioExample.java★ Servo motor

○ software: Python○ code:https://www.youtube.com/watch?v=ddlDgUymbxc

★ Webcam○ software: MJPG-streamer http://sourceforge.net/projects/mjpg-

streamer/★ Webpage

○ software: LAMP○ code: HTML, PHP, JavaScript AJAX http://php.

net/manual/en/function.shell-exec.php http://www.w3schools.com/ajax/ajax_example.asp

使用的現有軟體與來源

6

Page 7: 1032 practical linux system administration

ULN2003 Driver Board(Stepper motor)

實作過程 - GPIO 配置

7

Page 8: 1032 practical linux system administration

Servo motor

實作過程 - GPIO 配置 (cont’d)

8

Page 9: 1032 practical linux system administration

實作過程 - webcam

9

Page 10: 1032 practical linux system administration

Builds MJPG-streamer➢ sudo apt-get update➢ sudo apt-get install subversion libjpeg8-dev imagemagick➢ sudo svn checkout svn://svn.code.sf.net/p/mjpg-streamer/code➢ cd code/mjpg-streamer➢ sudo make clean all➢ export LD_LIBRARY_PATH=.➢ ./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so -w ./www"

Auto run MJPG-streamer when pi boots up➢ sudo vim /etc/rc.local➢ add codes before exit 0 :

export STREAMER_PATH=/home/pi/code/mjpg-streamerexport LD_LIBRARY_PATH=$ STREAMER_PATH$STREAMER_PATH/mjpg_streamer -i “input_uvc.so -y = YUYV” -o

“output_http.so -w $STREAMER_PATH/www” &s

實作過程 - MJPG-streamer

10

Page 11: 1032 practical linux system administration

★ servo90.php<?phpecho shell_exec("sudo python servo90.py")?>

實作過程 - Coding(servo90.php & servo90.py)

11

★ servo90.pyimport RPi.GPIO as GPIOimport time

GPIO.setmode(GPIO.BOARD)

GPIO.setup(7,GPIO.OUT)

p = GPIO.PWM(7,50)p.start(7.5)

count=0

while (count<4): p.ChangeDutyCycle(2.5) time.sleep(0.25) p.ChangeDutyCycle(7.5) time.sleep(0.25) count=count+1

p.stop()

GPIO.cleanup()

Page 12: 1032 practical linux system administration

★ servo180.php<?phpecho shell_exec("sudo python servo180.py")?>

實作過程 - Coding(servo180.php & servo180.py)

12

★ servo180.pyimport RPi.GPIO as GPIOimport time

GPIO.setmode(GPIO.BOARD)

GPIO.setup(7,GPIO.OUT)

p = GPIO.PWM(7,50)p.start(7.5)

count=0

while (count<4): p.ChangeDutyCycle(12.5) time.sleep(0.5) p.ChangeDutyCycle(2.5) time.sleep(0.5) count=count+1

p.stop()

GPIO.cleanup()

Page 13: 1032 practical linux system administration

★ step45.php<?phpecho shell_exec("sudo java -classpath .:classes:/opt/pi4j/lib/'*' step45")?>

★ step-45.php<?phpecho shell_exec("sudo java -classpath .:classes:/opt/pi4j/lib/'*' stepm45")?>

★ step90.php<?phpecho shell_exec("sudo java -classpath .:classes:/opt/pi4j/lib/'*' step90")?>

★ step-90.php<?phpecho shell_exec("sudo java -classpath .:classes:/opt/pi4j/lib/'*' stepm90")?>

實作過程 - Coding(step45/-45/90/-90/180/-180.php)

13

★ step180.php<?phpecho shell_exec("sudo java -classpath .:classes:/opt/pi4j/lib/'*' step180")?>

★ step-180.php<?phpecho shell_exec("sudo java -classpath .:classes:/opt/pi4j/lib/'*' stepm180")?>

Page 14: 1032 practical linux system administration

★ step45.javaimport com.pi4j.component.motor.impl.GpioStepperMotorComponent;import com.pi4j.io.gpio.GpioController;import com.pi4j.io.gpio.GpioFactory;import com.pi4j.io.gpio.GpioPinDigitalOutput;import com.pi4j.io.gpio.PinState;import com.pi4j.io.gpio.RaspiPin;

public class step45 {

public static void main(String[] args) throws InterruptedException {

System.out.println("<--Pi4J--> GPIO Stepper Motor Example ... started.");

// create gpio controller final GpioController gpio = GpioFactory.getInstance();

// provision gpio pins #00 to #03 as output pins and ensure in LOW state final GpioPinDigitalOutput[] pins = { gpio.provisionDigitalOutputPin(RaspiPin.GPIO_00, PinState.LOW), gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, PinState.LOW), gpio.provisionDigitalOutputPin(RaspiPin.GPIO_02, PinState.LOW), gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03, PinState.LOW)};

實作過程 - Coding(step45.java)

14

Page 15: 1032 practical linux system administration

★ step45.java (cont’d) // this will ensure that the motor is stopped when the program terminates gpio.setShutdownOptions(true, PinState.LOW, pins);

// create motor component GpioStepperMotorComponent motor = new GpioStepperMotorComponent(pins);

// @see http://www.lirtex.com/robotics/stepper-motor-controller-circuit/ // for additional details on stepping techniques

// create byte array to demonstrate a double-step sequencing // (In this method two coils are turned on simultaneously. This method does not generate // a smooth movement as the previous method, and it requires double the current, but as // return it generates double the torque.) byte[] double_step_sequence = new byte[4]; double_step_sequence[0] = (byte) 0b0011; double_step_sequence[1] = (byte) 0b0110; double_step_sequence[2] = (byte) 0b1100; double_step_sequence[3] = (byte) 0b1001;

// define stepper parameters before attempting to control motor // anything lower than 2 ms does not work for my sample motor using single step sequence motor.setStepInterval(1); motor.setStepSequence(double_step_sequence);

實作過程 - Coding(step45.java <cont’d>)

15

Page 16: 1032 practical linux system administration

★ step45.java (cont’d) // There are 32 steps per revolution on my sample motor, and inside is a ~1/64 reduction gear set. // Gear reduction is actually: (32/9)/(22/11)x(26/9)x(31/10)=63.683950617 // This means is that there are really 32*63.683950617 steps per revolution = 2037.88641975 ~ 2038 steps! motor.setStepsPerRevolution(2038);

motor.rotate(0.125);

System.out.println(" Motor STOPPED."); // final stop to ensure no motor activity motor.stop();

// stop all GPIO activity/threads by shutting down the GPIO controller // (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks) gpio.shutdown(); }}

實作過程 - Coding(step45.java <cont’d>)

16

Page 17: 1032 practical linux system administration

change some code...★ stepm45.javapublic class stepm45 {………………. motor.rotate(-0.125);

★ step90.javapublic class step90 {………………. motor.rotate(0.25);

★ stepm90.javapublic class stepm90 {………………. motor.rotate(-0.25);

實作過程 - Coding(stepm45/90/m90/180/m180.java)

17

★ step180.javapublic class step180 {………………. motor.rotate(0.5);

★ stepm180.javapublic class step180 {………………. motor.rotate(0.5);

Page 18: 1032 practical linux system administration

★ index.php<html><Iframe src="http://192.168.0.106:8080/javascript_simple.html" width="660" height="500"></Iframe><p>toy control:<button type="button" name="button" onclick="servo90()">90 degrees</button><button type="button" name="button2" onclick="servo180()">180 degrees</button></p><p>Webcam control:<img src="playmeow.png" align="right" height="100"><button type="button" name="button3" onclick="step45()">L 45 degrees</button><button type="button" name="button4" onclick="stepm45()">R 45 degrees</button></p><p><font color="#ffffff">Webcam control: </font><button type="button" name="button5" onclick="step90()">L 90 degrees</button><button type="button" name="button6" onclick="stepm90()">R 90 degrees</button></p><p><font color="#ffffff">Webcam control: </font><button type="button" name="button7" onclick="step180()">L 180 degrees</button><button type="button" name="button8" onclick="stepm180()">R 180 degrees</button></p><script>function servo90(){var xmlhttp=new XMLHttpRequest();xmlhttp.open("POST","servo90.php",true);xmlhttp.send();}

實作過程 - Coding(index.php)

18

Page 19: 1032 practical linux system administration

★ index.php (cont’d)function servo180(){var xmlhttp=new XMLHttpRequest();xmlhttp.open("POST","servo180.php",true);xmlhttp.send();}function step45(){var xmlhttp=new XMLHttpRequest();xmlhttp.open("POST","step45.php",true);xmlhttp.send();}function stepm45(){var xmlhttp=new XMLHttpRequest();xmlhttp.open("POST","step-45.php",true);xmlhttp.send();}function step90(){var xmlhttp=new XMLHttpRequest();xmlhttp.open("POST","step90.php",true);xmlhttp.send();}

實作過程 - Coding (index.php <cont’d>)

19

function stepm90(){var xmlhttp=new XMLHttpRequest();xmlhttp.open("POST","step-90.php",true);xmlhttp.send();}function step180(){var xmlhttp=new XMLHttpRequest();xmlhttp.open("POST","step180.php",true);xmlhttp.send();}function stepm180(){var xmlhttp=new XMLHttpRequest();xmlhttp.open("POST","step-180.php",true);xmlhttp.send();}</script></html>

Page 20: 1032 practical linux system administration

實作過程

20

Page 21: 1032 practical linux system administration

實作過程

21

Page 22: 1032 practical linux system administration

!在網頁上控制 伺服馬達&步進馬達 !➔ 以超連結控制會跳出新視窗 Noooooo~!!!

Helper - RichEGGRichEGG : 改用AJAX ~

!在沒有Public ip、路由器不是自己的情況下,從外部開啟控制網頁!➔ DDNS 無法設定 Noooooo~!!!➔ 以3G行動網卡代替 $_$不是長遠之計

Helper - BlueTBlueT : 可以用ssh 或vpn解決, 到 ipv6 普及就沒有這個問題了~

➔ ssh reverse tunnel 需要額外一台有Public ip的機器=.=➔ VPN 綁定裝置以外的裝置會無法使用 T_T➔ 無解 >_<....

實作過程 - 困難與解決

22

Page 23: 1032 practical linux system administration

實際產出 - 外觀

23

Page 24: 1032 practical linux system administration

實際產出 - 外觀

24

Page 25: 1032 practical linux system administration

實際產出 - 試玩(改良前)

25

Page 26: 1032 practical linux system administration

實際產出 - 試玩 (改良後)

26

Page 27: 1032 practical linux system administration

實際產出 - Firefox

27

Page 28: 1032 practical linux system administration

實際產出 - Safari

28

Page 29: 1032 practical linux system administration

實際產出 - Chrome

29

Page 30: 1032 practical linux system administration

實際產出 - ipad safari

30

Page 31: 1032 practical linux system administration

實際產出 - smartphone chrome

31

Page 32: 1032 practical linux system administration

網頁:http://www.w3schools.comhttps://www.youtube.com/watch?v=ddlDgUymbxchttp://www.codedata.com.tw/java/java-embedded-10-gpio-motorhttp://www.ntex.tw/wordpress/545.htmlhttps://sites.google.com/site/raspberypishare0918/http://www.powenko.com/wordpress/?p=4324

書籍:Raspberry Pi最佳入門與實戰應用 , 柯博文 , 碁峰 ,2015-01-08Raspberry Pi超炫專案與完全實戰 , 柯博文 , 碁峰 ,2014-09-26

參考資料

32

Page 33: 1032 practical linux system administration

ENDTHANK YOU !

Q & A

33