Jura-Python-BT
Code for control and payment system of Jura Coffee Machine
|
Functions | |
def | setupBuzzer (pin) |
Setup buzzer. | |
def | beep (duration) |
Make a beep sound. | |
def | lockUnlockMachine (code, lock_status, unlock_code="77e1") |
Lock or unlock the machine. | |
def | scanCard () |
Scan for RFID tag. | |
def | getAlerts (status) |
Get alerts from the decoded machine status and convert it to the corresponding alerts (if any) If the corresponding bit is not set, the alert is not active. | |
def | end_read (signal, frame) |
End the program Runs when Ctrl+C is pressed. | |
def | read_statistics () |
Read the statistics from the machine. | |
Variables | |
json | CHARACTERISTICS = json.load(open("/home/pi/Jura-Python-BT/data/uuids_handles.json"))["characteristics"] |
Global Constants The dictionary of UUIDs and handles of the bluetooth characteristics. | |
json | ALERTS = json.load(open("/home/pi/Jura-Python-BT/data/alerts.json"))["alerts"] |
The dictionary of alerts from machine status. | |
json | PRODUCTS = json.load(open("/home/pi/Jura-Python-BT/data/products.json"))["products"] |
The dictionary of products the machine can make. | |
json | PRICECOFFEE = json.load(open("/home/pi/Jura-Python-BT/data/prices.json"))["pricecoffee"] |
The dictionary of prices of the products. | |
int | BUZZER_PIN = 7 |
The pin for the buzzer. | |
os | DEVICE = os.getenv("DEVICE") |
Load the environment variables from .env file. | |
os | MASTERCARD1 = os.getenv("MASTER_CARD_1") |
The UID of master card 1 read from .env file. | |
os | MASTERCARD2 = os.getenv("MASTER_CARD_2") |
The UID of master card 2 read from .env file. | |
db_connect | DB = db_connect() |
The open database connection. | |
BtEncoder | BtEncoder = BtEncoder() |
The instance of the BtEncoder class. | |
JuraEncoder | JuraEncoder = JuraEncoder() |
The instance of the JuraEncoder class. | |
MFRC522 | RFIDREADER = MFRC522.MFRC522() |
The instance of the RFID reader class | |
filename | |
level | |
format | |
datefmt | |
lcddriver | lcd = lcddriver.lcd() |
Initialize LCD. | |
child = pexpect.spawn("gatttool -b " + DEVICE + " -I -t random") | |
Get all necessary variables from setup.py -> check file for more information. | |
keep_alive_code | |
locking_code | |
unlock_code | |
KEY_DEC | |
all_statistics | |
initial_time | |
CURRENT_STATISTICS = decoded | |
db_connect | c = DB.cursor() |
int | emergency_unlock = 0 |
else : | |
str | lock_status = "unlocked" |
try : | |
serial | port = serial.Serial("/dev/serial0", baudrate = 9600, timeout = 1.0) |
except : | |
bool | buttonPress = False |
The variables used in the main loop. | |
bool | continue_reading = True |
str | lastSeen = "" |
int | counter = 0 |
int | disp_init = 1 |
int | payment_to_date = 1 |
str | client_to_pay = "" |
int | admin_locked = 0 |
int | admin_prod = 0 |
int | total_prod = 0 |
int | payed_prod = 0 |
int | current_time = int(time.time() - initial_time) |
int | hour = int(time.strftime("%H")) |
int | minute = int(time.strftime("%M")) |
int | second = int(time.strftime("%S")) |
child | data = child.readline() |
BtEncoder | decoded = BtEncoder.encDecBytes(data, KEY_DEC) |
timeout | |
def | uid_str = scanCard() |
def | prod = read_statistics() |
bool | product_made = False |
get_value | value = get_value(DB, uid_str) |
str | value_str = str("Balance: " + str('%.2f' % value) + " EUR") |
get_name | lastName = get_name(DB, uid_str) |
get_vorname | preName = get_vorname(DB, uid_str) |
str | welStr = str("Hello " + preName) |
str | msgStr3 = str("Hold for 2s please ") |
str | msgStr4 = str("Chip below ") |
time | intial_time_2 = time.time() |
int | chosen = 0 |
int | started = 0 |
int | over = 0 |
int | time_total = int(time.time() - intial_time_2) |
list | data2 = [int(x, 16) for x in data.split()] |
list | as_hex = ["%02x" % d for d in decoded] |
json | price_product = PRICECOFFEE[product_made] |
int | value_new = 0 |
str | msgStr1 = str(product_made + " was made!") |
str | msgStr2 = str(" Happy betty :) ") |
def blue.beep | ( | duration | ) |
Make a beep sound.
duration | The time in ms of the beep. |
def blue.end_read | ( | signal, | |
frame | |||
) |
End the program Runs when Ctrl+C is pressed.
def blue.getAlerts | ( | status | ) |
Get alerts from the decoded machine status and convert it to the corresponding alerts (if any) If the corresponding bit is not set, the alert is not active.
status | machine status |
def blue.lockUnlockMachine | ( | code, | |
lock_status, | |||
unlock_code = "77e1" |
|||
) |
Lock or unlock the machine.
code | The code to unlock the machine. |
lock_status | The current status of the machine. |
unlock_code | The code to unlock the machine (default 77e1). |
def blue.read_statistics | ( | ) |
Read the statistics from the machine.
def blue.scanCard | ( | ) |
Scan for RFID tag.
def blue.setupBuzzer | ( | pin | ) |
Setup buzzer.
pin | The pin number of the buzzer. |
int blue.admin_locked = 0 |
int blue.admin_prod = 0 |
json blue.ALERTS = json.load(open("/home/pi/Jura-Python-BT/data/alerts.json"))["alerts"] |
The dictionary of alerts from machine status.
blue.all_statistics |
list blue.as_hex = ["%02x" % d for d in decoded] |
The instance of the BtEncoder class.
bool blue.buttonPress = False |
The variables used in the main loop.
int blue.BUZZER_PIN = 7 |
The pin for the buzzer.
db_connect blue.c = DB.cursor() |
json blue.CHARACTERISTICS = json.load(open("/home/pi/Jura-Python-BT/data/uuids_handles.json"))["characteristics"] |
Global Constants The dictionary of UUIDs and handles of the bluetooth characteristics.
pexpect blue.child = pexpect.spawn("gatttool -b " + DEVICE + " -I -t random") |
Get all necessary variables from setup.py -> check file for more information.
int blue.chosen = 0 |
str blue.client_to_pay = "" |
bool blue.continue_reading = True |
int blue.counter = 0 |
int blue.current_time = int(time.time() - initial_time) |
list blue.data = child.readline() |
list blue.data2 = [int(x, 16) for x in data.split()] |
blue.datefmt |
db_connect blue.DB = db_connect() |
The open database connection.
BtEncoder blue.decoded = BtEncoder.encDecBytes(data, KEY_DEC) |
os blue.DEVICE = os.getenv("DEVICE") |
Load the environment variables from .env file.
The BlackBetty2 mac address read from .env file
int blue.disp_init = 1 |
blue.else : |
int blue.emergency_unlock = 0 |
blue.except : |
blue.filename |
blue.format |
int blue.hour = int(time.strftime("%H")) |
blue.initial_time |
time blue.intial_time_2 = time.time() |
The instance of the JuraEncoder class.
blue.keep_alive_code |
blue.KEY_DEC |
str blue.lastSeen = "" |
lcddriver blue.lcd = lcddriver.lcd() |
Initialize LCD.
blue.level |
zockUnlockMachine blue.lock_status = "unlocked" |
blue.locking_code |
os blue.MASTERCARD1 = os.getenv("MASTER_CARD_1") |
The UID of master card 1 read from .env file.
os blue.MASTERCARD2 = os.getenv("MASTER_CARD_2") |
The UID of master card 2 read from .env file.
int blue.minute = int(time.strftime("%M")) |
str blue.msgStr1 = str(product_made + " was made!") |
str blue.msgStr2 = str(" Happy betty :) ") |
str blue.msgStr3 = str("Hold for 2s please ") |
str blue.msgStr4 = str("Chip below ") |
int blue.over = 0 |
int blue.payed_prod = 0 |
int blue.payment_to_date = 1 |
serial blue.port = serial.Serial("/dev/serial0", baudrate = 9600, timeout = 1.0) |
json blue.price_product = PRICECOFFEE[product_made] |
json blue.PRICECOFFEE = json.load(open("/home/pi/Jura-Python-BT/data/prices.json"))["pricecoffee"] |
The dictionary of prices of the products.
def blue.prod = read_statistics() |
bool blue.product_made = False |
json blue.PRODUCTS = json.load(open("/home/pi/Jura-Python-BT/data/products.json"))["products"] |
The dictionary of products the machine can make.
MFRC522 blue.RFIDREADER = MFRC522.MFRC522() |
The instance of the RFID reader class
int blue.second = int(time.strftime("%S")) |
int blue.started = 0 |
int blue.time_total = int(time.time() - intial_time_2) |
blue.timeout |
int blue.total_prod = 0 |
blue.try : |
def blue.uid_str = scanCard() |
blue.unlock_code |
get_value blue.value_new = 0 |
str blue.value_str = str("Balance: " + str('%.2f' % value) + " EUR") |
str blue.welStr = str("Hello " + preName) |