BACnet is the standard protocol of building automation (ISO 16484-5). Each device holds objects (analog inputs, binary outputs, schedules, trend logs and more), and each object has properties such as its present value, units and status. BACnet/IP (Annex J) carries it over UDP port 47808, with BBMDs and routers joining networks across subnets.
Where you meet it
- HVAC controllers, chillers, air handlers and VAV boxes
- Lighting, access control and fire panels
- Building energy meters and building management systems (BMS)
Quickstart
From the command line
Install bacnetctl with curl -fsSL https://get.otfabric.io/bacnetctl | sh, or on Windows irm https://get.otfabric.io/bacnetctl.ps1 | iex (all install options), then:
# Which devices are on this network?bacnetctl discover
# Its point list: every object with value, unit, status and descriptionbacnetctl objects --device 192.168.1.20 --values
# One valuebacnetctl read --device 192.168.1.20 analog-input:1 present-value
# Watch two points change, until Ctrl-Cbacnetctl monitor --device 192.168.1.20 analog-input:1 binary-input:3
# Override a setpoint at operator priority, then hand it backbacnetctl write --device 192.168.1.20 analog-value:1 present-value 22.5 --priority 8bacnetctl release --device 192.168.1.20 analog-value:1 --priority 8Objects are written as type:instance (analog-input:1, or ai:1) and properties by name (present-value, or pv).
No controller at hand? bacnetctl server run serves a simulated device to practise on, from a JSON device file or a built-in example:
# Terminal 1: the example device on loopback, every write printed as it happensbacnetctl server run --listen 127.0.0.1
# Terminal 2: use it like any devicebacnetctl objects --device 127.0.0.1 --valuesFrom Go
go get github.com/otfabric/go-bacnet@latestDiscover devices and print their names:
package main
import ( "context" "fmt" "log" "time"
"github.com/otfabric/go-bacnet" "github.com/otfabric/go-bacnet/client")
func main() { c, err := client.New() // binds UDP port 47808 if err != nil { log.Fatal(err) } defer c.Close()
ctx := context.Background() devices, err := c.Discover(ctx, client.DiscoveryOptions{Window: 3 * time.Second}) if err != nil { log.Fatal(err) } name := bacnet.PropertyReference{Identifier: bacnet.PropertyObjectName} for _, d := range devices { val, err := c.ReadProperty(ctx, d.Target(), d.DeviceID(), name) if err != nil { fmt.Printf("device %d at %s: %v\n", d.Instance, d.Address, err) continue } fmt.Printf("device %d at %s: %s\n", d.Instance, d.Address, val.Character.Value) }}Serve a device of your own, with a commandable setpoint:
dev, err := object.NewDevice(object.DeviceConfig{Instance: 1234, Name: "dev-1234", VendorID: 999})if err != nil { log.Fatal(err)}av, err := object.NewAnalogValue(object.PointConfig{Instance: 1, Name: "setpoint", Units: 62, Value: 21, Commandable: true})if err != nil { log.Fatal(err)}if err := dev.Add(av); err != nil { log.Fatal(err)}s, err := server.New(dev) // binds UDP port 47808if err != nil { log.Fatal(err)}defer s.Close()_ = s.IAm()// The application owns its values; COV subscribers are notified._ = av.SetPresentValue(bacnet.RealValue(22))The imports are github.com/otfabric/go-bacnet, github.com/otfabric/go-bacnet/server and github.com/otfabric/go-bacnet/server/object. A complete device that runs until interrupted is in examples/server.
What go-bacnet supports
| Roles | Client, and server: a BACnet device of your own with its objects, optionally also the BBMD of its subnet |
| Transport | BACnet/IP (Annex J) over IPv4, routed networks, foreign-device registration, segmentation in both directions |
| Client services | Who-Is / I-Am discovery, read and write properties, COV and alarm notifications, file transfer, object management |
| Server | Device, analog, binary and multi-state points, Notification Class, Trend Log, File, Calendar, Schedule, CharacterString, Integer and Positive Integer Value, Structured View; reads and writes, COV, intrinsic reporting and the alarm services, ReadRange, files, object creation and deletion, device management |
| Dependencies | Go standard library only |
| Go version | 1.26 or later |
Interoperability
bacnet-interop provides Dockerized devices from BACnet Stack (C), BACpypes3 and legacy BACpypes (Python), BACnet4J (Java), System.IO.BACnet (C#), Worldiety, cB-Sigma and ulbios (Go) and @bacnet-js/client (TypeScript), including BBMD and routed-network scenarios and cB-Sigma’s simulator with fault switches. Since v0.12.0 the BACnet Stack, BACnet4J and BACpypes3 images also run as clients, and v0.14.0 added legacy BACpypes, bacnet-js and ulbios in both roles, with scenario files for testing a BACnet server: discovery, reads and writes, COV, files, alarms, device management, segmentation and the BBMD. Since v0.15.0 it also publishes go-bacnet as an image, as a device and as a client, for others to test against.