WebIOPi-0.7.1の中にmyProjectというディレクトリを作り、sudo nano /etc/webiopi/configを打ち込んで[SCRIPTS]の一番下にmyscript = /home/pi/WebIOPi-0.7.1/myProject/script.py
[HTML]の#doc-root = /home/pi/webiopi/examples/scripts/macrosの下にdoc-root = /home/pi/WebIOPi-0.7.1/myProject/を追記しました。上書き保存をし、webiopiを起動してラズパイ内のブラウザにlocalhost:8000と打ち込んでみたところ「このサイトにアクセスできません」と出てきました。
デフォルトのHTMLとscriptを指定するためにはまだほかに設定するべきことがあるのでしょうか?myProjectに入っているコードは以下のとおりです。 回答よろしくお願いします。
indexhtml
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5 <meta http-equiv="Content-Style-Type" content="text/css"> 6 <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> 7 <title>課題研究</title> 8 <script type="text/javascript" src="/webiopi.js"></script> 9 <script type="text/javascript"> 10 function getParam(name, url) { 11 if (!url) url = window.location.href; 12 name = name.replace(/[[]]/g, "\$&"); 13 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), 14 results = regex.exec(url); 15 if (!results) return null; 16 if (!results[2]) return ''; 17 return decodeURIComponent(results[2].replace(/+/g, " ")); 18 } 19 20 window.addEventListener("deviceorientation", (dat) => { 21 var xAngle = parseInt(dat.alpha); // x軸(0°~360°) => 0°: 北, 90°: 西, 180°: 南, 270°: 東 22 var yAngle = parseInt(dat.beta); // y軸(-180°~180°)=> 0°: 水平, 90°: 垂直, °-180: 逆水平, -90°: 逆垂直 23 getAngle(xAngle, yAngle); 24 }); 25 26 webiopi().ready( function(){ 27 drive('stop'); 28 }); 29 30 function getDriveMode(mode){ 31 webiopi().callMacro("changeDriveMode", mode); 32 } 33 34 function getAngle(xAngle, yAngle) { 35 webiopi().callMacro("moveServo", [xAngle, yAngle]); 36 } 37 38 function resetServo() { 39 webiopi().callMacro("resetServo"); 40 } 41 </script> 42 </head> 43 <body> 44 <script type="text/javascript"> 45 var params = [getParam('event'), getParam('direction')]; 46 if(params[0] == 'stick') 47 getDriveMode(params[1]); 48 else if(params[0] == 'reset') 49 resetServo(); 50 </script> 51 </body> 52</html>
scriptpy
1import webiopi 2import time, os, sys, re, datetime 3 4webiopi.setDebug() 5GPIO = webiopi.GPIO 6PIN = {'R': {'1': 6, '2': 5, 'P': 12}, 'L': {'1': 13, '2': 19, 'P': 18} 'servo': {'x': 38, 'y': 40}} 7for key, value in PIN.items() : 8 for key2, value2 in value.items() : 9 GPIO.setFunction(value2, GPIO.PWM) 10 if key2 == 'P' : 11 GPIO.pwmWrite(value2, 1.0) 12past, now = {'x': 0, 'y': 0}, {'x': 0, 'y': 0} 13 14def ServoAngle(pin, angle): 15 up = int(1500 + (angle * 350) / 45) 16 down = 20000 - up 17 GPIO.pulseMicro(pin, up, down) 18 19def MotorDrive(in1, in2, state) : 20 GPIO.pwmWrite(in1, state[0]*1.0) 21 GPIO.pwmWrite(in2, state[1]*1.0) 22 23@webiopi.macro 24def changeDriveMode(mode) : 25 webiopi.debug("ChangeDriveMode : %s" % (mode)) 26 if mode == 'Stop' : 27 MotorDrive(PIN['L']['1'], PIN['L']['2'], [0, 0]) 28 MotorDrive(PIN['R']['1'], PIN['R']['2'], [0, 0]) 29 elif mode == 'Forward' : 30 MotorDrive(PIN['L']['1'], PIN['L']['2'], [1, 0]) 31 MotorDrive(PIN['R']['1'], PIN['R']['2'], [1, 0]) 32 elif mode == 'Backward' : 33 MotorDrive(PIN['L']['1'], PIN['L']['2'], [0, 1]) 34 MotorDrive(PIN['R']['1'], PIN['R']['2'], [0, 1]) 35 elif mode == 'CW' : 36 MotorDrive(PIN['L']['1'], PIN['L']['2'], [1, 0]) 37 MotorDrive(PIN['R']['1'], PIN['R']['2'], [0, 1]) 38 elif mode == 'CWW' : 39 MotorDrive(PIN['L']['1'], PIN['L']['2'], [0, 1]) 40 MotorDrive(PIN['R']['1'], PIN['R']['2'], [1, 0]) 41 42@webiopi.macro 43def moveServo(xAngle, yAngle): 44 webiopi.debug("moveServoAngle : %s, %s" % (xAngle, yAngle)) 45 now['x'] = (xAngle-past['x'])%360 46 now['y'] = (xAngle-past['y'])%180 47 past = {'x': xAngle, 'y': yAngle} 48 ServoAngle(PIN['servo']['x'], now['x']) 49 ServoAngle(PIN['servo']['y'], now['y']) 50 51@webiopi.macro 52def resetServo() : 53 webiopi.debug("Servo Reset...")
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/13 00:03
2018/09/13 01:59
2018/09/13 02:14
2018/09/13 04:07
2018/09/13 12:38
2018/09/15 16:55
2018/09/18 07:34
2018/09/19 02:38
2018/09/19 11:35
2018/09/19 12:40