首页 文章

LUA / NodeMCU中的HTTP GET

提问于
浏览
1

我每次按下按钮时都试图发送HTTP GET:

wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","PWD")
function loop() 
    if wifi.sta.status() == 5 then
        -- Stop the loop
        tmr.stop(0)
    else
        print("Connecting...")
    end
end
tmr.alarm(0, 100, 1, function() loop() end)
print(wifi.sta.getip())

outpin_led = 1
inpin_button = 3

gpio.mode(outpin_led,gpio.OUTPUT)
gpio.mode(inpin_button,gpio.INPUT)
light_on = false

function light()
    if not light_on then
        -- turn the light on
        gpio.write(outpin_led,gpio.HIGH)
        light_on = true
        http.get("https://google.com", function(clt, data)
            print(data)
        end)
    else
        -- turn the light off
        gpio.write(outpin_led,gpio.LOW)
        light_on = false
    end
end

gpio.trig(inpin_button,"down",light)

包含 http.get 的行正在抛出此错误消息:

> PANIC: unprotected error in call to Lua API (stdin:6: attempt to index global 'http' (a nil value))

我通过 http://nodemcu-build.com/ 编译确保我的NodeMCU构建包含 http 模块

任何的想法 ?

谢谢 .

1 回答

  • 1

    正如MarcelStör所指出的那样,在固件闪存期间确实存在问题 .

    非常感谢您的回复和http://nodemcu-build.com/的工作 .

相关问题