Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome General
 PowerHome Messageboard : PowerHome General
Subject Topic: Bond Bridge control via PH Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
Jerrem
Newbie
Newbie


Joined: December 23 2008
Location: United States
Online Status: Offline
Posts: 16
Posted: March 09 2023 at 09:50 | IP Logged Quote Jerrem

I am attempting to utilize the 'Bond Bridge' through
PowerHome to control RF 315MHz/433MHz ceiling fans and
shades. Going through the Bond API (http://docs-
local.appbond.com/) I have been able to utilize cURL
commands to read status and control devices.   I am now
in the process of moving the cURL commands into
PowerHome.

Reading through the Message Board, I found how to read
device status from the Bond Bridge using the ph_geturl1
command.
     cURL command to read device state:
           curl -H "BOND-Token: BOND-TOKEN-VALUE" -
i http://BOND-BRIDGE-IPADR/v2/devices//DEV-ID/state
          
     Equivalent PowerHome command:
           ph_geturl1("http://BOND-BRIDGE-
IPADR/v2/devices/DEV-ID/state","BOND-Token: BOND-TOKEN-
VALUE",5,5000)

Where I am stuck is implementing in PH the cURL "PUT"
option required to set the state of a device.
     cURL command to set fan speed to 3:
           curl -H "BOND-Token: BOND-TOKEN-VALUE"
-i http://BOND-BRIDGE-IPADR/devices/DEV-
ID/actions/SetSpeed -X PUT -d '{"argument": 3}'

I have seen references to implementing cURL command via
the ph_run1 command. Is that the preferred way? Or is
there a ph function that exists to directly handle the
PUT command via PowerHome?

All advice/help appreciated
Back to Top View Jerrem's Profile Search for other posts by Jerrem
 
gg102
Senior Member
Senior Member


Joined: January 29 2013
Location: United States
Online Status: Offline
Posts: 245
Posted: March 09 2023 at 10:03 | IP Logged Quote gg102

Hi,

I'm not familiar with your specific devices or commands, but have you investigated:

ph_posturl1 ( as_url, as_postdata, ai_type, al_timeout )

Back to Top View gg102's Profile Search for other posts by gg102
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: March 10 2023 at 21:37 | IP Logged Quote dhoward

Jerrem,

The ph_posturl1 function should do what you need. Based upon your cURL command, I believe the below will probably work but you may need to
check the ph_posturl1 help and try some of the other ai_type values (the example below is using 5).

ph_posturl1("http://BOND-BRIDGE-IPADR/devices/DEV-ID/actions /SetSpeed","BOND-Token: BOND-TOKEN-VALUE",'{"argument": 3}',5,2000)

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
Jerrem
Newbie
Newbie


Joined: December 23 2008
Location: United States
Online Status: Offline
Posts: 16
Posted: March 11 2023 at 08:50 | IP Logged Quote Jerrem

gg102 and Dave, thanks for your help!

The example Dave posted does seem to be the closest to
working. Unfortunately, executing the command with
ai_type 5 results in a 'method not allowed error' from
the Bond Bridge.   I have tried all 13 ai_types, which
result in various error messages.

I am currently searching through the Bond Bridge user
forum for clues. In the example provided in the Bond
Bridge documentation, they explicitly call out using the
'PUT' option on the cURL command, which does work.

Do any PowerHome command options utilize PUT instead of
post? I am wondering if the Bond code may explicitly
discern between PUT and POST and that is why it is
flagging the error - still researching...

As always any help or suggestions are greatly
appreciated.
Jerry
Back to Top View Jerrem's Profile Search for other posts by Jerrem
 
Jerrem
Newbie
Newbie


Joined: December 23 2008
Location: United States
Online Status: Offline
Posts: 16
Posted: March 11 2023 at 11:21 | IP Logged Quote Jerrem

Just an update - Using just Windows powershell, tried
replacing the

curl .. -X PUT...   

option in the known working cURL command with

curl .. -X POST...

This resulted in the same error message 'method not
allowed error" being returned, as when I try to execute
the ph_posturl1 command.
Back to Top View Jerrem's Profile Search for other posts by Jerrem
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: March 15 2023 at 16:01 | IP Logged Quote dhoward

Jerrem,

Try using the ph_httprequest() function. This function allows you to use other HTTP methods (such as PUT) instead of just the standard GET
and POST methods.

The function may need to be updated to make use of all the extra control types that I currently have in the ph_geturl1 and ph_posturl1
functions but it looks like alot of them are there.

I'll make a note to check on this.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
Jerrem
Newbie
Newbie


Joined: December 23 2008
Location: United States
Online Status: Offline
Posts: 16
Posted: March 15 2023 at 21:00 | IP Logged Quote Jerrem

Dave:

The ph_httprequest command works nicely!

An example powerhome command to turn the light on a ceiling
fan to ON:
ph_httprequest("http://BOND-BRIDGE-IPADR/v2/devices/DEV-
ID/actions/TurnLightOn","BOND-Token: BOND-TOKEN-
VALUE","PUT",'{"argument":1}',5,5000,1)

Thank you
Jerry
Back to Top View Jerrem's Profile Search for other posts by Jerrem
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: March 15 2023 at 22:01 | IP Logged Quote dhoward

Jerry,

Very happy to hear that function worked out for you.

Thanks for getting back to me.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum