-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholed_weather.py
60 lines (41 loc) · 1.08 KB
/
oled_weather.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import network
import time
import json
import urequests
import machine
import ssd1306
import dht
sta = network.WLAN(network.STA_IF)
sta.active(True)
sta.connect("ssid", "password")
#sta.ifconfig()
#print(ip)
sensor = dht.DHT22(machine.Pin(2))
#sensor.measure()
time.sleep(3)
delay = 0.5
#mengambil data dari accuweather
r = urequests.get("http://apidev.accuweather.com/currentconditions/v1/202242.json?language=en&apikey=hoArfRosT1215").json()
suhu = r[0]['Temperature']['Metric']['Value']
waktu = r[0]['LocalObservationDateTime']
jam = waktu[11] + waktu[12] + waktu[13] + waktu[14] + waktu[15]
i2c = machine.I2C(machine.Pin(5), machine.Pin(4))
oled = ssd1306.SSD1306_I2C(64, 48, i2c)
oled.fill(1)
oled.show()
time.sleep(2)
def monitor():
sensor.measure()
kelembaban = sensor.humidity()
time.sleep(2)
oled.fill(0)
oled.text('cuaca', 0, 0)
oled.text(str(suhu), 0, 10)
oled.text(jam, 0, 20)
oled.text(str(kelembaban), 0, 40)
oled.show()
print(kelembaban)
#time.sleep(0.5)
#for i in range(1,20):
while True:
monitor()