# HG changeset patch # User Michiel Broek # Date 1406659322 -7200 # Node ID 3446371e0bdba0a13bb1bbb63c17d2d7790719ce # Parent 54f9b5d39e4c335ba73213a8676a3ede14d05c54 Removed code dependencies to mosquitto and owfs diff -r 54f9b5d39e4c -r 3446371e0bdb config.h.in --- a/config.h.in Tue Jul 29 20:11:23 2014 +0200 +++ b/config.h.in Tue Jul 29 20:42:02 2014 +0200 @@ -11,9 +11,3 @@ /* Define if you have the header file. */ #undef HAVE_WIRINGPI_H - -/* Define if you have the header file. */ -#undef HAVE_MOSQUITTO_H - -/* Define if you have the header file. */ -#undef HAVE_OWNETAPI_H diff -r 54f9b5d39e4c -r 3446371e0bdb configure --- a/configure Tue Jul 29 20:11:23 2014 +0200 +++ b/configure Tue Jul 29 20:42:02 2014 +0200 @@ -3047,14 +3047,15 @@ # # Libraries for mbsePi-apps # - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for mosquitto_lib_init in -lmosquitto" >&5 -$as_echo_n "checking for mosquitto_lib_init in -lmosquitto... " >&6; } -if ${ac_cv_lib_mosquitto_mosquitto_lib_init+:} false; then : +WIRINGPI=No + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for wiringPiSetup in -lwiringPi" >&5 +$as_echo_n "checking for wiringPiSetup in -lwiringPi... " >&6; } +if ${ac_cv_lib_wiringPi_wiringPiSetup+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS -LIBS="-lmosquitto $LIBS" +LIBS="-lwiringPi $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -3064,33 +3065,34 @@ #ifdef __cplusplus extern "C" #endif -char mosquitto_lib_init (); +char wiringPiSetup (); int main () { -return mosquitto_lib_init (); +return wiringPiSetup (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_mosquitto_mosquitto_lib_init=yes + ac_cv_lib_wiringPi_wiringPiSetup=yes else - ac_cv_lib_mosquitto_mosquitto_lib_init=no + ac_cv_lib_wiringPi_wiringPiSetup=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_mosquitto_mosquitto_lib_init" >&5 -$as_echo "$ac_cv_lib_mosquitto_mosquitto_lib_init" >&6; } -if test "x$ac_cv_lib_mosquitto_mosquitto_lib_init" = xyes; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_wiringPi_wiringPiSetup" >&5 +$as_echo "$ac_cv_lib_wiringPi_wiringPiSetup" >&6; } +if test "x$ac_cv_lib_wiringPi_wiringPiSetup" = xyes; then : result=yes else result=no fi if test "$result" = "yes"; then + LIBS="$LIBS -lwiringPi -lwiringPiDev" ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -3488,70 +3490,7 @@ done -for ac_header in mosquitto.h -do : - ac_fn_c_check_header_mongrel "$LINENO" "mosquitto.h" "ac_cv_header_mosquitto_h" "$ac_includes_default" -if test "x$ac_cv_header_mosquitto_h" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_MOSQUITTO_H 1 -_ACEOF - MOSQUITTO=Yes -else - MOSQUITTO=No -fi - -done - -else - as_fn_error $? "libmosquitto not found" "$LINENO" 5 -fi - -WIRINGPI=No -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for wiringPiSetup in -lwiringPi" >&5 -$as_echo_n "checking for wiringPiSetup in -lwiringPi... " >&6; } -if ${ac_cv_lib_wiringPi_wiringPiSetup+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lwiringPi $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char wiringPiSetup (); -int -main () -{ -return wiringPiSetup (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_wiringPi_wiringPiSetup=yes -else - ac_cv_lib_wiringPi_wiringPiSetup=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_wiringPi_wiringPiSetup" >&5 -$as_echo "$ac_cv_lib_wiringPi_wiringPiSetup" >&6; } -if test "x$ac_cv_lib_wiringPi_wiringPiSetup" = xyes; then : - result=yes -else - result=no -fi - -if test "$result" = "yes"; then - LIBS="$LIBS -lwiringPi -lwiringPiDev" - for ac_header in wiringPi.h +for ac_header in wiringPi.h do : ac_fn_c_check_header_mongrel "$LINENO" "wiringPi.h" "ac_cv_header_wiringPi_h" "$ac_includes_default" if test "x$ac_cv_header_wiringPi_h" = xyes; then : @@ -3567,68 +3506,6 @@ fi -OWSERVER=No -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for OWNET_init in -lownet" >&5 -$as_echo_n "checking for OWNET_init in -lownet... " >&6; } -if ${ac_cv_lib_ownet_OWNET_init+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lownet $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char OWNET_init (); -int -main () -{ -return OWNET_init (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_ownet_OWNET_init=yes -else - ac_cv_lib_ownet_OWNET_init=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ownet_OWNET_init" >&5 -$as_echo "$ac_cv_lib_ownet_OWNET_init" >&6; } -if test "x$ac_cv_lib_ownet_OWNET_init" = xyes; then : - result=yes -else - result=no -fi - -if test "$result" = "yes"; then - LIBS="$LIBS -lownet" - for ac_header in ownetapi.h -do : - ac_fn_c_check_header_mongrel "$LINENO" "ownetapi.h" "ac_cv_header_ownetapi_h" "$ac_includes_default" -if test "x$ac_cv_header_ownetapi_h" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_OWNETAPI_H 1 -_ACEOF - OWSERVER=Yes -else - OWSERVER=No -fi - -done - -fi - - # # Additional commandline switches # @@ -5180,7 +5057,6 @@ Version : ............ ${VERSION} Main directory : ..... ${prefix} WiringPi : ........... ${WIRINGPI} - OWserver : ........... ${OWSERVER} Now type 'make' and 'sudo make install' " >&5 @@ -5192,7 +5068,6 @@ Version : ............ ${VERSION} Main directory : ..... ${prefix} WiringPi : ........... ${WIRINGPI} - OWserver : ........... ${OWSERVER} Now type 'make' and 'sudo make install' " >&6; } diff -r 54f9b5d39e4c -r 3446371e0bdb configure.ac --- a/configure.ac Tue Jul 29 20:11:23 2014 +0200 +++ b/configure.ac Tue Jul 29 20:42:02 2014 +0200 @@ -32,13 +32,6 @@ # # Libraries for mbsePi-apps # -AC_CHECK_LIB(mosquitto,mosquitto_lib_init,result=yes,result=no) -if test "$result" = "yes"; then - AC_CHECK_HEADERS(mosquitto.h,MOSQUITTO=Yes,MOSQUITTO=No) -else - AC_MSG_ERROR(libmosquitto not found) -fi - WIRINGPI=No AC_CHECK_LIB(wiringPi,wiringPiSetup,result=yes,result=no) if test "$result" = "yes"; then @@ -46,14 +39,6 @@ AC_CHECK_HEADERS(wiringPi.h,WIRINGPI=Yes,WIRINGPI=No) fi -OWSERVER=No -AC_CHECK_LIB(ownet,OWNET_init,result=yes,result=no) -if test "$result" = "yes"; then - LIBS="$LIBS -lownet" - AC_CHECK_HEADERS(ownetapi.h,OWSERVER=Yes,OWSERVER=No) -fi - - # # Additional commandline switches # @@ -107,7 +92,6 @@ Version : ............ ${VERSION} Main directory : ..... ${prefix} WiringPi : ........... ${WIRINGPI} - OWserver : ........... ${OWSERVER} Now type 'make' and 'sudo make install' ]) diff -r 54f9b5d39e4c -r 3446371e0bdb thermometers/Makefile --- a/thermometers/Makefile Tue Jul 29 20:11:23 2014 +0200 +++ b/thermometers/Makefile Tue Jul 29 20:42:02 2014 +0200 @@ -16,7 +16,7 @@ all: ${TARGET} thermometers: ${OBJS} - ${CC} -o thermometers ${OBJS} ${LDFLAGS} -lmosquitto ${LIBS} + ${CC} -o thermometers ${OBJS} ${LDFLAGS} ${LIBS} clean: rm -f ${TARGET} *.o *.h~ *.c~ core filelist Makefile.bak diff -r 54f9b5d39e4c -r 3446371e0bdb thermometers/rdconfig.c --- a/thermometers/rdconfig.c Tue Jul 29 20:11:23 2014 +0200 +++ b/thermometers/rdconfig.c Tue Jul 29 20:42:02 2014 +0200 @@ -23,7 +23,7 @@ #include "thermometers.h" -bool debug = FALSE; +int debug = FALSE; static char *mypath; static char *k, *v; static int linecnt = 0; @@ -31,10 +31,10 @@ +static int getw1(char **); +#ifdef HAVE_WIRINGPI_H static int getstr(char **); static int getint(char **); -static int getw1(char **); -#ifdef HAVE_WIRINGPI_H static int getrcs(char **); #endif //static int getbyt(char **); @@ -47,8 +47,6 @@ * System configuration table */ key_list keytab[] = { - {(char *)"mosq_host", getstr, &Config.mosq_host}, - {(char *)"mosq_port", getint, (char **)&Config.mosq_port}, {(char *)"w1therm", getw1, (char **)&Config.w1therms}, #ifdef HAVE_WIRINGPI_H {(char *)"lcd_cols", getint, (char **)&Config.lcd_cols}, @@ -73,11 +71,6 @@ free(Config.name); Config.name = NULL; - if (Config.mosq_host) - free(Config.mosq_host); - Config.mosq_host= (char *)"localhost"; - Config.mosq_port = 1883; - for (tmp1 = Config.w1therms; tmp1; tmp1 = old1) { old1 = tmp1->next; if (tmp1->master) @@ -199,6 +192,7 @@ +#ifdef HAVE_WIRINGPI_H static int getstr(char **dest) { if (debug) @@ -221,6 +215,7 @@ *((int*)dest)=atoi(v); return 0; } +#endif diff -r 54f9b5d39e4c -r 3446371e0bdb thermometers/thermometers.c --- a/thermometers/thermometers.c Tue Jul 29 20:11:23 2014 +0200 +++ b/thermometers/thermometers.c Tue Jul 29 20:42:02 2014 +0200 @@ -23,23 +23,10 @@ #include "thermometers.h" -#define STATUS_CONNECTING 0 -#define STATUS_CONNACK_RECVD 1 -#define STATUS_WAITING 2 - -/* Global variables for use in callbacks. */ -static int qos = 0; -static int status = STATUS_CONNECTING; -static int mid_sent = 0; -static int last_mid = -1; -static int last_mid_sent = -1; -static bool connected = true; -static bool disconnect_sent = false; -static bool connect_lost = false; -static bool my_shutdown = false; +static int my_shutdown = FALSE; static pid_t pgrp, mypid; -extern bool debug; +extern int debug; extern sys_config Config; #ifdef HAVE_WIRINGPI_H extern int lcdHandle; @@ -72,54 +59,7 @@ default: syslog(LOG_NOTICE, "die() on signal %d", onsig); } - my_shutdown = true; -} - - - -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 { - syslog(LOG_NOTICE, "my_connect_callback: %s\n", mosquitto_connack_string(result)); - } -} - - - -void my_disconnect_callback(struct mosquitto *mosq, void *obj, int rc) -{ - if (my_shutdown) { - syslog(LOG_NOTICE, "Acknowledged DISCONNECT from %s", Config.mosq_host); - connected = false; - } else { - /* - * The remove server was brought down. We must keep running - */ - syslog(LOG_NOTICE, "Received DISCONNECT from %s, connection lost", Config.mosq_host); - connect_lost = true; - } -} - - - -void my_publish_callback(struct mosquitto *mosq, void *obj, int mid) -{ - last_mid_sent = mid; -} - - - -void my_log_callback(struct mosquitto *mosq, void *obj, int level, const char *str) -{ - syslog(LOG_NOTICE, "MQTT: %s", str); - printf("MQTT: %s\n", str); + my_shutdown = TRUE; } @@ -155,7 +95,7 @@ break; switch (c) { - case 'd': debug = true; + case 'd': debug = TRUE; break; case 'h': help(); return 1; @@ -268,135 +208,33 @@ int server(void) { - char *id = NULL, *state = NULL; - struct mosquitto *mosq = NULL; char hostname[256], buf[1024]; - int temp, rc, deviation, keepalive = 60; + int temp, rc = 0, deviation; #ifdef HAVE_WIRINGPI_H int lcdupdate; #endif - unsigned int max_inflight = 20; - char err[1024]; w1_therm *tmp1, *old1; char *device, *alias, line[60], *p = NULL; FILE *fp; /* - * Initialize mosquitto communication - */ - mosquitto_lib_init(); - - /* * Build MQTT id */ hostname[0] = '\0'; gethostname(hostname, 256); hostname[255] = '\0'; - id = xstrcpy((char *)"thermometers/"); - id = xstrcat(id, hostname); - if(strlen(id) > MOSQ_MQTT_ID_MAX_LENGTH) { - /* - * Enforce maximum client id length of 23 characters - */ - id[MOSQ_MQTT_ID_MAX_LENGTH] = '\0'; - } - - mosq = mosquitto_new(id, true, NULL); - if(!mosq) { - switch(errno) { - case ENOMEM: - syslog(LOG_NOTICE, "mosquitto_new: Out of memory"); - break; - case EINVAL: - syslog(LOG_NOTICE, "mosquitto_new: Invalid id"); - break; - } - mosquitto_lib_cleanup(); - return 1; - } - - if (debug) { - mosquitto_log_callback_set(mosq, my_log_callback); - } - - /* - * Set our will - */ - state = xstrcpy((char *)"clients/"); - state = xstrcat(state, hostname); - state = xstrcat(state, (char *)"/thermometers/state"); - sprintf(buf, "0"); - if ((rc = mosquitto_will_set(mosq, state, strlen(buf), buf, qos, true))) { - if (rc == MOSQ_ERR_INVAL) { - syslog(LOG_NOTICE, "mosquitto_will_set: input parameters invalid"); - } else if (rc == MOSQ_ERR_NOMEM) { - syslog(LOG_NOTICE, "mosquitto_will_set: Out of Memory"); - } else if (rc == MOSQ_ERR_PAYLOAD_SIZE) { - syslog(LOG_NOTICE, "mosquitto_will_set: invalid payload size"); - } - mosquitto_lib_cleanup(); - return rc; - } - - mosquitto_max_inflight_messages_set(mosq, max_inflight); - mosquitto_connect_callback_set(mosq, my_connect_callback); - mosquitto_disconnect_callback_set(mosq, my_disconnect_callback); - mosquitto_publish_callback_set(mosq, my_publish_callback); - - if ((rc = mosquitto_connect(mosq, 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); - } - mosquitto_lib_cleanup(); - return rc; - } - syslog(LOG_NOTICE, "Connected with %s:%d", Config.mosq_host, Config.mosq_port); - /* * Initialise is complete, report our presence state */ - mosquitto_loop_start(mosq); - sprintf(buf, "1"); - rc = mosquitto_publish(mosq, &mid_sent, state, strlen(buf), buf, qos, 1); #ifdef HAVE_WIRINGPI_H // setBacklight(0); #endif - /* - * 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); + fprintf(stdout, (char *)"Enter loop\n"); do { - if (status == STATUS_CONNACK_RECVD) { #ifdef HAVE_WIRINGPI_H lcdupdate = FALSE; #endif @@ -459,12 +297,6 @@ * 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, 1))) { - if (rc == MOSQ_ERR_NO_CONN) - mosquitto_reconnect(mosq); - else - syslog(LOG_NOTICE, "mainloop: error %d from mosquitto_publish", rc); - } } else { syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, tmp1->lastval, temp); if (debug) { @@ -508,13 +340,6 @@ #endif if (my_shutdown) { - /* - * Final publish 0 to clients//thermometers/state - */ - sprintf(buf, "0"); - mosquitto_publish(mosq, &mid_sent, state, strlen(buf), buf, qos, true); - last_mid = mid_sent; - status = STATUS_WAITING; #ifdef HAVE_WIRINGPI_H lcdClear(lcdHandle); lcdPosition(lcdHandle, 0, 0); @@ -524,26 +349,11 @@ usleep(100000); - } else if (status == STATUS_WAITING) { - if (debug) - fprintf(stdout, (char *)"Waiting\n"); - if (last_mid_sent == last_mid && disconnect_sent == false) { - mosquitto_disconnect(mosq); - disconnect_sent = true; - } - usleep(100000); - } - rc = MOSQ_ERR_SUCCESS; - - } while (rc == MOSQ_ERR_SUCCESS && connected); + } while (! my_shutdown); if (debug) fprintf(stdout, (char *)"Out of loop\n"); - mosquitto_loop_stop(mosq, false); - mosquitto_destroy(mosq); - mosquitto_lib_cleanup(); - #ifdef HAVE_WIRINGPI_H stopLCD(); #endif diff -r 54f9b5d39e4c -r 3446371e0bdb thermometers/thermometers.h --- a/thermometers/thermometers.h Tue Jul 29 20:11:23 2014 +0200 +++ b/thermometers/thermometers.h Tue Jul 29 20:42:02 2014 +0200 @@ -31,7 +31,7 @@ /* mosquitto */ -#include +//#include #ifdef HAVE_WIRINGPI_H /* wiringPi */ @@ -72,8 +72,6 @@ typedef struct _sys_config { char *name; /* Configuration name */ - char *mosq_host; /* mosquitto server hostname */ - int mosq_port; /* mosquitto server port */ int my_port; /* my client/server port */ w1_therm *w1therms; /* 1-wire temp sensors */ #ifdef HAVE_WIRINGPI_H