rudders / homebridge-http

HTTP Plugin for Homebridge
Apache License 2.0
178 stars 110 forks source link

Possible to read multiple status stored in .xml file? #75

Open githubberboy opened 6 years ago

githubberboy commented 6 years ago

I've a status.xml file that contain multiple status values, like this:

<response>
<natOut1>1</natOut1>`
<natOut2>0</natOut2>
<natOut3>1</natOut3>
<natOut4>1</natOut4>
<natIn1>1</natIn1>
<natIn2>0</natIn2>
<natIn3>1</natIn3>
<natIn4>0</natIn4>
</response>

It is possible to read the 1|0 inside <natOut> <natIn> ?

Thanks.

arlettazm commented 6 years ago

I i have the same request? any solution? Thanks

troystanway commented 6 years ago

I've had a similar need trying to read status from my OpenSprinkler. The best way I could think up was to use a PHP script to read the values. If the output is always the same, except for the 1/0 variables you could use substr to interpret the values.

It outputs like this {"sn":[0,0,0,0,0,0,0,0],"nstations":8}

Then this script looks for the 8th character, length 1. And returns that value when you go to this php file on your web server:

<?php $ctx=stream_context_create(array('http'=> array( 'timeout' => 1 // 1 sec ) )); $url = file_get_contents('<URL HERE>', false, $ctx); $output = substr(".$url.", 8, 1); echo $output; ?>

I know this solution requires lots of counting, but as long as the output doesn't change its structure this does work. You would need 1 PHP script per http device, 1 status per device. And you would need to alter the value 8 to which ever position value you are looking for, count it out and then put in that number. But its just a suggestion