diff --git a/.gitignore b/.gitignore index 3ea3afbc541e350dc8225c67a1220a2786adbdab..7f142c50cbb9c41b3be17edc7a09146919e44d46 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,6 @@ ################################################################################ /.vs -/Debug -/x64/Release -/Release +/Debug +/x64/Release +/Release diff --git a/MqttClient.h b/MqttClient.h index 423413a0b6fb8971cfe1720692ebe8b7a3231d2a..e30bcfb2eccc4e94ceb539bf04c69ae68a2c8ffe 100644 --- a/MqttClient.h +++ b/MqttClient.h @@ -1,60 +1,60 @@ -#pragma once - -#include <mosquittopp.h> -#include <cstring> -#include <cstdio> - -#define MAX_PAYLOAD 50 -#define DEFAULT_KEEP_ALIVE 60 -#define PUBLISH_TOPIC "EXAMPLE_TOPIC" - -class MqttClient : public mosqpp::mosquittopp { -public: - MqttClient(const char* id, const char* host, int port) : mosquittopp(id) { - int keepalive = DEFAULT_KEEP_ALIVE; - connect(host, port, keepalive); - } - - ~MqttClient() {} - - void on_connect(int rc) { - if (!rc) std::cout << "Connected - code " << rc << std::endl; - } - - void on_subscribe(int mid, int qos_count, const int* granted_qos){ - std::cout << "Subscription succeeded." << std::endl; - } - - void on_message(const struct mosquitto_message* message) { - int payload_size = MAX_PAYLOAD + 1; - char buf[payload_size]; - - if (!strcmp(message->topic, PUBLISH_TOPIC)) { - memset(buf, 0, payload_size * sizeof(char)); - - /* Copy N-1 bytes to ensure always 0 terminated. */ - memcpy(buf, message->payload, MAX_PAYLOAD * sizeof(char)); - - std::cout << buf << std::endl; - - // Examples of messages for M2M communications... - if (!strcmp(buf, "STATUS")) { - snprintf(buf, payload_size, "This is a Status Message..."); - publish(NULL, PUBLISH_TOPIC, strlen(buf), buf); - std::cout << "Status Request Recieved." << std::endl; - } - - if (!strcmp(buf, "ON")) { - snprintf(buf, payload_size, "Turning on..."); - publish(NULL, PUBLISH_TOPIC, strlen(buf), buf); - std::cout << "Request to turn on." << std::endl; - } - - if (!strcmp(buf, "OFF")) { - snprintf(buf, payload_size, "Turning off..."); - publish(NULL, PUBLISH_TOPIC, strlen(buf), buf); - std::cout << "Request to turn off." << std::endl; - } - } - } +#pragma once + +#include <mosquittopp.h> +#include <cstring> +#include <cstdio> + +#define MAX_PAYLOAD 50 +#define DEFAULT_KEEP_ALIVE 60 +#define PUBLISH_TOPIC "EXAMPLE_TOPIC" + +class MqttClient : public mosqpp::mosquittopp { +public: + MqttClient(const char* id, const char* host, int port) : mosquittopp(id) { + int keepalive = DEFAULT_KEEP_ALIVE; + connect(host, port, keepalive); + } + + ~MqttClient() {} + + void on_connect(int rc) { + if (!rc) std::cout << "Connected - code " << rc << std::endl; + } + + void on_subscribe(int mid, int qos_count, const int* granted_qos){ + std::cout << "Subscription succeeded." << std::endl; + } + + void on_message(const struct mosquitto_message* message) { + int payload_size = MAX_PAYLOAD + 1; + char buf[payload_size]; + + if (!strcmp(message->topic, PUBLISH_TOPIC)) { + memset(buf, 0, payload_size * sizeof(char)); + + /* Copy N-1 bytes to ensure always 0 terminated. */ + memcpy(buf, message->payload, MAX_PAYLOAD * sizeof(char)); + + std::cout << buf << std::endl; + + // Examples of messages for M2M communications... + if (!strcmp(buf, "STATUS")) { + snprintf(buf, payload_size, "This is a Status Message..."); + publish(NULL, PUBLISH_TOPIC, strlen(buf), buf); + std::cout << "Status Request Recieved." << std::endl; + } + + if (!strcmp(buf, "ON")) { + snprintf(buf, payload_size, "Turning on..."); + publish(NULL, PUBLISH_TOPIC, strlen(buf), buf); + std::cout << "Request to turn on." << std::endl; + } + + if (!strcmp(buf, "OFF")) { + snprintf(buf, payload_size, "Turning off..."); + publish(NULL, PUBLISH_TOPIC, strlen(buf), buf); + std::cout << "Request to turn off." << std::endl; + } + } + } } \ No newline at end of file diff --git a/compatibility.h b/compatibility.h index 2b9134a42bbe5398756e3e87c8437c3973652c17..e776f4205a26c0cb868748b3dbdca39cb9f440d5 100644 --- a/compatibility.h +++ b/compatibility.h @@ -1,7 +1,7 @@ -void csleep(int time) { -#if defined(WIN32) || defined(WIN64) - Sleep(time); -#else - usleep((long) time); -#endif +void csleep(int time) { +#if defined(WIN32) || defined(WIN64) + Sleep(time); +#else + usleep((long) time); +#endif } \ No newline at end of file