Browse Source

读取数据

master
lijunjie 3 years ago
parent
commit
10fd9f5d97
  1. 142
      app/Http/Controllers/IndexController.php
  2. 40
      app/Http/Services/CommonService.php
  3. 9
      config/custom.php
  4. BIN
      public/image/lora2/kk1_2.png
  5. 10
      resources/views/http/lora22.blade.php

142
app/Http/Controllers/IndexController.php

@ -3,6 +3,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Http\Services\CommonService;
use Illuminate\Routing\Controller as BaseController; use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
@ -248,7 +249,9 @@ class IndexController extends BaseController
public function lora2() public function lora2()
{ {
return view('http.lora22'); Cache::flush();
return view('http.lora2');
} }
public function getPelmaStore() public function getPelmaStore()
@ -279,9 +282,39 @@ class IndexController extends BaseController
{ {
// echo Cache::get('blood'); // echo Cache::get('blood');
$data = request('blood'); $request_data = request()->all();
Cache::put('blood', $data);
Log::info($data); $lora_mac = config("custom.lora_mac");
if (empty($request_data['node']) || empty($request_data['data'])){
return 'error';
}
if (!in_array($request_data['node'], $lora_mac)){
return 'error';
}
//血氧80.1
$blood = substr($request_data['data'], 0, 4);
$blood1 = hexdec(substr($blood, 0, 2));
$blood2 = substr($blood, 2, 2);
$blood2 = CommonService::customHex2dec($blood2);
Cache::put('blood' . $request_data['node'], ($blood1 + $blood2) * 100);
//体温36.1
$temperature = substr($request_data['data'], 4, 4);
$temperature1 = hexdec(substr($temperature, 0, 2));
$temperature2 = substr($temperature, 2, 2);
$temperature2 = CommonService::customHex2dec($temperature2);
Cache::put('temperature' . $request_data['node'], $temperature1 + $temperature2);
//心跳70
$heart = substr($request_data['data'], 8, 4);
$heart = hexdec(substr($heart, 0, 2));
Cache::put('heart' . $request_data['node'], $heart);
//脉搏70
$heart2 = substr($request_data['data'], 12, 4);
$heart2 = hexdec(substr($heart2, 0, 2));
Cache::put('heart2' . $request_data['node'], $heart2);
return 'ok'; return 'ok';
} }
@ -325,55 +358,68 @@ class IndexController extends BaseController
*/ */
public function loraDeviceList() public function loraDeviceList()
{ {
return [ $lora_mac = config("custom.lora_mac");
[
'name' => '设备1', $devices = [];
'mac' => '61', foreach ($lora_mac as $key => $mac){
'online' => 0, $devices[] = [
], 'name' => '设备' . ($key + 1),
[ 'mac' => $mac,
'name' => '设备2',
'mac' => '62',
'online' => 0,
],
[
'name' => '设备3',
'mac' => '63',
'online' => 0, 'online' => 0,
], ];
]; }
return $devices;
} }
public function loraData2() public function loraData2()
{ {
$time = (int)(time() . '000'); $time = (int)(time() . '000');
$blood = [
[
$time,
80,
]
];
$temperature = [ $request_data = request()->all();
[
$time,
36.1,
]
];
$heart = [ $node = $request_data['node'] ?? config("custom.lora_mac")[0];
[
$time,
78,
]
];
$humidity = [ $return_data = [];
[ $blood_data = Cache::get('blood' . $node, '');
$time, if ($blood_data){
81.4, $return_data['blood'] = [
] [
]; $time,
$blood_data,
]
];
}
$temperature_data = Cache::get('temperature' . $node, '');
if ($temperature_data){
$return_data['temperature'] = [
[
$time,
$temperature_data,
]
];
}
$heart_data = Cache::get('heart' . $node, '');
if ($heart_data){
$return_data['heart'] = [
[
$time,
$heart_data,
]
];
}
$heart2_data = Cache::get('heart2' . $node, '');
if ($heart2_data){
$return_data['humidity'] = [
[
$time,
$heart2_data,
]
];
}
$total = [50, 70, 90, 85, 80, 75, 70, 65, 60, 55]; $total = [50, 70, 90, 85, 80, 75, 70, 65, 60, 55];
@ -386,13 +432,7 @@ class IndexController extends BaseController
]; ];
} }
return [ return $return_data;
'blood' => $blood,
'temperature' => $temperature,
'heart' => $heart,
'humidity' => $humidity,
'total_data' => $total_data,
];
} }
/** /**

40
app/Http/Services/CommonService.php

@ -0,0 +1,40 @@
<?php
namespace App\Http\Services;
class CommonService{
/**
* 十进制小数转十六进制
* @param float $decimal
* @param $len
* @return string
*/
public static function customDec2hex(float $decimal, $len = 8) {
$hex = '';
$count = 0;
# 只取小数部分
$decimal = fmod($decimal, 1);
while ($count++ < $len) {
$dec16 = $decimal * 16;
# 取整 转16进制
$hex .= dechex((int)$dec16);
# 取小数部分
$decimal = fmod($dec16, 1);
}
return $hex;
}
/**
* 十六进制小数转十进制
* @param $hexadecimal
* @return float|int
*/
public static function customHex2dec($hexadecimal) {
$dec = 0;
for ($i = 0; $i < strlen($hexadecimal); $i++) {
$dec += hexdec($hexadecimal[$i]) / pow(16, $i + 1);
}
return $dec;
}
}

9
config/custom.php

@ -0,0 +1,9 @@
<?php
return [
'lora_mac' => [
// "616162626364",
// "616162626365",
"616162626366",
],
];

BIN
public/image/lora2/kk1_2.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 979 B

After

Width:  |  Height:  |  Size: 3.6 KiB

10
resources/views/http/lora22.blade.php

@ -384,7 +384,7 @@
_rawData.temperature.forEach(value => data_temperature.push(value)); _rawData.temperature.forEach(value => data_temperature.push(value));
_rawData.heart.forEach(value => data_heart.push(value)); _rawData.heart.forEach(value => data_heart.push(value));
_rawData.humidity.forEach(value => data_humidity.push(value)); _rawData.humidity.forEach(value => data_humidity.push(value));
_rawData.total_data.forEach(value => data_total.push(value)); // _rawData.total_data.forEach(value => data_total.push(value));
myChart.setOption({ myChart.setOption({
series: [ series: [
@ -401,10 +401,10 @@
name: '湿度', name: '湿度',
data: data_humidity data: data_humidity
}, },
{ // {
name: '总体', // name: '总体',
data: data_total // data: data_total
} // }
] ]
}); });
}); });

Loading…
Cancel
Save