0
I have an Raspberry sending data every 15 seconds, however I have a value that takes time to update, will cleaning the buffer every iteration in while True solve the problem? my code is as follows::
import sys
sys.path.insert(0, "..")
import time
import subprocess
import logging
from opcua import Server
import BMP085
import mysql.connector as mysql
from datetime import datetime
import opcua
##### Sensor Data of BMP180 ######################
bmp = BMP085.BMP085()# Instantiation
temperature =bmp.read_temperature()# variable of temperature
altitude = bmp.read_altitude()# variable of altitude
pressure = bmp.read_pressure()# variable of pressure
################################################
if __name__ == "__main__":
logging.basicConfig(level = logging.WARNING)
# get Objects node, this is where we should put our nodes
# setup our server
server = Server()
server.set_endpoint("opc.tcp://192.168.1.10:4840/freeopcua/server/")
# setup our own namespace, not really necessary but should as spec
uri = "http://192.168.1.10:4840/freeopcua/server/"
idx = server.register_namespace(uri)
# get Objects node, this is where we should put our nodes
objects = server.get_objects_node()
# populating our address space
sensordata = objects.add_object(idx, "Sensor One BMP180")
temp_var_node= sensordata.add_variable(idx, "Temperature Sensor One", temperature)
print("the temp_var_node is:", temp_var_node)
altit_var_node = sensordata.add_variable(idx, "Altitude Sensor One", altitude)
print("the altit_var_node is:", altit_var_node)
press_var_node = sensordata.add_variable(idx, "Pressure Sensor One ", pressure)
print("the pressure_var_node is:", press_var_node)
#################### Set MyVariable to be writable by clients #################################
temp_var_node.set_writable()
altit_var_node.set_writable()
press_var_node.set_writable()
# starting de server OPCUA!
server.start()
try:
while True:
temp_var_node.set_value(bmp.read_temperature())
altit_var_node.set_value(bmp.read_altitude())
press_var_node.set_value(bmp.read_pressure())
time.sleep(1)
temp = temp_var_node.get_value()#get the node value of temp_var_node
print("The value of temp_var_node is:", temp)
altit = altit_var_node.get_value()#get the node value of altit_var_node
print("The value of altit_var_node is:", altit)
press = press_var_node.get_value()#get the node value of press_var_node
print("The value of press_var_node is:", press)
time.sleep(1)
finally:
server.stop()
You speak of the print on the screen?
– Giovanni Nunes
no, is when the value is sent over Ethernet network, I ask this because I have a magnetic sensor that takes time to update the value when I approach or push a magnet away.
– Sergio Nunes