Browse code

Am adaugat modulul de ALARMA

Liviu Pislaru authored on 07/03/2018 12:25:07
Showing 2 changed files
... ...
@@ -1,6 +1,6 @@
1 1
 #!/usr/bin/perl
2 2
 # parser pentru mesajele MQTT
3
-# Version: 1.0.6
3
+# Version: 1.0.7
4 4
 
5 5
 use strict;
6 6
 use warnings;
... ...
@@ -8,6 +8,7 @@ use JSON qw( decode_json );
8 8
 use DBI;
9 9
 use Proc::Daemon;
10 10
 use POSIX qw(strftime);
11
+use System::Timeout qw(system);
11 12
 
12 13
 # pentru debug pun daemon=0 ca sa nu mai ruleze ca daemon
13 14
 my $daemon=1;
... ...
@@ -126,6 +127,10 @@ while (my $mqttMessage = <$SUB> ) {
126 126
           addDB ($topic, "RestartReason", $decoded->{'RestartReason'});
127 127
         }
128 128
       } 
129
+      if ($queue eq "ALARM"){
130
+        $json=~ s/\"/\\"/g;
131
+        pushALARM ($topic, $json);
132
+      }      
129 133
     }
130 134
   }
131 135
   else {
... ...
@@ -138,6 +143,19 @@ if ($daemon==1){
138 138
   }
139 139
 }
140 140
 
141
+# loghez alarmele pe care le trimit
142
+sub pushALARM {
143
+  (my $topic, my $json) = @_;
144
+  my $script = "php /admin/scripts/alarma/alarm.php $topic $json";
145
+  my $logfile='/var/log/mqttparser/mqtt-alarm.log';   
146
+  my $timealarm = strftime("%d/%m/%Y %H:%M:%S", localtime(time));
147
+  open (my $lh, '>>', $logfile) or die "Cannot open $logfile";
148
+  print $lh "$timealarm - Am lansat: $script";
149
+  close $lh;
150
+  system('1', "$script"); # lansez scriptul de alarma cu timeout 1 secunda
151
+  return;
152
+}
153
+
141 154
 # adaug in fisierele pentru graficele senzorilor
142 155
 sub addFILE {
143 156
   (my $topic, my $camp, my $valoare) = @_;
... ...
@@ -12,6 +12,7 @@ stat/qbzesh-1250/ESP {<strong>"Temp":23.30</strong>,<strong>"Humi":41.00</strong
12 12
 stat/qbzesh-1250/ESP {<strong>"Module":"NodeMCU DHT22"</strong>,<strong>"Version":"v2.0.1"</strong>}<br>
13 13
 stat/qbzesh-1250/ESP {<strong>"ESPMac":"2C-3A-E8-3D-E8-2B"</strong>,<strong>"IPAddress":"192.168.1.35"</strong>}<br>
14 14
 stat/qbzesh-1250/ESP {<strong>"LoopInterval":"15 minute"</strong>}<br>
15
+stat/qbzesh-1250/ALARM {<strong>"PIR":1</strong>}<br>
15 16
 tele/64x35up-2452/INFO1 {<strong>"Module":"Sonoff Pow"</strong>,<strong>"Version":"5.10.0"</strong>,"FallbackTopic":"DVES_3B4994","GroupTopic":"sonoffs"}<br>
16 17
 tele/64x35up-2452/INFO2 {"WebServerMode":"Admin","Hostname":"64x35up-2452-2452",<strong>"IPAddress":"192.168.23.146"</strong>}<br>
17 18
 tele/64x35up-2452/INFO3 {<strong>"RestartReason":"Power on"</strong>}<br>