330 lines
12 KiB
INI
330 lines
12 KiB
INI
{
|
|
"controllers": [
|
|
{
|
|
"protocol": "Modbus-RTU",
|
|
"name": "flowmeter",
|
|
"endpoint": "rs485",
|
|
"args": {
|
|
"slaveAddr": 247,
|
|
"int16Ord": "ab",
|
|
"int32Ord": "cdab",
|
|
"float32Ord": "cdab",
|
|
"int64Ord": "ghefcdab",
|
|
"enableMsecSample": 0,
|
|
"continuousAcquisition": 1,
|
|
"maxContinuousNumber": 64,
|
|
"communicationInterval": 3,
|
|
"msecSamplePeriod": 500,
|
|
"msecPackage": 20
|
|
},
|
|
"samplePeriod": 10,
|
|
"expired": 10000
|
|
}
|
|
],
|
|
"measures": [
|
|
{
|
|
"name": "flowrate",
|
|
"ctrlName": "flowmeter",
|
|
"group": "default",
|
|
"uploadType": "periodic",
|
|
"dataType": "FLOAT",
|
|
"addr": "43874",
|
|
"readWrite": "ro",
|
|
"unit": "",
|
|
"desc": "",
|
|
"transformType": 0,
|
|
"decimal": 2,
|
|
"gain": "1.0",
|
|
"offset": "0.0",
|
|
"msecSample": 0
|
|
},
|
|
{
|
|
"name": "totalizer_1",
|
|
"ctrlName": "flowmeter",
|
|
"group": "default",
|
|
"uploadType": "periodic",
|
|
"dataType": "FLOAT",
|
|
"addr": "42610",
|
|
"readWrite": "ro",
|
|
"unit": "",
|
|
"desc": "",
|
|
"transformType": 0,
|
|
"decimal": 2,
|
|
"gain": "1.0",
|
|
"offset": "0.0",
|
|
"msecSample": 0
|
|
},
|
|
{
|
|
"name": "totalizer_2",
|
|
"ctrlName": "flowmeter",
|
|
"group": "default",
|
|
"uploadType": "periodic",
|
|
"dataType": "FLOAT",
|
|
"addr": "42810",
|
|
"readWrite": "ro",
|
|
"unit": "",
|
|
"desc": "",
|
|
"transformType": 0,
|
|
"decimal": 2,
|
|
"gain": "1.0",
|
|
"offset": "0.0",
|
|
"msecSample": 0
|
|
},
|
|
{
|
|
"name": "totalizer_3",
|
|
"ctrlName": "flowmeter",
|
|
"group": "default",
|
|
"uploadType": "periodic",
|
|
"dataType": "FLOAT",
|
|
"addr": "43010",
|
|
"readWrite": "ro",
|
|
"unit": "",
|
|
"desc": "",
|
|
"transformType": 0,
|
|
"decimal": 2,
|
|
"gain": "1.0",
|
|
"offset": "0.0",
|
|
"msecSample": 0
|
|
},
|
|
{
|
|
"name": "flow_unit",
|
|
"ctrlName": "flowmeter",
|
|
"group": "default",
|
|
"uploadType": "periodic",
|
|
"dataType": "INT",
|
|
"addr": "42103",
|
|
"readWrite": "ro",
|
|
"unit": "",
|
|
"desc": "",
|
|
"transformType": 0,
|
|
"gain": "1.0",
|
|
"offset": "0.0",
|
|
"msecSample": 0
|
|
},
|
|
{
|
|
"name": "totalizer_1_unit",
|
|
"ctrlName": "flowmeter",
|
|
"group": "default",
|
|
"uploadType": "periodic",
|
|
"dataType": "INT",
|
|
"addr": "44604",
|
|
"readWrite": "ro",
|
|
"unit": "",
|
|
"desc": "",
|
|
"transformType": 0,
|
|
"gain": "1.0",
|
|
"offset": "0.0",
|
|
"msecSample": 0
|
|
},
|
|
{
|
|
"name": "totalizer_2_unit",
|
|
"ctrlName": "flowmeter",
|
|
"group": "default",
|
|
"uploadType": "periodic",
|
|
"dataType": "INT",
|
|
"addr": "44605",
|
|
"readWrite": "ro",
|
|
"unit": "",
|
|
"desc": "",
|
|
"transformType": 0,
|
|
"gain": "1.0",
|
|
"offset": "0.0",
|
|
"msecSample": 0
|
|
},
|
|
{
|
|
"name": "totalizer_3_unit",
|
|
"ctrlName": "flowmeter",
|
|
"group": "default",
|
|
"uploadType": "periodic",
|
|
"dataType": "INT",
|
|
"addr": "44606",
|
|
"readWrite": "ro",
|
|
"unit": "",
|
|
"desc": "",
|
|
"transformType": 0,
|
|
"gain": "1.0",
|
|
"offset": "0.0",
|
|
"msecSample": 0
|
|
}
|
|
],
|
|
"alarmLables": [
|
|
"default"
|
|
],
|
|
"alarms": [],
|
|
"groups": [
|
|
{
|
|
"name": "default",
|
|
"uploadInterval": 600
|
|
}
|
|
],
|
|
"misc": {
|
|
"maxAlarmRecordSz": 2000,
|
|
"logLvl": "DEBUG",
|
|
"coms": [
|
|
{
|
|
"name": "rs232",
|
|
"baud": 9600,
|
|
"bits": 8,
|
|
"parityChk": "n",
|
|
"stopbits": 1
|
|
},
|
|
{
|
|
"name": "rs485",
|
|
"baud": 19200,
|
|
"bits": 8,
|
|
"parityChk": "n",
|
|
"stopbits": 1
|
|
}
|
|
]
|
|
},
|
|
"clouds": [
|
|
{
|
|
"cacheSize": 10000,
|
|
"enable": 1,
|
|
"name": "default",
|
|
"type": "Standard MQTT",
|
|
"args": {
|
|
"host": "hp.henrypump.cloud",
|
|
"port": 1883,
|
|
"clientId": "unknown",
|
|
"auth": 1,
|
|
"tls": 0,
|
|
"cleanSession": 0,
|
|
"mqttVersion": "v3.1.1",
|
|
"keepalive": 60,
|
|
"key": "",
|
|
"cert": "",
|
|
"rootCA": "",
|
|
"verifyServer": 0,
|
|
"verifyClient": 0,
|
|
"username": "unknown",
|
|
"passwd": "unknown"
|
|
}
|
|
}
|
|
],
|
|
"quickfaas": {
|
|
"genericFuncs": [],
|
|
"uploadFuncs": [
|
|
{
|
|
"qos": 1,
|
|
"funcName": "sendData",
|
|
"script": "# Enter your python code.\nimport json\nfrom datetime import datetime as dt\nfrom common.Logger import logger\nfrom quickfaas.remotebus import publish\nfrom mobiuspi_lib.gps import GPS \n\npayload = {}\n\ntry:\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 }\nexcept:\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\n\n\n\ndef sendData(message,wizard_api):\n logger.debug(message)\n payload = {\"ts\": (round(dt.timestamp(dt.now())/600)*600)*1000, \"values\": {}}\n resetPayload = {\"ts\": \"\", \"values\": {}}\n for measure in message[\"values\"][\"flowmeter\"].keys():\n try:\n if measure in [\"totalizer_1\"]:\n payload[\"values\"][\"day_volume\"], dayReset = totalizeDay(message[\"values\"][\"flowmeter\"][measure][\"raw_data\"])\n payload[\"values\"][\"week_volume\"], weekReset = totalizeWeek(message[\"values\"][\"flowmeter\"][measure][\"raw_data\"])\n payload[\"values\"][\"month_volume\"], monthReset = totalizeMonth(message[\"values\"][\"flowmeter\"][measure][\"raw_data\"])\n payload[\"values\"][\"year_volume\"], yearReset = totalizeYear(message[\"values\"][\"flowmeter\"][measure][\"raw_data\"])\n payload[\"values\"][measure] = message[\"values\"][\"flowmeter\"][measure][\"raw_data\"]\n except Exception as e:\n logger.error(e)\n try:\n payload[\"values\"][\"latitude\"], payload[\"values\"][\"longitude\"], payload[\"values\"][\"speed\"] = getGPS()\n except:\n logger.error(\"Could not get GPS coordinates\")\n publish(__topic__, json.dumps(payload), __qos__)\n\n if dayReset:\n resetPayload[\"values\"][\"day_volume\"] = 0\n resetPayload[\"values\"][\"yesterday_volume\"] = payload[\"values\"][\"day_volume\"]\n if weekReset:\n resetPayload[\"values\"][\"week_volume\"] = 0\n resetPayload[\"values\"][\"last_week_volume\"] = payload[\"values\"][\"week_volume\"]\n if monthReset:\n resetPayload[\"values\"][\"month_volume\"] = 0\n resetPayload[\"values\"][\"last_month_volume\"] = payload[\"values\"][\"month_volume\"]\n if yearReset:\n resetPayload[\"values\"][\"year_volume\"] = 0 \n resetPayload[\"values\"][\"last_year_volume\"] = payload[\"values\"][\"year_volume\"]\n\n if resetPayload[\"values\"]:\n resetPayload[\"ts\"] = 1 + (round(dt.timestamp(dt.now())/600)*600)*1000\n publish(__topic__, json.dumps(resetPayload), __qos__) \n\ndef saveTotalizers():\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 getGPS():\n # Create a gps instance\n gps = GPS()\n\n # Retrieve GPS information\n position_status = gps.get_position_status()\n logger.debug(\"position_status: \")\n logger.debug(position_status)\n latitude = position_status[\"latitude\"].split(\" \")\n longitude = position_status[\"longitude\"].split(\" \")\n lat_dec = int(latitude[0][:-1]) + (float(latitude[1][:-1])/60)\n lon_dec = int(longitude[0][:-1]) + (float(longitude[1][:-1])/60)\n if latitude[2] == \"S\":\n lat_dec = lat_dec * -1\n if longitude[2] == \"W\":\n lon_dec = lon_dec * -1\n #lat_dec = round(lat_dec, 7)\n #lon_dec = round(lon_dec, 7)\n logger.info(\"HERE IS THE GPS COORDS\")\n logger.info(f\"LATITUDE: {lat_dec}, LONGITUDE: {lon_dec}\")\n speedKnots = position_status[\"speed\"].split(\" \")\n speedMPH = float(speedKnots[0]) * 1.151\n return (f\"{lat_dec:.8f}\",f\"{lon_dec:.8f}\",f\"{speedMPH:.2f}\")\n\ndef totalizeDay(lifetime):\n now = dt.fromtimestamp(round(dt.timestamp(dt.now())/600)*600)\n reset = False\n value = lifetime - totalizers[\"dayHolding\"]\n if not int(now.strftime(\"%d\")) == int(totalizers[\"day\"]):\n totalizers[\"dayHolding\"] = lifetime\n totalizers[\"day\"] = int(now.strftime(\"%d\"))\n saveTotalizers()\n reset = True\n return (value,reset)\n\ndef totalizeWeek(lifetime):\n now = dt.fromtimestamp(round(dt.timestamp(dt.now())/600)*600)\n reset = False\n value = lifetime - totalizers[\"weekHolding\"]\n if not int(now.strftime(\"%U\")) == int(totalizers[\"week\"]) and now.strftime(\"%a\") == \"Sun\":\n totalizers[\"weekHolding\"] = lifetime\n totalizers[\"week\"] = now.strftime(\"%U\")\n saveTotalizers()\n reset = True\n return (value, reset)\n\ndef totalizeMonth(lifetime):\n now = dt.fromtimestamp(round(dt.timestamp(dt.now())/600)*600)\n reset = False\n value = lifetime - totalizers[\"monthHolding\"]\n if not int(now.strftime(\"%m\")) == int(totalizers[\"month\"]):\n totalizers[\"monthHolding\"] = lifetime\n totalizers[\"month\"] = now.strftime(\"%m\")\n saveTotalizers()\n reset = True\n return (value,reset)\n\ndef totalizeYear(lifetime):\n now = dt.fromtimestamp(round(dt.timestamp(dt.now())/600)*600)\n reset = False\n value = lifetime - totalizers[\"yearHolding\"]\n if not int(now.strftime(\"%Y\")) == int(totalizers[\"year\"]):\n totalizers[\"yearHolding\"] = lifetime\n totalizers[\"year\"] = now.strftime(\"%Y\")\n saveTotalizers()\n reset = True\n return (value, reset)",
|
|
"name": "sendData",
|
|
"trigger": "measure_event",
|
|
"topic": "v1/devices/me/telemetry",
|
|
"cloudName": "default",
|
|
"groups": [
|
|
"default"
|
|
],
|
|
"msgType": 0
|
|
}
|
|
],
|
|
"downloadFuncs": [
|
|
{
|
|
"name": "Receive Command",
|
|
"topic": "v1/devices/me/rpc/request/+",
|
|
"qos": 1,
|
|
"funcName": "receiveCommand",
|
|
"payload_type": "JSON",
|
|
"script": "import json\nimport time\nfrom common.Logger import logger\nfrom quickfaas.remotebus import publish\n\ndef resetTotalizers():\n with open(\"/var/user/files/totalizers.json\", \"r+\") as t:\n totalizers = json.load(t)\n if totalizers:\n totalizers[\"dayHolding\"] = 0\n totalizers[\"weekHolding\"] = 0\n totalizers[\"MonthHolding\"] = 0\n totalizers[\"yearHolding\"] = 0\n json.dump(totalizers,t)\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 resetTotalizers()\n publish(topic, json.dumps({\"msg\": {\"time\": time.time()}, \"metadata\": \"\", \"msgType\": \"\"}))\n",
|
|
"msgType": 0,
|
|
"cloudName": "default",
|
|
"trigger": "command_event"
|
|
}
|
|
]
|
|
},
|
|
"labels": [
|
|
{
|
|
"key": "SN",
|
|
"value": "GF5022223016129"
|
|
},
|
|
{
|
|
"key": "MAC",
|
|
"value": "00:18:05:21:b3:3f"
|
|
}
|
|
],
|
|
"modbusSlave": {
|
|
"enable": 0,
|
|
"protocol": "Modbus-TCP",
|
|
"port": 502,
|
|
"slaveAddr": 1,
|
|
"int16Ord": "ab",
|
|
"int32Ord": "abcd",
|
|
"float32Ord": "abcd",
|
|
"maxConnection": 5,
|
|
"mapping_table": []
|
|
},
|
|
"modbusRTUSlave": {
|
|
"enable": 0,
|
|
"protocol": "Modbus-RTU",
|
|
"coms": "rs485",
|
|
"slaveAddr": 1,
|
|
"int16Ord": "ab",
|
|
"int32Ord": "abcd",
|
|
"float32Ord": "abcd",
|
|
"mapping_table": []
|
|
},
|
|
"iec104Server": {
|
|
"enable": 0,
|
|
"cotSize": 2,
|
|
"port": 2404,
|
|
"serverList": [
|
|
{
|
|
"asduAddr": 1
|
|
}
|
|
],
|
|
"kValue": 12,
|
|
"wValue": 8,
|
|
"t0": 30,
|
|
"t1": 15,
|
|
"t2": 10,
|
|
"t3": 20,
|
|
"maximumLink": 5,
|
|
"timeSet": 1,
|
|
"byteOrder": "abcd",
|
|
"mapping_table": []
|
|
},
|
|
"iec104Client": {
|
|
"enable": 0,
|
|
"connectType": 2,
|
|
"serverAddr": "ipower.inhandcloud.cn",
|
|
"serverPort": 2404,
|
|
"communicationCode": "",
|
|
"protocol": 1,
|
|
"asduAddr": 1,
|
|
"tls": 0,
|
|
"mapping_table": {
|
|
"YX": [],
|
|
"YC": [],
|
|
"YK": []
|
|
}
|
|
},
|
|
"opcuaServer": {
|
|
"enable": 0,
|
|
"port": 4840,
|
|
"maximumLink": 5,
|
|
"securityMode": 0,
|
|
"identifierType": "String",
|
|
"mapping_table": []
|
|
},
|
|
"southMetadata": {},
|
|
"bindMetadata": {
|
|
"version": "",
|
|
"timestamp": ""
|
|
},
|
|
"bindConfig": {
|
|
"enable": 0,
|
|
"bind": {
|
|
"modelId": "",
|
|
"modelName": "",
|
|
"srcId": "",
|
|
"srcName": "",
|
|
"devId": "",
|
|
"devName": ""
|
|
},
|
|
"varGroups": [],
|
|
"variables": [],
|
|
"alerts": []
|
|
},
|
|
"version": "2.3.1"
|
|
} |