Merge branch 'develop' into 'master'
Attempt to hotfix coffee scale crash See merge request !41
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
from . import mqtt
|
from . import mqtt
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
logger.debug('Starting mqtt loop')
|
||||||
mqtt.client.loop_start()
|
mqtt.client.loop_start()
|
||||||
|
|||||||
+11
-2
@@ -3,6 +3,8 @@ import logging
|
|||||||
import datetime
|
import datetime
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
|
||||||
|
MQTT_HOST = "mqtt.sik.party"
|
||||||
|
|
||||||
TOPIC_TEMP = "sik/kiltahuone/kahvivaaka/temperature"
|
TOPIC_TEMP = "sik/kiltahuone/kahvivaaka/temperature"
|
||||||
TOPIC_WEIGHT = "sik/kiltahuone/kahvivaaka/weight"
|
TOPIC_WEIGHT = "sik/kiltahuone/kahvivaaka/weight"
|
||||||
|
|
||||||
@@ -31,10 +33,10 @@ def on_message(client, userdata, msg):
|
|||||||
|
|
||||||
|
|
||||||
def on_disconnect(client, userdata, rc):
|
def on_disconnect(client, userdata, rc):
|
||||||
client.loop_stop(force=False)
|
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
print("Unexpected disconnection.")
|
print("Unexpected disconnection.")
|
||||||
else:
|
else:
|
||||||
|
client.loop_stop(force=False)
|
||||||
print("Disconnected")
|
print("Disconnected")
|
||||||
|
|
||||||
|
|
||||||
@@ -62,4 +64,11 @@ client.on_connect = on_connect
|
|||||||
client.on_message = on_message
|
client.on_message = on_message
|
||||||
client.on_disconnect = on_disconnect
|
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))
|
||||||
|
|||||||
@@ -3,9 +3,15 @@ from django.http import JsonResponse
|
|||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
from .mqtt import get_latest
|
from .mqtt import get_latest
|
||||||
|
|
||||||
import coffee_scale.mqtt # somehow this is needed
|
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):
|
def get_cups_from_weight(weight):
|
||||||
if not weight:
|
if not weight:
|
||||||
@@ -21,7 +27,7 @@ def get_cups_from_weight(weight):
|
|||||||
if cups > 10:
|
if cups > 10:
|
||||||
cups = 10
|
cups = 10
|
||||||
|
|
||||||
print("cups: ", cups, "weight: ", weight)
|
logger.debug("cups: {}, weight: {}".format(cups, weight))
|
||||||
return cups
|
return cups
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user