顯示具有 php 標籤的文章。 顯示所有文章
顯示具有 php 標籤的文章。 顯示所有文章

2017年3月1日 星期三

網頁後台使用 php 執行 python 操作 serial (uart) 權限的設定




uart0.php... (透過 shell_exec 執行 python 碼)
===============================================
$cmd = escapeshellcmd ( '/usr/bin/python uart0.py' );
$output = shell_exec ( $cmd );
echo $output;
===============================================

uart0.py... (console下執行沒問題,但透過 php 執行沒結果)
===============================================
import serial
serialport = serial.Serial("/dev/ttyAMA0", 9600, timeout=0.5)
serialport.write( "TEST" )
response = serialport.readlines(None)
print response
===============================================

解決… (需要設定裝置的權限 ttyAMA0 屬於 dialout 群組)
=1=暫時-reboot後無效==============================
sudo chmod 777 /dev/ttyAMA0
=2=============================================
sudo adduser youruser dialout
usermod -aG dialout youruser
===============================================


2010年1月12日 星期二

PHP中計算某一周的起始及結束日期

以星期日為一周起始,函式傳入年份及第幾周,函式傳出開始及結束日期。


function findWeekPeriod( $week, $year )
{
    $aPeriod = array();
    $first_day = strtotime($year."-01-01");
    $is_week_first_day = date("w", $first_day) == 0;
    $is_weekone = strftime("%V", $first_day) == 1;
    if($is_weekone)
    {
        $week_one_start = $is_week_first_day ? strtotime("last sunday",$first_day) : $first_day;
    }
    else
    {
        $week_one_start = strtotime("next sunday", $first_day);
    }
    $aPeriod['start'] =  date("Y年m月d日", $week_one_start+(3600*24*7*($week-1)) );
    $aPeriod['end'] =  date("Y年m月d日", $week_one_start+(3600*24*(7*$week-1)) );
    return $aPeriod;      
}

例如…
      $week=date('W');
      $year=date('Y');
      $wPeriod=findWeekPeriod( $week, $year );
      /// 傳回當周的起始結束日期。

VirtualBox 空間減肥

@windows vm sdelete64 -z c: @macos VBoxManage  modifymedium  disk  "/Users/fellow/VirtualBox VMs/Win10/Win10.vdi"  --compact *.vdi...