System of WS2812B leds controled by Raspberry Pico W using API server hosted on the Pico device.
Languages:
- MicroPython
Leds library:
- blaz-r pi_pico_neopixel
You can download the master branch with code.
- Rename
config_template.json
toconfig.json
and fill all the data- endpointUrl points to the endpoint where Pico W will sync his IP address. Comment if not needed. My that kind of endpoint example is located below.
- pin is the number of Pico W output pin where board communicate with led strip.
- Upload the code to the Pico W device.
- Connect led strip with the Pico W and start the system!
Here's the endpoints that system handles at the moment.
API response will be 200 OK if the call will be accurate and realizable. Otherwise the response will be 400 Bad request with error message.
GET /color/hex
curl --location 'http://192.168.1.2/color/ff0000'
Changes strip color to desired hex. This example will change the color to red.
GET /brightness/0-255
curl --location 'http://192.168.1.2/color/50'
Changes brightness of the led strip. Scale of the brightness if 0-255.
GET /turn/on or off
curl --location 'http://192.168.1.2/turn/off'
Changes the strip color to black so practically it will turn the lights off. To turn it on just change the off to on!
<?php
$THE_ID = "RYBNICKALEDS";
$FILENAME = "leds.json";
if(isset($_GET["id"]) && isset($_GET["ip"]) && $_GET["id"] == $THE_ID) {
$obj = array();
$obj["id"] = $_GET["id"];
$obj["ip"] = $_GET["ip"];
$obj["timestamp"] = date("Y-m-d H:i:s");
$json = json_encode($obj, JSON_PRETTY_PRINT);
$fp = fopen($FILENAME, 'w');
fwrite($fp, $json);
fclose($fp);
unset($_GET["id"]);
unset($_GET["ip"]);
echo "OK";
}
Thank you for peeking at my project!
If you're interested check out my other stuff here