Android Question How to use the methode PUT

appie21

Active Member
Licensed User
Longtime User
Hello

I try to command my philips Hue lights
To comminucate with them I need the PUT command

How can I do this!

I have
B4X:
Sub JobDone (Job As HttpJob)
  Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
  Dim aan As String
  Dim lampstatus As String = "true"
  aan = "{""on"": " & lampstatus & "}"
  If Job.Success = True Then
      ToastMessageShow(Job.GetString,True)
Job.PostString("http://192.168.1.5/api/newdeveloper/lights/2/state", aan )
  Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
  End If
  Job.Release

  End Sub
 
Sub Button1_Click
      job1.Initialize("Job1", Me)
  job1.Download("http://192.168.1.5/api/newdeveloper/lights/2/state")
'job1.Download("http://192.168.1.5/api/newdeveloper/lights/1")
 
End Sub

What do i worng

De put data wgat i try to sent is : {"on":true}
and the link is : http://192.168.1.5/api/newdeveloper/lights/2/state

How can I fix sthis
 

appie21

Active Member
Licensed User
Longtime User
Hi thanks Erel and eps

Did this mean that I must convert it first?
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.Exception: Sub submitjob signature does not match expected signature.

Must I change a data type? here are some documentation of the Hue lights
http://developers.meethue.com/9_datatypes.html

Can some one take a lookthere and tell me what i must add or change?
 
Upvote 0

appie21

Active Member
Licensed User
Longtime User
Hi what is a siganure?

I found in my visualbasic code (where my lamps work) the following?
winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")


is that a signature

i found also a header
winHttpReq.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")

how to handle in B4A?

Also many thanks for so far
 
Upvote 0

appie21

Active Member
Licensed User
Longtime User
I have add my project

but i get now these errrors

Is there someone who know this?

B4X:
JobName = Job3, Success = true


[vvv0=, vvv4=Job3, vvvv6=null


, vvv6=, vvv7=, vvvv1=class anywheresoftware.b4a.samples.httputils2.main
, vvvv2=http://192.168.1.41/api/newdeveloper/lights/2/state, vvvv3=5, vvvv4=anywheresoftware.b4a.http.HttpClientWrapper$HttpUriRequestWrapper@41f56ec0
, vvvv5=null, vvv5=true]
 

Attachments

  • api.zip
    9.5 KB · Views: 132
Upvote 0

appie21

Active Member
Licensed User
Longtime User
Aha

nice

Now I get more result

see:
B4X:
JobName = Job3, Success = true


[errormessage=, httputils2service=null, jobname=Job3


, main=null, mlink=http://192.168.1.41/api/newdeveloper/lights/1/state, password=
, req=anywheresoftware.b4a.http.HttpClientWrapper$HttpUriRequestWrapper@422695f8, username=, target=class anywheresoftware.b4a.samples.httputils2.main
, taskid=2, success=true] I am  here
Hi This look better But I do not need password and username how to remove?

Also my request what i try to sent is not visible? "{""on"": ""False""}"
 

Attachments

  • alight.zip
    9.4 KB · Views: 148
Upvote 0

appie21

Active Member
Licensed User
Longtime User
Wow I thinkI am close now!

I get back
B4X:
JobName = Job3, Success = true


[{"error":{"type":7,"address":"/lights/1/state/on","description":"invalid value, false, for parameter, on"}}]


[errormessage=, httputils2service=null, jobname=Job3
, main=null, mlink=http://192.168.1.41/api/newdeveloper/lights/1/state, password=
, req=anywheresoftware.b4a.http.HttpClientWrapper$HttpUriRequestWrapper@422ebb08, username=, target=class anywheresoftware.b4a.samples.httputils2.main
, taskid=2, success=true] I am  here

The philps hue documentation is here http://developers.meethue.com/gettingstarted.html
Can you help me again? What is the correct value?
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Wow I thinkI am close now!

I get back
B4X:
JobName = Job3, Success = true


[{"error":{"type":7,"address":"/lights/1/state/on","description":"invalid value, false, for parameter, on"}}]


[errormessage=, httputils2service=null, jobname=Job3
, main=null, mlink=http://192.168.1.41/api/newdeveloper/lights/1/state, password=
, req=anywheresoftware.b4a.http.HttpClientWrapper$HttpUriRequestWrapper@422ebb08, username=, target=class anywheresoftware.b4a.samples.httputils2.main
, taskid=2, success=true] I am  here

The philps hue documentation is here http://developers.meethue.com/gettingstarted.html
Can you help me again? What is the correct value?

From that page :
OnboolOn/Off state of the light. On=true, Off=false

So On or Off...

On : true

Off : false
 
Upvote 0

appie21

Active Member
Licensed User
Longtime User
Hithanks what do you mean by OnboolOn/Of

is it not that he sent on"}}] that the "symbols is add (that is wrong)
[{"error":{"type":7,"address":"/lights/1/state/on","description":"invalid value, false, for parameter, on"}}]
 
Last edited:
Upvote 0

eps

Expert
Licensed User
Longtime User
It seems to think that you sent false with on, whereas it expects on to be sent with true.. Maybe it's because you didn't send anything with it, so it defaults nothing to false..?

e.g. (from the page you linked to)

{
"hue": 50000,
"on": true,
"bri": 200
}
 
Upvote 0

eps

Expert
Licensed User
Longtime User
To be honest on:false or on:true seems logical, but they seem to want them doubled up, which seems a little odd, but guess it's the way they've laid out their interface.
 
Upvote 0
Top