import network
import urequests
import json
from machine import I2C, Pin
from i2c_lcd import I2cLcd
from machine import Pin
from time import sleep
import dht
sensor = dht.DHT22(Pin(15))
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
sHum = str(hum)
sTemp = str(temp)
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect("Wokwi-GUEST", "")
while not wlan.isconnected():
pass
headers = {"Authorization": "Bearer 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", "Content-Type": "application/json",}
data = '{"model": "gpt-3.5-turbo-1106","messages":[{"role": "user", "content": "Tell me the thermic sensation temperature in celcius with a humidity percentage of ' + sHum + '% and temperature of ' + sTemp + ' Celcius, respond in 30 characters"}],"temperature": 0}'
URL = "https://api.openai.com/v1/chat/completions"
r = urequests.post(URL, headers=headers, data=data)
person_dict = json.loads(r.text)
print(person_dict['choices'][0]['message']['content'])
AddressOfLcd = 0x27
i2c = I2C(scl=Pin(22), sda=Pin(21), freq=400000) # connect scl to GPIO 22, sda to GPIO 21
lcd = I2cLcd(i2c, AddressOfLcd, 2, 16)
lcd.move_to(1,0)
lcd.putstr(person_dict['choices'][0]['message']['content'])