AJAX Light dimmer
Posted: Fri Apr 21, 2017 5:11 am
Stolen bits from everywhere to build this but it works! You can move the slide on the screen and it will instantly change the light level (PWM) on an LED on GPIO5.
BASIC
HTML/Javascript [upload to esp as index.htm]
Just browse to ESP_!P_ADDR/file?file=index.htm
I copied jquery onto the esp, not necessary if you don't intend to run the ESP in AP mode. I had to add a callback to the javascript otherwise the ESP gets inundated with request's and crashes. I tried to use multiple variables i.e wget "http://192.168.4.1/msg?pin=2&stat=1&action=po" -q -O - but again the ESP could not keep up and crashed. With one variable I could move the slider as much and as fast as I could.
I am making a RC car based off ESP8266 BASIC you can follow my progress here https://www.youtube.com/channel/UCXsnD8s75AEswtePX7EJmRA NOT MONETIZED This project is under Multi Episode Projects (wifi anything)
BASIC
Code: Select all
msgbranch [mybranch]
print "You can send msgs to the esp and do things based on accessing a URL"
wait
[mybranch]
MyReturnMsg = "Not a valid msg received"
pinStatus = val(msgget("stat"))
io(pwo,5,pinStatus)
MyReturnMsg = "200"
msgreturn MyReturnMsg
wait
HTML/Javascript [upload to esp as index.htm]
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>toggle test</title>
<script src="http://192.168.4.1/file?file=jquery.js"></script>
<script type="text/javascript">
var dimmer
window.onload = function() {
var dimmer = 1024,
html = '<li>Dimmer Value: \
<input type="range" min="0" max="' + dimmer + '" value="'+dimmer+'" name="dimmer_value" id="dimmer_value" />\
<span>' + dimmer + '</span>\
</li>';
$("body").append(html);
$('#dimmer_value').on("input change", function() {
$(this).next().html($(this).val());
dimmer = "http://192.168.4.1/msg?stat=" + $(this).val();
console.log(dimmer);
$.ajax({
url: dimmer,
async: false }).done(function( data ) {
console.log(data); //or whatever
})
});
}
</script>
</head>
<body>
</body>
</html>
Just browse to ESP_!P_ADDR/file?file=index.htm
I copied jquery onto the esp, not necessary if you don't intend to run the ESP in AP mode. I had to add a callback to the javascript otherwise the ESP gets inundated with request's and crashes. I tried to use multiple variables i.e wget "http://192.168.4.1/msg?pin=2&stat=1&action=po" -q -O - but again the ESP could not keep up and crashed. With one variable I could move the slider as much and as fast as I could.
I am making a RC car based off ESP8266 BASIC you can follow my progress here https://www.youtube.com/channel/UCXsnD8s75AEswtePX7EJmRA NOT MONETIZED This project is under Multi Episode Projects (wifi anything)