Welcome, Guest
Username: Password: Remember me

TOPIC: TCP Communication through nodemcu esp8266

TCP Communication through nodemcu esp8266 2 months 3 weeks ago #3745

  • Dr. Sana
  • Dr. Sana's Avatar
  • Offline
  • New Member
  • Posts: 2
  • Karma: 0
Hi!
My project is based on two esp8266 module labview app running on PC. I have to establish TCP Communication between Labview and the two esp8266 modules without using external router. In my present network one of my nodemcu is configured in AP mode and the other is in station mode and obviously my PC (server) is another station which is listening for some tcp request. The labview (software running on PC) is making tcp connection with the one in AP mode but not with one in station mode. So anyone who could guide me where the problem is and what could be the solution.
The esp8266 modules are configure in lua, Code is given below:

Access Point

wifi.setmode(wifi.SOFTAP)
cfg={}; cfg.ssid="myssid"; cfg.pwd="87654321"; wifi.ap.config(cfg)
dhcp_config ={}
dhcp_config.start = "192.168.4.1"
wifi.ap.dhcp.config(dhcp_config)
wifi.ap.dhcp.start()
conn=net.createConnection(net.TCP, 0)
conn:on("connection", function(connected)
print("$TCP^")
uart.on("data",'#', function(data)
conn:send(data);
end, 0)
end ,0)
conn:on("receive", function(conn, payload)
print(payload)
end)
conn:on("disconnection",function(disconnected)
print("$DIS^")
node.restart()
end)

Station:

uart.setup(0,9600,8,0,1)
print("ready to start")
print("Connecting to WiFi access point...")
wifi.setmode(wifi.STATION)
wifi.sta.config("myssid","87654321")
wifi.sta.autoconnect(1)
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip() == nil then
print("Waiting for IP address...")
else
tmr.stop(1)
print("WiFi connection established, IP address: " .. wifi.sta.getip())
end
end)
print("Open connection...")
conn=net.createConnection(net.TCP, 0)
--port and ip at which labview app is listening
conn:connect(4001,'192.168.4.2')
conn:on("connection", function(connected)
print("#")
uart.on("data",'#', function(data)
conn:send(data);
end, 0)
end ,0)
conn:on("receive", function(conn, payload)
print(payload)
end)
conn:on("disconnection",function(disconnected)
print("*")
end)
The administrator has disabled public write access.

TCP Communication through nodemcu esp8266 2 months 3 weeks ago #3746

  • EasyIoT
  • EasyIoT's Avatar
  • Offline
  • Administrator
  • Posts: 816
  • Thank you received: 254
  • Karma: 23
Dr. Sana wrote:
Hi!
My project is based on two esp8266 module labview app running on PC. I have to establish TCP Communication between Labview and the two esp8266 modules without using external router. In my present network one of my nodemcu is configured in AP mode and the other is in station mode and obviously my PC (server) is another station which is listening for some tcp request. The labview (software running on PC) is making tcp connection with the one in AP mode but not with one in station mode. So anyone who could guide me where the problem is and what could be the solution.
The esp8266 modules are configure in lua, Code is given below:

Access Point

wifi.setmode(wifi.SOFTAP)
cfg={}; cfg.ssid="myssid"; cfg.pwd="87654321"; wifi.ap.config(cfg)
dhcp_config ={}
dhcp_config.start = "192.168.4.1"
wifi.ap.dhcp.config(dhcp_config)
wifi.ap.dhcp.start()
conn=net.createConnection(net.TCP, 0)
conn:on("connection", function(connected)
print("$TCP^")
uart.on("data",'#', function(data)
conn:send(data);
end, 0)
end ,0)
conn:on("receive", function(conn, payload)
print(payload)
end)
conn:on("disconnection",function(disconnected)
print("$DIS^")
node.restart()
end)

Station:

uart.setup(0,9600,8,0,1)
print("ready to start")
print("Connecting to WiFi access point...")
wifi.setmode(wifi.STATION)
wifi.sta.config("myssid","87654321")
wifi.sta.autoconnect(1)
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip() == nil then
print("Waiting for IP address...")
else
tmr.stop(1)
print("WiFi connection established, IP address: " .. wifi.sta.getip())
end
end)
print("Open connection...")
conn=net.createConnection(net.TCP, 0)
--port and ip at which labview app is listening
conn:connect(4001,'192.168.4.2')
conn:on("connection", function(connected)
print("#")
uart.on("data",'#', function(data)
conn:send(data);
end, 0)
end ,0)
conn:on("receive", function(conn, payload)
print(payload)
end)
conn:on("disconnection",function(disconnected)
print("*")
end)

If I understand you correctly you are working without router. One ESP8266 is in AP mode and other in station mode. I guess PC WiFi is connected to ESP8266 operating as AP. Even ESP8266 is in AP mode it can not route IP traffic from ESP8266 in station mode to PC. This is the reason you can not connect ESP8266 in station mode to PC.
The administrator has disabled public write access.
Time to create page: 0.206 seconds
Powered by Kunena Forum