diff --git a/modules/umdk-m200.c b/modules/umdk-m200.c index 42582dc..3977c0e 100644 --- a/modules/umdk-m200.c +++ b/modules/umdk-m200.c @@ -387,7 +387,7 @@ void umdk_m200_command(char *param, char *out, int bufsize) { } else if (strstr(param, "iface ") == param) { param += strlen("iface "); // Skip command - uint8_t interface; + uint8_t interface = 0; if (strstr(param, "can") == param) { interface = 2; } diff --git a/modules/umdk-m230.c b/modules/umdk-m230.c index 7e7e1a7..cacde9c 100644 --- a/modules/umdk-m230.c +++ b/modules/umdk-m230.c @@ -389,7 +389,7 @@ void umdk_m230_command(char *param, char *out, int bufsize) { } else if (strstr(param, "set mode_tariff ") == param) { param += strlen("set mode_tariff "); // Skip command - uint8_t mode; + uint8_t mode = 0; if (strstr(param, "one") == param) { param += strlen("one"); // Skip command mode = 1; diff --git a/modules/umdk-pwm.c b/modules/umdk-pwm.c index daffb2b..02b424c 100644 --- a/modules/umdk-pwm.c +++ b/modules/umdk-pwm.c @@ -53,7 +53,7 @@ void umdk_pwm_command(char *param, char *out, int bufsize) { dev--; param += strlen(" "); // Skip space - uint8_t mask; + uint8_t mask = 0; if(strstr(param, "on ") == param) { param += strlen("on "); // Skip command mask = 1; diff --git a/mqtt.c b/mqtt.c index 0fdd548..e5d995b 100644 --- a/mqtt.c +++ b/mqtt.c @@ -1337,7 +1337,11 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } snprintf(pidval, sizeof(pidval), "%d\n", getpid()); - write(pidfile, pidval, strlen(pidval)); + + if (write(pidfile, pidval, strlen(pidval)) < 0) + { + exit(EXIT_FAILURE); + } sleep(30); } @@ -1491,9 +1495,19 @@ int main(int argc, char *argv[]) mosquitto_message_callback_set(mosq, my_message_callback); mosquitto_subscribe_callback_set(mosq, my_subscribe_callback); - if(mosquitto_connect(mosq, host, port, keepalive)){ - snprintf(logbuf, sizeof(logbuf), "Unable to connect.\n"); - logprint(logbuf); + if (mosquitto_connect(mosq, host, port, keepalive) == MOSQ_ERR_ERRNO) { + snprintf(logbuf, sizeof(logbuf), "Unable to connect"); + int errno_saved = errno; + char *errmsg_extracting = strerror_r(errno_saved, errbuf, sizeof(errbuf)); + if (errmsg_extracting != errbuf) { + logprint(strcat(logbuf, ".\n")); + } else { + strncat(logbuf, ": ", sizeof(logbuf) - (strlen(logbuf) + 1)); + strncat(logbuf, errbuf, sizeof(logbuf) - (strlen(logbuf) + 1)); + strncat(logbuf, "\n", sizeof(logbuf) - (strlen(logbuf) + 1)); + logprint(logbuf); + } + return 1; } diff --git a/unwds-mqtt.c b/unwds-mqtt.c index f688601..cd04145 100644 --- a/unwds-mqtt.c +++ b/unwds-mqtt.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2017 Unwired Devices LLC [info@unwds.com] + /* Copyright (c) 2017 Unwired Devices LLC [info@unwds.com] * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -260,4 +260,36 @@ int unwds_modid_by_name(char *name) { } return -1; +} + +/* GPS binary format decoder */ +/* format is used by umdk-gps, umdk-idcard and other GPS-enabled devices */ +void parse_gps_data(gps_data_t *gps, uint8_t *data, bool decode_nmea) { + memset(gps, 0, sizeof(gps_data_t)); + + gps->ready = (data[0] & 1); + + if (gps->ready) { + int lat, lat_d, lon, lon_d; + lat = data[1] + (data[2] << 8); + lat_d = data[3]; + lon = data[4] + (data[5] << 8); + lon_d = data[6]; + + gps->latitude = (float)lat + (float)lat_d/100.0; + gps->longitude = (float)lon + (float)lon_d/100.0; + + /* Apply sign bits from reply */ + if ((data[0] >> 5) & 1) { + gps->latitude = -gps->latitude; + } + + if ((data[0] >> 6) & 1) { + gps->longitude = -gps->longitude; + } + + gps->valid = (data[0] >> 7) & 1; + } + + return; } \ No newline at end of file