[buffer-length, api-endpoint] "color" => array(6, "rgb"), "brightness" => array(2, "brightness") ); // execute the first matching command foreach($passthru as $k => $v) { if(!isset($_POST[$k])) continue; $out = curl($k, $v[0], $v[1]); $code = 200; break; } // set headers header("HTTP/1.0 " . strval($code) . (200 === $code ?" OK" : " Bad Request")); $GLOBALS["http_response_code"] = $code; //http_response_code($code); exit("{$out}"); } /* else GET request, check for quick response parameters -- do not generate whole page */ { if(isset($_GET['req'])) { // default is to get color as decimal [0..255] values R,G,B $req = "dec"; switch($_GET['req']) { case "color": $req = "dec"; break; case "brightness": $req = "brightness"; break; case "correction": $req = "cfg"; break; } $uri = "http://rain-gutter-rgb.lan.rome7.com/{$req}"; // send GET request to the esp8266 $ch = curl_init(); error_log("sending [get: {$req}] via {$uri}"); curl_setopt($ch, CURLOPT_URL, $uri); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $out = curl_exec($ch); curl_close($ch); exit($out); } } // otherwise - generate a whole web-page echo ""; echo "
"; // either use mixbox non-commercial use under the CC BY-NC 4.0 license echo ""; // or the spectral.js MIT license echo ""; echo " "; // common functions echo " "; // render a color selection wheel echo " "; // simple color picker echo " "; // add a callback to the click event to send rgb value to esp8266 echo " "; /* make a brightness slider, esp8266 takes 0..15 levels of brightness * zero is off and should be ignored * * currently brightness control is very simple and operates without * modifying end-user color choices * * tldr; users have 24bit color selectivity, in hardware we have a * little over 1.5 bytes per color giving us somewhere near 37bit color * selectivity. so a user can select 0a3bcc as their color choise and * we can have thousands of shades of colors that are close to that. * The power section of the esp8266 is not optimal so the esp8266 will * limit running the LEDs at maximum current. This limits the color-space * by about 20%. The way we implement brightness is to cut give the end * user 24-bits of color selectivity, that fits into 1/20th of the color-space * then we can multiply those values linearly 1..15 before we hit that 80% * power limit. because we are amplifying colors evenly the selected output * color will not change. */ echo " "; // add a callback to the off-click event on the slider echo " "; echo ""; echo "";