Rick Kuhlman
Published © MIT

Beer Brew with Cloud Monitoring: Tilt + Pi + Initial State

Watch your homebrew fermentation from anywhere and get a text when it's ready using the Tilt Hydrometer, Raspberry Pi, and Initial State.

IntermediateFull instructions provided1 hour2,794
Beer Brew with Cloud Monitoring: Tilt + Pi + Initial State

Things used in this project

Story

Read more

Code

Modified Pytilt.py

Python
This will be the final code for pytilt.py after modifying the base Repo
import sys
import datetime
import time

import bluetooth._bluetooth as bluez
from ISStreamer.Streamer import Streamer

import blescan


TILTS = {
        'a495bb10c5b14b44b5121370f02d74de': 'Red',
        'a495bb20c5b14b44b5121370f02d74de': 'Green',
        'a495bb30c5b14b44b5121370f02d74de': 'Black',
        'a495bb40c5b14b44b5121370f02d74de': 'Purple',
        'a495bb50c5b14b44b5121370f02d74de': 'Orange',
        'a495bb60c5b14b44b5121370f02d74de': 'Blue',
        'a495bb70c5b14b44b5121370f02d74de': 'Yellow',
        'a495bb80c5b14b44b5121370f02d74de': 'Pink',
}


def distinct(objects):
    seen = set()
    unique = []
    for obj in objects:
        if obj['uuid'] not in seen:
            unique.append(obj)
            seen.add(obj['uuid'])
    return unique


def to_celsius(fahrenheit):
    return round((fahrenheit - 32.0) / 1.8, 2)


def monitor_tilt():
    streamer = Streamer(bucket_name="Beer Dashboard", bucket_key="Q6VBB6453YGA", access_key="ist_RGs3sp9k6OsM77HqeYBLMysALfrEJ4et")
    temperature_buffer = []
    gravity_buffer = []
    while True:
        beacons = distinct(blescan.parse_events(sock, 100))
	print (len(beacons))
	for beacon in beacons:
        if beacon['uuid'] in TILTS.keys():
		   temperature_buffer.append(beacon['major'])
		   gravity_buffer.append(beacon['minor'])
		if len(temperature_buffer) >= 10:
			temperature_average = round(float(sum(temperature_buffer))/float(len(temperature_buffer)),3)
			gravity_average = round(float(sum(gravity_buffer))/float(len(gravity_buffer)),3)
			print "Temp Avg:"
			print temperature_average
			print "Gravity Avg:"
			print gravity_average
			streamer.log("Temperature", temperature_average)
			streamer.log("Gravity", gravity_average)
			del temperature_buffer[:]
			del gravity_buffer[:]
	time.sleep(1)


if __name__ == '__main__':
    dev_id = 0
    try:
        sock = bluez.hci_open_dev(dev_id)
        print('Starting pytilt logger')
    except:
        print('error accessing bluetooth device...')
        sys.exit(1)

    blescan.hci_le_set_scan_parameters(sock)
    blescan.hci_enable_le_scan(sock)
    monitor_tilt()

Pytilt base repo

This is the base Repo used in this tutorial

Initial State Python Streamer

This will be installed to send data easily to Initial State.

Credits

Rick Kuhlman

Rick Kuhlman

2 projects โ€ข 2 followers

Comments