diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index e4db2e9..3c57fe5 100644 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; +use App\Http\Services\CommonService; use Illuminate\Routing\Controller as BaseController; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Log; @@ -248,7 +249,9 @@ class IndexController extends BaseController public function lora2() { - return view('http.lora22'); + Cache::flush(); + + return view('http.lora2'); } public function getPelmaStore() @@ -279,9 +282,39 @@ class IndexController extends BaseController { // echo Cache::get('blood'); - $data = request('blood'); - Cache::put('blood', $data); - Log::info($data); + $request_data = request()->all(); + + $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'; } @@ -325,55 +358,68 @@ class IndexController extends BaseController */ public function loraDeviceList() { - return [ - [ - 'name' => '设备1', - 'mac' => '61', - 'online' => 0, - ], - [ - 'name' => '设备2', - 'mac' => '62', - 'online' => 0, - ], - [ - 'name' => '设备3', - 'mac' => '63', + $lora_mac = config("custom.lora_mac"); + + $devices = []; + foreach ($lora_mac as $key => $mac){ + $devices[] = [ + 'name' => '设备' . ($key + 1), + 'mac' => $mac, 'online' => 0, - ], - ]; + ]; + } + + return $devices; } public function loraData2() { $time = (int)(time() . '000'); - $blood = [ - [ - $time, - 80, - ] - ]; - $temperature = [ - [ - $time, - 36.1, - ] - ]; + $request_data = request()->all(); - $heart = [ - [ - $time, - 78, - ] - ]; + $node = $request_data['node'] ?? config("custom.lora_mac")[0]; - $humidity = [ - [ - $time, - 81.4, - ] - ]; + $return_data = []; + $blood_data = Cache::get('blood' . $node, ''); + if ($blood_data){ + $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]; @@ -386,13 +432,7 @@ class IndexController extends BaseController ]; } - return [ - 'blood' => $blood, - 'temperature' => $temperature, - 'heart' => $heart, - 'humidity' => $humidity, - 'total_data' => $total_data, - ]; + return $return_data; } /** diff --git a/app/Http/Services/CommonService.php b/app/Http/Services/CommonService.php new file mode 100644 index 0000000..f187385 --- /dev/null +++ b/app/Http/Services/CommonService.php @@ -0,0 +1,40 @@ + [ +// "616162626364", +// "616162626365", + "616162626366", + ], +]; diff --git a/public/image/lora2/kk1_2.png b/public/image/lora2/kk1_2.png index c509849..e3d7464 100644 Binary files a/public/image/lora2/kk1_2.png and b/public/image/lora2/kk1_2.png differ diff --git a/resources/views/http/lora22.blade.php b/resources/views/http/lora22.blade.php index 6f4ffb2..c841a19 100644 --- a/resources/views/http/lora22.blade.php +++ b/resources/views/http/lora22.blade.php @@ -384,7 +384,7 @@ _rawData.temperature.forEach(value => data_temperature.push(value)); _rawData.heart.forEach(value => data_heart.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({ series: [ @@ -401,10 +401,10 @@ name: '湿度', data: data_humidity }, - { - name: '总体', - data: data_total - } + // { + // name: '总体', + // data: data_total + // } ] }); });