Update settings for language services, adjust simulator port, enhance error handling in ingestor, and refine Redis feeder script
61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
import json
|
|
import redis
|
|
|
|
|
|
# Redis connection settings
|
|
REDIS_HOST = "localhost"
|
|
REDIS_PORT = 6379
|
|
REDIS_USERNAME = None # "default"
|
|
REDIS_PASSWORD = None # "bdnZOpcyiL"
|
|
|
|
OPC_URL = "opc.tcp://sientia-opc-simulator-service.sientia-opc.svc.cluster.local:4841"
|
|
OPC_URL = "opc.tcp://localhost:4841"
|
|
|
|
# Connect to Redis
|
|
r = redis.Redis(host=REDIS_HOST, port=REDIS_PORT,
|
|
decode_responses=True, username=REDIS_USERNAME, password=REDIS_PASSWORD)
|
|
|
|
# Define the key pattern to target
|
|
PATTERN = "slot:opc_tags:*"
|
|
|
|
# Step 1: Find and delete matching keys
|
|
print("🔍 Searching for keys matching:", PATTERN)
|
|
for key in r.scan_iter(match=PATTERN):
|
|
r.delete(key)
|
|
print(f"❌ Deleted: {key}")
|
|
|
|
# Step 2: Insert new data
|
|
# Example new OPC tag data
|
|
new_data = {
|
|
"slot:opc_tags:1": {
|
|
"server1": {
|
|
"name": "server1",
|
|
"url": OPC_URL,
|
|
"server_uri": "http://opcua-server.simulator",
|
|
"tags": {
|
|
'ns=2;i=2': {
|
|
'tag_name': 'Counter',
|
|
'frequency': 1000,
|
|
'topics': ['opcua', 'counter'],
|
|
},
|
|
'ns=2;i=3': {
|
|
'tag_name': 'Rollout',
|
|
'frequency': 1000,
|
|
"topics": ['opcua', 'rollout'],
|
|
},
|
|
'ns=2;i=4': {
|
|
'tag_name': 'Square',
|
|
'frequency': 1000,
|
|
"topics": ['opcua'],
|
|
},
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for key, val in new_data.items():
|
|
r.set(key, json.dumps(val))
|
|
print(f"✅ Set: {key} -> {val}")
|
|
|
|
print("🚀 OPC tag keys replaced successfully.")
|