Advertisement
prjbrook

Perplexcsv1.py pico send file program

Aug 10th, 2024
220
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. https://capture.dropbox.com/bkF5UoX4ybyFx3Ja
  2. import network
  3. import socket
  4.  
  5. # Set up access point
  6. ap = network.WLAN(network.AP_IF)
  7.  
  8. #ap.config(essid='PicoW_AP',password='PASSWORD')  #Pb added password
  9. ap.config(essid='NAME2',password='PASSWORD')  #Pb added password
  10. ap.active(True)
  11. # Wait for connection
  12. while not ap.isconnected():
  13.     pass
  14.  
  15. print('AP Mode Is Active, You can Now Connect')
  16. print('IP Address To Connect to::', ap.ifconfig()[0])
  17.  
  18. # Set up socket
  19. addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
  20. s = socket.socket()
  21. s.bind(addr)
  22. s.listen(1)
  23.  
  24. print('Listening on', addr)
  25.  
  26. while True:
  27.     cl, addr = s.accept()
  28.     print('Got a connection from', addr)
  29.     request = cl.recv(1024)
  30.     print('Content received by Pico =', request)
  31.  
  32.     # Attempt to read the log.csv file
  33.     try:
  34.         with open('log.csv', 'r') as file:
  35.             log_data = file.read()
  36.     except OSError:
  37.         log_data = "Error: log.csv file not found."
  38.  
  39.     # Send a proper HTTP response with the CSV data
  40.     response = """\
  41. HTTP/1.1 200 OK
  42. Content-Type: text/csv
  43. Content-Disposition: attachment; filename="log.csv"
  44. Content-Length: {}
  45.  
  46. {}
  47.  
  48. """.format(len(log_data), log_data)
  49.  
  50.     cl.send(response)
  51.     cl.close()
  52.  
  53.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement