Advertisement
alexbergsland

DS18B20

Apr 7th, 2021
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 1.43 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. import os
  5. import glob
  6. import requests
  7. from w1thermsensor import W1ThermSensor
  8.  
  9. for sensor in W1ThermSensor.get_available_sensors():
  10.     print("Sensor %s has temperature %.2f" % (sensor.id, sensor.get_temperature()))
  11.     temp_round = round(sensor.get_temperature(),1)
  12.     if sensor.id == '00000938007e': #Hot
  13.         url = 'http://192.168.1.43:8080/json.htm?type=command&param=udevice&idx=10&nvalue=0&svalue=' + str(temp_round)
  14.     if sensor.id == '041754509cff': #2
  15.         url = 'http://192.168.1.43:8080/json.htm?type=command&param=udevice&idx=165&nvalue=0&svalue=' + str(temp_round)
  16.     if sensor.id == '00000a049960': #3
  17.         url = 'http://192.168.1.43:8080/json.htm?type=command&param=udevice&idx=166&nvalue=0&svalue=' + str(temp_round)
  18.     if sensor.id == '00000a03a9e7': #4
  19.         url = 'http://192.168.1.43:8080/json.htm?type=command&param=udevice&idx=167&nvalue=0&svalue=' + str(temp_round)
  20.  
  21.     try:
  22.         print (url)
  23.         r = requests.get(url)
  24.         page = r.content
  25.         print (page)
  26.     except  requests.exceptions.HTTPError as errh:
  27.         print ("Http Error:",errh)
  28.     except requests.exceptions.ConnectionError as errc:
  29.         print ("Error Connecting:",errc)
  30.     except requests.exceptions.Timeout as errt:
  31.         print ("Timeout Error:",errt)
  32.     except requests.exceptions.RequestException as err:
  33.         print ("OOps: Something Else",err)
  34.  
  35.  
  36.  
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement