Commit 4fd96664 authored by Michael Ott's avatar Michael Ott
Browse files

Modified MQTT topic to work with current CollectAgent

parent a0d6b754
include ../config.mk
CXXFLAGS = -O2 -g -Wall -Werror -I$(DCDBDEPLOYPATH)/include
CXXFLAGS = -O2 --std=c++11 -g -Wall -Werror -I$(DCDBDEPLOYPATH)/include
OBJS = sysfspusher.o helper.o
LIBS = -L$(DCDBDEPLOYPATH)/lib -lrudeconfig -lmosquitto -lssl -lcrypto -lpthread
TARGET = sysfspusher
......
......@@ -91,8 +91,8 @@ int main(int argc, char** argv) {
hostname[255] = '\0';
cout << "Hostname: " << hostname << endl;
string clientId(hostname);
clientId.append("/");
string clientId("/00/01/0203/04/05/06/07/10111213/FFFF/202");
struct mosquitto* mosq;
mosq = mosquitto_new(clientId.c_str(), false, NULL);
if (!mosq) {
......@@ -122,6 +122,8 @@ int main(int argc, char** argv) {
while (keepRunning) {
uint64_t sleepTime = nextWakeUp - currentTime;
uint64_t payload[2];
cout << endl << "Next wakeup will be in " << sleepTime << "ms." << endl;
usleep(sleepTime * 1000);
......@@ -134,11 +136,11 @@ int main(int argc, char** argv) {
size_t nelem = fread(buf, 1024, 1, sensorList[i].file);
(void)nelem;
buf[strlen(buf)-1] = 0;
payload[0] = atoi(buf);
payload[1] = currentTime;
cout << "[" << currentTime << "] " << sensorList[i].name << ": \"" << buf << "\""<< endl;
stringstream ss;
ss << currentTime << " " << buf;
if (mosquitto_publish(mosq, NULL, (clientId + sensorList[i].name).c_str(), ss.str().size(), ss.str().c_str(), 0, false) != MOSQ_ERR_SUCCESS) {
if (mosquitto_publish(mosq, NULL, (clientId + to_string(i)).c_str(), sizeof(payload), payload, 0, false) != MOSQ_ERR_SUCCESS) {
cerr << "Warning: cannot send message." << endl;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment