Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import blescan, sys, requests, time, OpenSSL
- import bluetooth._bluetooth as bluez
- # public key roM51Nwag0IgYROoJ99b
- url = "https://data.sparkfun.com/input/roM51Nwag0IgYROoJ99b?private_key=aaaaaaaaa&gravity=%.3f&temperature=%.1f"
- dev_id = 0
- try:
- sock = bluez.hci_open_dev(dev_id)
- print "ble thread started"
- except:
- print "error accessing bluetooth device..."
- sys.exit(1)
- blescan.hci_le_set_scan_parameters(sock)
- blescan.hci_enable_le_scan(sock)
- while True:
- returnedList = blescan.parse_events(sock, 10)
- for beacon in returnedList:
- b = beacon.split(",") #88:c2:55:ac:23:6a
- if (b[0][0:5] != '88:c2'):
- continue
- sg = float(b[3])/1000
- temperature = (float(b[2])-32)/1.8
- if (sg > 0.9 and sg < 1.2):
- try:
- r = requests.get(url % (sg, temperature))
- except OpenSSL.SSL.ZeroReturnError:
- print "Whoops, ZeroResultError, sparkfun is forked."
- except:
- print "Whoops, some error"
- print "%d: Temperature: %.1f, Gravity: %.3f (%s)" % (r.status_code, temperature, sg, b[3])
- break
- time.sleep(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement