Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step #39

Merged
merged 8 commits into from
Nov 22, 2023
Merged

Step #39

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
254 changes: 0 additions & 254 deletions node-red/flows.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,218 +290,6 @@
[]
]
},
{
"id": "28b5056b2ea2b762",
"type": "http request",
"z": "25496ff795f33417",
"name": "",
"method": "GET",
"ret": "txt",
"paytoqs": "ignore",
"url": "http://192.168.122.1:8000/get_model_id/from/program_name/{{{model_id}}}",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [
{
"keyType": "msg",
"keyValue": "req.params.model_id",
"valueType": "msg",
"valueValue": "payload.model_id"
}
],
"x": 550,
"y": 260,
"wires": [
[
"a7f642b0ed5f98d2"
]
]
},
{
"id": "a7f642b0ed5f98d2",
"type": "debug",
"z": "25496ff795f33417",
"name": "debug 10",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 720,
"y": 260,
"wires": []
},
{
"id": "5be28623d3270603",
"type": "inject",
"z": "25496ff795f33417",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 140,
"y": 260,
"wires": [
[
"22bbe12e58927ac2"
]
]
},
{
"id": "22bbe12e58927ac2",
"type": "change",
"z": "25496ff795f33417",
"name": "",
"rules": [
{
"t": "set",
"p": "model_id",
"pt": "msg",
"to": "1",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 310,
"y": 260,
"wires": [
[
"28b5056b2ea2b762"
]
]
},
{
"id": "3d5164f4898a5899",
"type": "http request",
"z": "25496ff795f33417",
"name": "post test",
"method": "POST",
"ret": "txt",
"paytoqs": "ignore",
"url": "http://192.168.122.1:8000/start/measurement/with/program_name",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [
{
"keyType": "Accept",
"keyValue": "",
"valueType": "application/json",
"valueValue": ""
},
{
"keyType": "Content-Type",
"keyValue": "",
"valueType": "application/json",
"valueValue": ""
}
],
"x": 540,
"y": 420,
"wires": [
[
"717f6e78c7680f89"
]
]
},
{
"id": "717f6e78c7680f89",
"type": "debug",
"z": "25496ff795f33417",
"name": "debug 12",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 720,
"y": 420,
"wires": []
},
{
"id": "e4b18df3986360dd",
"type": "inject",
"z": "25496ff795f33417",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 140,
"y": 420,
"wires": [
[
"e532f3297773b9d8"
]
]
},
{
"id": "e532f3297773b9d8",
"type": "change",
"z": "25496ff795f33417",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{ \"mtconnect_interval\": 0, \"interval\": 0, \"threshold\": 0, \"program_name\": \"string\" }",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 340,
"y": 420,
"wires": [
[
"3d5164f4898a5899"
]
]
},
{
"id": "a0450bbf0d4d00ca",
"type": "mqtt in",
Expand Down Expand Up @@ -1190,27 +978,6 @@
"to": "model_id",
"tot": "flow"
},
{
"t": "set",
"p": "payload.mtconnect_interval",
"pt": "msg",
"to": "50",
"tot": "num"
},
{
"t": "set",
"p": "payload.interval",
"pt": "msg",
"to": "10",
"tot": "num"
},
{
"t": "set",
"p": "payload.threshold",
"pt": "msg",
"to": "1000",
"tot": "num"
},
{
"t": "set",
"p": "status",
Expand Down Expand Up @@ -1436,27 +1203,6 @@
"z": "344499584571a0ed",
"name": "post payload",
"rules": [
{
"t": "set",
"p": "payload.mtconnect_interval",
"pt": "msg",
"to": "50",
"tot": "num"
},
{
"t": "set",
"p": "payload.interval",
"pt": "msg",
"to": "10",
"tot": "num"
},
{
"t": "set",
"p": "payload.threshold",
"pt": "msg",
"to": "1000",
"tot": "num"
},
{
"t": "set",
"p": "payload.program_name",
Expand Down
14 changes: 8 additions & 6 deletions server/data/config/dev.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
mtconnect:
url: https://demo.metalogi.io/current?path=//Axes/Components/Linear/DataItems/DataItem
latency: 30 # ms

edge:
arc:
number: 4

mqtt:
host: 192.168.0.19
password: opencmm
port: 1883
username: opencmm
password: opencmm
mtconnect:
interval: 100 # ms
latency: 30 # ms
url: https://demo.metalogi.io/current?path=//Components
sensor:
interval: 10 # ms
threshold: 1000
14 changes: 8 additions & 6 deletions server/data/config/production.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
mtconnect:
url: http://192.168.0.19:5000/current?path=//Axes/Components/Linear/DataItems
latency: 30 # ms

edge:
arc:
number: 4

mqtt:
host: 192.168.0.19
password: opencmm
port: 1883
username: opencmm
password: opencmm
mtconnect:
interval: 100 # ms
latency: 30 # ms
url: http://192.168.0.19:5000/current?path=//Components
sensor:
interval: 10 # ms
threshold: 1000
10 changes: 7 additions & 3 deletions server/server/listener/listener.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import threading
from server.config import (
MQTT_BROKER_URL,
get_config,
)
from . import hakaru, mt
import logging
Expand All @@ -11,18 +12,21 @@

def listener_start(
mysql_config: dict,
mtconnect_interval: int,
process_id: int,
streaming_config: tuple,
):
conf = get_config()
mtconnect_interval = conf["mtconnect"]["interval"]
sensor_interval = conf["sensor"]["interval"]
sensor_threshold = conf["sensor"]["threshold"]

thread1 = threading.Thread(
target=hakaru.listen_sensor,
args=(
(
MQTT_BROKER_URL,
process_id,
mysql_config,
streaming_config,
(sensor_interval, sensor_threshold),
)
),
)
Expand Down
1 change: 1 addition & 0 deletions server/server/listener/mt/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def mtconnect_streaming_reader(
hostname=mqtt_url,
auth={"username": MQTT_USERNAME, "password": MQTT_PASSWORD},
)
status.add_end_timestamp(mysql_config, process_id)
break

raw_data = chunk.decode("utf-8")
Expand Down
12 changes: 12 additions & 0 deletions server/server/listener/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,15 @@ def get_prev_next_process(mysql_config: dict, model_id: int, process_id: int):
next_process = process_status[i + 1][0]
break
return prev_process, next_process


def add_end_timestamp(mysql_config: dict, process_id: int):
mysql_conn = mysql.connector.connect(**mysql_config, database="coord")
mysql_cur = mysql_conn.cursor()
mysql_cur.execute(
"UPDATE process SET end_timestamp = NOW() WHERE id = %s",
(process_id,),
)
mysql_conn.commit()
mysql_cur.close()
mysql_conn.close()
Loading
Loading