JoelBender / BACpypes3

BACnet communications library
33 stars 7 forks source link

Regarding Alarm Services #23

Open shashankgowdasd opened 7 months ago

shashankgowdasd commented 7 months ago

Hi Sir @JoelBender ,

I have tried with event-server.py for the Alarm services but I am unable to see the changes nether in the status flags nor in the notification class for the changes in the presentValue and for to check alarm services I have made the analogValue object presentValue changing for every 5 seconds but i didnt observer a Alarm notification in yabe,So please guide reagarding this sir...

bbartling commented 6 months ago

Not alot of Wisdom here in event notifications in BACnet... but if i run sandbox/event-server-avo1-ir.py

I get this error:

Traceback (most recent call last):
  File "/usr/lib/python3.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/bbartling/.local/lib/python3.9/site-packages/bacpypes3/local/event.py", line 411, in state_transition_delayed
    self.state_transition(new_state, True)
  File "/home/bbartling/.local/lib/python3.9/site-packages/bacpypes3/local/event.py", line 618, in state_transition
    ] = self.event_notification_parameters()
  File "/home/bbartling/.local/lib/python3.9/site-packages/bacpypes3/local/event.py", line 1686, in event_notification_parameters
    return event_values
UnboundLocalError: local variable 'event_values' referenced before assignment

It starts with $ python event-server-avo1-ir.py --debug

Where then my rasp pi comes up as a discoverable BACnet device on my test bench LAN with a few points. image

And if I modified my AnalogValueObjectIR to these values:

timeDelay=10,
notificationClass=1,
highLimit=70.0,
lowLimit=40.0,
deadband=5.0,

Where then in my BACnet scan tool I adjusted the AnalogValueObjectIR below the lowLimit threshold: image

Where then after the timeDelay it does appear to trigger an event notification that i can see in the logs... but then yields the error UnboundLocalError: local variable 'event_values' referenced before assignment

Here's the whole traceback:

$ python event-server-avo1-ir.py --debug
DEBUG:__main__:args: Namespace(loggers=False, debug=[], color=None, route_aware=None, name='Excelsior', instance=999, network=0, address=None, vendoridentifier=999, foreign=None, ttl=30, bbmd=None)
DEBUG:__main__:app: <bacpypes3.app.Application object at 0x75595940>
DEBUG:__main__:avo1: <bacpypes3.local.analog.AnalogValueObjectIR object at 0x755599a0>
    <bacpypes3.local.analog.AnalogValueObjectIR object at 0x755599a0>
        objectIdentifier = <property object at 0x75c2bb68>
        objectName = <property object at 0x75c2baf0>
        objectType = <ObjectType: analog-value>
        description = 'test analog value'
        propertyList = <property object at 0x75c2bbe0>
        presentValue = 50.0
        statusFlags = <property object at 0x75c2bc58>
        eventState = <EventState: normal>
        outOfService = 0
        units = <EngineeringUnits: degrees-fahrenheit>
        priorityArray = <PriorityArray _obj=<bacpypes3.local.analog.AnalogValueObjectIR object at 0x755599a0>>
        relinquishDefault = 50.0
        timeDelay = 10
        notificationClass = 1
        highLimit = 70.0
        lowLimit = 40.0
        deadband = 5.0
        limitEnable = <LimitEnable: low-limit-enable;high-limit-enable>
        eventEnable = <EventTransitionBits: to-offnormal;to-fault;to-normal>
        ackedTransitions = <EventTransitionBits: >
        notifyType = <NotifyType: alarm>
        eventTimeStamps = [<bacpypes3.basetypes.TimeStamp object at 0x756428c8>, <bacpypes3.basetypes.TimeStamp object at 0x75633ac0>, <bacpypes3.basetypes.TimeStamp object at 0x756336d0>]
        eventMessageTexts = ['', '', '']
        eventDetectionEnable = 1
        eventAlgorithmInhibit = 0
        timeDelayNormal = 2
        currentCommandPriority = <bacpypes3.basetypes.OptionalUnsigned object at 0x756256a0>
            null = ()
DEBUG:__main__:nc1: <bacpypes3.object.NotificationClassObject object at 0x755591c0>
    <bacpypes3.object.NotificationClassObject object at 0x755591c0>
        objectIdentifier = (<ObjectType: notification-class>, 1)
        objectName = 'nc1'
        objectType = <ObjectType: notification-class>
        description = 'test notification class'
        notificationClass = 1
        priority = [9, 9, 9]
        ackRequired = <EventTransitionBits: >
        recipientList = [<bacpypes3.basetypes.Destination object at 0x75559220>]
