Android Question IoT problem

billmoultrie

Member
Licensed User
Longtime User
I am working with the Particle device and want to drive it using hptutils2.
The html required is as follows..

<!DOCTYPE>
<html>
<body>
<center>
<form action="https://api.particle.io/v1/devices/...oken=bec1daef10297164128006b00xxxxd8cf1bdee2b" method="POST">
Tell your device what to do!<br>
<br>
<input type="radio" name="args" value="on">Turn the LED on.
<br>
<input type="radio" name="args" value="off">Turn the LED off.
<br>
<input type="submit" value="Do it!">
</form>
</center>
</body>
</html>

I have tested the html version and it works.

I am doing the following.

B4X:
Sub Button1_click


    HTTP = "https://api.particle.io/v1/devices/3B002B000Axxxxxx38383138/toggle?access_token=bec1daef10297164128006b00xxxxd8cf1bdee2b"


    Log("LED On ")
    job1.Initialize("Job1", Me)

    Dim OnOff As String
    OnOff = "on"
    HTTP = HTTP & ",value=" & OnOff
   
    Log ("HTTP " & HTTP)
    job1.Download(HTTP)
   
End Sub

I am sending

https://api.particle.io/v1/devices/...daef10297164128006b00xxxxd8cf1bdee2b,value=on

I get back an error of "error": "invalid_token",
But the token is correct.
if I remove the ,value=on then I get no value provided.

It would appear I am not parsing the value correctly.
Can anyone help.
 

DonManfred

Expert
Licensed User
Longtime User
I think additional it should be args=ON (or OFF) instead of value=
 
Upvote 0

billmoultrie

Member
Licensed User
Longtime User
I think additional it should be args=ON (or OFF) instead of value=
Thank you gentlemen
The & is correct but I am still getting argument problems.
If I change the HTTP line to
HTTP = "https://api.particle.io/v1/devices/...oken=bec1daef10297164128006b00xxxxd8cf1bdee2b"
I have removed the toggle (which is important as it is the function name in the Particle module) then it does not give an error, the log shows


Jobdone
JobName = Job1, Success = true
Results...{
"id": "3b002b000axxxxxx38383138",
"name": "turkey_trochee",
"last_app": null,
"last_ip_address": "81.148.236.158",
"last_heard": "2016-07-28T16:28:42.593Z",
"product_id": 6,
"connected": true,
"platform_id": 6,
"cellular": false,
"status": "normal",
"variables": {},
"functions": [
"toggle"
]

The Particle manual shows how an API should be sent

The API request will look something like this:

POST /v1/devices/{DEVICE_ID}/toggle

# EXAMPLE REQUEST IN TERMINAL
# Core ID is 0123456789abcdef
# Your access token is 123412341234
curl https://api.particle.io/v1/devices/0123456789abcdef/toggle \
-d access_token=123412341234 \
-d params=on

Can that be used to show how to to do it?
 
Upvote 0
Top