Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

Commit 5f191b59 authored by Micha Mueller's avatar Micha Mueller
Browse files

MQTTPusher: change old text output to new logging format

parent ebddabfa
......@@ -20,14 +20,14 @@ MQTTPusher::MQTTPusher(int brokerPort, const std::string& brokerHost,
//first print some info
int mosqMajor, mosqMinor, mosqRevision;
mosquitto_lib_version(&mosqMajor, &mosqMinor, &mosqRevision);
std::cout << "mosquitto " << mosqMajor << "." << mosqMinor << "." << mosqRevision << std::endl;
LOG(info) << "mosquitto " << mosqMajor << "." << mosqMinor << "." << mosqRevision;
char hostname[256];
if (gethostname(hostname, 255) != 0) {
fprintf(stderr, "Cannot get hostname.\n");
LOG(fatal) << "Cannot get hostname";
exit(EXIT_FAILURE);
}
hostname[255] = '\0';
std::cout << "Hostname: " << hostname << std::endl;
LOG(info) << "Hostname: " << hostname;
//enough information
//init mosquitto-struct
......@@ -51,12 +51,11 @@ void MQTTPusher::push() {
//connect to broker (if necessary)
while (keepRunning && !_connected) {
if (mosquitto_connect(_mosq, _brokerHost.c_str(), _brokerPort, 1000) != MOSQ_ERR_SUCCESS) {
std::cout << "Mosquitto: could not connect to MQTT broker "
<< _brokerHost << ":"
<< _brokerPort << std::endl;
LOG(error) << "Mosquitto: could not connect to MQTT broker " << _brokerHost << ":" << _brokerPort;
sleep(1);
} else {
_connected = true;
LOG(info) << "Mosquitto: Connection established!";
}
}
......@@ -70,11 +69,13 @@ void MQTTPusher::push() {
//there was a (unintended) disconnect in the meantime --> reconnect
if (!_connected) {
LOG(error) << "Mosquitto: Lost connection. Reconnecting...";
if (mosquitto_reconnect(_mosq) != MOSQ_ERR_SUCCESS) {
std::cout << "mosquitto: could not reconnect to MQTT broker " << _brokerHost << ":" << _brokerPort << std::endl;
LOG(error) << "Mosquitto: could not reconnect to MQTT broker " << _brokerHost << ":" << _brokerPort << std::endl;
sleep(1);
} else {
_connected = true;
LOG(info) << "Mosquitto: Connection established!";
}
}
......@@ -84,16 +85,19 @@ void MQTTPusher::push() {
std::size_t count = s->popReadingQueue(reads, 1024);
totalCount+= count;
#ifdef DEBUG
std::cout << s->getName() << " has read " << count << " values:" << std::endl;
LOG(debug) << "Mosquitto: Sending " << count << " values from " << s->getName();
#endif
#if 0
for (std::size_t i=0; i<count; i++) {
std::cout << " " << reads[i].timestamp << " " << reads[i].value << std::endl;
LOG(debug) << " " << reads[i].timestamp << " " << reads[i].value;
}
#endif
//try to send them to the broker
if (mosquitto_publish(_mosq, NULL, (s->getMqtt()).c_str(), sizeof(reading_t)*count, reads, 0, false) != MOSQ_ERR_SUCCESS) {
//could not send them --> push the sensor values back into the queue
std::cerr << "mosquitto: could not send message! Trying again later" << std::endl;
LOG(error) << "Mosquitto: Could not send message! Trying again later";
mosquitto_disconnect(_mosq);
_connected = false;
s->pushReadingQueue(reads, count);
......
......@@ -28,6 +28,8 @@ private:
sensorVector_t& _sensors;
struct mosquitto* _mosq;
bool _connected;
boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;
};
#endif /* MQTTPUSHER_H_ */
Markdown is supported
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