Lua GSM模块与nodemcu的接口
我写这段代码是为了连接gsm模块,有人能检查一下代码并给我一些建议吗Lua GSM模块与nodemcu的接口,lua,gsm,esp8266,Lua,Gsm,Esp8266,我写这段代码是为了连接gsm模块,有人能检查一下代码并给我一些建议吗 hex1= '0x1A'; function delay_s(delay) delay = delay or 1 local time_to = os.time() + delay while os.time() < time_to do end end uart.alt(1); uart.setup(0, 9600, 8, uart.PARITY_NONE, uart.STOPBITS_1, 1) uart.write
hex1= '0x1A';
function delay_s(delay)
delay = delay or 1
local time_to = os.time() + delay
while os.time() < time_to do end
end
uart.alt(1);
uart.setup(0, 9600, 8, uart.PARITY_NONE, uart.STOPBITS_1, 1)
uart.write(0,"AT+IPR=9600\n")
for j = 1, 10 do
uart.write(0, "AT\n")
end
delay_s(1000)
uart.write(0, "AT\n")
delay_s(1000)
uart.write(0, 'AT+CSCS="GSM"\n')
delay_s(1000)
uart.write(0, 'AT+CMGF=1\n')
delay_s(1000)
uart.write(0, 'AT+CMGS="+21654102832"\n')
delay_s(1000)
uart.write(0, " Salut tout le mond !!!\n")
delay_s(1000)
uart.write(0, hex1)
delay_s(1000)
hex1='0x1A';
功能延迟(延迟)
延迟=延迟或1
本地时间=操作系统时间()+延迟
而os.time()
此代码甚至不会在NodeMCU上运行,因为标准Lua将失败,因为os
模块不可用。我建议你深入研究
此外,即使它可用,os.time()
也有1秒的分辨率
返回的值是一个数字,其含义取决于您的系统。在POSIX、Windows和其他一些系统中,这个数字统计自某个给定的开始时间(“历元”)起的秒数
因此,您的delay_s(1000)
会将执行延迟1000秒。在忙碌的等待中这样做…不是最佳的
您可能希望使用
您没有指定要用于通信的管脚,或者使用
uart.alt(0)代码>对于标准引脚请提供模块型号我有sim900a gsm模块您有来自模块的anu响应吗?好吧。请说得更具体一点不,使用nodemcu我没有任何反应,但我用arduino测试了这个模块,它工作得很好。当我更改uart.alt(1)时,我编写的程序无法上传到主板上,你知道吗?谢谢你的回答。我想使用nodemcu连接gsm模块,但这不起作用。我是否应该添加软件UART iin以便能够使用其他NOdemcu GPIO?
uart.alt(x);
0 - standard pins
1 - alternate the pins