Browse code

bug fix timestamp insert get433info table

Liviu Pislaru authored on 15/09/2018 23:20:30
Showing 1 changed files
... ...
@@ -108,7 +108,9 @@ while (my $mqttMessage = <$SUB> ) {
108 108
       if ($queue eq "RESULT"){ # topic nou sonoff v6.2.1 sonoff bridge
109 109
         my $decoded = decode_json($json);
110 110
         if (exists $decoded->{'RfReceived'}{'Data'}){
111
-          addRF ($topic, $decoded->{'RfReceived'}{'Sync'}, $decoded->{'RfReceived'}{'Low'}, $decoded->{'RfReceived'}{'High'}, $decoded->{'RfReceived'}{'Data'}, "now()");
111
+          my ($sec,$min,$hour,$mday,$mon,$year)=localtime(time);
112
+          my $timestamp = sprintf ( "%04d-%02d-%02d %02d:%02d:%02d", $year+1900,$mon+1,$mday,$hour,$min,$sec);
113
+          addRF ($topic, $decoded->{'RfReceived'}{'Sync'}, $decoded->{'RfReceived'}{'Low'}, $decoded->{'RfReceived'}{'High'}, $decoded->{'RfReceived'}{'Data'}, $timestamp);
112 114
           my $script="php /admin/scripts/mqttparser/rf433.php $topic $decoded->{'RfReceived'}{'Data'}";
113 115
           runSCRIPT ($script);
114 116
         }
... ...
@@ -240,11 +242,11 @@ sub delDB {
240 240
 
241 241
 # adaug/updatez in tabela get433info din baza de date 
242 242
 sub addRF {
243
-  (my $topic, my $sync, my $low, my $high, my $data) = @_;
243
+  (my $topic, my $sync, my $low, my $high, my $data, my $timestamp) = @_;
244 244
   (my $user, my $devid) = split /\-/, $topic;
245 245
   my $query = "insert into get433info values (?, ?, ?, ?, ?, ?, ?) on duplicate key update log=?";
246 246
   my $sth = $dbh->prepare($query) or die "Can't prepare $query: $dbh->errstr\n";
247
-  $sth->execute("$user", "$devid", "$sync", "$low", "$high", "$data", "now()" ,"now()");
247
+  $sth->execute("$user", "$devid", "$sync", "$low", "$high", "$data", "$timestamp", "$timestamp");
248 248
   $sth->finish();
249 249
   return;
250 250
 }