Jump to content

PHP newbie - how to run a command, parse the output


fsusr

Recommended Posts

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 months later...
  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.