Jump to content

fsusr

New Members
  • Posts

    5
  • Joined

  • Last visited

fsusr's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello, I have a hub device (Wink hub) that I want to query for status. I have no experience with this, but PHP looks like a good tool to use. I'm a total newbie, and was hoping someone here can "whip up a script" for me. From a Raspberry Pi, I'm running a command that queries a Wink Hub (home automation hub) for the status of a device. I can run this command from the Raspberry Pi like this: curl "http://192.168.1.19/set_dev_value.php" -d "nodeId=a&attrId=aprontest -m1 -l;" The return for this command, which just gets spit out from the prompt is something like this: Gang ID: 0x7c2f22ed Manufacturer ID: 0x1131, Product Number: 0xa047 Device has 20 attributes... New IAS Zone ATTRIBUTE | DESCRIPTION | TYPE | MODE | GET | SET 61440 | ZCLVersion | UINT8 | R | 1 | 61441 | ApplicationVersion | UINT8 | R | 20 | 61442 | StackVersion | UINT8 | R | 51 | 61443 | HWVersion | UINT8 | R | 16 | 61444 | ManufacturerName | STRING | R | Sercomm Corp. | 61445 | ModelIdentifier | STRING | R | Tripper | 61446 | DateCode | STRING | R | 20140814 | 61447 | PowerSource | UINT8 | R | 3 | 127008 | BatteryVoltage | UINT8 | R | 29 | 127029 | BatteryAlarmMask | UINT8 | R/W | 15 | 127030 | BatteryVoltageMinThreshold | UINT8 | R/W | 25 | 127031 | BatteryVoltageThreshold1 | UINT8 | R/W | 25 | 127032 | BatteryVoltageThreshold2 | UINT8 | R/W | 25 | 127033 | BatteryVoltageThreshold3 | UINT8 | R/W | 26 | 83947520 | ZoneState | UINT8 | R | 0 | 83947521 | ZoneType | UINT16 | R | 21 | 83947522 | ZoneStatus | UINT16 | R | 49 | 83947536 | IasCieAddress | UINT64 | R | | 83947537 | ZoneID | UINT8 | R | 1 | 1699842 | ZB_CurrentFileVersion | UINT32 | R | | The "ZoneStatus" value is 49 for "opened" and 48 for "closed". I need to parse this for 48 or 49, and then I want to then use the php script, in a IF statement (depending on if it's opened or closed), to run a command like this: curl --header "Content-Type: text/plain" --request PUT --data "OFF" http://192.168.1.21:8080/rest/items/MyLight/state I'm super new to this and hoping someone can just "do it for me". I know I know, not going about it the "teach me to fish" way
  2. Oh, thanks. I don't have any experience debugging this. Your tips are helpful. Will try and report back.
  3. Opps, sorry I wasn't clear. I meant the first "if" statement where it looks to see "if(!$f)" results in the "error" text, so $f returned false when ran. I'm still pretty new to this, if there is somewhere else to look for more verbose error messages, please let me know. I'm fairly certain the IP address I use is valid because I can paste in the same IP address and port on the browser and get to the stream. I'm doing the test on LAN.
  4. Hello, I have a webcam on a computer running Motion, a webcam streaming program popular in Linux. Motion basically outputs a mjpeg stream. I'd like to use PHP to grab a single jpeg from the mjpeg stream and display it. The reason I'm doing this is because Motion doesn't have any built in password protection. With PHP, I can hide the port and IP address of my home server. I'm trying code provided by the creators of Motion on their website. The code is suppose to grab just a single jpeg from the mjpeg stream, but I get an error when trying to run it on an nginx server locally. <? $camurl="http://127.0.0.1:8080/"; $boundary="\n--"; $f = fopen($camurl,"r") ; if(!$f) { //**** cannot open echo "error"; } else { //**** URL OK while (substr_count($r,"Content-Length") != 2) $r.=fread($f,512); $start = strpos($r,'ΓΏ'); $end = strpos($r,$boundary,$start)-1; $frame = substr("$r",$start,$end - $start); header("Content-type: image/jpeg"); echo $frame; } fclose($f); ?> For reference, this is where I got the code from: http://www.lavrsen.dk/foswiki/bin/view/Motion/MjpegFrameGrabPHP Maybe someone could help me out? I have very little understanding of PHP, and don't understand why the fopen command is returning a fault. In case you're wondering, I've also tried this code snippet. It works, but it's grabbing an entire mjpeg stream. When ran locally on my lan, it works, but when I try the code on a shared host, the shared host computer seems to be trying to download the entire mjpeg stream, which would never complete of course. That's why I'm trying to find code that grabs just a single jpeg instead of streaming the mjpeg. set_time_limit(0); $fp = fsockopen ("xxxx.dyndns.org", 20804, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br>\n"; } else { fputs ($fp, "GET / HTTP/1.0\r\n\r\n"); while ($str = trim(fgets($fp, 4096))) header($str); fpassthru($fp); fclose($fp); }
  5. Hello, I have a webcam on my home LAN that can be accessed on the net. The router port forwards the port XXX to the port number for the webcam's mjpeg stream. The webcam doesn't have any password protection features, so I just pick a really difficult to guess port number . I also have a shared host account. I'd like to use PHP to display the webcam (either as a single image or mjpeg stream). This way, I'm hiding the IP address and port number of the my home webcam, and I can wrap the whole thing around a simple password prompt, and all the sensitive info would be on the server side. I played with PHP on a home PC with nginx installed, and found this code works. But when I use the same PHP code on my shared host, it doesn't. The share host seems to be going to my home network and try to download the mjpeg stream (which would never complete) instead of stream it back to me real time. That is my guess on what's happening anyways. On the browser, all I see is the "waiting for host..." message. So, I might switch strategies and instead of streaming the mjpeg stream, I would like a way to just grab a single frame of the mjpeg stream. But I don't have a clue on how to do this. Here's the code I've been using to grab the entire stream. It works locally, but not when the code is on the shared host. Locally, I just change the dynamic dns address to the IP of the webcam, and the port number to the internal port number of the webcam stream. Also, I copied this code from another site, and have very little understanding of what the code is actually doing. set_time_limit(0); $fp = fsockopen ("xxxx.dyndns.org", 20804, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br>\n"; } else { fputs ($fp, "GET / HTTP/1.0\r\n\r\n"); while ($str = trim(fgets($fp, 4096))) header($str); fpassthru($fp); fclose($fp); } Thanks for any help.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.