Added alias names

Tue, 29 Apr 2014 17:27:42 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 29 Apr 2014 17:27:42 +0200
changeset 14
21901dc95501
parent 13
7f8432413321
child 15
01fec4ddad17

Added alias names

thermometers/main.c file | annotate | diff | comparison | revisions
--- a/thermometers/main.c	Sat Apr 26 22:53:10 2014 +0200
+++ b/thermometers/main.c	Tue Apr 29 17:27:42 2014 +0200
@@ -326,6 +326,32 @@
     sprintf(buf, "1");
     rc = mosquitto_publish(mosq, &mid_sent, state, strlen(buf), buf, qos, 1);
 
+    /*
+     * Report alias names
+     */
+    for (tmp1 = Config.w1therms; tmp1; tmp1 = old1) {
+	old1 = tmp1->next;
+
+	alias = xstrcpy((char *)"/raw/");
+	alias = xstrcat(alias, hostname);
+	alias = xstrcat(alias, (char *)"/thermometers/w1/");
+	alias = xstrcat(alias, tmp1->master);
+	alias = xstrcat(alias, (char *)"/");
+	alias = xstrcat(alias, tmp1->name);
+	alias = xstrcat(alias, (char *)"/alias");
+
+	sprintf(buf, "%s", tmp1->alias);
+	if ((rc = mosquitto_publish(mosq, &mid_sent, alias, strlen(buf), buf, qos, 1))) {
+	    if (rc == MOSQ_ERR_NO_CONN)
+		mosquitto_reconnect(mosq);
+	    else
+		syslog(LOG_NOTICE, "mainloop: error %d from mosquitto_publish", rc);
+	}
+
+	free(alias);
+	alias = NULL;
+    }
+
     if (debug)
 	fprintf(stdout, (char *)"Enter loop, connected %d\n", connected);
 

mercurial