public function test4()
 {
     set_time_limit(0);
     $arr = [1, 2, 3, 1, 3, 4, 1, 2, 2, 1, 1, 3, 4, 3, 2, 3, 4, 2, 3, 1];
     while (true) {
         foreach ($arr as $result) {
             // MQTT 수면단계 태스트
             $topic = '/madcat' . '/sleepStep';
             $message = sprintf("%d", $result);
             $mqtt = new MQTT("laravel.ssm.n-pure.net", 1883, "NeuroskyMQTTPUSH");
             //Change client name to something unique
             if ($mqtt->connect()) {
                 $mqtt->publish($topic, $message, 0);
                 $mqtt->close();
             } else {
                 echo ' connect fail ';
             }
             echo '<br /> TEST SET : ' . $result . PHP_EOL;
             flush();
             sleep(3);
         }
     }
 }
 /**
  * @brief 라즈베리파이에서 측정된 30초 윈도우 받아서 가공
  * @details 30초 윈도우 데이터를 외부 C 프로그램으로 분류하고 결과를 DB에 저장하고 MQTT 전송
  * @param bluetoothaddr (String)
  * @param rawdata (String)
  * @return Util
  */
 public function userRawDataReceiver()
 {
     $validRule = ['bluetoothaddr' => array('required', 'regex:/^[0-9a-zA-Z]{2}:[0-9a-zA-Z]{2}:[0-9a-zA-Z]{2}:[0-9a-zA-Z]{2}:[0-9a-zA-Z]{2}:[0-9a-zA-Z]{2}$/')];
     $bluetoothaddr = array_map('trim', Input::only('bluetoothaddr'));
     $validator = Validator::make($bluetoothaddr, $validRule);
     $rawdata = Input::get('rawdata');
     $noiseFile = Input::file('noisefile');
     $noisePeak = Input::get('noisepeak');
     if (!isset($noisePeak)) {
         $noisePeak = NULL;
     }
     if ($validator->fails()) {
         return Utils::result(Utils::CANNOT_PASS_VALIDATOR, true);
     }
     // 블루투스로 유저 조회
     $member = Member::where('bluetoothaddr', $bluetoothaddr)->first();
     if (!isset($member)) {
         return Utils::result(Utils::CANNOT_FIND_MEMBER);
     }
     //---------------------------
     //  RAW 데이터 처리
     //---------------------------
     $_startConvertData = microtime(true);
     $arrayRawData = explode(',', $rawdata);
     if (count($arrayRawData) == 0) {
         return Utils::result(Utils::CANNOT_PASS_VALIDATOR, true);
     }
     $arrayVoltageData = $this->matlabExec->convertRawData($arrayRawData);
     // RAW 데이터를 Voltage 데이터로 변환.
     // voltage 파일 저장
     $saveResult = $this->matlabExec->saveRawData($arrayVoltageData);
     if ($saveResult === FALSE) {
         return Utils::result(Utils::CANNOT_PASS_VALIDATOR . " FAIL TO SAVE", true);
     }
     $_endConvertData = microtime(true);
     // MATLAB 필터
     $_startClassify = microtime(true);
     // 실행시간 측정
     $sleepStep = $this->matlabExec->execNeutralNetFilter();
     //---------------------------------------------------------
     // noise 파일 업로드 부분
     //---------------------------------------------------------
     $uploadFileName = NULL;
     if (isset($noiseFile)) {
         $extension = $noiseFile->getClientOriginalExtension();
         $originalFileName = $noiseFile->getClientOriginalName();
         $uploadFileName = sprintf("%s_%d.%s", md5(time()), time(), $extension);
         // 업로드 시작
         $noiseFile->move(public_path() . '/upload/', $uploadFileName);
     }
     //---------------------------------------------------------
     // AvgSleep & SleepRecord 업데이트
     //---------------------------------------------------------
     $lastRegIdx = $this->avgSleepRepo->getLastRegIdx($member);
     $lastRegTime = $this->avgSleepRepo->getLastRegTime($member, $lastRegIdx);
     // 가장 마지막 시간 가져옴
     $currentTime = time();
     $currentDate = date('Y-m-d H:i:s', $currentTime);
     if (abs($currentTime - strtotime($lastRegTime)) > 3600) {
         /* 현재시간과 마지막 묶음 시간차이가 1시간 이상이면 다른 묶음으로 처리 */
         $lastRegIdx += 1;
         $this->avgSleepRepo->addAvgSleep($member, $lastRegIdx);
     }
     $this->sleepRecordRepo->addSleepRecord($member, $lastRegIdx, $sleepStep, $currentDate, $uploadFileName, $noisePeak);
     // 수면 단계 업데이트
     if (in_array($sleepStep, [1, 2, 3, 4])) {
         $this->avgSleepRepo->increaseTotalRecord($member, $lastRegIdx);
         if (in_array($sleepStep, [3, 4])) {
             $this->avgSleepRepo->increaseDeepRecord($member, $lastRegIdx);
         }
     }
     // MQTT 전송부분
     $topic = $member->userid . '/sleepStep';
     $message = sprintf("%d", $sleepStep);
     $mqtt = new MQTT("laravel.ssm.n-pure.net", 1883, "NeuroskyMQTTPUSH");
     //Change client name to something unique
     if ($mqtt->connect()) {
         $mqtt->publish($topic, $message, 0);
         $mqtt->close();
     }
     $_endClassify = microtime(true);
     // 측정끝
     $output = new stdClass();
     $output->sleepStep = (int) $sleepStep;
     $output->elapsedConvertFile = $_endConvertData - $_startConvertData;
     $output->elapsedClassification = $_endClassify - $_startClassify;
     $output->elapsedTime = $output->elapsedConvertFile + $output->elapsedClassification;
     // RAW 데이터 삭제
     $this->matlabExec->removeRawData();
     return Utils::result($output);
 }