# Wireless Communication using Access Point Mode of RPi Pico W
# Libraries
import machine
import network
import socket
import time # same as utime library
# Create an Access Point
ssid = 'BUILDING_MANAGEMENT_SYSTEM_1' #Set access point name. you can change this name.
password = '12345678' #Set your access point password. You can use your own password
ap = network.WLAN(network.AP_IF)
ap.config(essid=ssid, password=password)
ap.active(True) # Activate the access point
while ap.active() == False:
pass
print('Connection is successful')
print(ap.ifconfig()) # this line will print the IP address of the Pico board
# Create a socket server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(5) # maximum number of requests that can be queued
# create a web page
def web_page():
html = """
<!DOCTYPE html>
<html>
<body>
<p>Welcome to my web page!</p>
</body>
</html>
"""
return html
#@brief Gets values from the specifed sensor
#@param sensor specified eg. adc = machine.ADC()
#@return the value of the sensor (float)
def Get_R_Value(adc, Resistance_known):
Vin = 3.3
adc_value = adc.read_u16()
Vout = (Vin / 65535) * adc_value
return (Resistance_known * (Vin - Vout) / Vout)
#put ts in a while loop
def read_ambient(machine):
min_resistance =
if(Get_R_Value(machine) > min)
return 1
return 0
# Response when connection received
#Update so this is continuly checked while other code runs
while True:
conn, addr = s.accept()
print('Got a connection from %s' % str(addr))
request = conn.recv(1024)
response = web_page() # indicate the response when connection is received
conn.send("HTTP/1.1 200 OK\n")
conn.send("Content-Type: text/html\n")
conn.send("Connection: close\n\n")
conn.sendall(response)
conn.close()
# request = str(request)
# print('Content = %s' % request)
Inwards
Outwards