BAC0
BAC0 copied to clipboard
point.value Vs point.lastValue
So I think I understand when using connect
that point.lastValue
returns the last value of the Pandas series df.
- Does point.value perform a fresh read request and point.lastValue is just what was found during last poll of the point?
But just curious why my script operates like this....I notice different things happening when I switch point.value Vs point.lastValue in my code below inside the def printData():
recurring task.
For example is I just use point.value
the code will loop through all four points from the 2 devices and print each sensor reading as expected, 4 sensors in total from 2 different devices. The nan
readings are correct I just have a wire missing off the controller on my test bench at the moment:
2022-09-24 09:43:01,291 - INFO | Ready!
2022-09-24 09:43:01,292 - INFO | Device defined for normal polling with a delay of 10sec
2022-09-24 09:43:01,292 - INFO | Polling started, values read every 10 seconds
{'TEST1': 71.53999328613281}
{'TEST1': nan}
{'TEST2': nan}
{'TEST2': nan}
{'TEST1': 71.53999328613281}
{'TEST1': nan}
{'TEST2': nan}
{'TEST2': nan}
{'TEST1': 71.49999237060547}
{'TEST1': nan}
{'TEST2': nan}
{'TEST2': nan}
{'TEST1': 71.50999450683594}
{'TEST1': nan}
{'TEST2': nan}
{'TEST2': nan}
{'TEST1': 71.12999725341797}
{'TEST1': nan}
{'TEST2': nan}
{'TEST2': nan}
{'TEST1': 71.49999237060547}
{'TEST1': nan}
But when I use point.lastValue
its like the code is stuck only returning one sensor reading over and over. Looks like this:
2022-09-24 09:36:31,159 - INFO | Device defined for normal polling with a delay of 10sec
2022-09-24 09:36:31,160 - INFO | Polling started, values read every 10 seconds
{'TEST1': 70.89999389648438}
{'TEST1': 70.89999389648438}
{'TEST1': 70.89999389648438}
{'TEST1': 70.89999389648438}
{'TEST1': 70.89999389648438}
{'TEST1': 70.89999389648438}
{'TEST1': 70.89999389648438}
{'TEST1': 70.89999389648438}
{'TEST1': 70.89999389648438}
{'TEST1': 70.89999389648438}
Here's my code, is this because a time.sleep
or something is hosing up BACnet polling processes? Its the same thing I noticed in my other issue that is closed that you helped with some code....
import BAC0
from BAC0.tasks.RecurringTask import RecurringTask
import time
bacnet = BAC0.lite()
furnace_obj_list = [('analogInput', 2),
('analogInput', 3)]
hotwaterhtr_obj_list = [('analogInput', 2),
('analogInput', 3)]
furnace = BAC0.device('12345:2',
201201,
bacnet,
object_list=furnace_obj_list,
segmentation_supported=False)
hotwaterheatr = BAC0.device('12345:6',
201202,
bacnet,
object_list=hotwaterhtr_obj_list,
segmentation_supported=False)
time.sleep(3)
devices = [furnace,hotwaterheatr]
def printData():
for device in devices:
for point in device.points:
#print(point)
data = {
#device.properties.name : point.lastValue
device.properties.name : point.value
}
print(data)
time.sleep(10)
def main():
task1 = RecurringTask(printData,delay=60)
task1.start()
while True:
time.sleep(0.01)
if __name__ == "__main__":
main()
bacnet.disconnect()
print('disconnected')
Sleep is bad... the thread are stopped... This is why in the while loop, I use a very small delay in the sleep function. This way, after 0.01sec, if the thread needs to run, there is a chance for it to do so.
try this
import BAC0
from BAC0.tasks.RecurringTask import RecurringTask
import time
bacnet = BAC0.lite()
furnace_obj_list = [('analogInput', 2),
('analogInput', 3)]
hotwaterhtr_obj_list = [('analogInput', 2),
('analogInput', 3)]
furnace = BAC0.device('12345:2',
201201,
bacnet,
object_list=furnace_obj_list,
segmentation_supported=False)
hotwaterheatr = BAC0.device('12345:6',
201202,
bacnet,
object_list=hotwaterhtr_obj_list,
segmentation_supported=False)
# will tolerate this one... but you could test if it is really required.
time.sleep(3)
devices = [furnace,hotwaterheatr]
def printData():
for device in devices:
for point in device.points:
#print(point)
data = {
#device.properties.name : point.lastValue
device.properties.name : point.value
}
print(data)
#time.sleep(10)
def main():
task1 = RecurringTask(printData,delay=60)
task1.start()
while True:
time.sleep(0.01)
if __name__ == "__main__":
main()
bacnet.disconnect()
print('disconnected')