Jura-Python-BT
Code for control and payment system of Jura Coffee Machine
Loading...
Searching...
No Matches
Functions | Variables
blue Namespace Reference

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 :) ")
 

Function Documentation

◆ beep()

def blue.beep (   duration)

Make a beep sound.

Parameters
durationThe time in ms of the beep.

◆ end_read()

def blue.end_read (   signal,
  frame 
)

End the program Runs when Ctrl+C is pressed.

◆ getAlerts()

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.

Parameters
statusmachine status
Returns
list of alerts according to ..data/alerts.json

◆ lockUnlockMachine()

def blue.lockUnlockMachine (   code,
  lock_status,
  unlock_code = "77e1" 
)

Lock or unlock the machine.

Parameters
codeThe code to unlock the machine.
lock_statusThe current status of the machine.
unlock_codeThe code to unlock the machine (default 77e1).
Returns
lock_status The new status of the machine ("locked" or "unlocked")

◆ read_statistics()

def blue.read_statistics ( )

Read the statistics from the machine.

Returns
list of statistics

◆ scanCard()

def blue.scanCard ( )

Scan for RFID tag.

Returns
uid_str The UID of the tag or "0" if no tag is found

◆ setupBuzzer()

def blue.setupBuzzer (   pin)

Setup buzzer.

Parameters
pinThe pin number of the buzzer.

Variable Documentation

◆ admin_locked

int blue.admin_locked = 0

◆ admin_prod

int blue.admin_prod = 0

◆ ALERTS

json blue.ALERTS = json.load(open("/home/pi/Jura-Python-BT/data/alerts.json"))["alerts"]

The dictionary of alerts from machine status.

◆ all_statistics

blue.all_statistics

◆ as_hex

list blue.as_hex = ["%02x" % d for d in decoded]

◆ BtEncoder

The instance of the BtEncoder class.

◆ buttonPress

bool blue.buttonPress = False

The variables used in the main loop.

◆ BUZZER_PIN

int blue.BUZZER_PIN = 7

The pin for the buzzer.

◆ c

db_connect blue.c = DB.cursor()

◆ CHARACTERISTICS

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.

◆ child

pexpect blue.child = pexpect.spawn("gatttool -b " + DEVICE + " -I -t random")

Get all necessary variables from setup.py -> check file for more information.

◆ chosen

int blue.chosen = 0

◆ client_to_pay

str blue.client_to_pay = ""

◆ continue_reading

bool blue.continue_reading = True

◆ counter

int blue.counter = 0

◆ CURRENT_STATISTICS

BtEncoder blue.CURRENT_STATISTICS = decoded

◆ current_time

int blue.current_time = int(time.time() - initial_time)

◆ data

list blue.data = child.readline()

◆ data2

list blue.data2 = [int(x, 16) for x in data.split()]

◆ datefmt

blue.datefmt

◆ DB

db_connect blue.DB = db_connect()

The open database connection.

◆ decoded

◆ DEVICE

os blue.DEVICE = os.getenv("DEVICE")

Load the environment variables from .env file.

The BlackBetty2 mac address read from .env file

◆ disp_init

int blue.disp_init = 1

◆ else

blue.else :

◆ emergency_unlock

int blue.emergency_unlock = 0

◆ except

blue.except :

◆ filename

blue.filename

◆ format

blue.format

◆ hour

int blue.hour = int(time.strftime("%H"))

◆ initial_time

blue.initial_time

◆ intial_time_2

time blue.intial_time_2 = time.time()

◆ JuraEncoder

The instance of the JuraEncoder class.

◆ keep_alive_code

blue.keep_alive_code

◆ KEY_DEC

blue.KEY_DEC

◆ lastName

get_name blue.lastName = get_name(DB, uid_str)

◆ lastSeen

str blue.lastSeen = ""

◆ lcd

lcddriver blue.lcd = lcddriver.lcd()

Initialize LCD.

◆ level

blue.level

◆ lock_status

zockUnlockMachine blue.lock_status = "unlocked"

◆ locking_code

blue.locking_code

◆ MASTERCARD1

os blue.MASTERCARD1 = os.getenv("MASTER_CARD_1")

The UID of master card 1 read from .env file.

◆ MASTERCARD2

os blue.MASTERCARD2 = os.getenv("MASTER_CARD_2")

The UID of master card 2 read from .env file.

◆ minute

int blue.minute = int(time.strftime("%M"))

◆ msgStr1

str blue.msgStr1 = str(product_made + " was made!")

◆ msgStr2

str blue.msgStr2 = str(" Happy betty :) ")

◆ msgStr3

str blue.msgStr3 = str("Hold for 2s please ")

◆ msgStr4

str blue.msgStr4 = str("Chip below ")

◆ over

int blue.over = 0

◆ payed_prod

int blue.payed_prod = 0

◆ payment_to_date

int blue.payment_to_date = 1

◆ port

serial blue.port = serial.Serial("/dev/serial0", baudrate = 9600, timeout = 1.0)

◆ preName

get_vorname blue.preName = get_vorname(DB, uid_str)

◆ price_product

json blue.price_product = PRICECOFFEE[product_made]

◆ PRICECOFFEE

json blue.PRICECOFFEE = json.load(open("/home/pi/Jura-Python-BT/data/prices.json"))["pricecoffee"]

The dictionary of prices of the products.

◆ prod

def blue.prod = read_statistics()

◆ product_made

bool blue.product_made = False

◆ PRODUCTS

json blue.PRODUCTS = json.load(open("/home/pi/Jura-Python-BT/data/products.json"))["products"]

The dictionary of products the machine can make.

◆ RFIDREADER

MFRC522 blue.RFIDREADER = MFRC522.MFRC522()

The instance of the RFID reader class

◆ second

int blue.second = int(time.strftime("%S"))

◆ started

int blue.started = 0

◆ time_total

int blue.time_total = int(time.time() - intial_time_2)

◆ timeout

blue.timeout

◆ total_prod

int blue.total_prod = 0

◆ try

blue.try :

◆ uid_str

def blue.uid_str = scanCard()

◆ unlock_code

blue.unlock_code

◆ value

get_value blue.value = get_value(DB, uid_str)

◆ value_new

get_value blue.value_new = 0

◆ value_str

str blue.value_str = str("Balance: " + str('%.2f' % value) + " EUR")

◆ welStr

str blue.welStr = str("Hello " + preName)