File "recv_OLD20201022.php"
Full path: /www/arduino/honmoku/1/OLD/recv_OLD20201022.php
File size: 3.11 KiB (3187 bytes)
MIME-type: text/x-php
Charset: utf-8
<?php
//■■計測データの変換(16進⇒10進)
function data_convert($data,$st,$ct)
{
$conv_data = substr($data,$st,$ct) .substr($data,$st-2,$ct);
return hexdec($conv_data) /10;
}
//■■データの項目名の変換(16進⇒アスキー文字)
function name_convert($data,$st,$ct)
{
$conv_name = substr($data,$st,$ct) .substr($data,$st-2,$ct);
//■16進⇒10進⇒2進
$conv_name = decbin(hexdec($conv_name));
$len = strlen($conv_name);
$name_1 = "011" .str_pad(substr($conv_name,0,$len -10),5,0, STR_PAD_LEFT);
$name_2 = "011" .substr($conv_name,$len -10,5);
$name_3 = "011" .substr($conv_name,$len -5,5);
$_log = fopen("data_conv.txt" ,"a");
fwrite($_log , date("Y-m-d H:i:s",time()) ."__" .$name_1 ."__" .$name_2 ."__" .$name_3 . "\n");
fclose($_log);
//■再度変換(2進⇒10進⇒アスキーコード)
//1文字目
$name_1 = chr(bindec($name_1));
//2文字目
$name_2 = chr(bindec($name_2));
//3文字目
$name_3 = chr(bindec($name_3));
$name_ = $name_1 .$name_2 .$name_3;
return $name_;
}
function gpsLL2degree($s){
$x_degree = floor($s / 100);
$x_minute = $s - ($x_degree * 100);
$x_minute2 = $x_minute / 60;
return number_format($x_degree + $x_minute2,6,".","");
}
// ===============================================
// 送信データの取得
// ===============================================
$json_string = file_get_contents('php://input'); //読み取り
$t_log = fopen("recv_test.log" ,"a");
fwrite($t_log , date("Y-m-d H:i:s",time()) ."," .$json_string . "\n");
fclose($t_log);
//2019-11-15 10:12:16,$GPRMC,005712.800,V,,,,,0.00,0.00,060180,,,N*4B,2
$statusId = "";
$constId = "999";
$applicationId = "999";
//================================================
// データベース接続
// 備考 :
// 更新 : 2012/11/29 KMK-Teraoka
//================================================
//$conn = pg_connect("
// host = ". $HOST. "
// dbname = ". $DB. "
// user = ". $USER. "
// password= ". $PASS. "
//");
/*
if ($status_id = 1)
{
$refreshTerminal = "INSERT INTO qgis.his_measure_gps";
$refreshTerminal .= " (status_id, const_id, app_id, terminal_name, measure_interval, measure_result, location_send_interval, acc_omit, stop_distance, area_events_fname, work_status, upddatetime, regdatetime)";
$refreshTerminal .= " VALUES";
$refreshTerminal .= " ('". $statusId. "','". $constId. "','". $applicationId. "','". $terminalName. "','". $measureInterval. "','". $measureResult. "','". $locationSendInterval. "','". $accOmit. "','". $stopDistance. "','". $areaEventsFname. "','". $workStatus. "',current_timestamp,current_timestamp)";
$refreshTerminal .= ";";
}
*/
$obj = json_decode($json_string,1); //一度デコード
$data = $obj['data'];
$data_save = fopen("data.csv" ,"a");
fwrite($data_save , date("Y-m-d H:i:s",time()) .$data ."\n");
fclose($data_save);
$now_log = fopen("header.txt" ,"a");
fwrite($now_log , date("Y-m-d H:i:s",time()) .json_encode(getallheaders ()) . "\n");
fclose($now_log);
//file_put_contents("data_.txt",json_encode($payload)); // ログに保存
//file_put_contents("header.txt",json_encode(getallheaders ())); // ←追加
?>