diff -r 102c44bb8c9d -r 7f8432413321 thermometers/main.c --- a/thermometers/main.c Thu Apr 24 19:49:30 2014 +0200 +++ b/thermometers/main.c Sat Apr 26 22:53:10 2014 +0200 @@ -36,6 +36,7 @@ static int last_mid_sent = -1; static bool connected = true; static bool disconnect_sent = false; +static bool connect_lost = false; static bool shutdown = false; static pid_t pgrp, mypid; @@ -76,6 +77,11 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result) { + if (connect_lost) { + connect_lost = false; + syslog(LOG_NOTICE, "Reconnect: %s", mosquitto_connack_string(result)); + } + if (!result) { status = STATUS_CONNACK_RECVD; } else { @@ -94,10 +100,8 @@ /* * The remove server was brought down. We must keep running */ - syslog(LOG_NOTICE, "Received DISCONNECT from %s but we want to run", Config.mosq_host); - /* - * We need a temp state - */ + syslog(LOG_NOTICE, "Received DISCONNECT from %s, connection lost", Config.mosq_host); + connect_lost = true; } } @@ -341,12 +345,13 @@ device = xstrcat(device, (char *)"/"); device = xstrcat(device, tmp1->name); device = xstrcat(device, (char *)"/w1_slave"); - alias = xstrcpy((char *)"sensor/temperature/"); + alias = xstrcpy((char *)"/raw/"); alias = xstrcat(alias, hostname); - alias = xstrcat(alias, (char *)"/"); + alias = xstrcat(alias, (char *)"/thermometers/w1/"); alias = xstrcat(alias, tmp1->master); alias = xstrcat(alias, (char *)"/"); - alias = xstrcat(alias, tmp1->alias); + alias = xstrcat(alias, tmp1->name); + alias = xstrcat(alias, (char *)"/temperature"); /* * Read sensor data @@ -383,7 +388,7 @@ * Temperature is changed and valid, update and publish this. */ sprintf(buf, "%.1f", temp / 1000.0); - if ((rc = mosquitto_publish(mosq, &mid_sent, alias, strlen(buf), buf, qos, 0))) { + if ((rc = mosquitto_publish(mosq, &mid_sent, alias, strlen(buf), buf, qos, 1))) { if (rc == MOSQ_ERR_NO_CONN) mosquitto_reconnect(mosq); else