#Oled Display ansteuern
from machine import Pin, I2C
import ssd1306
from time import sleep as delay
import dht
from machine import Pin
from neopixel import NeoPixel
import network # Für WLAN Object
from umqtt.robust import MQTTClient #Für den MQTT Client
oled_width = 128
oled_height = 64
i2c = I2C(0, scl = Pin(22), sda = Pin(21))
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
#Wifi-connection
oled.text('Connecting...', 10, 0)
oled.show()
#WLAN Object
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True) #activate WLAN
sta_if.connect('Wokwi-GUEST','')
i=0
while not sta_if.isconnected():
print(".", end = "")
oled.text('.', i, 10)
oled.show()
delay(0.1)
i=i+5
oled.text('WIFI connected', 10, 25)
oled.show()
#MQTT Setup
SERVER = "industrial.api.ubidots.com"
port = 1883
client_name = "Weatherstation24"
topic = b"/v1.6/devices/weatherstation24"
token = "BBUS-jbYNhURhIMAybu4zwgIVqmNJ0mUjmA"
#MQTT client Object:
client = MQTTClient(client_name, SERVER, port, user = token, password = token)
oled.text('MQTT connected', 10, 50)
oled.show()