PHP Identifying position entries with alarm in attributes (EXAMPLE)

jaimzj8 years ago

If you need to identify from position tables, if there are any alarm data in the attributes for any device, the query below can help, However Please note filters can be set further based on protocol type, based on time etc, This is example is just to give you an idea how this can be achieved.

What you do with the resulting queries data is upto you to set inside the while loop, as an example, I am outputing the power value, ignition value and status value (Again this depends on if these values are available for the said device/protocol. You can replace it with your own.) or even sit conditions.

//Define today's date to limit query on recent position entries only
$FDate=date("Y-m-d");
$sql=mysql_query("SELECT * FROM position WHERE attributes LIKE '%alarm%' AND fixTime>='".$FDate." 00:00:00"."'");
while($row=mysql_fetch_array($sql)){
    $obj = json_decode($row['attributes']);
    $power = $obj->{'power'};
    $ignition = $obj->{'ignition'};
    $status = $obj->{'status'};
}