Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mqtt packet is always {} #10

Open
kskenyon opened this issue Dec 21, 2020 · 7 comments
Open

mqtt packet is always {} #10

kskenyon opened this issue Dec 21, 2020 · 7 comments
Labels
good first issue Good for newcomers

Comments

@kskenyon
Copy link

I know support for mqtt other than infinimesh is limited.

I modified the mqtt_client.js to run on mosquito with username and password authentication.

However, with several different bacnet devices, all I get is empty {} messages to mqtt on a weird subscription. devices/0x132/state/reported/delta
which seems hardwired into the code and doesn't make much sense to me. I'm mostly a poke and try coder and I don't fully understand bacnet-stack.

I can read the bacnet OK with other apps including node-red. I think I have the correct type and instances in the config file.

Also, the web server doesn't seem to work. I get the main screen for "who is" and "object" but nothing happens when I click the buttons. The REST API doesn't work either.

So is this so totally entwined with infinimesh that it is hopeless to try to fix it?

I think there are others who would like to use this gateway with their existing setup.

Kevin

pi@pi3:~/bacnet-mqtt-gateway $ npm start

[email protected] start /home/pi/bacnet-mqtt-gateway
node src/app.js

{"level":"info","message":"Gateway server listening on port 8083","timestamp":"2020-12-20 21:57:39"}
{"level":"info","message":"Device configs found: baspi.json,baspi1.json,baspi2.json","timestamp":"2020-12-20 21:57:39"}
{"level":"info","message":"Client connected","timestamp":"2020-12-20 21:57:39"}
{"level":"info","message":"Schedule polling for device 10.0.1.32 with expression */3 * * * * *","timestamp":"2020-12-20 21:57:39"}
{"level":"info","message":"Schedule polling for device 10.0.1.150 with expression */3 * * * * *","timestamp":"2020-12-20 21:57:39"}
{"level":"info","message":"Schedule polling for device 10.0.1.150 with expression */3 * * * * *","timestamp":"2020-12-20 21:57:39"}
{"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:42"}
{"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:42"}
{"level":"info","message":"Sending actuals for device 10.0.1.150 to IoT Hub","timestamp":"2020-12-20 21:57:42"}
{"level":"info","message":"{}","timestamp":"2020-12-20 21:57:42"}
{"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:42"}
{"level":"info","message":"Sending actuals for device 10.0.1.150 to IoT Hub","timestamp":"2020-12-20 21:57:42"}
{"level":"info","message":"{}","timestamp":"2020-12-20 21:57:42"}
{"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:42"}
{"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:42"}
{"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:45"}
{"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:45"}
{"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:45"}
{"level":"info","message":"Sending actuals for device 10.0.1.150 to IoT Hub","timestamp":"2020-12-20 21:57:45"}
{"level":"info","message":"{}","timestamp":"2020-12-20 21:57:45"}
{"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:45"}
{"level":"info","message":"Sending actuals for device 10.0.1.150 to IoT Hub","timestamp":"2020-12-20 21:57:45"}
{"level":"info","message":"{}","timestamp":"2020-12-20 21:57:45"}
{"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:45"}
{"level":"info","message":"Sending actuals for device 10.0.1.32 to IoT Hub","timestamp":"2020-12-20 21:57:45"}
{"level":"info","message":"{}","timestamp":"2020-12-20 21:57:45"}
{"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:45"}
{"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:48"}
{"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:48"}
{"level":"info","message":"Sending actuals for device 10.0.1.32 to IoT Hub","timestamp":"2020-12-20 21:57:48"}
{"level":"info","message":"{}","timestamp":"2020-12-20 21:57:48"}
{"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:48"}
{"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:48"}
{"level":"info","message":"Sending actuals for device 10.0.1.150 to IoT Hub","timestamp":"2020-12-20 21:57:48"}
{"level":"info","message":"{}","timestamp":"2020-12-20 21:57:48"}
{"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:48"}
{"level":"info","message":"Sending actuals for device 10.0.1.150 to IoT Hub","timestamp":"2020-12-20 21:57:48"}
{"level":"info","message":"{}","timestamp":"2020-12-20 21:57:48"}
{"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:48"}
{"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:51"}
{"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:51"}
{"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:51"}
{"level":"info","message":"Sending actuals for device 10.0.1.150 to IoT Hub","timestamp":"2020-12-20 21:57:51"}
{"level":"info","message":"{}","timestamp":"2020-12-20 21:57:51"}
{"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:51"}
{"level":"info","message":"Sending actuals for device 10.0.1.32 to IoT Hub","timestamp":"2020-12-20 21:57:51"}
{"level":"info","message":"{}","timestamp":"2020-12-20 21:57:51"}
{"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:51"}
{"level":"info","message":"Sending actuals for device 10.0.1.150 to IoT Hub","timestamp":"2020-12-20 21:57:51"}
{"level":"info","message":"{}","timestamp":"2020-12-20 21:57:51"}
{"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:51"}
^C

