TobKra96 / music_led_strip_control

Audio visualization for LED strips in real-time with web interface on a raspberry pi.
https://tobkra96.github.io/music_led_strip_control/
MIT License
298 stars 64 forks source link

API with python #65

Closed GithubuserLED closed 3 years ago

GithubuserLED commented 3 years ago

I would like to be able to control the rest API via Python. So i thought i can use the 'requests' and the 'json' libary. Then I wrote a tiny Python script including this:

payload = {'effect' : 'effect_off'} r = requests.get("http://pi-ip-adress/SetActiveEffectForAll", json=payload)

When I am running the script from the MLSC returns:

"GET /SetActiveEffectForAll HTTP/1.1" 405 -

But the light is not changing, so i think the request must be wrong.

what do I have to change so the payload is right?

TobKra96 commented 3 years ago

Hi,

you have to send a post, not a get:

import requests

payload = {'effect' : 'effect_single'}
r = requests.post("http://<IP>:8080/SetActiveEffectForAll", json=payload)

For me, this code works. Let me know if you have problems with it. Have a great day!