publish json data
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import re
|
||||
|
||||
import json
|
||||
|
||||
class InvalidDataObjectException(Exception):
|
||||
def __init__(self, message):
|
||||
@ -21,4 +21,10 @@ class DataObject(object):
|
||||
return self.serverName + '/' + str(self.nameSpaceIndex) + '/' + self.variableName
|
||||
|
||||
def getPayload(self):
|
||||
return self.value
|
||||
payload = {
|
||||
"serverName": self.serverName,
|
||||
"nameSpaceIndex": self.nameSpaceIndex,
|
||||
"variableName": self.variableName,
|
||||
"value": self.value
|
||||
}
|
||||
return json.dumps(payload)
|
@ -16,6 +16,7 @@ class OpcUaRequester(threading.Thread):
|
||||
self.url = self.config['url']
|
||||
self.nodes = self.config['nodes']
|
||||
self.delay = self.config['delay']
|
||||
self.timeout = self.config['timeout']
|
||||
|
||||
# consider this flag in the localLoop
|
||||
self.killBill = False
|
||||
@ -25,7 +26,7 @@ class OpcUaRequester(threading.Thread):
|
||||
async def opcUaRequesterInnerLoop(self):
|
||||
while not self.killBill:
|
||||
try:
|
||||
async with Client(url=self.url, timeout=10.0) as client:
|
||||
async with Client(url=self.url, timeout=self.timeout) as client:
|
||||
for nodeSpec in self.nodes:
|
||||
try:
|
||||
logger.debug(f"Trying {self.name} {self.url} ns={nodeSpec['ns']};{nodeSpec['n']}")
|
||||
|
@ -10,11 +10,12 @@
|
||||
"url": "opc.tcp://172.16.3.60:4840",
|
||||
"name": "apl",
|
||||
"delay": 1.0,
|
||||
"timeout": 1.0,
|
||||
"nodes": [
|
||||
{ "ns": 0, "n": "i=345", "d": "pv" },
|
||||
{ "ns": 0, "n": "i=348", "d": "sv" },
|
||||
{ "ns": 0, "n": "i=351", "d": "tv" },
|
||||
{ "ns": 0, "n": "i=35400", "d": "qv" }
|
||||
{ "ns": 0, "n": "i=354", "d": "qv" }
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -22,6 +23,7 @@
|
||||
"url": "opc.tcp://192.168.254.5:4863",
|
||||
"name": "sh",
|
||||
"delay": 1.0,
|
||||
"timeout": 10.0,
|
||||
"nodes": [
|
||||
{ "ns": 1, "n": "s=A201CD124/MOT_01.AV_Out#Value", "d": "A201CD124" },
|
||||
{ "ns": 1, "n": "s=A201CJ003/PID_01.PV_Out#Value", "d": "A201CJ003" },
|
||||
|
Reference in New Issue
Block a user