Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
863644fa56
|
|||
41ea343be2
|
|||
f8f9449c99
|
|||
ab35b815fb
|
|||
ec3fb5c72c
|
|||
9da6eab743
|
@ -28,7 +28,7 @@ dockerize:
|
|||||||
- tags
|
- tags
|
||||||
variables:
|
variables:
|
||||||
GIT_STRATEGY: none
|
GIT_STRATEGY: none
|
||||||
CONTAINER_NAME: level-preprocessor
|
CONTAINER_NAME: cem-preprocessor
|
||||||
script:
|
script:
|
||||||
- docker stop $CONTAINER_NAME || echo "container not running, never mind"
|
- docker stop $CONTAINER_NAME || echo "container not running, never mind"
|
||||||
- docker rm $CONTAINER_NAME || echo "container not existing, never mind"
|
- docker rm $CONTAINER_NAME || echo "container not existing, never mind"
|
||||||
|
@ -63,7 +63,7 @@ class DbOp(object):
|
|||||||
'unit': res[2]
|
'unit': res[2]
|
||||||
}
|
}
|
||||||
logger.debug(f"{variable=}")
|
logger.debug(f"{variable=}")
|
||||||
return application
|
return variable
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error getting variable: {e}")
|
logger.error(f"Error getting variable: {e}")
|
||||||
raise VariableNotFoundException(appId, converterId, deviceId, variableId)
|
raise VariableNotFoundException(appId, converterId, deviceId, variableId)
|
||||||
@ -79,7 +79,7 @@ class DbOp(object):
|
|||||||
with conn.cursor() as cur:
|
with conn.cursor() as cur:
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
insert into measurement_t (time, application, variable, value, unit)
|
insert into measurement_t (time, application, variable, value, unit)
|
||||||
values (now(), %(application)s, %(variable)s, %(value)s, %(unit)s
|
values (now(), %(application)s, %(variable)s, %(value)s, %(unit)s)
|
||||||
""",
|
""",
|
||||||
{
|
{
|
||||||
'application': measurement['application'],
|
'application': measurement['application'],
|
||||||
@ -100,14 +100,14 @@ def splitTopic(topic):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
raise InvalidTopicException(topic)
|
raise InvalidTopicException(topic)
|
||||||
r = rest.split('/')
|
r = rest.split('/')
|
||||||
if (len(r) == 1:
|
if (len(r) == 1):
|
||||||
deviceId = 'mains',
|
deviceId = 'mains',
|
||||||
variableId = r[0]
|
variableId = r[0]
|
||||||
elif (len(r) == 2:
|
elif (len(r) == 2):
|
||||||
(deviceId, variableid) = r
|
(deviceId, variableId) = r
|
||||||
else:
|
else:
|
||||||
raise InvalidTopicException(topic)
|
raise InvalidTopicException(topic)
|
||||||
return (appId, converterId, deviceId, variableid)
|
return (appId, converterId, deviceId, variableId)
|
||||||
|
|
||||||
def mqttOnConnectCallback(client, userdata, flags, rc):
|
def mqttOnConnectCallback(client, userdata, flags, rc):
|
||||||
logger.info("mqtt connected")
|
logger.info("mqtt connected")
|
||||||
@ -124,12 +124,12 @@ def mqttOnMessageCallback(client, userdata, message):
|
|||||||
(appId, converterId, deviceId, variableId) = splitTopic(topic)
|
(appId, converterId, deviceId, variableId) = splitTopic(topic)
|
||||||
|
|
||||||
dbh = DbOp(config)
|
dbh = DbOp(config)
|
||||||
variable = dbh.getVariable(appId, converterId, deviceId, variableid)
|
variable = dbh.getVariable(appId, converterId, deviceId, variableId)
|
||||||
measurement = {
|
measurement = {
|
||||||
"application": variable["application"],
|
"application": variable["application"],
|
||||||
"variable": variable["variable"],
|
"variable": variable["variable"],
|
||||||
"unit": variable["unit"],
|
"unit": variable["unit"],
|
||||||
"value": payload
|
"value": float(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(f"{measurement=}")
|
logger.debug(f"{measurement=}")
|
||||||
|
Reference in New Issue
Block a user