开发主要是两个网站:
pin=4
gpio.mode(pin,gpio.OUTPUT)
--开启pin4--
gpio.write(pin,gpio.LOW)
--置端口输出低电位,灯亮--
gpio.write(pin,gpio.HIGH)
--置端口输出高电位,灯灭--
编译时不能有中文
单行注释 --
多行注释
--[[
多行注释
多行注释
--]]
--函数
function test()
end
--判断
if wifi.sta.getip() ==nil then
else
end
--串口输出
print("disconnect..")
timer =tmr.create()
--定时循环函数
function test()
end
timer:alarm(1000,tmr.ALARM_AUTO,test)
定时器模式
tmr.ALARM_SINGLE
一次性警报(不需要调用unregister())tmr.ALARM_SEMI
ALARM_SEMI手动重复报警(call start()重新启动)tmr.ALARM_AUTO
自动重复告警timer =tmr.create()
function serial()
uart.on("data", 4,
function(data)
print("receive from uart:", data)
uart.write(0,data)
end, 0)
end
timer:alarm(2000,tmr.ALARM_AUTO,serial)
timer =tmr.create()
cfg = {}
cfg.ssid = "username" -- wifi username
cfg.pwd = "passwd" -- wifi passwd
wifi.sta.config(cfg)
wifi.sta.connect()
function reconnect()
if wifi.sta.getip() ==nil then
print("disconnect..")
else
timer:stop()
print("connect success")
print(wifi.sta.getip())
end
end
timer:alarm(1000,tmr.ALARM_AUTO,reconnect)
--connect to Access Point (DO NOT save config to flash)
station_cfg={}
station_cfg.ssid="NODE-AABBCC"
station_cfg.pwd="password"
station_cfg.save=false
wifi.sta.config(station_cfg)
--connect to Access Point (DO save config to flash)
station_cfg={}
station_cfg.ssid="NODE-AABBCC"
station_cfg.pwd="password"
station_cfg.save=true
wifi.sta.config(station_cfg)
--connect to Access Point with specific MAC address (DO save config to flash)
station_cfg={}
station_cfg.ssid="NODE-AABBCC"
station_cfg.pwd="password"
station_cfg.bssid="AA:BB:CC:DD:EE:FF"
wifi.sta.config(station_cfg)
--configure station but don‘t connect to Access point (DO save config to flash)
station_cfg={}
station_cfg.ssid="NODE-AABBCC"
station_cfg.pwd="password"
station_cfg.auto=false
wifi.sta.config(station_cfg)
dht_pin =5
function AcDht()
status, temp, humi, temp_dec, humi_dec = dht.read11(dht_pin)
print("temp is:"..temp,"humi is:"..humi)
end
timer1:alarm(1000,tmr.ALARM_AUTO,AcDht)
pin =5
function readADC()
val = adc.read(pin)
print("val:"..val)
end
timer1:alarm(1000,tmr.ALARM_AUTO,readADC)
如果ESP8266被配置为使用ADC读取系统电压,该函数将始终返回65535。这是硬件和/或SDK的限制
原文:https://www.cnblogs.com/noobhukai/p/14229780.html