SHARE
TWEET

Untitled

a guest Jan 21st, 2020 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. try:
  2.   import usocket as socket
  3. except:
  4.   import socket
  5.  
  6. import network
  7.  
  8. import esp
  9. esp.osdebug(None)
  10.  
  11. import gc
  12. gc.collect()
  13.  
  14. import time
  15.  
  16. from machine import Pin
  17. led = Pin(2, Pin.OUT)
  18. led.value(1)
  19.  
  20. ssid = 'zkAP'
  21. password = 'passwd123'
  22.  
  23. ap = network.WLAN(network.AP_IF)
  24. ap.active(True)
  25. ap.config(essid=ssid, password=password)
  26.  
  27. while ap.active() == False:
  28.   pass
  29.  
  30. print('Connection successful')
  31. print(ap.ifconfig())
  32.  
  33. def web_page():
  34.   html = """<html><head><meta name="viewport" content="width=device-width, initial-scale=1"></head>
  35.   <body><h1>Led!</h1><a id="blik_button" href="/?led=blink">Blink</a></body></html>"""
  36.   return html
  37.  
  38. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  39. s.bind(('', 85))
  40. s.listen(5)
  41.  
  42. def blink_led():
  43.   led.value(0)
  44.   time.sleep(0.5)
  45.   led.value(1)
  46.  
  47. while True:
  48.   conn, addr = s.accept()
  49.   print('Got a connection from %s' % str(addr))
  50.   request = conn.recv(1024)
  51.   print('Content = %s' % str(request))
  52.   request = str(request)
  53.   blink = request.find('/?led=blink')
  54.   if blink != -1:
  55.     blink_led()
  56.   response = web_page()
  57.   conn.send('HTTP/1.1 200 OK\n')
  58.   conn.send('Content-Type: text/html\n')
  59.   conn.send('Connection: close\n\n')
  60.   conn.send(response)
  61.   conn.close()
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. BOTTTTTT
  70.  
  71. import requests
  72.  
  73. url = 'http://192.168.4.1:85/?led=blink'
  74. r = requests.get(url)
  75. r = requests.get(url)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top