-1

I wrote this code to interface the gsm module, can anyone check the code and give me some propositions ?

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)
Sawssen Bejaoui
  • 67
  • 1
  • 1
  • 4

2 Answers2

0

This code won't even run on NodeMCU because the standard Lua os.time() will fail since the os module is not available. I suggest you dig into http://nodemcu.readthedocs.io/en/latest/en/lua-developer-faq/#how-is-nodemcu-lua-different-to-standard-lua.

Besides, even if it were available os.time() has 1 second resolution.

The returned value is a number, whose meaning depends on your system. In POSIX, Windows, and some other systems, this number counts the number of seconds since some given start time (the "epoch").

Hence, your delay_s(1000) would delay execution for 1000 seconds. Doing that with busy-waiting is...not optimal.

You probably want to use the tmr module instead.

Marcel Stör
  • 22,695
  • 19
  • 92
  • 198
  • Thanks for your response. I would like to interface the gsm module using the nodemcu, but that doesen't work. should i add software uarts iin order to be able to use other NOdemcu GPIOs ? – Sawssen Bejaoui Feb 02 '17 at 07:23
0
uart.alt(x);

0 - standard pins
1 - alternate the pins

You havent specify which pins you are gonna use for the communication, or else use uart.alt(0); for standard pins

Leonardo Alves Machado
  • 2,747
  • 10
  • 38
  • 53