@magicmatt007
Copy link

magicmatt007 commented Dec 21, 2020

Hi Kevin,

if you are using other BACnet sniffer tools like YABE on the same PC, where you run the BACnet2MQTT gateway, make sure you close them all before running npm start.

Regarding the publishing format: You can edit the publish_msg in mqtt_client.js to your desire. E.g., you can publish each BACnet object on a separate topic. For example like this:

publishMessage(messageJson) {
    if(sendConfig == true) { // Publish config:
        console.log('CONFIGURATION:');
        console.table(messageJson);
    
    // Publish values:
    console.log('PUBLISH UPDATE:');
        Object.keys(messageJson).forEach(key => {
            // console.table('Key : ' + key + ', Value : ' + JSON.stringify(messageJson[key]))
            // const topic = 'devices/' + gatewayId + '/state/reported/'+key;
            const objectType = key.split('_')[0];
            var type = 'sensor';
            // console.log('ObjType: ' + objectType);
            if (objectType == '0') {
                type = 'sensor';
            } else if (objectType == '3') {
                type = 'binary_sensor';
            } else if (objectType == '13') {
                type = 'sensor';
            } else { type = 'unknownObject' };

            const topic = 'homeassistant/' + type + '/' + key + "/state";
            const message = JSON.stringify(messageJson[key].value);
            console.log(topic, message)
            this.client.publish(topic, message);
        });
    }
}

Matthias

@kskenyon
Copy link
Author

Thanks Matthias, that was helpful. I still don't read any objects and the web interface still doesn't work but there is some progress in mqtt.

@magicmatt007
Copy link

I wasn't successful with the web interface either. I'm just editing the "baspi.json" with my bacnet objects:

Enter the IP of the BACnet device you want to read from.

Add the BACnet objects, which you want to read. You can use tools like YABE to figure out the objects you want to read:
ObjectType needs to be translated to its number, e.g. check here: https://www.winccoa.top/help314p016/BACnet/Bacnet_Applikation-06.htm
Instance number is available directly from YABE

@2pk03
Copy link
Owner

2pk03 commented Dec 22, 2020

@magicmatt007 thanks, can you please file an PR and we can add this into the readme. And if you find bugs, pls contribute the fix. We built this stack some time ago on customer needs. We are happy to look into improvements :)

@2pk03 2pk03 added the good first issue Good for newcomers label Dec 22, 2020
@jjanderson
Copy link

could I

I know support for mqtt other than infinimesh is limited.

I modified the mqtt_client.js to run on mosquito with username and password authentication.

However, with several different bacnet devices, all I get is empty {} messages to mqtt on a weird subscription. devices/0x132/state/reported/delta which seems hardwired into the code and doesn't make much sense to me. I'm mostly a poke and try coder and I don't fully understand bacnet-stack.

I can read the bacnet OK with other apps including node-red. I think I have the correct type and instances in the config file.

Also, the web server doesn't seem to work. I get the main screen for "who is" and "object" but nothing happens when I click the buttons. The REST API doesn't work either.

So is this so totally entwined with infinimesh that it is hopeless to try to fix it?

I think there are others who would like to use this gateway with their existing setup.

Kevin

pi@pi3:~/bacnet-mqtt-gateway $ npm start

[email protected] start /home/pi/bacnet-mqtt-gateway
node src/app.js

