Esempio n. 1
0
                $response = callArduino("on/{$out_id}");
                if (strpos($response, "OK") !== false) {
                    $sql = "UPDATE OUTPUTS SET OUT_STATUS = " . STATUS_ON . " WHERE OUT_ID = {$out_id}";
                    DBexec($db_handler, $sql);
                    logEvent($db_handler, TYPE_OUT_ON, "Output {$out_id} turned ON by a schedule");
                    logMessage("IrrighinoTask - OUT_ID {$out_id} turned ON and event logged in the DB");
                } else {
                    logEvent($db_handler, TYPE_ERROR, "Unable to turn ON output {$out_id}");
                    logMessage("IrrighinoTask - Error while calling Arduino to turn ON OUT_ID {$out_id}, response: {$response}");
                }
            }
        } else {
            logMessage("IrrighinoTask - No events found for this OUT_ID");
            // if the output is ON, turn it OFF
            if ($out_status == STATUS_ON) {
                $response = callArduino("off/{$out_id}");
                if (strpos($response, "OK") !== false) {
                    $sql = "UPDATE OUTPUTS SET OUT_STATUS = " . STATUS_OFF . " WHERE OUT_ID = {$out_id}";
                    DBexec($db_handler, $sql);
                    logEvent($db_handler, TYPE_OUT_OFF, "Output {$out_id} turned OFF by a schedule");
                    logMessage("IrrighinoTask - OUT_ID {$out_id} turned OFF and event logged in the DB");
                } else {
                    logEvent($db_handler, TYPE_ERROR, "Unable to turn OFF output {$out_id}");
                    logMessage("IrrighinoTask - Error while calling Arduino to turn ON OUT_ID {$out_id}, response: {$response}");
                }
            }
        }
    }
    // the query command returned false (= error)
} else {
    logMessage("IrrighinoTask - Error while querying the DB: " . $db_handler->errorInfo()[2]);
Esempio n. 2
0
         $sql = "UPDATE OUTPUTS SET OUT_STATUS = " . STATUS_OFF . " WHERE OUT_ID = {$output_id}";
         DBexec($db_handler, $sql);
         $sql = "UPDATE OUTPUTS SET MANAGED_BY = " . MANAGED_BY_WEB . " WHERE OUT_ID = {$output_id}";
         DBexec($db_handler, $sql);
         // log the event and return OK
         logEvent($db_handler, TYPE_OUT_OFF, "Output {$output_id} manually turned OFF via web");
         logMessage("IrrighinoService - OUT_ID {$output_id} turned OFF and event logged in the DB");
         sendReturnCode(0, "OK");
     } else {
         logEvent($db_handler, TYPE_ERROR, "Unable to manually turn OFF output {$output_id}");
         logMessage("IrrighinoService - Error while calling Arduino to turn ON OUT_ID {$output_id}, response: {$response}");
         sendReturnCode(-1, "Unable to call Arduino to manually turn OFF output {$output_id}, error code: {$response}");
     }
 } else {
     if ($status_id == 2) {
         $response = callArduino("on/\${$output_id}");
         if (strpos($response, "OK") !== false) {
             // change the output status and managed by in the DB
             $sql = "UPDATE OUTPUTS SET OUT_STATUS = " . STATUS_ON . " WHERE OUT_ID = {$output_id}";
             DBexec($db_handler, $sql);
             $sql = "UPDATE OUTPUTS SET MANAGED_BY = " . MANAGED_BY_WEB . " WHERE OUT_ID = {$output_id}";
             DBexec($db_handler, $sql);
             // log the event and return OK
             logEvent($db_handler, TYPE_OUT_ON, "Output {$output_id} manually turned ON via web");
             logMessage("IrrighinoService - OUT_ID {$output_id} turned ON and event logged in the DB");
             sendReturnCode(0, "OK");
         } else {
             logEvent($db_handler, TYPE_ERROR, "Unable to manually turn ON output {$output_id}");
             logMessage("IrrighinoService - Error while calling Arduino to turn ON OUT_ID {$output_id}, response: {$response}");
             sendReturnCode(-1, "Unable to call Arduino to manually turn ON output {$output_id}, error code: {$response}");
         }