Veralite AlternateEventServer

Hi, I’m a real newbie with this stuff and gave up coding for a living many years ago (although I love to dabble) so this might turn out to be really obvious to someone more experienced… After reviewing the post http://forum.micasaverde.com/index.php?topic=15245.0 and attempting to get it working with both web service and PHP on my QNAP NAS, I discovered that the document was specific to a version U15 and I’m running U17 on VeraLite. I also found that the SSL certificate on the QNAP was not recognised. Rather than dig any further into problems with my specific hardware, I decided to set up a fresh web server on Azure, stick some code in to just accept a POST and log that a request had come through. Simple, I thought. Did all that and pointed the VeraLite at this new server as a AlternateEventServer. The log however is giving me the following error very often (every time it is trying to log activity is my guess):

01 12/13/15 14:06:54.268 FileUtils::ReadURL 0/resp:405 user: pass: size 102 https://myserver.azurewebsites.net/event/event/event response: The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used. <0x2bde0680>
01 12/13/15 14:06:54.271 RAServerSync::SendAlert 0x11b6bf0 retries 35 failed https://myserver.azurewebsites.net/event/event/event age: 29552 file: /etc/cmh/persist/a_1449894990_1449939262_11b6bf0 err: 0 sess: serv: myserver.azurewebsites.net/ <0x2bde0680>

The code is really straight forward so not really sure why the server should be having such difficulty. Any help greatly appreciated.

Code resides in an a file named index.php which lies under the web server root at \event\event\event as documented at http://wiki.micasaverde.com/index.php/AlternateEventServer. File contains:

<html>
<head>
</head>
<body>
<?php

header_remove();
header("Content-Type: ");
header("HTTP/1.1 200 OK");
header("Content-Length: 35");

print "{<br>    \"PK_Event\": 1234,<br>    \"Key\": \"1234\"<br>}";

$myfile = fopen("logfile.txt","a");
$txt = "Record Start\n";
fwrite ($myfile,$txt);


/* The following command is EXTREMELY INSECURE!!!
**
** Never, and I mean, NEVER, make this php script accessible to the
** outside world
**
** This is just a convenient way to get all vars passed in
*/

/*extract($_POST);
foreach ($_POST as $key => $value){
  fwrite ($myfile, "{$key} = {$value}\r\n");
}*/

fclose ($myfile);

?>
</body>
</html>

My final intention is get all log event data forwarded on and I’ll extract and place in a MySQL database alongside other automation data and then I’ll front end that with mobile and other apps and analysis. I never thought it would this hard to just get the log data out! Any help very much appreciated.

Stephen

I’ve spent some more time on this but I’m still struggling (know more about php though!). I’ve changed the code to just generate the response, then log the json that was sent into a logfile. Tried to run this on azure but I started getting server errors (5xx) with no idea why. Took it back to the QNAP and installed SSL cert so I’m able to access the device using https cleanly (tested using the admin pages). Stopped 443 on admin and transferred it across to the Qnap web site. Dropped a ‘hello world’ script in and was able to go into the site using https with no problems. created event/event/event and dropped the new index.php in there to generate the plain text response documented on AlternateEventServer wiki page and repointed the Vera to access this site. When I access manually usiing https, I get the response page expected and I also generate a line in the log file. When I restart Vera, the log shows it is getting to the right location but does not seem to be seeing the response or triggering the log. Is there anybody out there that has any idea what I might be missing? Code is below and I’ve attached what I see in the browser when accessing directly as well as what the vera log is showing. I’m not sure what else I can do to further diagnose.

<?php

header("Content-Type: text/html");
header("HTTP/1.1 200 OK");
header("Content-Length: 200");

/*header('Content-type: application/json');*/

$mandatory = "{<br> \"PK_Event\": 1234,<br> \"Key\": \"1234\"<br>}";
echo ($mandatory);

/*$data2=array('PK_Event' => 1234, 'Key' => '1234');
echo json_encode($data2);*/

$myfile = fopen("logfile.txt","a");
$txt = "Record Start".PHP_EOL;
fwrite ($myfile,$txt);

if (isset($_REQUEST['json'])) {
  $decoded = json_decode(stripslashes($_REQUEST['json']), TRUE);
  if (is_null($decoded)) {
    $response['status'] = array(
      'type' => 'error',
      'value' => 'Invalid JSON value found',
    );
    $response['request'] = $_REQUEST['json'];
  }
  else {
    $response['status'] = array(
      'type' => 'message',
      'value' => 'Valid JSON value found',
    );
    //Send the original message back.
    $response['request'] = $decoded;
  }
}
else {
  $response['status'] = array(
    'type' => 'error',
    'value' => 'No JSON value set',
  );
}

$encoded = json_encode($response);
/*fwrite ($myfile, $data2.PHP_EOL);*/
fwrite ($myfile, $encoded.PHP_EOL);
fclose ($myfile);

//header('Content-type: application/json');
exit();


/*extract($_POST);
foreach ($_POST as $key => $value){
  fwrite ($myfile, "{$key} = {$value}\r\n");
}*/


?>

I know you haven’t posted on this message in quite some time, but I was wondering if you ever solved this problem. I also can’t figure out what VERA is expecting back from my web server. I do text/plain for the content type and send the PK_Event and Key seemly correct and can’t get the error messages to go away and keep receiving the same events in the logs.
Anyone else out there solve this problem.

Thanks.