-->
Page 1 of 1

Change respond as access point -on the run

PostPosted: Fri Jul 31, 2015 1:56 pm
by rant
To create a new connection i do :

Code: Select allwifi.setmode(wifi.STATIONAP)
cfg={}
cfg.ssid="myname"
cfg.pwd="mypass"       
wifi.ap.config(cfg)     

sv=net.createServer(net.TCP) 
sv:listen(80,function(c)     
 c:on(\"receive\", function(c, pl) print(pl) end)       
c:send(\"HTTP/1.1 200 OK\\r\\n\")
c:send(\"Content-Type: application/json\\n\\n\")
c:send(\"ok\")       end)           
   



So it works great and i return ok , for every input communication,
Question is, what happens, if i want to send data to the client, or even return different data on next receive ?
For example the esp8266 got a request to check something in my mcu , then i want to respond to him with a specific value,with the check results, how would i do that ?

Do i have to recreate again the function with a different respond like this(seems very wrong) :

Code: Select allsv=net.createServer(net.TCP) 
sv:listen(80,function(c)     
 c:on(\"receive\", function(c, pl) print(pl) end)       
c:send(\"HTTP/1.1 200 OK\\r\\n\")
c:send(\"Content-Type: application/json\\n\\n\")
c:send(" ****different respond !!! ")       end)                     // ** new respond changed every time   




or there is a different way to just set a different respond/ send back data to the client ?


thanks .

Re: Change respond as access point -on the run

PostPosted: Sat Aug 01, 2015 5:25 am
by rant
Anyone? i cant find a "professional" way to set a different respond to different requests.
If i use the esp as a server , and i get a request from client to check something in my EXTERNAL mcu (arduino) , and that i would like to respond with a result, i cant do that because you set the esp server respond- ONE time , and then its programmed with that respond.

I would like to get from client request "test", then respond with an integer value from my arduino mcu, where that value is changed for every request (a sensor?) .

if i just do this every time i like to set a different respond :

Code: Select allSerial.println(F("sv:listen(80,function(c) c:on(\"receive\", function(c, pl) print(pl) end)       c:send(\"HTTP/1.1 200 OK\\r\\n\") c:send(\"Content-Type: application/json\\n\\n\") c:send(\"new\")       end)   " ) );     


it creates many problems ,because i change the listening function on the run .

Is there any way to solve this ??

Re: Change respond as access point -on the run

PostPosted: Thu Aug 06, 2015 4:59 am
by rant
There is no one in this world that knows how to make a direct connection to send and receive data dynamically ???