0

I'm trying to create a tool, where you can log data from a specific BACnet object, by using BAC0: https://bac0.readthedocs.io/en/latest/

https://buildmedia.readthedocs.org/media/pdf/bac0/latest/bac0.pdf

I'm currently failing to implement a precise timer, to log the data in the wanted time intervals(e.g. 100ms, 200ms, 500ms, 1000ms). When running the following code:

#=============================================================================#
# Main Loop                                                                   #
#=============================================================================#

if __name__=='__main__':

    i = 16
    
    try:
        bacnet = BAC0.lite(ip)
    except Exception as e:
        print(e)
        
    try:
        address, device_id = bacnet.whois('103061 103061')[0]
    except Exception as e:
        print(e)
                
    while(i>0):
            ZUL1_T.append(bacnet.readMultiple(ip, request_dict=_rpm))
            TIME_T.append(time.time_ns())
            i-=1
        
    with open('zzz.csv', 'w') as file:
            writer = csv.writer(file)
            zeilen = []
                    
            writer.writerow(ZUL1_T)
            writer.writerow(TIME_T)

I get the answers to the requests in the following time intervals:

65ms 58ms 63ms 65ms 64ms 60ms 69ms 58ms 62ms 65ms 47ms 67ms 63ms 61ms 61ms

So I added time.sleep(0.1) at the end of the while loop and expected the time intervals all to be around 160ms. But when i started the programm, I got the following time intervalls between to requests:

774ms 362ms 838ms 1015ms 299ms 281ms 160ms 1052ms 167ms 499ms 628ms 200ms 249ms 392ms 652ms

For me, these time intervalls appear to be completely arbitrary. Has anyone an idea why that is or how I could implement a better solution?

I now found out that it works perfectly fine on a Linux computer, so the problem seems to be my Windows os. Is there a way to still run it on Windows, e.g giving more CPU capacity to Visual Studio Code or similar?

1 Answers1

0

There are multiple things that will influence the readings on a BACnet device. Typically, those devices monitor temperature and other properties that are taking much longer than a few ms to update.

BACnet also provide other mechanisms to be informed if boolean points change without having to poll a device every ms. It is called COV (change of value). It works with binary and analog value (when supported by the device).

Worth notice that BAC0 can natively record data in the form of Pandas Series when using a BAC0.device.

A connector to InfluxDB is also being developed

  • First of all, thank you very much for sharing BAC0, it has helped me a lot! I managed to get the data in 100 ms (+-10ms) intervals using a Linux operating system. Since I use the data for system identification, the cov is not suitable for my application. I tried using: my_obj_list = [ ('analogInput', 12),('loop', 1)] fx = BAC0.device(address, device_id, bacnet, object_list = my_obj_list) BAC0.tasks.Poll.DeviceFastPoll(fx,0.1) But I haven't figured out where the data goes. So for example, using: print(fx[('analogInput',12)].history) only gave me a history with one value. – Beginnerlevel Jul 27 '22 at 15:01
  • Using devices, you will not be able to get something below 1 sec. example ``` pcv = BAC0.device('2:5', 55005, bacnet, object_list=objlst, poll=0.1) ``` Here, using Windows, I hardly get 1 sec. That said. BACnet and BAC0 are not meant (in my humble opinion) for polling time that fast. .history will output a Pandas series, maybe if you play with "_history" which is a simple list of the values and timestamps, you'll have more chance. – Christian Tremblay Jul 28 '22 at 18:55