Writing an application in Open AT Lua


I am looking for example in lua that show how to connect two modem, and send data from one modem UART to the second modem UART.
throw GPRS.

In my final product i will need to connect one modem(as client) to two modem(serve as servers) and this connections need to stay all the time
and pass data from one UART to another UART according to the data come from UART.

Do you know of some example that can show me part of this program.
  • when you say ‘AT+LUA is only available when the Lua sample is loaded’ - Lua sample is the shell example because i try to use it
    and i get error there.

  • can i use the shell during another Lua program is running and using UART port.
    if yes how can i change the debug trace to the shell i will open from another gprs connection?


Hello everybody,

I proved the example and although I make it work I have several doubts. this does not work to me.

$ 1 ('at.lua');
Compilation error: shell:1: unexpected symbol near '1'

This code works fine: :slight_smile:

x=internal.ftp_client ('', 'anonymous', 'some_dummy_password', 21, true); x:hook('*', function(...) print(...); return 'again'; end)

I can donwload of the server FTP a file. Until here quite well, but:
Where keeps the file?
as I can execute it in case of being a lua script file?


It’s an “ell”, as in “Load”, not a “one”! :slight_smile: l(‘at.lua’), not 1(‘at.lua’). Notice also that when there’s a single arg which is a litteral string, parentheses are optional, so you can just type l’at.lua’; moreover, the function will add the ‘.lua’ prefix if you provide a filename without an extension, so you can just type: l ‘at’. Finally, it remembers the last file names used, even across reboots, so if you reload at.lua a second time you can just type l(). Since that’s a command you’re going to type a lot, you’d better shorten it as much as possible!

It works pretty much like WIP: x:get() returns a channel on which you can read your content, and put it wherever you want. For instance (untested code):

$ session = wip.ftp("192.168.4") -- defaults to anonymous login
$ data_channel = session:get 'scheduling.lua'
$ file_content = data_channel:read '*a' -- '*a' means "the whole file", cf. doc
$ data_channel:close(); session:close(); data_channel, session = nil, nil -- release resources

From now on, you can do pretty much what you want with the file content, for instance:

$ save 'file_content' -- commit the global variable to flash
$ compiled_code, error_msg = loadstring(file_content) -- compile it, assuming it's a source file
$ if compile_code then compile_code() -- run the resulting function if compilation succeeded
+ else printf("Couldn't compile your stuff: %s", error_msg) end
$ save 'compiled_code' -- you can also save the compiled function if you prefer

Of course, you might want the file in other ways than just a single string, especially if the file is huge or if you have to fir within 256KB. Again, refer to the doc for more advanced tricks.

BTW, hooking a print function to the channel to better follow what it does is a pretty neat trick :slight_smile: However, you normally don’t have to use the content of the “internal” module: it only provides crude interfaces to C features, but whatever you have to use will be offered in other modules, generally with a nicer API. In this case, wip.ftp_client() will wait for authentication to complete, and make most parameters optional.