Search code examples
phpmysqlifttt

IFTTT : Trying to run a php script using Maker webhooks


Good day,

I have created an IFTTT receipe that if a "myfox" alarm system is armed, a php script is executed on my NAS (192.165.x.x). The php script is supposed to trigger a stored procedure in my mysql database.

The following PHP script has been tested by other means and I'm sure that it works :

<?php

/*
    php_update_mode_armed.php

    *****************************************************************************************
    * This script updates the value of the components in the table tbl_eedomus_current_mode
    * It calls the stored procedure 'sp_tbl_eedomus_current_mode_armed'
    *****************************************************************************************

    Version 1.00, 09.06.2017, Initial version of the script
*/


mainProcess();

function mainProcess()
{
    $ServerIP = "192.165.x.x";
    $sqlUser = "domoos";
    $sqlDatabase = "domoos";
$pw = "myPass";

    // Connect
    $mysqli = new mysqli($ServerIP, $sqlUser, $pw, $sqlDatabase);
    if(!$mysqli) {[![enter image description here][1]][1]
    header('Location: error.php?error=DbConnectionFailure');
    die();
    }

    // Call stored procedure sp_tbl_eedomus_current_mode_armed 
    if(!$mysqli->query("CALL sp_tbl_eedomus_current_mode_armed ()"))
    {
        echo "OK";
    if($mysqli) $mysqli->close(); // Close DB connection
    //header('Location: error.php?error=QueryFailure');
    die();
    }

    if($mysqli) $mysqli->close(); // Close DB connection    
}


?>

Below, also, a screen shot of my "then" part of the IFTTT receipe.

Am I doing something wrong here or is the use of IFTTT not fit for the purpose I'm trying to achieve here?

Many thanks for your help on this matter and have a great day.

enter image description here


Solution

  • Most likly IFTTT can't access your NAS from the internet due to home router firewall etc. Also the ip address used in IFTTT shouldn't be a local ip like 192.168.* but your public ip address. You can figure this out by googling for "whats my ip".

    Best way to test your setup using your laptop is to disconnect from local wifi network, tether your phone to your laptop and try visiting the NAS ip url to see if it still works. You can use chrome postman app to send out POST requests.

    If that's all fine, get PHP to log incoming connections by writing to a file. file_put_contents("log.txt", print_r($_REQUESTS, true));

    I would suggest trying with a GET request first with default content type. Good luck!