-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot setOn with POST #21
Comments
Can you try this?
"setOn": {
"url" : "http://10.54.236.84/power",
"httpMethod" : "POST",
"body" : "{\"value\":${value==true?1:0}}"
}
…On Mon, 27 Apr 2020 at 21:50, skytoastar ***@***.***> wrote:
I have a "light bulb" I'm hoping to control through Homebridge. It's an
ESP8266 running a basic web server to control a light strip. It's running
code found in this project
<https://github.com/jasoncoon/esp8266-fastled-webserver>. It exposes URLs
to POST data to to be able to control it.
I can control it from the ESP8266's built-in web app. I can even control
it from this basic python script running on my computer:
import requests
url = "http://10.54.236.84/power"
data = {'value':1} # 1:on, 0:off
r = requests.post(url = url, data = data)
For the life of me I can't seem to find the right mapping value to get it
to work from this plugin. I stepped through the python code to see the body
of the request is 'value=1'. I've tried the following:
"setOn": {
"url" : "http://10.54.236.84/power",
"httpMethod" : "POST",
"body" : "{value}",
"mappers": [{
"type": "static",
"parameters": {
"mapping": {
"true": {"value":"1"},
"false": {"value":"0"}
}
}
}]
}
"setOn": {
"url" : "http://10.54.236.84/power",
"httpMethod" : "POST",
"body" : "{value}",
"mappers": [{
"type": "static",
"parameters": {
"mapping": {
"true": "1",
"false": "0"
}
}
}]
}
"setOn": {
"url" : "http://10.54.236.84/power",
"httpMethod" : "POST",
"body" : "{value}",
"mappers": [{
"type": "static",
"parameters": {
"mapping": {
"true": "value=1",
"false": "value=0"
}
}
}]
}
I added some debugging prints to index.js to know that the mapping is
actually working and adding the mapped value to body before calling
httpRequest.
But none successfully turn the light on. Also unusual is that when the
light actually is on, whatever mapping value I send to turn it off will
turn it off. I just can't turn it on.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#21>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABBP2MLHCIY23L3OOQDM5ADROXOZLANCNFSM4MSGY2GQ>
.
|
Sorry, value is already 0 or 1.
So this should work for you:
"setOn": {
"url" : "http://10.54.236.84/power",
"httpMethod" : "POST",
"body" : "{\"value\":{value}}"
}
…On Tue, 28 Apr 2020 at 14:38, Guido Moscarella ***@***.***> wrote:
Can you try this?
"setOn": {
"url" : "http://10.54.236.84/power",
"httpMethod" : "POST",
"body" : "{\"value\":${value==true?1:0}}"
}
On Mon, 27 Apr 2020 at 21:50, skytoastar ***@***.***> wrote:
> I have a "light bulb" I'm hoping to control through Homebridge. It's an
> ESP8266 running a basic web server to control a light strip. It's running
> code found in this project
> <https://github.com/jasoncoon/esp8266-fastled-webserver>. It exposes
> URLs to POST data to to be able to control it.
>
> I can control it from the ESP8266's built-in web app. I can even control
> it from this basic python script running on my computer:
>
> import requests
> url = "http://10.54.236.84/power"
> data = {'value':1} # 1:on, 0:off
> r = requests.post(url = url, data = data)
>
> For the life of me I can't seem to find the right mapping value to get it
> to work from this plugin. I stepped through the python code to see the body
> of the request is 'value=1'. I've tried the following:
>
> "setOn": {
> "url" : "http://10.54.236.84/power",
> "httpMethod" : "POST",
> "body" : "{value}",
> "mappers": [{
> "type": "static",
> "parameters": {
> "mapping": {
> "true": {"value":"1"},
> "false": {"value":"0"}
> }
> }
> }]
> }
>
> "setOn": {
> "url" : "http://10.54.236.84/power",
> "httpMethod" : "POST",
> "body" : "{value}",
> "mappers": [{
> "type": "static",
> "parameters": {
> "mapping": {
> "true": "1",
> "false": "0"
> }
> }
> }]
> }
>
> "setOn": {
> "url" : "http://10.54.236.84/power",
> "httpMethod" : "POST",
> "body" : "{value}",
> "mappers": [{
> "type": "static",
> "parameters": {
> "mapping": {
> "true": "value=1",
> "false": "value=0"
> }
> }
> }]
> }
>
> I added some debugging prints to index.js to know that the mapping is
> actually working and adding the mapped value to body before calling
> httpRequest.
>
> But none successfully turn the light on. Also unusual is that when the
> light actually is on, whatever mapping value I send to turn it off will
> turn it off. I just can't turn it on.
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <#21>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ABBP2MLHCIY23L3OOQDM5ADROXOZLANCNFSM4MSGY2GQ>
> .
>
|
Neither of the above worked. So I decided to compare payloads using Wireshark and I found that I could correctly construct the 7-byte payload using Python or this plugin. Those seven bytes are 'value=1'. But only in the python case did it turn the light on. The python-sent payload was specifying the payload as a form of type So I hacked this into the index.js file of this plugin to make request send the data as form data:
Then I used the following for "setOn" in the config file:
And it worked! That being said, my code probably isn't the right way to specify form key/val pairs in the config file given my hard-coded key. |
@skytoastar I had a similar issue using non-form POST, as outlined here with PHP as an example:
which would explain your success with your "form" code. I solved it by the above technique (reading the received POST raw and decoding manually) that works with non-form POST (I am able to as I am author of the code that gets and processes the received POST). |
I have a "light bulb" I'm hoping to control through Homebridge. It's an ESP8266 running a basic web server to control a light strip. It's running code found in this project. It exposes URLs to POST data to to be able to control it.
I can control it from the ESP8266's built-in web app. I can even control it from this basic python script running on my computer:
For the life of me I can't seem to find the right mapping value to get it to work from this plugin. I stepped through the python code to see the body of the request is 'value=1'. I've tried the following:
I added some debugging prints to index.js to know that the mapping is actually working and adding the mapped value to body before calling httpRequest.
But none successfully turn the light on. Also unusual is that when the light actually is on, whatever mapping value I send to turn it off will turn it off. I just can't turn it on.
The text was updated successfully, but these errors were encountered: