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

Feature request: define/override MQTT client identifier #2197

Closed
TheKorn2 opened this issue Oct 9, 2022 · 6 comments
Closed

Feature request: define/override MQTT client identifier #2197

TheKorn2 opened this issue Oct 9, 2022 · 6 comments

Comments

@TheKorn2
Copy link

TheKorn2 commented Oct 9, 2022

Scenario: two rtl_433 instances using identical hardware on two different machines talking to the same MQTT server. (It's setup and works, why would I need two?)

Problem: automatically generated mqtt identifiers are identical across both machines, so they take turns killing the other's MQTT session. MQTT sees identical session identifiers and assumes they're duplicate sessions of each other (mosquitto log, machine #1 is 127.0.0.1 and machine #2 is 172.18.0.84):

2022-10-09T04:21:24: New client connected from 172.18.0.84 as rtl_433-0a97ffff (p2, c0, k60, u'mqtt').
2022-10-09T04:21:24: New connection from 127.0.0.1 on port 1883.
2022-10-09T04:21:25: Client rtl_433-0a97ffff already connected, closing old connection.
2022-10-09T04:21:25: New client connected from 127.0.0.1 as rtl_433-0a97ffff (p2, c0, k60, u'mqtt').
2022-10-09T04:21:25: New connection from 172.18.0.84 on port 1883.
2022-10-09T04:21:25: Client rtl_433-0a97ffff already connected, closing old connection.

So need the ability to set/override the MQTT client identifier. I think the current default behavior is good, just need a way to override the default for situations like these.

@merbanan
Copy link
Owner

merbanan commented Oct 9, 2022

Try -d

@TheKorn2
Copy link
Author

TheKorn2 commented Oct 9, 2022

 [-d <RTL-SDR USB device index> | :<RTL-SDR USB device serial> | <SoapySDR device query> | rtl_tcp | help]

I don't see how -d could help, please explain.

@TheKorn2
Copy link
Author

TheKorn2 commented Oct 9, 2022

I tried whipping a "-d 0" onto one of the clients, same result:

2022-10-09T05:04:27: New connection from 127.0.0.1 on port 1883.
2022-10-09T05:04:28: Client rtl_433-0a97ffff already connected, closing old connection.
2022-10-09T05:04:28: New client connected from 127.0.0.1 as rtl_433-0a97ffff (p2, c0, k60, u'mqtt').
2022-10-09T05:04:29: New connection from 172.18.0.84 on port 1883.
2022-10-09T05:04:29: Client rtl_433-0a97ffff already connected, closing old connection.
2022-10-09T05:04:29: New client connected from 172.18.0.84 as rtl_433-0a97ffff (p2, c0, k60, u'mqtt').
2022-10-09T05:04:29: New connection from 127.0.0.1 on port 1883.
2022-10-09T05:04:30: Client rtl_433-0a97ffff already connected, closing old connection.
2022-10-09T05:04:30: New client connected from 127.0.0.1 as rtl_433-0a97ffff (p2, c0, k60, u'mqtt').
2022-10-09T05:04:30: New connection from 172.18.0.84 on port 1883.
2022-10-09T05:04:30: Client rtl_433-0a97ffff already connected, closing old connection.
2022-10-09T05:04:30: New client connected from 172.18.0.84 as rtl_433-0a97ffff (p2, c0, k60, u'mqtt').
2022-10-09T05:04:31: New connection from 127.0.0.1 on port 1883.
2022-10-09T05:04:31: Client rtl_433-0a97ffff already connected, closing old connection.
2022-10-09T05:04:31: New client connected from 127.0.0.1 as rtl_433-0a97ffff (p2, c0, k60, u'mqtt').
2022-10-09T05:04:32: New connection from 172.18.0.84 on port 1883.
2022-10-09T05:04:32: Client rtl_433-0a97ffff already connected, closing old connection.
2022-10-09T05:04:32: New client connected from 172.18.0.84 as rtl_433-0a97ffff (p2, c0, k60, u'mqtt').
2022-10-09T05:04:32: New connection from 127.0.0.1 on port 1883.
2022-10-09T05:04:33: Client rtl_433-0a97ffff already connected, closing old connection.
2022-10-09T05:04:33: New client connected from 127.0.0.1 as rtl_433-0a97ffff (p2, c0, k60, u'mqtt').
2022-10-09T05:04:33: New connection from 172.18.0.84 on port 1883.
2022-10-09T05:04:33: Client rtl_433-0a97ffff already connected, closing old connection.
2022-10-09T05:04:33: New client connected from 172.18.0.84 as rtl_433-0a97ffff (p2, c0, k60, u'mqtt').
2022-10-09T05:04:34: New connection from 127.0.0.1 on port 1883.
2022-10-09T05:04:35: Client rtl_433-0a97ffff already connected, closing old connection.
2022-10-09T05:04:35: New client connected from 127.0.0.1 as rtl_433-0a97ffff (p2, c0, k60, u'mqtt').
2022-10-09T05:04:35: New connection from 172.18.0.84 on port 1883.
2022-10-09T05:04:35: Client rtl_433-0a97ffff already connected, closing old connection.
2022-10-09T05:04:35: New client connected from 172.18.0.84 as rtl_433-0a97ffff (p2, c0, k60, u'mqtt').
2022-10-09T05:04:36: New connection from 127.0.0.1 on port 1883.
2022-10-09T05:04:36: Client rtl_433-0a97ffff already connected, closing old connection.
2022-10-09T05:04:36: New client connected from 127.0.0.1 as rtl_433-0a97ffff (p2, c0, k60, u'mqtt').
2022-10-09T05:04:36: New connection from 172.18.0.84 on port 1883.
2022-10-09T05:04:37: Client rtl_433-0a97ffff already connected, closing old connection.

@zuckschwerdt
Copy link
Collaborator

The client ID is derived from hostname and device spec.

rtl_433/src/output_mqtt.c

Lines 484 to 488 in e066b66

// generate a short deterministic client_id to identify this input device on restart
uint16_t host_crc = crc16((uint8_t *)mqtt->hostname, strlen(mqtt->hostname), 0x1021, 0xffff);
uint16_t devq_crc = crc16((uint8_t *)dev_hint, dev_hint ? strlen(dev_hint) : 0, 0x1021, 0xffff);
char client_id[17];
snprintf(client_id, sizeof(client_id), "rtl_433-%04x%04x", host_crc, devq_crc);

Either use different hostnames (I guess both are named the default raspberrypi?) or use a unique -d. Using a serial number is recommended, i.e. rtl_eeprom and -d :myserial.

@TheKorn2
Copy link
Author

TheKorn2 commented Oct 9, 2022

I'm afraid I don't understand how to use the -d properly when it's a USB device. I can use -d 0 and get device 0, but -d :myserial just tanks rtl_433:

Could not find device with serial 'myserial' (err -3)

Any example I could look at?

@TheKorn2
Copy link
Author

TheKorn2 commented Oct 9, 2022

For anyone else... read your rtl_433 serial with rtl_eeprom, then add -d:(that serial number) to one instance to get a different mqtt client identifier.

In my case, I added "-d :00000001" to one of the clients to get them to stop bashing each other.

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

No branches or pull requests

3 participants