{"level":"info","message":"Gateway server listening on port 8083","timestamp":"2020-12-20 21:57:39"} {"level":"info","message":"Device configs found: baspi.json,baspi1.json,baspi2.json","timestamp":"2020-12-20 21:57:39"} {"level":"info","message":"Client connected","timestamp":"2020-12-20 21:57:39"} {"level":"info","message":"Schedule polling for device 10.0.1.32 with expression */3 * * * * *","timestamp":"2020-12-20 21:57:39"} {"level":"info","message":"Schedule polling for device 10.0.1.150 with expression */3 * * * * *","timestamp":"2020-12-20 21:57:39"} {"level":"info","message":"Schedule polling for device 10.0.1.150 with expression */3 * * * * *","timestamp":"2020-12-20 21:57:39"} {"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:42"} {"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:42"} {"level":"info","message":"Sending actuals for device 10.0.1.150 to IoT Hub","timestamp":"2020-12-20 21:57:42"} {"level":"info","message":"{}","timestamp":"2020-12-20 21:57:42"} {"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:42"} {"level":"info","message":"Sending actuals for device 10.0.1.150 to IoT Hub","timestamp":"2020-12-20 21:57:42"} {"level":"info","message":"{}","timestamp":"2020-12-20 21:57:42"} {"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:42"} {"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:42"} {"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:45"} {"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:45"} {"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:45"} {"level":"info","message":"Sending actuals for device 10.0.1.150 to IoT Hub","timestamp":"2020-12-20 21:57:45"} {"level":"info","message":"{}","timestamp":"2020-12-20 21:57:45"} {"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:45"} {"level":"info","message":"Sending actuals for device 10.0.1.150 to IoT Hub","timestamp":"2020-12-20 21:57:45"} {"level":"info","message":"{}","timestamp":"2020-12-20 21:57:45"} {"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:45"} {"level":"info","message":"Sending actuals for device 10.0.1.32 to IoT Hub","timestamp":"2020-12-20 21:57:45"} {"level":"info","message":"{}","timestamp":"2020-12-20 21:57:45"} {"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:45"} {"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:48"} {"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:48"} {"level":"info","message":"Sending actuals for device 10.0.1.32 to IoT Hub","timestamp":"2020-12-20 21:57:48"} {"level":"info","message":"{}","timestamp":"2020-12-20 21:57:48"} {"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:48"} {"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:48"} {"level":"info","message":"Sending actuals for device 10.0.1.150 to IoT Hub","timestamp":"2020-12-20 21:57:48"} {"level":"info","message":"{}","timestamp":"2020-12-20 21:57:48"} {"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:48"} {"level":"info","message":"Sending actuals for device 10.0.1.150 to IoT Hub","timestamp":"2020-12-20 21:57:48"} {"level":"info","message":"{}","timestamp":"2020-12-20 21:57:48"} {"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:48"} {"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:51"} {"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:51"} {"level":"info","message":"Fetching device object values","timestamp":"2020-12-20 21:57:51"} {"level":"info","message":"Sending actuals for device 10.0.1.150 to IoT Hub","timestamp":"2020-12-20 21:57:51"} {"level":"info","message":"{}","timestamp":"2020-12-20 21:57:51"} {"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:51"} {"level":"info","message":"Sending actuals for device 10.0.1.32 to IoT Hub","timestamp":"2020-12-20 21:57:51"} {"level":"info","message":"{}","timestamp":"2020-12-20 21:57:51"} {"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:51"} {"level":"info","message":"Sending actuals for device 10.0.1.150 to IoT Hub","timestamp":"2020-12-20 21:57:51"} {"level":"info","message":"{}","timestamp":"2020-12-20 21:57:51"} {"level":"info","message":"Publish message to MQTT Broker","timestamp":"2020-12-20 21:57:51"} ^C

could I be cheeky and ask for your mosquitto config for this? I am battling to get the formatting right... many many thanks

@mikihacia
Copy link

@kskenyon

Any chance that you still keep the mosquito config file?

@Bagunda
Copy link

Bagunda commented Dec 21, 2023

I modified the mqtt_client.js to run on mosquito with username and password authentication.

Can you post the code for the modified mqtt_client.js?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

6 participants