Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthenning/dbd79d6659e026ef15ce17034f67af03 to your computer and use it in GitHub Desktop.
Save matthenning/dbd79d6659e026ef15ce17034f67af03 to your computer and use it in GitHub Desktop.
from bluepy import btle
from bluepy.btle import BTLEException, Scanner, DefaultDelegate
import sys, getopt
# Argument 1: Mac Address
# Argument 2: BT Scan timeout in seconds (optional, default 8)
# Example: python3 check_inkbird_ibsth1.py 50:51:a9:7d:94:3b 5
opts, args = getopt.getopt(sys.argv, "")
if len(args) > 2:
bttimeout = float(args[2])
else:
bttimeout = 8.0
scanner = Scanner()
scanner.clear()
scanner.start()
try:
scanner.process(timeout=bttimeout)
except:
e = sys.exc_info()[0]
results = scanner.getDevices()
for dev in results:
if dev.addr == args[1]:
for (adtype, desc, value) in dev.getScanData():
if adtype == 255:
humidity = "%2.2f" % (int(value[6:8]+value[4:6], 16)/100)
temperature = int(value[2:4]+value[:2], 16)
temperature_bits = 16
if temperature & (1 << (temperature_bits-1)):
temperature -= 1 << temperature_bits
temperature = "%2.2f" % (temperature / 100)
battery = str(int(value[14:16], 16))
print("Temperature: " + temperature + "°C, Humidity: " + humidity + "%, Battery: " + battery + "% |'temperature_celsius'=" + temperature + " 'humidity_percent'=" + humidity + " 'battery_percent'=" + battery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment