Board Drops Comm with PC while testing Web Server

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
Post Reply
Techcoder
Posts: 3
Joined: Sun Apr 14, 2019 1:13 am

Board Drops Comm with PC while testing Web Server

Post by Techcoder » Sun Apr 14, 2019 1:44 am

My new D Board is running a test AP Web Server well, but it looses connection with the PC while it is running an updated script. I have no known way to stop the script from running so I can communicate with it, PC does not see a com port nor does it show up as a drive anymore!?! (Something in the script I would guess)

-AP mode, devices receive test web page fine
-Script is in the boot
-LED turns Green as soon as the board is powered (not in the script)

How can I stop the script from running at power up so it can be found by the PC?
What is in my basic Script that is causing it?

I thought I knew enough but I was wrong :(

My Test Script for first Web Server:

Code: Select all

# MicroPython boot.py 
try:
  import usocket as socket
except:
  import socket
import network
wl_ap = network.WLAN(1)
wl_ap.config(essid='PYBD')          # set AP SSID
wl_ap.config(password='pybd0123')   # set AP password
wl_ap.config(channel=6)             # set AP channel
wl_ap.active(1)                     # enable the AP
wl_ap.status('stations')    # get a list of connection stations
#wl_ap.active(0)  

while wl_ap.isconnected() == False:
  pass

def web_page(request):
    
  html = """<html><head> <title>Matts Web Page</title> 
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" href="data:,"> <style>
  html{font-family: Helvetica; display:inline-block; margin: 0px auto; text-align: center;}
  h1{color: #0F3376; padding: 2vh;}p{font-size: 1.5rem;}
  .button{display: inline-block; background-color: #e7bd3b; border: none; 
  border-radius: 4px; color: white; text-decoration: none; font-size: 30px; width:100%}
  .button2{background-color: #4286f4; width:49%}
  </style></head>
  <body> <h1>Matts Web Page</h1> 
    </body></html>"""
  
  return html

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(1)

while True:
  conn, addr = s.accept()
  print('Got a connection from %s' % str(addr))
  request = conn.recv(1024)
  request = str(request)
  print('The Content = %s' % request)
  response = web_page(request)
  conn.send(response)
  conn.close()

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Board Drops Comm with PC while testing Web Server

Post by Roberthh » Sun Apr 14, 2019 6:38 pm

Putting the script in boot.py is not the best choice, since both boot.py and main.py are executed at boot time. Better put it into a separate script, e.g. server.py and import it while testing or later from main.py with:
import server
For now, you can skip the execution of boot.py and main.py by pushing the USR button, push reset and hold the user button until the green led starts flickering. Then release the user button.

Techcoder
Posts: 3
Joined: Sun Apr 14, 2019 1:13 am

Re: Board Drops Comm with PC while testing Web Server

Post by Techcoder » Sun Apr 14, 2019 9:11 pm

Thank you for your time and kindness for the reply. I did not have the right button sequence to stop it.
Now back to testing why it locks up the board.
I wish there was a good example to compare with.

Thank you again.

Techcoder
Posts: 3
Joined: Sun Apr 14, 2019 1:13 am

Re: Board Drops Comm with PC while testing Web Server

Post by Techcoder » Mon Apr 15, 2019 1:24 pm

Roberthh,

Script runs fine outside boot(?) and in its own file. Will not use boot again.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Board Drops Comm with PC while testing Web Server

Post by Roberthh » Mon Apr 15, 2019 1:58 pm

Boot.py is good for initialization tasks, like mounting the SD, setting interface paramters.

Post Reply