0

Good evening, i'm writing a code for a school project where we have to create our own web server using a raspberry pi pico W while connected to the electric outlet and directing anyone who enters the IP to a web page i created with microdot that shows Time,Date,Pico's Temperature and client IP. So far i've been doing everything but i cannot implement a code where i can see the IP of a client who's visiting my page.

i've been trying a method that is shown in a video i found but when i do that i get an error saying that the server is already in use or something like that.

i've also got an issue with the clock of my raspberry, when i use it while plugged on my pc the localtime is shown correctly but somehow when i used as its plugged in the elecric outlet the time just starts from 00:00 and the date is wrong

here's my code:

from microdot import Microdot, Response, Request
from microdot_utemplate import render_template
import time
import temperatura_lib
import machine
import socket
import boot_oled_debug as boot

app = Microdot()
Response.default_content_type = 'text/html'



#apri il server alle connessioni

@app.route("/",methods=['GET'])
def index(req):
    #calcolo la temperatura pico
    val= machine.ADC(4)
    steps = val.read_u16()
    coeff_conv= 3.3/(65535)
    vin= steps*coeff_conv
    farenheit= vin*100
    
    
    #assegno le variabili che sostituiranno i campi nella pagina html
    titolo= "ESAME FINALE LIVELLO 1"
    tempo = time.localtime()
    ora= ':'.join([str(tempo[3]),str(tempo[4]),str(tempo[5])]) #time
    data= '-'.join([str(tempo[2]),str(tempo[1]),str(tempo[0])]) #date
    sistema = 'RASPBERRY PI PICO W'
    temp = str(round(temperatura_lib.C_F(farenheit),0)) + '^C' 
    
    
    return render_template('finale.html',titolo=titolo,sistema=sistema, ora=ora, data=data, temp=temp)
    

    
#apro la connessione a tutti
if __name__ == "__main__":
    boot
    app.run(host='0.0.0.0', port=80, debug = True)
    

any help would be greatly appreciated, Thanks

tried to use socket accept before opening the server but this ended up giving me an error whenever i tried to start a server

0 Answers0