# HG changeset patch # User Michiel Broek # Date 1399991627 -7200 # Node ID f3c5ae78b746cdec8069f18e5452e4ed34a0b8e2 # Parent 38e3e3a49320e4c8e329dfa6aa367cd6b7f6b8e0 Mosquitto init does several tries before giving up. The DHT11 sensor now uses a temperature offset too. diff -r 38e3e3a49320 -r f3c5ae78b746 coolers/mosquitto.c --- a/coolers/mosquitto.c Mon May 12 19:45:11 2014 +0200 +++ b/coolers/mosquitto.c Tue May 13 16:33:47 2014 +0200 @@ -100,7 +100,7 @@ { char *id = NULL, *state = NULL; char buf[1024]; - int rc, keepalive = 60; + int try, rc, keepalive = 60; unsigned int max_inflight = 20; char err[1024]; w1_therm *tmp1, *old1; @@ -169,13 +169,21 @@ mosquitto_disconnect_callback_set(mymosq, my_disconnect_callback); mosquitto_publish_callback_set(mymosq, my_publish_callback); - if ((rc = mosquitto_connect(mymosq, Config.mosq_host, Config.mosq_port, keepalive))) { - if (rc == MOSQ_ERR_ERRNO) { - strerror_r(errno, err, 1024); - syslog(LOG_NOTICE, "mosquitto_connect: error: %s", err); - } else { - syslog(LOG_NOTICE, "mosquitto_connect: unable to connect (%d)", rc); - } + try = 10; rc = -1; + while (try && rc) { + if ((rc = mosquitto_connect(mymosq, Config.mosq_host, Config.mosq_port, keepalive))) { + if (rc == MOSQ_ERR_ERRNO) { + strerror_r(errno, err, 1024); + syslog(LOG_NOTICE, "mosquitto_connect: error: %s, try=%d", err, 11-try); + } else { + syslog(LOG_NOTICE, "mosquitto_connect: unable to connect (%d)", rc); + } + sleep(2); + try--; + } + } + if (rc) { + syslog(LOG_NOTICE, "mosquitto_connect: too many tries, giving up"); mosquitto_lib_cleanup(); return rc; } diff -r 38e3e3a49320 -r f3c5ae78b746 dht11/dht11.c --- a/dht11/dht11.c Mon May 12 19:45:11 2014 +0200 +++ b/dht11/dht11.c Tue May 13 16:33:47 2014 +0200 @@ -36,7 +36,7 @@ if (wiringPiSetup() == -1) return 0; - dht11Init(PIN, 0, 6); + dht11Init(PIN, 1, 6); dht11Read(); if (dht11_valid) { fprintf(stdout, "DHT11: temperature %d degrees, humidity %d%%\n", dht11_temperature, dht11_humidity);