# Lua-interactive failure

**URL:** <https://forum.sierrawireless.com/t/lua-interactive-failure/3324>\
**Category:** Open AT\
**Created:** [June 10, 2009, 8:23pm UTC](https://forum.sierrawireless.com/t/lua-interactive-failure/3324 "2009-06-10T20:23:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisvan](https://avatars.discourse-cdn.com/v4/letter/c/6bbea6/32.png) [@chrisvan](https://forum.sierrawireless.com/u/chrisvan)\
**Post date:** [June 10, 2009, 8:23pm UTC](https://forum.sierrawireless.com/t/lua-interactive-failure/3324/1 "2009-06-10T20:23:40Z")

</div>

I’m using Lua-interactive to communicate with a Fastrack Supreme. When I  
try to list all the SMSes with at+cmgl the setup crashes almost every time:  
once in about 8 to 10 tries all the SMSes are listed correctly. There  
are 18 very short SMSes (the messages are ‘m01’, ‘m02’, … ‘m18’).  
Here are the commands of a newly started session.

Lua interactive shell  
$ =at(‘at+cpin=1234’);  
= { “\r\nOK” }  
$ =at(‘at+cmgl=“REC READ”’)

A few seconds after entering the at+cmgl command the following three error  
dialogs pop up:

Link to q26-gsm failed. Reconnecting …

PuTTY: Connection closed by remote host.

PuTTY Fatal Error: Software caused connection abort.

q26-gsm is the name of the shortcut that establishes the network  
connection. After this the network reconnects and I must restart PuTTY.  
It makes no difference if the output of the +cmgl command is displayed or  
not.

If I read the messages one at a time with the following loop it all works  
fine.

for k = 1,25 do  
p(at(string.format(‘at+cmgr=%d’, k)))  
end

Any idea what is actually failing or why at+cmgl fails?

Setup info:  
CPU: FSU005 (Fastrack Supreme)  
Firmware: R73\_00gg.FSU005  
OS: 6.20  
M2M Studio 1.0.2.200903311200

Thanks  
chris

---

<div class="post-metadata">

**Author:** ![fft](https://avatars.discourse-cdn.com/v4/letter/f/e8c25b/32.png) [@fft](https://forum.sierrawireless.com/u/fft)\
**Post date:** [June 18, 2009, 11:47am UTC](https://forum.sierrawireless.com/t/lua-interactive-failure/3324/2 "2009-06-18T11:47:11Z")

</div>

Hi,

the most likely reason why you have this issue is Open AT’s watchdog: if the user application remains busy for too long, the whole CPU reset as a “safety” measure. Newer versions of the Lua VM keep the watchdog quiet as long as the VM isn’t stuck, so you don’t have to take care of the watchdog anymore in Lua.

I’ll put the latest version online ASAP (or you can get them by svn from [https://svn.anyware-tech.com/wavecom/openat-lua/oatlua/](https://svn.anyware-tech.com/wavecom/openat-lua/oatlua/)), please tell me whether it fixes your issue.

---

<div class="post-metadata">

**Author:** ![chrisvan](https://avatars.discourse-cdn.com/v4/letter/c/6bbea6/32.png) [@chrisvan](https://forum.sierrawireless.com/u/chrisvan)\
**Post date:** [June 22, 2009, 4:19am UTC](https://forum.sierrawireless.com/t/lua-interactive-failure/3324/3 "2009-06-22T04:19:53Z")

</div>

I tried to compile the new oatlua-1.40 library and lua\_interactive program under OS-6.20.4, Firmware 7.3 and WIP 5.10.2020 using wmmake. (I created the projects with the Project Wizard and then switched to the commandline functions.) Compiling the library was okay; there were some warning messages about incompatible pointer types and discarded pointer qualifiers but things should work okay.

For lua\_interactive I’ve added the following wmnew options to use the new oatlua-1.40 library:

-libname gcc\_oatlua-140.lib -extlib d:/openat-tests/oatlua-1.40/gcc/out -inc d:/openat-tests/oatlua-1.40/itf

and added plugin WIP. When I compile lua\_interactive using wmmake I get the following errors:

… Compiling appli.c

In file included from appli.c:32:  
mempool.h:11: error: variable-size type declared outside of any function  
appli.c: In function ‘adl\_main’:  
appli.c:129: warning: passing argument 1 of ‘luaW\_memPoolInit’ from incompatible pointer type  
appli.c:129: error: too many arguments to function ‘luaW\_memPoolInit’  
make.exe: \*\*\* [appli.o] Error 1  
Done.  
[wmmake error #1] Build error.

If I move the line

#include “mempool.h”

into adl\_main() the first error (mempool.h:11: error: …) goes away but then there is another error (mempool.h:35: error: …, see below)

… Compiling appli.c

In file included from appli.c:117:  
mempool.h: In function ‘adl\_main’:  
mempool.h:35: error: invalid storage class for function ‘evh\_openat\_error’  
appli.c:130: warning: passing argument 1 of ‘luaW\_memPoolInit’ from incompatible pointer type  
appli.c:130: error: too many arguments to function ‘luaW\_memPoolInit’  
c:\bin\openat-2.20\IDE\MINGW\3.8.0.1\bin\make.exe: \*\*\* [appli.o] Error 1  
Done.  
[wmmake error #1] Build error.

The biggest problem appears to be the definition of luaW\_memPoolInit() that has changed. The old version had multiple arguments passed to this function but the new version takes a luaW\_memPoolHeader and I can’t figure out how to use this struct. I’m also not sure if this will fix the problem because precompiled library functions may depend on the old function definition.

I’ve also tried to use an older version of wiplua.h (some of the functions are defined there) but this was not succesful.

Any ideas how to fix the problem?

BTW, what happened to wmnew and wmmake in M2M studio? Is it still possible to work on the commandline?

Thanks  
chris

---

<div class="post-metadata">

**Author:** ![fft](https://avatars.discourse-cdn.com/v4/letter/f/e8c25b/32.png) [@fft](https://forum.sierrawireless.com/u/fft)\
**Post date:** [June 24, 2009, 12:04pm UTC](https://forum.sierrawireless.com/t/lua-interactive-failure/3324/4 "2009-06-24T12:04:21Z")

</div>

I forgot to mention that the memory initialization process has been changed: you don’t need mempool.h anymore, adn the prototype for luaW\_mempoolInit() has changed as well. A new version of the sample can be found here: [http://people.anyware-tech.com/~fabien/lua\_interactive.c](http://people.anyware-tech.com/~fabien/lua_interactive.c)

---

<div class="post-metadata">

**Author:** ![chrisvan](https://avatars.discourse-cdn.com/v4/letter/c/6bbea6/32.png) [@chrisvan](https://forum.sierrawireless.com/u/chrisvan)\
**Post date:** [June 24, 2009, 7:46pm UTC](https://forum.sierrawireless.com/t/lua-interactive-failure/3324/5 "2009-06-24T19:46:39Z")

</div>

Fabien,  
Thanks a lot for the help, it is working fine now. To make sure the watchdog is not triggered I created a loop and retrieved all the SMSes several times, the total time being more than 8 seconds, and it worked perfectly.  
Thanks again  
chris

---

<div class="post-metadata">

**Author:** ![chrisvan](https://avatars.discourse-cdn.com/v4/letter/c/6bbea6/32.png) [@chrisvan](https://forum.sierrawireless.com/u/chrisvan)\
**Post date:** [June 25, 2009, 8:16pm UTC](https://forum.sierrawireless.com/t/lua-interactive-failure/3324/6 "2009-06-25T20:16:43Z")

</div>

If I use sms.list() in the new version of oatlua I get an error about  
at.parse being a nil value.

$ =at(‘at+cpin=1234’)  
= { “\r\nOK” }  
$ m = sms.list(“REC READ”)  
run(): error: src\_lua\sms\_lua.lua:25: attempt to call field ‘parse’ (a nil value)  
stack traceback:  
src\_lua\sms\_lua.lua:25: in function ‘list’  
shell:1: in function ‘code’  
src\_lua/shell.lua:82: in function \<src\_lua/shell.lua:80\>

In older versions of oatlua at.parse() used to be in src\_lua/at.lua but I  
can’t find it anywhere in the latest version. If I comment out  
the call at.parse(x) in sms.list() then processing fails because x is not in  
the correct format:

$ m = sms.list(“REC READ”)  
run(): error: shell:11: table index is nil  
stack traceback:  
shell:11: in function ‘list’  
shell:1: in function ‘code’  
src\_lua/shell.lua:82: in function \<src\_lua/shell.lua:80\>

For now I just plugged in an older version of at.parse() to keep going but it would probably better to fix sms.list() in the long run.  
chris

---

<div class="post-metadata">

**Author:** ![fft](https://avatars.discourse-cdn.com/v4/letter/f/e8c25b/32.png) [@fft](https://forum.sierrawireless.com/u/fft)\
**Post date:** [June 29, 2009, 9:10am UTC](https://forum.sierrawireless.com/t/lua-interactive-failure/3324/7 "2009-06-29T09:10:51Z")

</div>

at.parse() proved to be less practical, and _much_ more resource-hungry than a simple regular expression, and as such should be considered deprecated. oatlua being open source, the correct way to override deprecation is to copy/paste the old definition in your program, which is just what you did.

If you’re using the sample given with oatlua to parse SMS, here’s a regexp-based version of the relevant loop (warning, untested code):

```auto
local lines = at'at+cmgl="ALL"'
   for i=1, #lines-4, 3 do
      local sms = { text = lines[i+2] }
      sms.n, sms.phone, sms.date = lines[i+1] :match '+CMGL: (%d+),".-","(.-)",.-,"(.-)"'
      sms_table[sms.n] = sms
   end
```

The money quote is the call to method :match(); a description of Lua regular expressions can be found [in the official Lua manual](http://www.lua.org/pil/20.2.html). To tune your regexps, I suggest to test them interactively on the telnet shell; spending an hour or so learning to toy with them will pay off in no time if you do any kind of parsing, of AT commands results or any other non-binary protocol.

---

<div class="post-metadata">

**Author:** ![chrisvan](https://avatars.discourse-cdn.com/v4/letter/c/6bbea6/32.png) [@chrisvan](https://forum.sierrawireless.com/u/chrisvan)\
**Post date:** [June 30, 2009, 7:34pm UTC](https://forum.sierrawireless.com/t/lua-interactive-failure/3324/8 "2009-06-30T19:34:34Z")

</div>

Fabien  
Thanks for the help. I forgot to respond to ypur post after I read it yesterday. I’m familiar for regular expressions as used in awk/sed, etc as well as with Lua’s pattern matching. And you are right, the responses can easily be parsed with these.

Thanks  
chris
