Bilgiler > DS18B20 Sıcaklık Ölçüp Kaydetme Programı-Micropython ESP8266
DS18B20 Sıcaklık Ölçüp Kaydetme Programı-Micropython ESP8266
#Hava DUrumu istasyonu
from time import sleep
import machine
machine.freq() # get the current frequency of the CPU
machine.freq(160000000) # set the CPU frequency to 160 MHz
import esp
#esp.osdebug(None) # turn off vendor O/S debugging messages
esp.osdebug(0) # redirect vendor O/S debugging messages to UART(0)
#_______DS18B20'den sicaklik okuma
from machine import Pin
import time, ds18x20
import onewire
ow=onewire.OneWire(Pin(14))
def olc():
ds=ds18x20.DS18X20(ow)
roms=ds.scan()
ds.convert_temp()
for rom in roms:
var=ds.read_temp(rom)
print(var)
return(var)
#______Internet sitesine sicaklik post etme
from urllib import urequest
def icerik_yazdir(var):
response = urequest.urlopen("http://www.temelelektronik.inf...?sensor=3&temp={}".format(var))
response.close()
# set the correct charset below
#page_source = response.read().decode('Windows-1254')
#sleep(10)
print('siteye veri gonderildi')
#______ESP'yi internete baglama
import network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect('HUAWEI P smart 2019', '12345687')
if wlan.isconnected():
print('network config:', wlan.ifconfig())
#______Ana program
from machine import Pin
led=Pin(2,Pin.OUT)
while True:
if wlan.isconnected():
try:
var=olc()
icerik_yazdir(var)
led.value(1)#hata yoksa mavi led'i söndür
sleep(5)
except Exception as e:
led.value(0)
print(e)#hata varsa mavi led'i yak
sleep(5)
sleep(1200)
***