where('lable',$item['label'])->order("id","desc")->value("time"); $data[] = [ 'mac' => $mac, 'lable' => $item['label'], 'rssi' => $item['rssi'], 'time' => $item['time'], 'addTime' => time(), 'move' => $item['move'], 'step' => empty($item['step']) ? 0 : $item['step'], 'temperature' => empty($item['temperature']) ? 0 : $item['temperature'], //告警 'temperWarn' => empty($item['temperWarn']) ? 00 : $item['temperWarn'], // "interval_time"=>empty($onetime) ?0:($item['time']-$onetime) ]; } $tage = new TagHistory(); $tage->saveAll($data); json_success('上传成功'); } //储存数据到redis public function redis_to_mysql(){ $ues_redis=Cache::store('redis')->handler(); $text=null; while(1){ $jsonData= $ues_redis->rpop("mqtt_data"); debug_log("InAndOUT",'数据redis'.$jsonData); if(empty($jsonData)){ debug_log("InAndOUT",'没有数据'); sleep(1); continue; } // debug_log("InAndOUT",$jsonData); $data=json_decode($jsonData,true); // debug_log("InAndOUT",$data['cnt']); $time=$data['time']; $mac=$data['imei']; $list=[]; $text=$text.$data['cnt']; if(strlen($text)<24){ continue; } while(strlen($text)>=24){ $da=substr($text,0,24); $t1 = substr($da,8,2)=='00'||substr($da,8,2)=='10'||substr($da,8,2)=='01' ? true:false; $t2 =substr($da,10,6)=="FFFFFF"||substr($da,10,6)=="000000" ?true:false; if($t1&&$t2){ $label= substr($da,0,8); $rssi1= substr($da,16,2); $rssi2= substr($da,18,2); $rssi3= substr($da,20,2); $rssi4= substr($da,22,2); $DA=[ 'mac' => $mac, 'label' =>$label, 'rssi1' => hexdec($rssi1), 'rssi2' => hexdec($rssi2), 'rssi3' => hexdec($rssi3), 'rssi4' => hexdec($rssi4), 'report_time'=>$time ]; debug_log("InAndOUT","数据:".json_encode($DA,true)); //保存计算中 //分为8个桶 // $num=Hexdec($label); // $Identification=$num%8; // $key="buckets".$Identification; // $ues_redis->rPush($key,json_encode($DA,true)); try{ $dispose = new dispose($ues_redis); $computedata=$dispose->computeData($DA); debug_log("InAndOUT","计算完成的数据:".json_encode($DA,true)); $dispose->computeResout($computedata); }catch(Exception $e){ debug_log("InAndOUT","抛出异常".json_encode($DA,true)); } $text=substr($text,24); }else{ $text=substr($text,1); } } // $tage = new Access(); // $tage->saveAll($list); } } public function test(){ try{ $ues_redis=Cache::store('redis')->handler(); $jsonData= $ues_redis->rpop("mqtt_data"); debug_log("InAndOUT","1212"); }catch(Exception $e){ var_dump($e->getMessage()); } } /** * 删除前1天的数据 * * @return void */ public function deleteHistory() { while(true) { $where[] = ['addTime','<',strtotime("-1 day")]; Db::name('tag_history')->where($where)->delete(); sleep(60*60*24); } } /** * 检测小程序版本版本 function * * @return void */ public function detectionVersion(){ $token = $_GET['token']; if (!$token || $token != '444333d3') { json_fail('缺少token或者token不对'); } $data["url"]="http://116.62.220.88:8112/static/app/蓝牙小程序/1.1.1/rl-release.apk"; $data["version"]="1.1.1"; json_success("查询版本成功",$data); } }