I might have to make this my first windows phone app.
does the API handle the cloud and direct login?
.net I hope?
documentation would be cool.
- 124 Views
- Last Post 19 February 2013
I might have to make this my first windows phone app.
does the API handle the cloud and direct login?
.net I hope?
You'll only really have access to the direct connect option. You could start here with the API to get an idea of what you need to post in your http calls then move to the rest of the members to see what all you can do.
in an effort to learn powershell i discovered that PS supports invoking web service methods, which i thought would be cool to quickly script the test of my devices as i add them in to the house from my surface without UI yet. but ramp up on learning json too i'm blocked on formatting for methods that did not have sample code like getscenes.
I wanted to run a method that'll allow me to list out devices and their id guids, so that I can start playing with the Set* methods.
PS C:\Users\user1> $url = "http://remotehost:1178/zwave/devices/getscenes?password=xxx000xxx"
__________________________
PS C:\Users\user1> $a = [System.Net.WebRequest]::Create($url)
__________________________
PS C:\Users\user1> $a.Method ="POST"
___________________________
PS C:\Users\user1> $a.GetResponse()
my $Url is wrong - any suggestions?
in an effort to learn powershell i discovered that PS supports invoking web service methods, which i thought would be cool to quickly script the test of my devices as i add them in to the house from my surface without UI yet. but ramp up on learning json too i'm blocked on formatting for methods that did not have sample code like getscenes.
I wanted to run a method that'll allow me to list out devices and their id guids, so that I can start playing with the Set* methods.
PS C:\Users\user1> $url = "http://remotehost:1178/zwave/devices/getscenes?password=xxx000xxx"
__________________________
PS C:\Users\user1> $a = [System.Net.WebRequest]::Create($url)
__________________________
PS C:\Users\user1> $a.Method ="POST"
___________________________
PS C:\Users\user1> $a.GetResponse()
my $Url is wrong - any suggestions?
I've never used power shell myself, so I'm not sure on the exact format. Your method needs to be "PUT" and you need to be able to specify a "Content-Type" header of "application/json" and any body you send with parameters needs to be JSON formatted.
Perhaps this example of using CURL would help too.
which one would {password : xxxx} go into? you mentioned body, but I'm wondering if header or creds are right? in cURL i see they use a -d with the json format stuff, but no indication of what field this info is shoved into. I did have to calc content length though.
AllowAutoRedirect : True
AllowWriteStreamBuffering : True
HaveResponse : False
KeepAlive : True
Pipelined : True
PreAuthenticate : False
UnsafeAuthenticatedConnectionSharing : False
SendChunked : False
AutomaticDecompression : None
MaximumResponseHeadersLength : 64
ClientCertificates : {}
CookieContainer :
RequestUri : http://192.168.0.xxx:1178/zwave/getscenes
ContentLength : 23
Timeout : 100000
ReadWriteTimeout : 300000
Address : http://192.168.0.xxx:1178/zwave/getscenes
ContinueDelegate :
ServicePoint : System.Net.ServicePoint
MaximumAutomaticRedirections : 50
Method : PUT
Credentials : System.Net.NetworkCredential
UseDefaultCredentials : False
ConnectionGroupName :
Headers : {Content-Type}
Proxy : System.Net.WebRequest+WebProxyWrapper
ProtocolVersion : 1.1
ContentType : application/json
MediaType :
TransferEncoding :
Connection :
Accept :
Referer :
UserAgent :
Expect :
IfModifiedSince : 2/16/2013 10:50:38 PM
CachePolicy : Level:BypassCache
AuthenticationLevel : MutualAuthRequested
ImpersonationLevel : Delegation
As we add newer commands it'll be moving to the header; but for now it's in the body.
k I think it wasn't working properly due to the system.net.webrequest - there didn't seem to be a way to add in a body at all (wasn't clear to me anyhow - an excercise left for someone else with PS knowledge)
However I found that invoke-webrequest does indeed support body right up front.
Very simple to use. Building the json object was a trick - but neat
$jsonobject = [ordered]@{}
$jsonobject.password = "xxx"
$pw = $jsonobject | convertto-json
invoke-webrequest -method "PUT" -body $pw -contenttype "application/json;charset=utf-8" -uri "http://192.168.0.xxx:1178/zwave/getscenes"
Simple to add more parameters into the
$jsonobject = [ordered]@{}
$jsonobject.password = "xxx"
$jsonobject.sceneid = "xxxxxxxx-xxxx-aaaa-aaaa-rrrrpppzzzz"
$scene = $jsonobject | convertto-json
invoke-webrequest -method "PUT" -body $scene -contenttype "application/json;charset=utf-8" -uri "http://192.168.0.xxx:1178/zwave/getscenedevices"
So as a quick test - I can create a shortcut on my surface RT for powershell and point to the script.ps1 above in the shortcut.
Shortcuts to EXE's can be pinned to the start menu or taskbar, shortcuts to just the scripts cannot.
My next step - hopefully tonight I'll turn on/off the lights from the start menu.