Skip to content

Commit 21a30f4

Browse files
committed
[FCT] Add flexible connection address
1 parent 9c4118c commit 21a30f4

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

demo/._project.godot

4 KB
Binary file not shown.

demo/addons/GDPaho/PahoClient.gd

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ signal error_received(message, reason_code)
1515

1616
@export var client_id: String = "MQTTClient"
1717
@export var clean_session: bool = true
18+
@export var protocol: String = "tcp"
1819
@export var broker_address: String = "localhost"
1920
@export var broker_port: int = 1883
21+
@export var broker_address_end: String = ""
2022
@export var broker_keep_alive: int = 60
2123
@export var username: String = ""
2224
@export var password: String = ""
@@ -35,7 +37,7 @@ func initialise() -> void:
3537
_mqtt_client.connect("log", Callable(self, "_on_MQTTClient_log"))
3638
_mqtt_client.connect("error", Callable(self, "_on_MQTTClient_error"))
3739

38-
var rc_initialise: int = _mqtt_client.initialise(client_id, broker_address, str(broker_port))
40+
var rc_initialise: int = _mqtt_client.initialise_full_address(client_id, protocol + "://" + broker_address + ":" + str(broker_port) + "/" + broker_address_end)
3941
var rc = rc_initialise
4042
if not rc_initialise:
4143
if username != "" and password != "":

demo/project.godot

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ config_version=5
1212

1313
config/name="GDPaho Demo"
1414
run/main_scene="res://scenes/Main.tscn"
15-
config/features=PackedStringArray("4.1")
15+
config/features=PackedStringArray("4.2")
1616
config/icon="res://GDPaho.png"
1717

1818
[autoload]

src/GDPaho.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ GDPaho::~GDPaho() {
2929
void GDPaho::_bind_methods() {
3030
// Methods
3131
ClassDB::bind_method(D_METHOD("loop"), &GDPaho::loop);
32+
ClassDB::bind_method(D_METHOD("initialise_full_address"), &GDPaho::initialise_full_address);
3233
ClassDB::bind_method(D_METHOD("initialise"), &GDPaho::initialise);
3334
ClassDB::bind_method(D_METHOD("username_pw_set"), &GDPaho::username_pw_set);
3435
ClassDB::bind_method(D_METHOD("is_connected_to_broker"), &GDPaho::is_connected_to_broker);
@@ -112,16 +113,20 @@ void GDPaho::loop() {
112113
// Wrapped methods
113114
//###############################################################
114115

115-
int GDPaho::initialise(const String p_id, const String p_host, const String p_port) {
116+
int GDPaho::initialise_full_address(const String p_id, const String p_full_address) {
116117
try {
117-
String m_connection_address = "tcp://" + p_host + ":" + p_port;
118+
String m_connection_address = p_full_address;
118119
m_wrapper = new PahoWrapper(*this, p_id.utf8().get_data(), m_connection_address.utf8().get_data());
119120
return mqtt::ReasonCode::SUCCESS;
120121
} catch (std::exception& p_exception) {
121122
return atoi(p_exception.what());
122123
}
123124
}
124125

126+
int GDPaho::initialise(const String p_id, const String p_host, const String p_port) {
127+
return initialise_full_address(p_id, "tcp://" + p_host + ":" + p_port);
128+
}
129+
125130
int GDPaho::username_pw_set(const String p_username, const String p_password) {
126131
if (!m_wrapper) {
127132
return PAHO_ERR_NOT_INIT;

src/GDPaho.h

+8
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ namespace godot {
107107
// Wrapped methods
108108
//###############################################################
109109

110+
/**
111+
* Create a new paho client instance
112+
* @param p_id string to use as the client id. If NULL, a random client id will be generated. If id is NULL, clean_session must be true
113+
* @param p_full_address the full connection address
114+
* @return the reason code, if something wrong happen. 0 = OK (see https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901031)
115+
*/
116+
int initialise_full_address(const String p_id, const String p_full_address);
117+
110118
/**
111119
* Create a new paho client instance
112120
* @param p_id string to use as the client id. If NULL, a random client id will be generated. If id is NULL, clean_session must be true

0 commit comments

Comments
 (0)