various updates

This commit is contained in:
Nico Melone
2024-02-28 14:25:02 -06:00
parent 14c29b6718
commit bc942efe3d
22 changed files with 12429 additions and 2035 deletions

View File

@@ -4,15 +4,7 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"abbflow_tcp_tb_v3.cfg\n"
]
}
],
"outputs": [],
"source": [
"import convert_config\n",
"import os\n",
@@ -32,9 +24,35 @@
" return max_version + 1\n",
"\n",
"# Example usage\n",
"root = \"/Users/nico/Documents/GitHub/HP_InHand_IG502/Pub_Sub\"\n",
"devicetype = \"abbflow_tcp\"\n",
"platform = \"thingsboard\" # or \"mistaway\"\n",
"root = \"/Users/nico/Documents/GitHub/HP_InHand_IG502/Pub_Sub\"\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"\n",
"devicetype = \"flowmeterskid\"\n",
"platform = \"thingsboard\" # or \"mistaway\"\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"flowmeterskid_tb_v4.cfg\n"
]
}
],
"source": [
"\n",
"platform_short = \"tb\" if platform == \"thingsboard\" else \"ma\" \n",
"startversion = get_latest_version(root, devicetype, platform)\n",
"\n",
@@ -47,18 +65,20 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/Users/nico/Documents/GitHub/HP_InHand_IG502/Pub_Sub/abbflow_tcp/thingsboard\n",
"/Users/nico/Documents/GitHub/HP_InHand_IG502/Pub_Sub/abbflow_tcp/thingsboard\n",
"Path did not exist creating path: /Users/nico/Documents/GitHub/HP_InHand_IG502/Pub_Sub/abbflow_tcp/thingsboard/abbflow_tcp_tb_v3.cfg\n",
"/Users/nico/Documents/GitHub/HP_InHand_IG502/Pub_Sub/abbflow_tcp/thingsboard/pub\n",
"/Users/nico/Documents/GitHub/HP_InHand_IG502/Pub_Sub/abbflow_tcp/thingsboard/sub\n"
"/Users/nico/Documents/GitHub/HP_InHand_IG502/Pub_Sub/flowmeterskid/thingsboard\n",
"/Users/nico/Documents/GitHub/HP_InHand_IG502/Pub_Sub/flowmeterskid/thingsboard\n",
"Path did not exist creating path: /Users/nico/Documents/GitHub/HP_InHand_IG502/Pub_Sub/flowmeterskid/thingsboard/flowmeterskid_tb_v4.cfg\n",
"/Users/nico/Documents/GitHub/HP_InHand_IG502/Pub_Sub/flowmeterskid/thingsboard/pub\n",
"<DirEntry 'receiveCommand.py'>\n",
"{'name': 'Receive Command', 'topic': 'v1/devices/me/rpc/request/+', 'qos': 1, 'funcName': 'receiveCommand', 'payload_type': 'JSON', 'script': 'import json\\nfrom datetime import datetime as dt\\nfrom common.Logger import logger\\nfrom quickfaas.measure import write\\nfrom quickfaas.remotebus import publish\\n\\n\\ndef get_totalizers():\\n try:\\n with open(\"/var/user/files/totalizers.json\", \"r\") as t:\\n totalizers = json.load(t)\\n if not totalizers:\\n logger.info(\"-----INITIALIZING TOTALIZERS-----\")\\n totalizers = {\\n \"day\": 0,\\n \"week\": 0,\\n \"month\": 0,\\n \"year\": 0,\\n \"lifetime\": 0,\\n \"dayHolding\": 0,\\n \"weekHolding\": 0,\\n \"monthHolding\": 0,\\n \"yearHolding\": 0\\n }\\n except:\\n totalizers = {\\n \"day\": 0,\\n \"week\": 0,\\n \"month\": 0,\\n \"year\": 0,\\n \"lifetime\": 0,\\n \"dayHolding\": 0,\\n \"weekHolding\": 0,\\n \"monthHolding\": 0,\\n \"yearHolding\": 0\\n }\\n return totalizers\\n\\ndef saveTotalizers(totalizers):\\n try:\\n with open(\"/var/user/files/totalizers.json\", \"w\") as t:\\n json.dump(totalizers,t)\\n except Exception as e:\\n logger.error(e)\\n\\ndef resetTotalizers():\\n try:\\n totalizers = get_totalizers()\\n \\n totalizers[\"dayHolding\"] = 0\\n totalizers[\"weekHolding\"] = 0\\n totalizers[\"monthHolding\"] = 0\\n totalizers[\"yearHolding\"] = 0\\n saveTotalizers(totalizers) \\n return True\\n except Exception as e:\\n logger.error(e)\\n return e\\n\\ndef receiveCommand(topic, payload):\\n logger.debug(topic)\\n logger.debug(json.loads(payload))\\n p = json.loads(payload)\\n command = p[\"method\"]\\n if command == \"resetTotalizers\":\\n r = resetTotalizers()\\n \\n if r == True:\\n message = [{\"name\": \"flowmeter\", \"measures\":[{\"name\":\"reset_totalizers\", \"value\": 1}]}]\\n try:\\n resp = write(message)\\n payload = {\\n \"ts\": (round(dt.timestamp(dt.now())/600)*600)*1000,\\n \"values\": {\\n \"day_volume\": 0,\\n \"yesterday_volume\": 0,\\n \"week_volume\": 0,\\n \"last_week_volume\": 0,\\n \"month_volume\": 0,\\n \"last_month_volume\": 0,\\n \"year_volume\": 0,\\n \"last_year_volume\": 0\\n }\\n }\\n publish(\"v1/devices/me/telemetry\",json.dumps(payload))\\n except Exception as e:\\n logger.error(\"Failed to write message\")\\n logger.error(e)\\n \\n ack(topic.split(\"/\")[-1], r)\\n\\ndef ack(msgid, r):\\n #logger.debug(msgid)\\n #logger.debug(mac)\\n #logger.debug(name)\\n #logger.debug(value)\\n publish(\"v1/devices/me/rpc/response/\" + str(msgid), json.dumps({\"msg\": {\"time\": (round(dt.timestamp(dt.now())/600)*600)*1000, \"response\": r}, \"metadata\": \"\", \"msgType\": \"\"}))', 'msgType': 0, 'cloudName': 'default', 'trigger': 'command_event'}\n",
"/Users/nico/Documents/GitHub/HP_InHand_IG502/Pub_Sub/flowmeterskid/thingsboard/sub\n"
]
}
],
@@ -86,7 +106,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.9.12"
}
},
"nbformat": 4,

File diff suppressed because it is too large Load Diff