TCP/IP over Wifi

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
radders
Posts: 7
Joined: Mon Feb 04, 2019 4:41 pm

TCP/IP over Wifi

Post by radders » Tue Dec 10, 2019 1:48 pm

Hello,

I'm using an ESP8266 board, and have a small program which creates an AP and waits for a Wifi connection,
then opens a TCP/IP port and waits for a 'telnet' type connection on port 23:

Code: Select all

  while station.isconnected() == False:
    pass
 
  print('Wifi Connection successful')
  print(station.ifconfig())

  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  print('Bind')
  s.bind(('', 23))
  print('Bound')
  print('Listen')
  s.listen(5)
  print('Listening')
  print('Accept')
  conn, addr = s.accept()
  print('Accepted')
  conn.setblocking(False)
  
  print('Got a TCP/IP connection from %s' % str(addr))
This seems to work ok, but what happens if the WiFi connection gets dropped whilst it is sitting at the:

Code: Select all

conn, addr = s.accept()
line?

How do I detect that condition? I tried it, and disconnection the WiFi at that point does nothing. It just stays at that point.
Thanks, Dave

Post Reply