Skip to content

Commit

Permalink
cleanup(mqtt_client): Clean up custom client id PR
Browse files Browse the repository at this point in the history
  • Loading branch information
pkwagner committed Oct 13, 2023
1 parent e427fd6 commit 0b597ea
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ docker run \
| MQTT_SERVER | | example.com |
| MQTT_PORT | | 1883 |
| MQTT_SSL_CERT | *Optional*<br><br>Path to `cert.pem` file<br>*If you want to use MQTTS, you have to define the path to the cert here and add the cert to the container (e.g. mount a volume)* | /etc/certs/cert.pem |
| MQTT_CLIENT_ID | *Optional* | yasdi2mqtt |
| MQTT_QOS_LEVEL | *Optional*<br><br>See [here](http://www.steves-internet-guide.com/understanding-mqtt-qos-levels-part-1/) for explanation. | 2 |
| MQTT_USER | *Optional* | johndoe |
| MQTT_PASSWORD | *Optional* | sEcReT |
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ services:
MQTT_PORT: 1883
MQTT_USER: "johndoe"
MQTT_PASSWORD: "sEcReT"
MQTT_CLIENT_ID: "yasdi2mqtt"
8 changes: 3 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ int main(int argc, char **argv)
char *mqtt_user = getenv("MQTT_USER");
char *mqtt_password = getenv("MQTT_PASSWORD");

char *mqtt_client_id;
char *mqtt_client_id = "yasdi2mqtt";
if (getenv("MQTT_CLIENT_ID"))
{
mqtt_client_id = getenv("MQTT_CLIENT_ID");
} else {
mqtt_client_id = "yasdi2mqtt";
mqtt_client_id = getenv("MQTT_CLIENT_ID");
}

int mqtt_qos_level = 2;
Expand All @@ -51,10 +49,10 @@ int main(int argc, char **argv)
log_info("Configuration | MQTT_SERVER = %s", mqtt_server);
log_info("Configuration | MQTT_PORT = %u", mqtt_port);
log_info("Configuration | MQTT_SSL_CERT = %s", mqtt_ssl_cert);
log_info("Configuration | MQTT_CLIENT_ID = %s", mqtt_client_id);
log_info("Configuration | MQTT_QOS_LEVEL = %d", mqtt_qos_level);
log_info("Configuration | MQTT_USER = %s", mqtt_user);
log_info("Configuration | MQTT_PASSWORD = %s", mqtt_password);
log_info("Configuration | MQTT_CLIENT_ID = %s", mqtt_client_id);

if (!mqtt_init(mqtt_server, mqtt_port, mqtt_ssl_cert, mqtt_user, mqtt_password, mqtt_topic_prefix, mqtt_qos_level, mqtt_client_id))
{
Expand Down
2 changes: 1 addition & 1 deletion src/mqtt_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdint.h>
#include <stdbool.h>

bool mqtt_init(char *server, uint16_t port, char *ssl_cert, char *user, char *password, char *topic_prefix, int qos_level, char *mqtt_client_id);
bool mqtt_init(char *server, uint16_t port, char *ssl_cert, char *user, char *password, char *topic_prefix, int qos_level, char *client_id);
void mqtt_destroy();
bool mqtt_send(char *topic, char *payload);

Expand Down

0 comments on commit 0b597ea

Please sign in to comment.