Skip to content

Instantly share code, notes, and snippets.

View JoelBender's full-sized avatar
🎯
Focusing

Joel Bender JoelBender

🎯
Focusing
View GitHub Profile
@JoelBender
JoelBender / whois_timer_sample.py
Created May 21, 2021 03:43
Periodically generate a Who-Is request
#!/usr/bin/env python
"""
This application generates a Who-Is request based on a timer, then lines up
the corresponding I-Am for incoming traffic and prints out the contents.
"""
import sys
from bacpypes.debugging import bacpypes_debugging, ModuleLogger
@JoelBender
JoelBender / local_objects.py
Created January 3, 2021 16:45
Local Objects
#!/usr/bin/env python
"""
This sample application is a server that has a local, writable, Analog Value
and Binary Value object.
On a network with two IPv4 workstations make a copy of the BACpypes~.ini file
called in BACpypes.ini and set the 'address:' to the CIDR address of the
workstation. For example, the first one is 192.168.10.11/24 and the second
is 192.168.10.21/24.
@JoelBender
JoelBender / COVClientApp.py
Last active December 7, 2020 17:45
This non-threaded BACpypes COV client application maintains a "context" for subscriptions.
#!/usr/bin/env python
"""
Configured with a subscription context object which is passed to the
application, it sends a SubscribeCOVRequest and listens for confirmed or
unconfirmed COV notifications, lines them up with the context, and passes the
APDU to the context to print out.
Making multiple subscription contexts and keeping them active based on their
lifetime is left as an exercise for the reader.
@JoelBender
JoelBender / simple_analog_values.py
Created October 20, 2020 02:31
Simple way of serving analog value objects
#!/usr/bin/env python
"""
This sample application shows how to create analog value objects with
different values.
"""
import os
import random
from bacpypes.primitivedata import TagList
from bacpypes.basetypes import (
DeviceObjectPropertyReference,
EventParameterAccessEventAccessEvent,
)
x = EventParameterAccessEventAccessEvent(
listOfAccessEvents=["deniedMaxAttempts"],
accessEventTimeReference=DeviceObjectPropertyReference(
objectIdentifier=("analogValue", 1), propertyIdentifier="presentValue"
@JoelBender
JoelBender / chips.py
Created April 29, 2020 13:24
Chips and wires
"""
Chips
"""
from typing import Any, List
_all_chips: List["Chip"] = []
_all_wires: List["Wire"] = []
@JoelBender
JoelBender / threading_1.py
Created April 17, 2020 01:09
Threading Examples
#!/usr/bin/python
"""
This application demonstrates doing something at a regular interval.
"""
import sys
from bacpypes.debugging import bacpypes_debugging, ModuleLogger
from bacpypes.consolelogging import ArgumentParser
@JoelBender
JoelBender / FlaskReadProperty.py
Created September 13, 2018 17:47
Flask based web server that reads values based on `MultipleReadProperty.py` sample. Not for production use.
#!/usr/bin/env python
"""
A web server based on flask that reads properties from objects and returns an
HTML page of the results.
"""
from flask import Flask
from jinja2 import Template
from threading import Thread
@JoelBender
JoelBender / gist:0879b78ebc474502ada48870c51a266b
Created September 19, 2019 22:20
asyncio signal handler
import sys
import asyncio
import signal
def ctrl_c():
print("hit!")
sys.exit(1)
loop = asyncio.get_event_loop()
loop.add_signal_handler(signal.SIGINT, ctrl_c)
@JoelBender
JoelBender / who_is_and_device_info.py
Created September 10, 2019 13:43
Who-Is and Device Information
#!/usr/bin/env python
"""
This application generates a Who-Is request at startup and collects the I-Am
responses into a list, then reads various properties of the device objects,
then outputs the content as a JSON document.
"""
import sys
import json