-
Notifications
You must be signed in to change notification settings - Fork 0
/
PfcWdaWriteParam.py
75 lines (63 loc) · 1.89 KB
/
PfcWdaWriteParam.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Script for Write WDA Data out of Wago PFC
# More information on http://<pfc_ip>/openapi/wda.openapi.html
# Author: Michael Drost
# Version: 0.2
# PythonVersion: 3.7.3
import requests
import json
import time
import os
# ++++ Controller IP
ip = '192.168.2.129'
# ++++ Authorization for Wago Controller
username = "admin"
password = "wago"
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
# ++++ The Api Endpoints
#"https://192.168.2.129/wda/devices"
#"https://192.168.2.129/wda/parameters"
#"https://192.168.2.129/wda/features"
#"https://192.168.2.129/wda/methods"
# ++++ The Api Endpoint
url = "https://"+ip+"/wda/parameters"
# ++++ write Parameter
# 1. Set acutal Time
# 2. activate Docker
headers={'Content-Type': 'application/vnd.api+json'}
print(bcolors.WARNING + "write parameters")
parameter = {
"data": [
{"id": "0-0-systemtime-now",
"type": "parameters",
"attributes": {
"value": 1686037778
}},
{"id": "0-0-docker-enabled",
"type": "parameters",
"attributes": {
"value": True
}}
]
}
# set actual millis
ts = time.time()
parameter["data"][0]["attributes"]["value"] = int(ts)
response = requests.patch(url, auth=(username, password), data=json.dumps(parameter), headers=headers, verify=False)
print(bcolors.OKGREEN + "done!")
# ++++ Check if Docker is Running
print(bcolors.WARNING + "check parameters")
url = "https://"+ip+"/wda/parameters/0-0-docker-isRunning"
response = requests.get(url, auth=(username, password), verify=False)
response_json = response.json()
print("Docker state is: " + str(response_json["data"]["attributes"]["value"]))
print(bcolors.OKGREEN + "Done!")
print(bcolors.ENDC)