Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get Device Info #16

Open
zaxxon72 opened this issue Jun 18, 2020 · 0 comments
Open

get Device Info #16

zaxxon72 opened this issue Jun 18, 2020 · 0 comments

Comments

@zaxxon72
Copy link

zaxxon72 commented Jun 18, 2020

not an issue, but I never submitted any code, so I'm trying this route... staying under the radar ;)

My use case: I set/unset locking status in automatically at 01:00 and 05:00 so the cat doesn't play catch-and-crunch with mice during the night under our bed.... and when I manually set the flap to 'out' because of [some reason], the script at 01:00 would override that with 'in' so the cat got out again. So I needed my script to check the locking status before setting, to include the status from before...

I thus frankensteined setLockMode.php and some stuff I gleaned from rcastberg/sure_petcare so I could read the locking status of my flap. The status includes some more data, so I tried some other stuff. This needs more interpretation and reality-alignment, but comes in handy.

What do you think. is this usable?

<?php

include_once 'getDevices.php';

$json = json_encode(array("locking" => "$lock"));
$ch = curl_init($endpoint."/api/device/$flap/status");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $token"));
$result = json_decode(curl_exec($ch),true) or die("Curl Failed\n");

/* Output of status page, can be used to extend this script
Array
(
    [data] => Array
        (
            [locking] => Array
                (
                    [mode] => 1
                )

            [version] => Array
                (
                    [device] => Array
                        (
                            [hardware] => 0
                            [firmware] => 335
                        )

                )

            [battery] => 5.25
            [learn_mode] => 
            [online] => 1
            [signal] => Array
                (
                    [device_rssi] => -87.25
                    [hub_rssi] => -85
                )

        )

)
*/


switch($argv[1]) {
	case "locking":
        switch($result['data']['locking']['mode']) {
                case "2":
                        $lock = "in";
                        break;
                case "1":
                        $lock = "out";
                        break;
                case "3":
                        $lock = "both";
                        break;
                case "0":
                        $lock = "none";
                        break;
        }
        print "Device locking status: ".$lock."\n";
		break;
	case "battery":
		$b_volts=$result['data']['battery'];
        print "Device battery status: ".$b_volts." Volts\n";		
		break;
	case "signal":
		$rssi=$result['data']['signal']['hub_rssi'];
        print "Hub RSSI: ".$rssi." dB\n";		
		break;
	case "version":
		$firm_version=$result['data']['version']['device']['firmware'];
        print "Device Firmware Version: ".$firm_version." dB\n";		
		break;
	default:
		die("Usage: php ".$_SERVER['PHP_SELF']." [locking|battery|signal|version]\n");
}


?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant