Created
September 26, 2019 13:25
-
-
Save abobija/d3fc5b495bae1df0ef174d3370c8bc3b to your computer and use it in GitHub Desktop.
Code written in YouTube video https://youtu.be/A_j-nDV46Ik
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>ESP32</title> | |
</head> | |
<body> | |
<h1>Hello from ESP32</h1> | |
<button id="toggle-btn" style="padding:20px; font-size:20px">Toggle LED</button> | |
<script> | |
document.getElementById('toggle-btn').addEventListener('click', () => { | |
fetch('/toggle-led', { method: 'POST' }); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local api = nil | |
local BLUE_LED = 2 | |
gpio.config({ gpio = BLUE_LED, dir = gpio.IN_OUT }) | |
gpio.write(BLUE_LED, 0) | |
local function init() | |
if api ~= nil then return end | |
api = require('api32') | |
.create() | |
.on_get('/', 'index.html') | |
.on_post('/toggle-led', function() | |
if gpio.read(BLUE_LED) == 1 then | |
gpio.write(BLUE_LED, 0) | |
else | |
gpio.write(BLUE_LED, 1) | |
end | |
end) | |
end | |
wifi.mode(wifi.STATION) | |
wifi.sta.config({ | |
ssid = 'Renault 1.9D', | |
pwd = 'renault19', | |
auto = false | |
}) | |
wifi.sta.on('got_ip', init) | |
wifi.start() | |
wifi.sta.connect() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment