T.o.p.r.a.k
Decapat
- Katılım
- 27 Temmuz 2023
- Mesajlar
- 108
Daha fazla  
				
					
						
						
							
	
		
	
		
			
			
				
			
			
		
		
	- Cinsiyet
- Erkek
İyi akşamlar, Raspberry Pi Pico W ile bir Web Serveri oluşturup Pico'nun üstündeki dahili led, ısı sensörünü kullanacaktım fakat 4 farklı kaynaktaki kodları denememe rağmen Web Serveri bir türlü açılmıyor. Kodlar çalışıyor, konsolda bana bir IP veriliyor fakat o IP'yi Googleye yazdığım zaman açılmıyor. Yardım ederseniz çok makbule geçer. (Kullandığım IDE Thonny)
		
		
	
	
		
 
	
Boyalı bölgenin altındaki IP adresine bağlanamıyorum.
Kullandığım Kodlar:
	
	
	
	
	
		
	
		
			
		
		
	
				
			Boyalı bölgenin altındaki IP adresine bağlanamıyorum.
Kullandığım Kodlar:
		HTML:
	
	1.Dosya web_server.py:
import network
import socket
from time import sleep
import machine
ssid = '****'
password = '****'
def connect():
    #Connect to WLAN
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    wlan.connect(ssid, password)
    while wlan.isconnected() == False:
        print('Baglanti Bekleniyor...')
        sleep(1)
    ip = wlan.ifconfig()[0]
    print(f'Connected on {ip}')
    return ip
def open_socket(ip):
    # Open a socket
    address = (ip, 80)
    connection = socket.socket()
    connection.bind(address)
    connection.listen(1)
    return connection
def webpage(temperature, state):
    #Template HTML
    html = f"""
            <!DOCTYPE html>
            <html>
            <form action="./lighton">
            <input type="submit" value="Light on" />
            </form>
            <form action="./lightoff">
            <input type="submit" value="Light off" />
            </form>
            <p>LED is {state}</p>
            <p>Temperature is {temperature}</p>
            </body>
            </html>
            """
    return str(html)
def serve(connection):
    #Start a web server
    state = 'OFF'
    pico_led.off()
    temperature = 0
    while True:
        client = connection.accept()[0]
        request = client.recv(1024)
        request = str(request)
        try:
            request = request.split()[1]
        except IndexError:
            pass
        if request == '/lighton?':
            pico_led.on()
            state = 'ON'
        elif request =='/lightoff?':
            pico_led.off()
            state = 'OFF'
            temperature = pico_temp_sensor.temp
        html = webpage(temperature, state)
        client.send(html)
        client.close()
try:
    ip = connect()
    connection = open_socket(ip)
except KeyboardInterrupt:
    machine.reset()
2.Dosya index.html:
<!DOCTYPE html>
<html>
<body>
<form action="./lighton">
<input type="submit" value="Light on" />
</form>
<form action="./lightoff">
<input type="submit" value="Light off" />
</form>
<p>LED is {state}</p>
<p>Temperature is {temperature}</p>
</body>
</html> 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		