roleoroleo / yi-hack-Allwinner-v2

Custom firmware for Yi 1080p camera based on Allwinner platform
MIT License
752 stars 90 forks source link

Device Error on RESTful API #891

Closed KayGundhardt closed 1 month ago

KayGundhardt commented 1 month ago

Hello everybody!

Tried to set up a RESTful command within HomeAssistant to turn the webcams recording feature on and off (see below). As these are my first baby steps into API commands any help or tips would be kindly appreciated - thank you! ❤️

This here is this repository’s link to its API documentation which tells me to change the configuration taking into account:

Set configuration

http://IP_CAM/cgi-bin/set_configs.sh?conf=CONF
CONF action
system Update system configuration
(…) (…)

Need POST method with a json file.

The relevant system setting and its payload within would be:

{
…,
"REC_WITHOUT_CLOUD":"yes",
…
}

And my RESTful service command from HA to the cam is:

rest_command:
  cam_eg_surveillance_on:
    url: "http://username:pass@0.0.0.0:8080/cgi-bin/set_configs.sh?conf=system"
    method: POST
    payload: "REC_WITHOUT_CLOUD=yes"
    content_type: 'application/json; charset=utf-8'
  cam_eg_surveillance_off:
    url: "http://username:pass@0.0.0.0:8080/cgi-bin/set_configs.sh?conf=system"
    method: POST
    content_type: 'application/json; charset=utf-8'
    payload: "REC_WITHOUT_CLOUD=no"

But when I call the service I get only

Error: Client error occurred when calling resource "http://username:pass@0.0.0.0:8080/cgi-bin/set_configs.sh?conf=system"
Result:
params:
  domain: rest_command
  service: cam_eg_surveillance_off
  service_data: {}
  target: {}
running_script: false

Any ideas ? :(

KayGundhardt commented 1 month ago

Actually found out that

https://github.com/roleoroleo/yi-hack-Allwinner-v2/blob/master/src/www/httpd/cgi-bin/set_configs.sh

does not include a manipulation of my desired keys value (REC_WITHOUT_CLOUD) although the

get_configs.sh

script lists this key. Is it possible to add the possibility to change this value into

set_configs.sh

Would be great! :)

roleoroleo commented 1 month ago

It should work using set_configs.sh Try with this content: {"REC_WITHOUT_CLOUD":"yes"}

To test it, try a browser extension like this one: immagine

KayGundhardt commented 1 month ago

THANK YOU @roleoroleo ❤️

Solution is coming now: :partying_face:

Correct syntax must be like this:

rest_command:
  cam_eg_surveillance_on:
    url: "http://0.0.0.0/cgi-bin/set_configs.sh?conf=system"
    username: “username“
    password: “password“
    method: POST
    payload: ‘{"REC_WITHOUT_CLOUD“:“yes"}‘
    content_type: 'application/json; charset=utf-8'
  cam_eg_surveillance_off:
    url: "http://0.0.0.0/cgi-bin/set_configs.sh?conf=system"
    username: “username“
    password: “password“
    method: POST
    content_type: 'application/json; charset=utf-8'
    payload: ‘{"REC_WITHOUT_CLOUD“:“no"}‘

As you can see I pulled out the username and pass from the url and especially changed payload formatting!

Working like a charm now!