def web_page(): bme = BME680_I2C(i2c=i2c) temp = str(round(bme.temperature, 2)) + ' C' hum = str(round(bme.humidity, 2)) + ' %' pres = str(round(bme.pressure, 2)) + ' hPa' gas = str(round(bme.gas/1000, 2)) + ' KOhms' html = """ MicroPython BME680 Web Server

MicroPython BME680 WEB SERVER

Temp. Celsius

""" + temp+ """

Humidity

""" + hum + """

PRESSURE

""" + pres +"""

Gas

""" + gas + """

""" return html s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('', 80)) s.listen(5) while True: try: if gc.mem_free() < 102000: gc.collect() conn, addr = s.accept() conn.settimeout(3.0) print('Got a connection from %s' % str(addr)) request = conn.recv(1024) conn.settimeout(None) request = str(request) print('Content = %s' % request) response = web_page() 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() except OSError as e: conn.close() print('Connection closed')