Skip to content

Instantly share code, notes, and snippets.

@abobija
Created April 1, 2019 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abobija/d569c38978c5cef853d3e530089245bc to your computer and use it in GitHub Desktop.
Save abobija/d569c38978c5cef853d3e530089245bc to your computer and use it in GitHub Desktop.
Code written in YouTube video https://bit.ly/2V8BgH9
local BLUE_LED = 2
gpio.config({ gpio = BLUE_LED, dir = gpio.IN_OUT })
gpio.write(BLUE_LED, 0)
local api = nil
local function init_api32()
if api == nil then
api = require('api32')
.create({
auth = {
user = 'master',
pwd = 'api32secret'
}
})
.on_get('/', function()
return { message = 'Welcome to the API32!' }
end)
.on_get('/test', function()
return { message = 'Hello from TEST endpoint.' }
end)
.on_get('/led', function()
return {
device = 'Blue LED',
state = gpio.read(BLUE_LED)
}
end)
.on_post('/led', function(jreq)
if jreq == nil or jreq.state == nil then return end
gpio.write(BLUE_LED, jreq.state)
return {
new_state = gpio.read(BLUE_LED)
}
end)
.on_get('/complex', function()
return {
param1 = (2 + 2 * 2),
param2 = {
param2_1 = 'test',
param2_2 = 'hello'
}
}
end)
end
end
wifi.mode(wifi.STATION)
wifi.sta.config({
ssid = 'Renault 1.9D',
pwd = 'renault19',
auto = false
})
wifi.sta.on('got_ip', init_api32)
wifi.start()
wifi.sta.connect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment