the only way to use wifi with LUA right now is with netlib. There's no tut for it, but there is a very easy example with it. Ah whatever I'll write a very short tut:
what you need:
- netlib2.0
The file itself is called "netlib.lua". Put it in the same folder as your app (this isn't necessairy, you can also put it somewhere else, the path in the "dofile()" command will just change).
First the stuff that should be before your main loop (also remember to turn on the wifi with "Wlan.init()" and connect to the internet using "Wlan.useConnectionConfig (connection)", where "connection" is the number of the connection you want to use. For example: with Wlan.useConnectionConfig( 1) you would connect to your first connection):
1) In your app you have to import it by saying "dofile("netlib.lua") ".
2) After that you have to connect to the server with this "netconnect()"
3) Now before you can send and receive date, you have to create a variable on the server where you can send and receive your data to. You do this with the following command: netreg(id), where id is the name you want the variable to have.
(This command also makes sure the server sends the valua of the variable, whenever the valua of it changes)
Now comes the part that should be in the main loop itself
4) Now you have created a variable on the server you can send data to it by using "netsend(id, data, attribute)", where "id" is the name of the variable, data is the data in a string format (this means you have to turn tables and numbers and other formats into a string first) and where "attribute" is the way you want the data to be put in the variable. The attribute can either be "w" or "a". "w" means write and you will replace data, "a" means append and you will add the new data to the data that was already in the variable.
5) To receive data, you would say "netrecv()". This will receive all incoming data.
6) You don't have the value of the variable yet though. For that you need to use "netvalue(id)", where "id" is again the name of the variable. You need to put this after the "netrecv()" command.
After the main loop, you will need to delete the variable and close the connection:
7) To delete the variable on the server: netunreg(id), where "id" is the name of the variable
8) To close the connection to the server: netclose()
9) To close wifi: Wlan.term()
As an example I have put the example of yoursam (the author of this app) here:
Code:
--[[
netlib example
by youresam
]]
dofile("netlib.lua") -- netlib
Wlan.init()
print("Connecting to "..Wlan.getConnectionConfigs()[1].."...")
Wlan.useConnectionConfig(1)
print("Connecting to netlib server...")
netconnect() -- connect to netlib server
print("Setting up AMW for 'netlibtest' (wont do anything in this example..)")
netreg("netlibtest")
print("Sending 'helloworld' to 'netlibtest'")
netsend("netlibtest","helloworld","w") -- id:netlibtest data:helloworld mode:write
print("Getting 'netlibtest'...(Press start to quit)")
netget("netlibtest")
while true do
netrecv() --recieve all incoming data
buffer = netvalue("netlibtest") --what is the value of the id 'netlibtest'?
if buffer ~= "" then --if it exists...
print(buffer)
break
end
if Controls.read():start() then break end
end
netunreg("netlibtest") --ALWAYS unregister a variable when your done
netclose() --close the netlib connection
Wlan.term()
print("Program finished, hold start to exit.")
As you can see he uses netget(id) instead of netrecv() and netvalue(id). Eventhough its possible, its way slower (so he said to me). He still uses it because he only needs to get the data once and not continues (I think?). If you want to get the data every loop its better to use netrecv() and netvalue(id).
Hope it's clear enough (and right. If not please correct me anyone). I didn't explain the mail, sms and call functions. I just explained the basic sending and receiving.