Skip to content

Commit

Permalink
fixed connection error
Browse files Browse the repository at this point in the history
  • Loading branch information
fpersson committed Dec 18, 2021
1 parent 74b56ef commit f11afab
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 7 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ To autostart the sensor at boot (or restart if it crash) use systemd.
```bash
$ mkdir ~/bin
$ cp <src_path>/build/tempsensor ~/bin/
$ cp <src_path>/systemd/start_sensor.sh ~/bin/
$ sudo cp <src_path>/systemd/tempsensor.service /etc/systemd/system/tempsensor.service
$ sudo systemctl enable tempsensor.service
$ sudo systemctl start tempsensor.service
Expand Down
6 changes: 4 additions & 2 deletions libmqtt/src/Mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@ namespace TempSensor{
bool Mqtt::connect() {
bool connection_state = false;
int ret = mosquitto_connect(mosq, mSettings.server.c_str(), mSettings.port, 30);
std::cerr << "Connecting to: " << mSettings.server.c_str() << "@" << mSettings.port << std::endl;
if(ret != MOSQ_ERR_SUCCESS){
connection_state = true;
std::cerr << "Mqtt::connect: connection error: " << ret << std::endl;
}else{
std::cerr << "Mqtt::connected..." << std::endl;
std::cerr << "Mqtt::connect connected." << std::endl;
connection_state = true;
isConnected = true;
}

Expand Down
1 change: 0 additions & 1 deletion libsensor/src/MqttClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ void TempSensor::MqttClient::notify(const std::string &data) {

void TempSensor::MqttClient::onConnected() {
std::cout << "Mqtt Connected..." << std::endl;

notify(mPendingData); //make sure to send pending data asap we get connection
}

Expand Down
3 changes: 0 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ int main(int argc, char **argv){
if(history_topic != "N/A") {
std::thread historyThread = postHistoryTask.thread_run([&mqtt, &dbManager, &history_topic]() {
dbManager.getHistory(Serialize::historyQuery);
#ifdef DEBUGMODE
std::cout << HistoryData::getInstance().getSerializeHistory() << std::endl;
#endif
mqtt.publish(history_topic, HistoryData::getInstance().getSerializeHistory(), 2);
HistoryData::getInstance().clear();
});
Expand Down

0 comments on commit f11afab

Please sign in to comment.