> Exception in callback EventAlgorithm.state_transition_delayed()
handle: <TimerHandle when=1855.115028604 EventAlgorithm.state_transition_delayed()>
Traceback (most recent call last):
  File "/usr/lib/python3.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/bbartling/.local/lib/python3.9/site-packages/bacpypes3/local/event.py", line 411, in state_transition_delayed
    self.state_transition(new_state, True)
  File "/home/bbartling/.local/lib/python3.9/site-packages/bacpypes3/local/event.py", line 618, in state_transition
    ] = self.event_notification_parameters()
  File "/home/bbartling/.local/lib/python3.9/site-packages/bacpypes3/local/event.py", line 1686, in event_notification_parameters
    return event_values
UnboundLocalError: local variable 'event_values' referenced before assignment
shashankgowdasd commented 6 months ago

Hi @JoelBender Sir, Is their any substitute methods or example for internsic alarming in bacpypes3 or bacpypes please Suggest me sir......

JoelBender commented 6 months ago

The sandbox application that Ben references should be working (along with the others that are similarly named). I'll fix it up and post back here.

JoelBender commented 6 months ago

There is now a new event-notification-recipient.py sample application for receiving events, and the event-server-avo1-ir.py sample has been updated (the others also updated but not tested yet).

I have this nagging feeling that the relationship between normal/fault transitions and normal/off-normal transitions aren't quite right yet with respect to timers.

shashankgowdasd commented 6 months ago

Thank you Sir @JoelBender, I have used the event-server-avo1-ir.py for internsic alarming but when I adjust the presentValue above the HighLimit , I got the below error after the time delay

Error: Exception in callback EventAlgorithm.state_transition_delayed() handle: <TimerHandle when=466190.093 EventAlgorithm.state_transition_delayed()> Traceback (most recent call last): File "C:\Users\vimel\AppData\Local\Programs\Python\Python39\lib\asyncio\events.py", line 80, in _run self._context.run(self._callback, *self._args) File "C:\Users\vimel\AppData\Local\Programs\Python\Python39\lib\site-packages\bacpypes3\local\event.py", line 411, in state_transition_delayed self.state_transition(new_state, True) File "C:\Users\vimel\AppData\Local\Programs\Python\Python39\lib\site-packages\bacpypes3\local\event.py", line 618, in state_transition
] = self.event_notification_parameters() File "C:\Users\vimel\AppData\Local\Programs\Python\Python39\lib\site-packages\bacpypes3\local\event.py", line 1686, in event_notification_parameters return event_values UnboundLocalError: local variable 'event_values' referenced before assignment

JoelBender commented 6 months ago

I think you are still running the old code, those lines should look like this. Please turn on debugging by adding --debug bacpypes3.local.event.OutOfRangeEventAlgorithm and when event_notification_parameters() is called it should dump out the private _current_state and new_state values. If the event_values is unset then the transition isn't being recognized.

The format for building a DeviceAddress (described in basetypes) is the same as other BACpypes addresses. This is one of the rare cases where going from BACnetAddress in the standard to Address in the library would cause headaches, so I renamed it to DeviceAddress:

>>> DeviceAddress("1.2.3.4").debug_contents()
    networkNumber = 0
    macAddress = b'\x01\x02\x03\x04\xba\xc0'

>>> DeviceAddress("5:6").debug_contents()
    networkNumber = 5
    macAddress = b'\x06'

>>> DeviceAddress("*").debug_contents()
    networkNumber = 0
    macAddress = b''

I'm not sure why I excluded global broadcasts, I've looked in the standard and I couldn't find it explicitly excluded.

>>> DeviceAddress("*:*").debug_contents()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/joel/BACpypes3/bacpypes3/constructeddata.py", line 228, in __call__
    return cast(Sequence, type.__call__(new_type, *args, **kwargs))
  File "/home/joel/BACpypes3/bacpypes3/basetypes.py", line 1898, in __init__
    raise ValueError(arg)
ValueError: *:*
JoelBender commented 6 months ago

Note that the samples have a recipient device specified by its device object identifier, so for a notification to be sent out the application needs to have it "bound" (see this code). So execute a Who-Is for the destination device, the library doesn't do that automatically.

shashankgowdasd commented 6 months ago

Hi @JoelBender Sir, Thank you for your previous suggestions; I was able to see the intrinsic reporting using the event-server-avo1-ir.py. However, I now face the challenge of incorporating alarm services using Bacpypes3. I have developed the entire project using Bacpypes, and I attempted to integrate the AnalogObjectIR from Bacpypes3 directly into my application. Unfortunately, I have encountered difficulties and have not achieved success.

I kindly request your guidance and suggestions on how to effectively implement intrinsic reporting using Bacpypes3 within my Bacpypes-based application. Your expertise and advice will be greatly appreciated.