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

How to configure for anonymous broker connection? #112

Open
Jibun-no-Kage opened this issue Aug 4, 2022 · 4 comments
Open

How to configure for anonymous broker connection? #112

Jibun-no-Kage opened this issue Aug 4, 2022 · 4 comments

Comments

@Jibun-no-Kage
Copy link

Jibun-no-Kage commented Aug 4, 2022

How to configure for anonymous broker connection? I set user and password in configuration_t, but getting errors? Per the documentation user and password can be omitted? But still errors.

@EdJoPaTo
Copy link
Contributor

EdJoPaTo commented Aug 4, 2022

providing the error might help finding the cause. omitting user and password is possible for sure. You can also set them to NULL.

This is basically my minimal setup:

EspMQTTClient client(
  "WifiSSID",
  "WifiPassword",
  "hostname",       // MQTT Broker server ip
  "TestClient"      // Client name that uniquely identify your device
);

@Jibun-no-Kage
Copy link
Author

Jibun-no-Kage commented Aug 5, 2022

Odd, that I did should have worked...

EspMQTTClient::EspMQTTClient(
const char* wifiSsid,
const char* wifiPassword,
const char* mqttServerIp,
const char* mqttClientName,
const short mqttServerPort) :
EspMQTTClient(wifiSsid, wifiPassword, mqttServerIp, NULL, NULL, mqttClientName, mqttServerPort)

I qualified ssid, passphrase, broker ip, client id, then port, but it generates and error.

no matching function for call to 'EspMQTTClient::EspMQTTClient(const String&, const String&, const String&, const String&, const int&)'

EspMQTTClient theClient(
NETWORK,
PASSWORD,
BROKER,
ID,
PORT
);

First 4 are string constants, and port is a int constant.

@EdJoPaTo
Copy link
Contributor

EdJoPaTo commented Aug 5, 2022

The method is expecting a const char* and not a String. (Basically C vs C++)

You can convert the String to a c style const char* with c_str() like this: something.c_str().

@EdJoPaTo
Copy link
Contributor

EdJoPaTo commented Aug 5, 2022

Personally I use #define BROKER "hostname" instead of String constants. This has the benefit of concating multiple ones at compile time like this:

#define DEVICE_NAME something
#define BASE_TOPIC DEVICE_NAME "/status/"

BASE_TOPIC will be something/status/ and thats done on compile time so no runtime String logic to be done.

for all the rest I prefer const Variables over defines (like the PORT)

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

2 participants