update mqttd, test SHT2X support ok
| | |
| | | mqtt_ctx_t *ctx = (mqtt_ctx_t *)userdata; |
| | | int rv = 0; |
| | | char msg[128]; |
| | | float temp = 0.0; |
| | | float temp = 0.0; /* temperature */ |
| | | float rh = 0.0; /* relative humidity */ |
| | | int retain = 0; |
| | | |
| | | if( result ) |
| | |
| | | } |
| | | } |
| | | |
| | | if( ctx->hwconf.sht2x ) |
| | | { |
| | | memset(msg, 0, sizeof(msg)); |
| | | |
| | | if( sht2x_get_temp_humidity(&temp, &rh) < 0 ) |
| | | snprintf(msg, sizeof(msg), "{ \"id\":%s, \"temp\":\"error\", \"RH\":\"error\" }", ctx->id); |
| | | else |
| | | snprintf(msg, sizeof(msg), "{ \"id\":%s, \"temp\":\"%.2f\", \"RH\":\"%.2f\" }", ctx->id, temp, rh); |
| | | |
| | | rv = mosquitto_publish(mosq, NULL, ctx->pubTopic, strlen(msg)+1, msg, ctx->pubQos, retain); |
| | | if( rv ) |
| | | { |
| | | log_err("Publisher broadcast message '%s' failure: %d\n", msg, rv); |
| | | } |
| | | else |
| | | { |
| | | log_nrml("Publisher broadcast message '%s' ok\n", msg); |
| | | } |
| | | } |
| | | |
| | | |
| | | log_nrml("Publisher broadcast over and disconnect broker now\n", ctx->host, ctx->port); |
| | | mosquitto_disconnect(mosq); |
| | | |