diff --git a/.vscode/launch.json b/.vscode/launch.json index df9afb5..5288246 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,7 +5,28 @@ "version": "0.2.0", "configurations": [ { - "type": "cppdbg" + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/mqttClient", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ] } ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 82a3931..a04097d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,7 @@ "makefile.launchConfigurations": [ { "cwd": "/home/mreenen/Documents/git/relayClient", - "binaryPath": "/home/mreenen/Documents/git/relayClient/relayClient", + "binaryPath": "/home/mreenen/Documents/git/relayClient/mqttClient", "binaryArgs": [] } ] diff --git a/compile.sh b/compile.sh deleted file mode 100755 index 2849589..0000000 --- a/compile.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -gcc src/main.c src/gpio.c \ - -lpthread -lpaho-mqtt3a \ - -o relayClient \ - -I src -I include/paho-mqtt diff --git a/relayClient.service b/mqttClient.service similarity index 76% rename from relayClient.service rename to mqttClient.service index 64c6cdc..cbed63b 100644 --- a/relayClient.service +++ b/mqttClient.service @@ -12,14 +12,9 @@ Group= WorkingDirectory=/home/ ExecStart=/home//.local/bin/relayClient -# Use SIGINT to stop -KillSignal=SIGINT -# Auto restart on crash Restart=on-failure RestartSec=20 -# Tag things in the log SyslogIdentifier=relayClient -#StandardOutput=syslog [Install] WantedBy=multi-user.target diff --git a/src/conf.h b/src/conf.h index 2920098..02f55f8 100644 --- a/src/conf.h +++ b/src/conf.h @@ -3,6 +3,8 @@ #define ADDRESS "tcp://10.2.0.3:1883" #define CLIENTID "mqttClient" +#define MQTT_USER "mreenen" +#define MQTT_PASS "somepass" #define BASE_TOPIC "/cool/" #define TIMEOUT 10000L diff --git a/src/mqtt.c b/src/mqtt.c index 4624a8d..c40934a 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -34,7 +34,6 @@ void MQTT_subscribe(char* topic, int qos, void (*onMessage)(char* topicName, int { int rc; - if (Subscriptions == NULL) { Subscriptions = (Subscription_t *) malloc(sizeof(Subscription_t) * 5); @@ -63,7 +62,6 @@ void MQTT_subscribe(char* topic, int qos, void (*onMessage)(char* topicName, int } else { - // copy topic to allow passing local variable char *newTopic = malloc(strlen(topic) + 1); memcpy(newTopic, topic, strlen(topic) + 1); sub.topic = newTopic; @@ -72,7 +70,7 @@ void MQTT_subscribe(char* topic, int qos, void (*onMessage)(char* topicName, int memcpy(Subscriptions + sizeof(Subscription_t)*(Subscriptions_len), &sub, sizeof(Subscription_t)); Subscriptions_len++; - printf("INFO: MQTT_subscribe(): Subscribing to topic %s (QoS%d)\n", sub.topic, sub.qos); + printf("INFO: MQTT_subscribe(): Subscribing to topic '%s' (QoS%d)\n", sub.topic, sub.qos); MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; opts.onSuccess = &onSubscribe; @@ -204,6 +202,8 @@ clientConf_t* MQTT_connect(void (*onConnect_cb)(void* context)){ Client->conn_opts.onSuccess = onConn; Client->conn_opts.onFailure = onConnectFailure; Client->conn_opts.context = &Client; + Client->conn_opts.username = MQTT_USER; + Client->conn_opts.password = MQTT_PASS; printf("connecting to MQTT server (%s)\n", ADDRESS); rc = MQTTAsync_connect(Client->client, &(Client->conn_opts)); if(rc != MQTTASYNC_SUCCESS){