import uPyConfig hw = uPyConfig.esp8266(variant='heltec') #print family, variant and IP address (using oled, if available on-board) import init_sample init_sample.init_sample(hw) # Main app #from uPySensor import BME280, LM75A, SHT21 #bme280=BME280(hw.i2c.bus) #lm75a =LM75A(hw.i2c.bus) #sht21 =SHT21(hw.i2c.bus) from uPySensor import DS18B20 hw.owc.__init__(hw.owc, 12) ds18b20=DS18B20(hw.owc.bus) #fallback microserver #commented out to use tinyWebServer instead #def header(): return "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nServer: horny\r\n\r\n" #import socket #wssock=socket.getaddrinfo("0.0.0.0",80)[0][-1] #wss=socket.socket() #wss.bind(wssock) #wss.listen(1) # #print("Server started on 0.0.0.0:80") # ##main loop #while True: # wcl, wcsock = wss.accept() # print("Client connected") # wclfh = wcl.makefile('rwb', 0) # jsn='' # while True: # wcline = wclfh.readline() # if not wcline or wcline == b'\r\n': break # wcline=wcline.split(b' ') # if len(wcline) == 3 and wcline[2].startswith('HTTP'): # if wcline[0] != b'GET': wcl.close() # elif wcline[1] == b'/': jsn='{"result":"error","message":"use /bme280, /lm75a or /sht21 for sensor readings"}' # elif wcline[1] == b'/sht21': jsn=_sht21 () # elif wcline[1] == b'/lm75a': jsn=_lm75a () # elif wcline[1] == b'/bme280': jsn=_bme280() # wcl.send(header()+jsn) # wcl.close() import tinyWebServer ws = tinyWebServer.tinyWebServer(verbose=True) def _get(request): return ws.respond( '{"error":"sensors available on /ds18b20"}', status=404) def _get_ds18b20(request): return ws.respond( '{"temperature":"%0.3f"}' % ds18b20.read_tempC() ) ws.add_route('/', _get) ws.add_route('/ds18b20', _get_ds18b20) ws.start()