Merge branch 'develop' into 'master'

Attempt to hotfix coffee scale crash

See merge request !41
This commit is contained in:
Jan Tuomi
2017-09-19 17:02:36 +03:00
3 changed files with 22 additions and 4 deletions
+3
View File
@@ -1,3 +1,6 @@
from . import mqtt
import logging
logger = logging.getLogger(__name__)
logger.debug('Starting mqtt loop')
mqtt.client.loop_start()
+11 -2
View File
@@ -3,6 +3,8 @@ import logging
import datetime
from collections import deque
MQTT_HOST = "mqtt.sik.party"
TOPIC_TEMP = "sik/kiltahuone/kahvivaaka/temperature"
TOPIC_WEIGHT = "sik/kiltahuone/kahvivaaka/weight"
@@ -31,10 +33,10 @@ def on_message(client, userdata, msg):
def on_disconnect(client, userdata, rc):
client.loop_stop(force=False)
if rc != 0:
print("Unexpected disconnection.")
else:
client.loop_stop(force=False)
print("Disconnected")
@@ -62,4 +64,11 @@ client.on_connect = on_connect
client.on_message = on_message
client.on_disconnect = on_disconnect
client.connect("mqtt.sik.party", 1883, 60)
try:
logging.info('Connecting to MQTT at {}...'.format(MQTT_HOST))
client.connect_async(MQTT_HOST, 1883, 60)
logging.info('Connected successfully to MQTT.')
except Exception as ex:
logging.error(ex)
logging.error('Failed to connect to MQTT at {}'.format(MQTT_HOST))
+8 -2
View File
@@ -3,9 +3,15 @@ from django.http import JsonResponse
import datetime
from .mqtt import get_latest
import coffee_scale.mqtt # somehow this is needed
import logging
from django.conf import settings
logger = logging.getLogger(__name__)
logging.basicConfig(format='[%(levelname)s]%(asctime)s %(message)s',
level=settings.LOGGERLEVEL, filename=settings.LOGPATH)
def get_cups_from_weight(weight):
if not weight:
@@ -21,7 +27,7 @@ def get_cups_from_weight(weight):
if cups > 10:
cups = 10
print("cups: ", cups, "weight: ", weight)
logger.debug("cups: {}, weight: {}".format(cups, weight))
return cups