Write Value
To write the value of a variable, the client should use WRITE_REQUEST request.
Write Request
Field |
Description |
Header |
|
|
|
MessageType |
Must be WRITE_REQUEST. |
|
ClientHandler |
See Message Format. |
Body |
|
|
|
Variable |
The name of the variable to write |
|
Value |
|
|
|
Value |
|
|
|
|
Body |
The value of the variable. |
|
|
|
Type |
The type ID of the variable. |
|
|
[Status] |
The OPC UA status of the variable. |
|
|
[SourceTimestamp] |
The time of the value given by the source in ISO
8601 format. Example: “2015-09-06T09:03:21Z” |
|
|
[ServerTimestamp] |
The time of the value given by the server in ISO
8601 format. Example: “2015-09-06T09:03:21Z” |
Write Response
Field |
Description |
Header |
|
|
|
MessageType |
Must be WRITE_RESPONSE. |
|
ClientHandler |
See Message Format. |
Body |
|
|
|
[Status] |
The OPC UA status of the variable
if it is not Success. |
Status Codes
Status Code |
Description |
BadInternalError |
The server failed to process the request due to internal
error. |
BadAttributeInvalid |
The server failed decode the body of the message. |
BadNodeIdUnknown |
The variable name isn’t found in the server configuration. |
BadSessionClosed |
The connection with OPC UA server is lost. |
Example in Python
import websocket
import json
msg = {
'Header': {
'ClientHandle': '1',
'MessageType': 'WRITE_REQUEST'
},
'Body': {
'Variable': 'Int32Test',
'Value': {
'Value': {
'Body': '555',
'Type': '8'
}
}
}
}
ws = websocket.create_connection('ws://127.0.0.1:8081')
resp = ws.recv()
json.loads(resp) #=> {
# "Header": {
# "MessageType": "WRITE_RESPONSE",
# "ClientHandle": "1"
# },
# "Body": {}
#}