Commit 6bd91d19 authored by Micha Mueller's avatar Micha Mueller
Browse files

Add possiblity to specify address_cache file for BACnet plugin in config...

Add possiblity to specify address_cache file for BACnet plugin in config (relies on BACnet-stack patch)
parent 98b52f09
......@@ -394,7 +394,7 @@ Explanation of the values specific for the PDU plugin:
## BACnet
The BACnet plugin enables dcdbpusher to communicate and request data from devices which communicate via the BACnet protocol. A so called "read property" request is sent by the plugin to the BACnet devices as configured in the config file. The response value is then stored in the database. Usually one is only interested in collecting the current reading of a BACnet device (property PROP_PRESENT_VALUE, ID 85). However, also reading of other properties is supported.
> NOTE     On startup BACnet plugin does no device discovery. Instead it relies on the user providing an `address_cache` file with addresses of all required BACnet devices. One can generate such a address-file for example by using the `bacwi` demo tool provided by the BACnet-Stack. Currently the `address_cache` file is expected to be in the same directory as the dcdbpusher binary.
> NOTE     On startup BACnet plugin does no device discovery. Instead it relies on the user providing a file with addresses of all required BACnet devices. One can generate such an address-file for example by using the `bacwi` demo tool provided by the BACnet-Stack.
### config file format
......@@ -402,6 +402,7 @@ The config file for the BACnet plugin should fulfill the following scheme:
```
global {
mqttPrefix /FF112233445566778899FFFF
address_cache ../test.cache
interface eth0
port 22222
timeout 1000
......@@ -455,6 +456,7 @@ Explanation of the values specific for the BACnet plugin:
| Value | Explanation |
|:----- |:----------- |
| address_cache | (Path to and) filename of the address cache file where the addresses of BACnet devices are stored (as noted above).
| interface | Network interface (IPv4) which is to be used by the plugin to send its "Read Property" requests.
| port | Port to use on the interface
| timeout | Value of µ-seconds to wait for a response packet.
......
global {
mqttPrefix /FF112233445566778899FFFF
address_cache ../../test.cache
interface eth0
port 22222
timeout 1000
......
......@@ -32,11 +32,16 @@ BACnetClient::~BACnetClient() {
datalink_cleanup();
}
void BACnetClient::init(std::string interface, unsigned port, unsigned timeout, unsigned apdu_timeout, unsigned retries) {
void BACnetClient::init(std::string interface, const std::string& address_cache, unsigned port, unsigned timeout, unsigned apdu_timeout, unsigned retries) {
_timeout = timeout;
//compile BACnet stack with BACNET_ADDRESS_CACHE_FILE for initialization from file address_cache
address_init();
if (FILE *file = fopen(address_cache.c_str(), "r")) {
fclose(file);
} else {
throw std::runtime_error("Can not open address cache file");
}
address_init_by_file(address_cache.c_str());
//setup datalink
......
......@@ -38,12 +38,13 @@ public:
* to enable initialization of address cache from file "address_cache".
*
* @param interface Name of network interface to use
* @param address_cache (Path and) filename of the address cache file where the addresses of BACnet devices are stored
* @param port Which port to use of the interface
* @param timeout Number of milliseconds to wait for a packet when receiving
* @param apdu_timeout Number of milliseconds before timeout when sending
* @param retries Number of retries after an apdu timeout occurs
*/
void init(std::string interface, unsigned port = 47808, unsigned timeout = 1000, unsigned apdu_timeout = 200, unsigned retries = 0);
void init(std::string interface, const std::string& address_cache, unsigned port = 47808, unsigned timeout = 1000, unsigned apdu_timeout = 200, unsigned retries = 0);
/**
* Sends a READ_PROPERTY request for PROP_PRESENT_VALUE to specified device and decodes the response (READ_PROPERTY_ACK).
......
......@@ -29,14 +29,17 @@ std::vector<Sensor*>& BACnetConfigurator::readConfig(std::string cfgPath) {
boost::property_tree::read_info(cfgPath, cfg);
_bacClient = new BACnetClient();
std::string interface, mqttPartDevice, mqttPartObject;
std::string interface, address_cache, mqttPartDevice, mqttPartObject;
unsigned port = 47808, timeout = 1000, apdu_timeout = 200, apdu_retries = 0;
unsigned deviceInstance = 0, objInstance = 0;
BACNET_OBJECT_TYPE objType = OBJECT_DEVICE; /* = 8 */
//read global variables (if present overwrite those from global.conf)
BOOST_FOREACH(boost::property_tree::iptree::value_type &global, cfg.get_child("global")) {
if (boost::iequals(global.first, "interface")) {
if (boost::iequals(global.first, "address_cache")) {
address_cache = global.second.data();
LOG(debug) << " Address Cache: " << address_cache;
} else if (boost::iequals(global.first, "interface")) {
interface = global.second.data();
LOG(debug) << " Interface " << interface;
} else if (boost::iequals(global.first, "port")) {
......@@ -60,7 +63,7 @@ std::vector<Sensor*>& BACnetConfigurator::readConfig(std::string cfgPath) {
}
try {
_bacClient->init(interface, port, timeout, apdu_timeout, apdu_retries);
_bacClient->init(interface, address_cache, port, timeout, apdu_timeout, apdu_retries);
} catch (const std::exception& e) {
LOG(error) << "Could not initialize BACnetClient: " << e.what();
return _sensors;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment