NubeIO / driver-bacnet

0 stars 2 forks source link

add bacnet master (bacnet-client) #35

Closed NubeDev closed 1 year ago

NubeDev commented 1 year ago

the idea would be that we could send the bacnet stack a message over MQTT and then MQTT would publish the result back on a topic

we need to resue the same bacnet instance so we can run both services on the same ethenet port

example send a whois

publish to a topic

bacnet/whois/send {network:eth0, timeout:2000}

basic scope

add better support for read

send json body

{
"objectType":"1",
"objectInstance":"1",
"property":"85",
"deviceInstance":"1",
"mac":"123",
"dnet":"1",
}
aidan@pop-os-ryan:~/code/helpers/bacnet-stack-bacnet-stack-1.0.0/bin$ ./bacrp --help
Usage: bacrp device-instance object-type object-instance property [index]
       [--dnet][--dadr][--mac]
       [--version][--help]
Read a property from an object in a BACnet device
and print the value.
--mac A
Optional BACnet mac address.Valid ranges are from 00 to FF (hex) for MS/TP or ARCNET,
or an IP string with optional port number like 10.1.2.3:47808
or an Ethernet MAC in hex like 00:21:70:7e:32:bb

--dnet N
Optional BACnet network number N for directed requests.
Valid range is from 0 to 65535 where 0 is the local connection
and 65535 is network broadcast.

--dadr A
Optional BACnet mac address on the destination BACnet network number.
Valid ranges are from 00 to FF (hex) for MS/TP or ARCNET,
or an IP string with optional port number like 10.1.2.3:47808
or an Ethernet MAC in hex like 00:21:70:7e:32:bb

device-instance:
BACnet Device Object Instance number that you are
trying to communicate to.  This number will be used
to try and bind with the device using Who-Is and
I-Am services.  For example, if you were reading
Device Object 123, the device-instance would be 123.

object-type:
The object type is object that you are reading. It
can be defined either as the object-type name string
as defined in the BACnet specification, or as the
integer value of the enumeration BACNET_OBJECT_TYPE
in bacenum.h. For example if you were reading Analog
Output 2, the object-type would be analog-output or 1.

object-instance:
This is the object instance number of the object that
you are reading.  For example, if you were reading
Analog Output 2, the object-instance would be 2.

property:
The property of the object that you are reading. It
can be defined either as the property name string as
defined in the BACnet specification, or as an integer
value of the enumeration BACNET_PROPERTY_ID in
bacenum.h. For example, if you were reading the Present
Value property, use present-value or 85 as the property.

index:
This integer parameter is the index number of an array.
If the property is an array, individual elements can
be read.  If this parameter is missing and the property
is an array, the entire array will be read.

Example:
If you want read the Present-Value of Analog Output 101
in Device 123, you could send either of the following
commands:
bacrp 123 analog-output 101 present-value
bacrp 123 1 101 85
If you want read the Priority-Array of Analog Output 101
in Device 123, you could send either of the following
commands:
bacrp 123 analog-output 101 priority-array
bacrp 123 1 101 87

add better support for write

send json body

write PV

{
"value":"22",
"objectType":"1",
"objectInstance":"1",
"property":"85",
"deviceInstance":"1",
"mac":"123",
"dnet":"1",
}

write priority

{
"value":"22",
"priority":"22",
"objectType":"1",
"objectInstance":"1",
"property":"85",
"deviceInstance":"1",
"mac":"123",
"dnet":"1",
}
aidan@pop-os-ryan:~/code/helpers/bacnet-stack-bacnet-stack-1.0.0/bin$ ./bacwp --help
Usage: bacwp device-instance object-type object-instance property priority index tag value [tag value...]
device-instance:
BACnet Device Object Instance number that you are trying to
communicate to.  This number will be used to try and bind with
the device using Who-Is and I-Am services.  For example, if you were
writing to Device Object 123, the device-instance would be 123.

object-type:
The object type is object that you are reading. It
can be defined either as the object-type name string
as defined in the BACnet specification, or as the
integer value of the enumeration BACNET_OBJECT_TYPE
in bacenum.h. For example if you were reading Analog
Output 2, the object-type would be analog-output or 1.

object-instance:
This is the object instance number of the object that you are 
writing to.  For example, if you were writing to Analog Output 2, 
the object-instance would be 2.

property:
The property of the object that you are reading. It
can be defined either as the property name string as
defined in the BACnet specification, or as an integer
value of the enumeration BACNET_PROPERTY_ID in
bacenum.h. For example, if you were reading the Present
Value property, use present-value or 85 as the property.

priority:
This parameter is used for setting the priority of the
write. If Priority 0 is given, no priority is sent.  The BACnet 
standard states that the value is written at the lowest 
priority (16) if the object property supports priorities
when no priority is sent.

index
This integer parameter is the index number of an array.
If the property is an array, individual elements can be written
to if supported.  If this parameter is -1, the index is ignored.

tag:
Tag is the integer value of the enumeration BACNET_APPLICATION_TAG 
in bacenum.h.  It is the data type of the value that you are
writing.  For example, if you were writing a REAL value, you would 
use a tag of 4.
Context tags are created using two tags in a row.  The context tag
is preceded by a C.  Ctag tag. C2 4 creates a context 2 tagged REAL.

value:
The value is an ASCII representation of some type of data that you
are writing.  It is encoded using the tag information provided.  For
example, if you were writing a REAL value of 100.0, you would use 
100.0 as the value.

Here is a brief overview of BACnet property and tags:
Certain properties are expected to be written with certain 
application tags, so you probably need to know which ones to use
with each property of each object.  It is almost safe to say that
given a property and an object and a table, the tag could be looked
up automatically.  There may be a few exceptions to this, such as
the Any property type in the schedule object and the Present Value
accepting REAL, BOOLEAN, NULL, etc.  Perhaps it would be simpler for
the demo to use this kind of table - but I also wanted to be able
to do negative testing by passing the wrong tag and have the server
return a reject message.

Example:
If you want send a value of 100 to the Present-Value in
Analog Output 0 of Device 123 at priority 16,
send the one of following commands:
bacwp 123 analog-output 0 present-value 16 -1 4 100
bacwp 123 1 0 85 16 -1 4 100
To send a relinquish command to the same object:
bacwp 123 analog-output 0 present-value 16 -1 0 0
bacwp 123 1 0 85 16 -1 0 0
Shiny380 commented 1 year ago

Goal is to be able to run a Server AND a Master at the same time. This enabled 2 devices to have two-way communication with each other, i.e. 2 of our Rubix-Computes.

We will need to do a smaller scale test first to make sure this will work on the same port and that messages get in and out still. The main requirement is the you can do master requests but the server still has to run and be readable

shomaglasang commented 1 year ago

@NubeDev @Shiny380 mate so basically the bacnet server subscribes to MQTT topics. And these topics correspond to commands (e.g. read present values of an object instance, write object name of an instance ). And the response/result is published over MQTT, perhaps in a different topic so the server will not read them back. Am I correct mate? The published value from the server will be in json format.