<commit_before>#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

#include "thread.h"
#include "xtimer.h"
#include "periph/i2c.h"

#include "mqtt_bmx280.h"
#include "mqtt_utils.h"

#include "bmx280.h"
#include "bmx280_params.h"

#define ENABLE_DEBUG (0)
#include "debug.h"

#ifndef APPLICATION_NAME
#define APPLICATION_NAME "Node"
#endif

#define PUBLISH_INTERVAL       (5U)    /* set interval to 5 seconds */

#define PUBLISH_QUEUE_SIZE     (8U)
static msg_t _publish_msg_queue[PUBLISH_QUEUE_SIZE];
static char publish_stack[THREAD_STACKSIZE_DEFAULT];

static bmx280_t bmx280_dev;

void get_temperature(char *value) {
    ssize_t p = 0;
    int16_t temp = bmx280_read_temperature(&bmx280_dev);
    p += sprintf(value, "{\"value\":\"%d.%d°C\"}",
                 temp / 100, (temp % 100) /10);
    value[p] = '\0';
    DEBUG("[DEBUG] Get temperature '%s'\n", value);
}

void get_pressure(char *value) {
    ssize_t p = 0;
    uint32_t pres = bmx280_read_pressure(&bmx280_dev);
    p += sprintf(value, "{\"value\":\"%lu.%dhPa\"}",
                 (unsigned long)pres / 100,
                 (int)pres % 100);
    value[p] = '\0';
    DEBUG("[DEBUG] Get pressure '%s'\n", value);
}

#ifdef MODULE_BME280
void get_humidity(char *value) {
    ssize_t p = 0;
    uint16_t hum = bme280_read_humidity(&bmx280_dev);
    p += sprintf(value, "{\"value\":\"%u.%02u%%\"}",
                 (unsigned int)(hum / 100),
                 (unsigned int)(hum % 100));
    value[p] = '\0';<commit_msg>mqtt_bmx280: fix wrong temperature formatting<commit_after>#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

#include "thread.h"
#include "xtimer.h"
#include "periph/i2c.h"

#include "mqtt_bmx280.h"
#include "mqtt_utils.h"

#include "bmx280.h"
#include "bmx280_params.h"

#define ENABLE_DEBUG (0)
#include "debug.h"

#ifndef APPLICATION_NAME
#define APPLICATION_NAME "Node"
#endif

#define PUBLISH_INTERVAL       (5U)    /* set interval to 5 seconds */

#define PUBLISH_QUEUE_SIZE     (8U)
static msg_t _publish_msg_queue[PUBLISH_QUEUE_SIZE];
static char publish_stack[THREAD_STACKSIZE_DEFAULT];

static bmx280_t bmx280_dev;

void get_temperature(char *value) {
    ssize_t p = 0;
    int16_t temp = bmx280_read_temperature(&bmx280_dev);
    bool negative = temp < 0;
    if (negative) {
        temp = -temp;
    }
    p += sprintf(value, "{\"value\":\"%s%d.%d°C\"}",
                 negative ? "-" : "",
                 temp / 100, (temp % 100) / 10);
    value[p] = '\0';
    DEBUG("[DEBUG] Get temperature '%s'\n", value);
}

void get_pressure(char *value) {
    ssize_t p = 0;
    uint32_t pres = bmx280_read_pressure(&bmx280_dev);
    p += sprintf(value, "{\"value\":\"%lu.%dhPa\"}",
                 (unsigned long)pres / 100,
                 (int)pres % 100);
    value[p] = '\0';
    DEBUG("[DEBUG] Get pressure '%s'\n", value);
}

#ifdef MODULE_BME280
void get_humidity(char *value) {
    ssize_t p = 0;
    uint16_t hum = bme280_read_humidity(&bmx280_dev);
    p += sprintf(value, "{\"value\":\"%u.%02u%%\"}",
                 (unsigned int)(hum / 100),
                 (unsigned int)(hum % 100));
    value[p] = '\0';
{'fraction_non_alphanumeric': 0.1666148585638794, 'fraction_numerical': 0.04787068697544296, 'mean_word_length': 3.173800259403372, 'pattern_counts': {'":': 6, '<': 14, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2249485', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1222, 'n_words': 262}