· 5 years ago · Jul 13, 2020, 05:26 PM
1<?php
2
3namespace App\Http\Controllers;
4
5use Illuminate\Http\Request;
6use Illuminate\Http\Response;
7use App\Libraries\PlugField;
8use App\Libraries\SessionFilter;
9use App\Models\Farm;
10use App\Models\FarmStation;
11use App\Models\Station;
12use Carbon\Carbon;
13use Illuminate\Support\Facades\Auth;
14use Illuminate\Support\Facades\File;
15use Illuminate\Support\Facades\Storage;
16use App\Models\Crop;
17use App\Models\StationInmet;
18use GuzzleHttp\Client;
19
20/**
21 * Controller responsável por gerenciar estações climáticas.
22 *
23 * @author Gabriel Ribeiro <gabriel.geodata@gmail.com>
24 * @since 30/01/2020
25 * @version 1.0.0
26 */
27class StationController extends Controller {
28
29 private $plugField;
30 private $path;
31 private $data;
32 private $root;
33
34 public function __construct() {
35
36 $this->root = storage_path().'/cache';
37 $this->path = $this->root . '/plug-field-data.json';
38
39 //Verifica se o diretório existe
40 if(!File::exists($this->root)) {
41 File::makeDirectory($this->root);
42 }
43
44 //Verifica se o arquivo existe
45 if(!File::exists($this->path)) {
46 File::put($this->path, '');
47 }
48
49 $this->data = json_decode(File::get($this->path));
50 $this->plugField = new PlugField();
51
52 }
53
54 /**
55 * Trata os parâmetros conforme o tipo da estação (Manual ou Automática)
56 *
57 * @param integer $cropId
58 * @return void
59 */
60 private function getInmetParams($type, $keyParam, $keyValue, $data) {
61
62 $keyArr = [
63 'temperature' => [
64 'min' => [ 'T' => 'TEM_MIN', 'M' => 'TEMP_MIN' ],
65 'last' => [ 'T' => 'TEM_INS', 'M' => 'TEMP_HORA' ],
66 'max' => [ 'T' => 'TEM_MAX', 'M' => 'TEMP_MAX' ],
67 ],
68 'humidity' => [
69 'min' => [ 'T' => 'UMD_MIN', 'M' => 'UMD_MIN' ],
70 'last' => [ 'T' => 'UMD_INS', 'M' => 'UMID_HORA' ],
71 'max' => [ 'T' => 'UMD_MAX', 'M' => 'UMD_MAX' ],
72 ],
73 'wind-speed' => [
74 'last' => [ 'T' => 'VEN_VEL', 'M' => 'VENT_VEL' ],
75 ],
76 'wind-direction' => [
77 'last' => ['T' => 'VEN_DIR', 'M' => 'VENT_DIR']
78 ],
79 'preassure' => [
80 'last' => ['T' => 'PRE_INS', 'M' => 'PRESS_EST']
81 ],
82 'gust-speed' => [
83 'last' => ['T' => 'VEN_RAJ']
84 ]
85 ];
86
87 if ($data && isset($keyArr[$keyParam]) && isset($keyArr[$keyParam][$keyValue]) && isset($keyArr[$keyParam][$keyValue][$type]) && isset($data[$keyArr[$keyParam][$keyValue][$type]])) {
88 return $data[$keyArr[$keyParam][$keyValue][$type]];
89 }
90
91 return null;
92 }
93
94 /**
95 * Obtém os dados da estação do INMET
96 *
97 * @param integer $cropId
98 * @return void
99 */
100 public function getInmetStationInfoByCrop($cropId) {
101
102 if (is_numeric($cropId)) {
103
104 $user = Auth::user();
105
106 $crop = Crop::findById($cropId, $user)->select('crops.*', 'f.lat', 'f.lng')->first();
107
108 if($crop) {
109
110 try {
111
112 $fs = FarmStation::findByFarmId($crop->farm_id, $user)->select('farm_stations.*')->first();
113
114 //Verifica se existe ao menos uma estação na fazenda!
115 if($fs) {
116
117 return $this->getMeasures($fs->id);
118 }
119
120 $inmetStation = StationInmet::findByCoordinates($crop->lat, $crop->lng)->first();
121
122 if ($inmetStation) {
123
124 $station = [];
125
126 $station['station'] = [
127 'code' => $inmetStation->code,
128 'name' => ucwords(strtolower($inmetStation->name)),
129 'lat' => $inmetStation->lat,
130 'lng' => $inmetStation->lng,
131 ];
132
133 $station['updated_at'] = null;
134
135 $station['sensors'] = [];
136
137 $currentDate = date('Y-m-d');
138
139 $url = 'https://apitempo.inmet.gov.br/estacao/' . $currentDate . '/' . $currentDate . '/' . $inmetStation->code;
140
141 $client = new Client([ 'timeout' => 10 ]);
142
143 $options = [
144 "headers" => [
145 "Accept" => "*/*"
146 ]
147 ];
148
149 $response = $client->request('GET', $url, $options);
150
151 if ($response->getStatusCode() == Response::HTTP_OK) {
152
153 $data = json_decode($response->getBody()->getContents(), true);
154
155 if ($data && count($data) > 0) {
156
157 $measures = collect([]);
158
159 $tempMinMin = null;
160 $tempMaxMax = null;
161
162 foreach ($data as $row) {
163
164 if ($row['DT_MEDICAO'] && $row['HR_MEDICAO']) {
165
166 $date = Carbon::createFromFormat('Y-m-dHi', $row['DT_MEDICAO'].$row['HR_MEDICAO']);
167
168 $temperatureArrKey = 'temperature';
169
170 $inmetStationType = $inmetStation->type;
171
172 $tempLast = $this->getInmetParams($inmetStationType, $temperatureArrKey, 'last', $row);
173 $tempMin = $this->getInmetParams($inmetStationType, $temperatureArrKey, 'min', $row);
174 $tempMax = $this->getInmetParams($inmetStationType, $temperatureArrKey, 'max', $row);
175
176 if ($tempMin && (!$tempMinMin || $tempMin < $tempMinMin)) {
177 $tempMinMin = $tempMin;
178 }
179
180 if ($tempMax && (!$tempMaxMax || $tempMax > $tempMaxMax)) {
181 $tempMaxMax = $tempMax;
182 }
183
184 if ($date < now() && $tempLast) {
185
186 $station['updated_at'] = $date->format('Y-m-d H:i:s');
187
188 $sensors = [];
189
190 $temperatureInfo = [
191 'key' => 'temperature',
192 "unit" => "°",
193 "values" => [
194 "min" => $this->getInmetParams($inmetStationType, $temperatureArrKey, 'min', $row),
195 "last" => $tempLast,
196 "max" => $this->getInmetParams($inmetStationType, $temperatureArrKey, 'max', $row),
197 ]
198 ];
199
200 $altitudeInfo = [
201 'key' => 'altitude',
202 "unit" => "m",
203 "values" => [
204 "last" => $inmetStation->altitude,
205 ]
206 ];
207
208 array_push($sensors, $altitudeInfo, $temperatureInfo);
209
210 $humidityArrKey = 'humidity';
211
212 $currentHumidty = $this->getInmetParams($inmetStationType, $humidityArrKey, 'last', $row);
213
214 if (isset($currentHumidty)) {
215
216 $humidtyInfo = [
217 'key' => 'humidity',
218 "unit" => "%",
219 "values" => [
220 "min" => $this->getInmetParams($inmetStationType, $humidityArrKey, 'min', $row),
221 "last" => $currentHumidty,
222 "max" => $this->getInmetParams($inmetStationType, $humidityArrKey, 'max', $row)
223 ]
224 ];
225
226 array_push($sensors, $humidtyInfo);
227 }
228
229 if (isset($row['CHUVA'])) {
230
231 $pluviometryInfo = [
232 'key' => 'pluviometry',
233 "unit" => "mm",
234 "values" => [
235 "last" => $row['CHUVA'],
236 ]
237 ];
238
239 array_push($sensors, $pluviometryInfo);
240 }
241
242 $currentWindSpeed = $this->getInmetParams($inmetStationType, 'wind-speed', 'last', $row);
243
244 if ($currentWindSpeed) {
245
246 $windSpeedInfo = [
247 'key' => 'wind-speed',
248 "unit" => "Km/h",
249 "values" => [
250 "last" => $currentWindSpeed,
251 ]
252 ];
253
254 array_push($sensors, $windSpeedInfo);
255 }
256
257 $currentWindDir = $this->getInmetParams($inmetStationType, 'wind-direction', 'last', $row);
258
259 if ($currentWindDir) {
260
261 $windDirection = [
262 'key' => 'wind-direction',
263 "unit" => null,
264 "values" => [
265 "last" => $currentWindDir,
266 ],
267 'formattedValues' => [
268 'last' => formatCardinalPoint($currentWindDir)
269 ]
270 ];
271
272 array_push($sensors, $windDirection);
273 }
274
275 $currentGustSpeed = $this->getInmetParams($inmetStationType, 'gust-speed', 'last', $row);
276
277 if ($currentGustSpeed) {
278
279 $gustSpeedInfo = [
280 'key' => 'gust-speed',
281 "unit" => 'Km/h',
282 "values" => [
283 "last" => $currentGustSpeed,
284 ],
285 ];
286
287 array_push($sensors, $gustSpeedInfo);
288 }
289
290 $currentPreassure = $this->getInmetParams($inmetStationType, 'preassure', 'last', $row);
291
292 if ($currentPreassure) {
293
294 $preassureInfo = [
295 'key' => 'pressure',
296 "unit" => "hPa",
297 "values" => [
298 "last" => $currentPreassure,
299 ]
300 ];
301
302 array_push($sensors, $preassureInfo);
303 }
304
305 $station['sensors'] = $sensors;
306
307 $measures->push($station);
308 }
309 }
310 }
311
312 if ($measures->count()) {
313
314 $station = $measures->sortBy('updated_at')->last();
315
316 //Atualiza a temperatura mínima e máxima do dia
317 if (isset($tempMinMin) || isset($tempMaxMax)) {
318
319 foreach($station['sensors'] as $k => $sensor) {
320
321 if ($sensor['key'] == 'temperature') {
322
323 if (isset($tempMinMin)) {
324 $station['sensors'][$k]['values']['min'] = $tempMinMin;
325 }
326
327 if (isset($tempMaxMax)) {
328 $station['sensors'][$k]['values']['max'] = $tempMaxMax;
329 }
330 }
331
332 }
333 }
334
335 return $station;
336
337 }
338
339 return response('Não foi possível encontrar dados climáticos para as últimas 24 horas', Response::HTTP_NOT_FOUND);
340 }
341 }
342
343 return response('Não foi possível encontrar dados climáticos para as últimas 24 horas', Response::HTTP_NOT_FOUND);
344 }
345 } catch (\Exception $e) {
346
347 return response('Houve um erro interno, tente novamente mais tarde.', Response::HTTP_INTERNAL_SERVER_ERROR);
348 }
349
350 return response('Estação não encontrada', Response::HTTP_NOT_FOUND);
351 }
352
353 return response('A safra informada não foi encontrada', Response::HTTP_NOT_FOUND);
354 }
355
356 return response('Safra inválida', Response::HTTP_BAD_REQUEST);
357 }
358
359 /**
360 * Retorna lista de estações disponíveis para o usuário.
361 *
362 * @param Request $request
363 * @return void
364 */
365 public function index(Request $request) {
366
367 $request = SessionFilter::updateFilters($request);
368 list($limit, $column, $sort, $status) = $filters = filterSearch($request, 50);
369
370 $stations = FarmStation::search($request->search, Auth::user())
371 ->select('st.*', 'farm_stations.id as fs_id', 'f.name as farm_name', 'p.name as producer_name')
372 ->paginate(10);
373
374 return view('stations.index', [ "stations" => $stations,"filters" => $filters ]);
375 }
376
377 /**
378 * Retorna a lista de estações para a api
379 *
380 * @return void
381 */
382 public function getStations(Request $request) {
383
384 try {
385 $stations = FarmStation::search(null, Auth::user())
386 ->select('st.*', 'farm_stations.id as fs_id', 'f.name as farm_name', 'p.name as producer_name')
387 ->get();
388
389 return $stations;
390 } catch(\Exception $e) {
391
392 return response('Houve um erro interno, tente novamente mais tarde!', Response::HTTP_INTERNAL_SERVER_ERROR);
393 }
394
395 }
396
397 /**
398 * Carrega view para a criação de uma nova Estação Climática
399 *
400 * @return void
401 */
402 public function create() {
403
404 $station = new Station();
405 $farms = Farm::search()->select('farms.*')->get();
406
407 return view('stations.create-edit', ['station' => $station, 'farms' => $farms]);
408 }
409
410 /**
411 * Insere uma nova Estação Climática
412 *
413 * @param Request $request
414 * @return void
415 */
416 public function insert(Request $request, $recursively = false) {
417
418 $this->validate($request, [
419 'farm_id' => 'required|numeric|min:1|max:2147483647',
420 'name' => 'required|string|',
421 'key' => 'required|string'
422 ]);
423
424 try {
425
426 $deviceList = $this->plugField->deviceAssociate($request->key);
427
428 //Salva estação inserida na base de dados
429 $this->save($deviceList, $request);
430
431 return redirect('stations')->withSuccess('Estação inserida com sucesso!');
432
433 } catch(\Exception $e) {
434
435 //Verifica se o token foi expirado
436 if($e->getCode() == Response::HTTP_UNAUTHORIZED) {
437
438 //Verifica se é uma chamada recursiva
439 if(!$recursively) {
440 $login = $this->plugField->login();
441
442 if($login) {
443
444 //Tenta inserir novamente a estação
445 return $this->insert($request, true);
446
447 }
448 }
449
450 return back()->withErrors('Houve um erro interno, tente novamente mais tarde!');
451 } else {
452 return back()->withErrors($e->getMessage());
453 }
454 }
455 }
456
457 /**
458 * Salva estação inserida na base de dados
459 *
460 * @param [type] $key
461 * @param [type] $deviceList
462 * @return void
463 */
464 private function save($deviceList, $request) {
465
466 //Filtra a lista de estções pela chave de acesso e retorna a estação inserida.
467 $device = arrayUnwrapp(array_filter($deviceList, function($elm) use ($request) {
468
469 return $elm->accessCode == $request->key;
470 }));
471
472 //Verifica se estação já existe.
473 $station = Station::where('device_id', $device->id)->first();
474
475 if(!$station) {
476 $station = new Station();
477 $station->name = $request->name;
478 $station->device_id = $device->id;
479 $station->save();
480 }
481
482 //Verifica se a estação já está atrelada a fazenda solicitada.
483 $farmStation = FarmStation::findByRelation($station->id, $request->farm_id)->first();
484
485 if(!$farmStation) {
486
487 $farmStation = new FarmStation();
488
489 $farmStation->station_id = $station->id;
490 $farmStation->farm_id = $request->farm_id;
491 $farmStation->save();
492
493 } else {
494 throw new \Exception('Não foi possível inserir. Estação já esta atrelada á esta fazenda!');
495 }
496
497 }
498
499 /**
500 * Atauliza informações da Estação
501 *
502 * @return void
503 */
504 public function edit(Request $request, $stationId) {
505
506 try {
507
508 if(!empty($stationId)) {
509 $station = FarmStation::findById($stationId, Auth::user())->select('st.*', 'farm_stations.farm_id')->first();
510
511 if($station) {
512
513 $device = $this->plugField->getDevice($station->device_id);
514 $deviceInfo = (object)['lat' => $device->latitude, 'lng' => $device->longitude];
515 $farms = Farm::search()->select('farms.*')->get();
516
517 return view('stations.create-edit', ['station' => $station, 'deviceInfo' => $deviceInfo, 'farms' => $farms]);
518 }
519 }
520
521 return redirect('stations')->withErrors('Nada foi encontrado!');
522
523 } catch(\Exception $e) {
524
525 return back()->withErrors($e->getMessage());
526 }
527 }
528
529 /**
530 * Atualiza um registro
531 *
532 * @return void
533 */
534 public function update(Request $request) {
535
536 $this->validate($request, [
537 'farm_id' => 'required|numeric|min:1|max:2147483647',
538 'name' => 'required|string|',
539 ]);
540
541 $station = Station::findById($request->station_id, Auth::user())->first();
542
543 if($station) {
544
545 //Verifica se a estação já está atrelada a fazenda solicitada.
546 $farmStation = FarmStation::findByRelation($station->id, $request->farm_id)->first();
547
548 if($farmStation) {
549
550 $station->name = $request->name;
551 $farmStation->farm_id = $request->farm_id;
552 $station->save();
553
554 return redirect('stations')->withSuccess('Estação atualizada com sucesso!');
555 }
556
557 }
558
559 return redirect('stations')->withErrors('Nada foi encontrado!');
560 }
561
562 /**
563 * Remove uma associação.
564 *
565 * @return void
566 */
567 public function delete(Request $request) {
568
569 $this->validate($request, [
570 'id' => 'required|numeric'
571 ]);
572
573 $farmStations = FarmStation::findById($request->id, Auth::user())->select('farm_stations.*')->first();
574 if($farmStations) {
575
576 try {
577
578 $farmStations->delete();
579 return back()->withSuccess('Estação removida com sucesso!');
580 } catch(\Exception $e) {
581 return back()->withErrors('Houve um erro interno, tente novamente mais tarde!');
582 }
583 }
584
585 return redirect('farms')->withErrors('Nada foi encontrado!');
586 }
587
588 /**
589 * Retorna estações juntamente com seus valores atuais.
590 *
591 * @return void
592 */
593 public function getStationsDashboard(Request $request) {
594
595 $this->validate($request, [
596 'farm_id' => 'required|numeric'
597 ]);
598
599 $query = FarmStation::join('stations as st', 'st.id', 'farm_stations.station_id' )
600 ->where('farm_id', $request->farm_id);
601
602 if($request->station_id) {
603 $query->where('station_id', $request->station_id);
604 }
605
606 $stationsIds = $query->select('farm_stations.id', 'st.device_id')
607 ->pluck('device_id', 'farm_stations.id')->toArray();
608
609 $deviceList = $this->plugField->getDeviceList();
610
611 if(!empty($stationsIds)) {
612
613 $stations = array_filter($deviceList, function($elm) use($stationsIds) {
614
615 if(in_array($elm->id, $stationsIds)) {
616
617 $elm->fs_id = array_search($elm->id, $stationsIds);
618 }
619
620 return in_array($elm->id, $stationsIds) == true;
621 });
622
623 return $stations;
624 } else {
625 return null;
626 }
627 }
628
629 /**
630 * Retorna o dashboard de uma estação especificada pelo id.
631 *
632 * @param Request $request
633 * @return void
634 */
635 public function getMeasures($farmStationId, $repeat = true) {
636
637 try {
638
639 $station = FarmStation::findById($farmStationId, Auth::user())
640 ->select('st.*', 'farm_stations.farm_id')
641 ->first();
642
643 $device = null;
644
645 if(!$this->checkLastUpdate()) {
646
647 $device = $this->plugField->getDevice($station->device_id);
648
649 } else {
650
651 $device = $this->getLocalDashboard($station->device_id);
652 }
653
654 if($device) {
655
656 $measure = [];
657
658 $measure['station'] = [
659 "code" => $device->serialNumber,
660 "name" => $device->name,
661 "lat" => $device->latitude,
662 "lng" => $device->longitude
663 ];
664
665 $updatedAt = Carbon::createFromFormat('d/m/Y H:i', $device->updateDateTime);
666
667 $measure['updated_at'] = $updatedAt->format('Y-m-d H:i:s');
668
669 $measure['sensors'] = [];
670
671 if (isset($device->altitude)) {
672
673 $altitudeInfo = [
674
675 "key" => "altitude",
676 "unit" => "m",
677 "values" => [
678 "last" => $device->altitude
679 ]
680 ];
681
682 array_push($measure['sensors'], $altitudeInfo);
683 }
684
685 if ($device->dashboard) {
686
687 if (isset($device->dashboard->temp)) {
688
689 $temperatureInfo = [
690 'key' => 'temperature',
691 'unit' => '°',
692 'values' => [
693 'last' => $device->dashboard->temp
694 ]
695 ];
696
697 if ($device->dashboard->tempMin) {
698
699 $temperatureInfo['values']['min'] = $device->dashboard->tempMin;
700 }
701
702 if($device->dashboard->tempMax) {
703
704 $temperatureInfo['values']['max'] = $device->dashboard->tempMax;
705 }
706
707 array_push($measure['sensors'], $temperatureInfo);
708 }
709
710 if (isset($device->dashboard->humi)) {
711
712 $humidtyInfo = [
713 'key' => 'humidity',
714 'unit' => '%',
715 'values' => [
716 'last' => $device->dashboard->humi
717 ]
718 ];
719
720 array_push($measure['sensors'], $humidtyInfo);
721 }
722
723 if (isset($device->dashboard->rain)) {
724
725 $pluviometryInfo = [
726 'key' => 'pluviometry',
727 'unit' => 'mm',
728 'values' => [
729 'last' => $device->dashboard->rain,
730 'day' => $device->dashboard->rainDay,
731 'month' => $device->dashboard->rainMonth,
732 'year' => $device->dashboard->rainYear
733 ]
734 ];
735
736 array_push($measure['sensors'], $pluviometryInfo);
737 }
738
739 if (isset($device->dashboard->wind)) {
740
741 $windSpeedInfo = [
742 'key' => 'wind-speed',
743 'unit' => 'Km/h',
744 'values' => [
745 'last' => $device->dashboard->wind,
746 ],
747 ];
748
749 array_push($measure['sensors'], $windSpeedInfo);
750 }
751
752 if (isset($device->dashboard->dire)) {
753
754 $windDirectionInfo = [
755 'key' => 'wind-direction',
756 'unit' => null,
757 'values' => [
758 'last' => $device->dashboard->dire,
759 ],
760 'formattedValues' => [
761 'last' => $device->dashboard->direString
762 ]
763 ];
764
765 array_push($measure['sensors'], $windDirectionInfo);
766 }
767
768 if (isset($device->dashboard->winb)) {
769
770 $gustSpeedInfo = [
771 'key' => 'gust-speed',
772 "unit" => 'Km/h',
773 "values" => [
774 "last" => $device->dashboard->winb,
775 ],
776 ];
777
778 array_push($measure['sensors'], $gustSpeedInfo);
779 }
780
781 if (isset($device->dashboard->prre)) {
782
783 $preassureInfo = [
784 'key' => 'pressure',
785 'unit' => 'hPa',
786 'values' => [
787 'last' => $device->dashboard->prre,
788 ],
789 ];
790
791 array_push($measure['sensors'], $preassureInfo);
792 }
793
794 if (isset($device->dashboard->radi)) {
795
796 $solarRadiationInfo = [
797 'key' => 'solar-radiation',
798 'unit' => 'lux',
799 'values' => [
800 'last' => $device->dashboard->radi,
801 ],
802 ];
803
804 array_push($measure['sensors'], $solarRadiationInfo);
805 }
806
807 if (isset($device->dashboard->uv)) {
808
809 $uvRadiationInfo = [
810 'key' => 'uv',
811 'unit' => null,
812 'values' => [
813 'last' => $device->dashboard->uv,
814 ],
815 ];
816
817 array_push($measure['sensors'], $uvRadiationInfo);
818 }
819
820 if (isset($device->dashboard->duep)) {
821
822 $duepInfo = [
823 'key' => 'dew-point',
824 'unit' => '°',
825 'values' => [
826 'last' => $device->dashboard->duep,
827 ],
828 ];
829
830 array_push($measure['sensors'], $duepInfo);
831 }
832 }
833
834 return $measure;
835
836 } else {
837
838 return response('Houve um erro.', Response::HTTP_INTERNAL_SERVER_ERROR);
839 }
840
841 } catch(\Exception $e) {
842
843 //Verifica se é uma chamada recursiva
844 if($e->getCode() == Response::HTTP_UNAUTHORIZED && $repeat) {
845
846 $login = $this->plugField->login();
847
848 if($login) {
849
850 //Tenta buscar novamente o dashboard
851 return $this->getMeasures($farmStationId, false);
852 }
853 }
854
855 return response($e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
856 }
857 }
858
859 /**
860 * Retorna o dashboard de uma estação especificada pelo id, a partir das informações gravadas localmente.
861 *
862 * @param [type] $deviceId
863 * @return void
864 */
865 private function getLocalDashboard($deviceId) {
866
867 $devices = collect($this->data->data);
868
869 return $devices->where('id', $deviceId)->first();
870 }
871
872 /**
873 * Checa a última atualização das informações e verifica se deve buscar novamente
874 *
875 * @return void
876 */
877 private function checkLastUpdate() {
878
879 if(isset($this->data)) {
880
881 $createdAt = Carbon::create($this->data->created_at);
882 $diff = $createdAt->diffInMinutes(now());
883
884 if($diff < 5) {
885 return true;
886 }
887 }
888
889 return false;
890 }
891
892 /**
893 * Retorna um json com os nomes e as métricas dos sensores.
894 *
895 * @return void
896 */
897 public function getMetrics() {
898 return File::get(storage_path().'/cache/plug-field-metrics.json');
899 }
900}