Having trouble obtaining token from api/v1/new method

Started by autumn__rain__529

autumn__rain__529

I am trying to use the open API to control my Light Panels (yes, the original panels)
As I understand it, the first step is to obtain a token using the api/v1/new method.

  1. Per the documentation, I held the power button down on the controller for 5-7 seconds until the LED on the controller started flashing
  2. Within 3 seconds, I issued the curl command from my Windows command shell (curl -X POST http://192.168.1.56/api/v1/new)
  3. I received the following response:
    C:\Users\c_m_m>curl -X POST http://192.168.1.56/api/v1/new
    curl: (7) Failed to connect to 192.168.1.56 port 80 after 2063 ms: Couldn't connect to server

I verified the IP address by looking at the MAC address in the app for that controller and matching that up to the DHCP reservation in my router. I pinged that address successfully.
I tried the above twice with no success.
Any suggestions?

autumn__rain__529

Hopefully you don't mind me asking a follow up question:
Now that I have the token, I am trying to use the API to turn on the light panels. Here's the curl command I'm using (below). What is wrong with my syntax that is causing it to think it is an "Unprocessable Entity"?
C:\Users\c_m_m>curl -X PUT -d "{on : {value:true}}" http://192.168.1.56:16021/api/v1/FEq9X15ep4rfozIoTjhTT54rUNaaK6d5/state/on -v

  • Trying 192.168.1.56:16021…
  • Connected to 192.168.1.56 (192.168.1.56) port 16021

    PUT /api/v1/FEq9X15ep4rfozIoTjhTT54rUNaaK6d5/state/on HTTP/1.1
    Host: 192.168.1.56:16021
    User-Agent: curl/8.4.0
    Accept: /
    Content-Length: 19

    < HTTP/1.1 422 Unprocessable Entity
    < Content-Length: 0
    <

  • Connection #0 to host 192.168.1.56 left intact

autumn__rain__529

There was a line missing in my previous post in the output from the curl command. This line appeared immediately after the content length line. For some reason, the page won't let me enter it as is without getting the error "Containing links are not whitelisted". I put spaces between each letter in order to submit it.

C o n t e n t - T y p e : a p p l i c a t i o n / x - w w w - f o r m - u r l e n c o d e d
Thanks.

autumn__rain__529

@"Aliakbar Eski"

I made a little progress on this, but am still stuck. Any coaching is appreciated.
C:\Users\c_m_m>curl -X PUT "http://192.168.1.56:16021/api/v1/FEq9X15ep4rfozIoTjhTT54rUNaaK6d5/state" -H "Content-Type: application/json" -d "{"on": {"value": true } }" -v

  • Trying 192.168.1.56:16021…
  • Connected to 192.168.1.56 (192.168.1.56) port 16021

    PUT /api/v1/FEq9X15ep4rfozIoTjhTT54rUNaaK6d5/state HTTP/1.1
    Host: 192.168.1.56:16021
    User-Agent: curl/8.4.0
    Accept: /
    C o n t e n t - T y p e : a p p l i c a t i o n / j s o n
    Content-Length: 25

    < HTTP/1.1 204 No Content
    < Content-Length: 0
    <

  • Connection #0 to host 192.168.1.56 left intact

Note: I had to add spaces to the content type line so this page would accept it.

Aliakbar Eski

Hey @autumn__rain__529

The curl command would look like this:
curl -vvv -X PUT <ip>:16021/api/v1/<auth>/state -d '{"on":{"value":true}}'

Notes:

  1. I did not need to explicitly add a Content-Type header. This is actually not required. The controller does not process it, since it doesn't accept anything other than JSON. Whatever curl adds as default is fine, since the controller will ignore it.
  2. I enclosed my data in single quotes ' ' instead of double quotes " "

For instance:

curl -vvv  -X PUT 192.168.86.34:16021/api/v1/a7URUM9St0pIAQP2zwxuBM4gGu09HKhh/state -d '{"on":{"value":true}}'
*   Trying 192.168.86.34...
* TCP_NODELAY set
* Connected to 192.168.86.34 (192.168.86.34) port 16021 (#0)
> PUT /api/v1/a7URUM9St0pIAQP2zwxuBM4gGu09HKhh/state HTTP/1.1
> Host: 192.168.86.34:16021
> User-Agent: curl/7.64.1
> Accept: */*
> Content-Length: 21
> Content-Type: application/ x - www - form- url encoded
>
* upload completely sent off: 21 out of 21 bytes
< HTTP/1.1 204 No Content
< Content-Length: 0
<
* Connection #0 to host 192.168.86.34 left intact
* Closing connection 0

Hope this helps
Regards
Aliakbar Eski

Aliakbar Eski

your last post gave you back a 204 No Content, which is equivalent to a success. your panels should have turned on, if they were off.

autumn__rain__529

@"Aliakbar Eski" Thank you. It is working now.

That said, I am having trouble getting the token from the 2nd light panel controller now (see below). I thought I used the exact same command line string as before (with a different IP), but I'm getting this error:

-C:\Users\c_m_m>curl -X POST http://192.168.1.55:16021/api/v1/new -v
-* Trying 192.168.1.55:16021…
-* Connected to 192.168.1.55 (192.168.1.55) port 16021
-> POST /api/v1/new HTTP/1.1
-> Host: 192.168.1.55:16021
-> User-Agent: curl/8.4.0
-> Accept: * / *
->
-< HTTP/1.1 403 Forbidden
-< Content-Length: 0
-<
-* Connection #0 to host 192.168.1.55 left intact

Note: I added an hyphen to the beginning of each line so the text would appear correctly on the page.

What do you suggest?

Aliakbar Eski

You need to hold down the power button on the controller for 5s which opens up a 30s pairing window. Within those 30s you need to send the above curl command.

Regards
Aliakbar Eski

autumn__rain__529

Thank you. That was the issue. My computer is downstairs and the light panels are in a room upstairs. I thought I was getting back to the computer fast enough. But evidently I was not. So, I queued up the curl command in the shell and took my wireless keyboard with me upstairs and pressed "enter" after putting the controller into pairing mode. That did the trick.

Aliakbar Eski

haha, been there, done that.
Glad we got you unblocked on that.

Have fun over the weekend!

Regards