怎么修改Neuron MQTT上报的数据格式,需要修改哪些代码

Neuron MQTT 插件将采集到的数据以 JSON 形式发布到指定的主题。 上报数据的具体格式由上报数据格式 参数指定,有 tags-formatvalues-format 两种格式。

结合ekuiper使用,或者直接用neuronex,然后数据处理中加规则修改格式;或者直接修改代码实现自己要的格式

我把源代码下下来了,


这个函数里边这段代码,跳进去看没看懂
特别是这个函数

int neu_json_encode_read_resp1(void *json_object, void *param)
{
    int                   ret  = 0;
    neu_json_read_resp_t *resp = (neu_json_read_resp_t *) param;

    void *values = neu_json_encode_new();
    void *errors = neu_json_encode_new();
    void *metas  = neu_json_encode_new();

    neu_json_read_resp_tag_t *p_tag = resp->tags;
    for (int i = 0; i < resp->n_tag; i++) {
        neu_json_elem_t tag_elem = { 0 };

        if (p_tag->error == 0) {
            tag_elem.name      = p_tag->name;
            tag_elem.t         = p_tag->t;
            tag_elem.v         = p_tag->value;
            tag_elem.precision = p_tag->precision;
            neu_json_encode_field(values, &tag_elem, 1);
        } else {
            tag_elem.name      = p_tag->name;
            tag_elem.t         = NEU_JSON_INT;
            tag_elem.v.val_int = p_tag->error;
            neu_json_encode_field(errors, &tag_elem, 1);
        }

        if (p_tag->n_meta > 0) {
            void *meta = neu_json_encode_new();
            for (int k = 0; k < p_tag->n_meta; k++) {
                neu_json_elem_t meta_elem = { 0 };
                meta_elem.name            = p_tag->metas[k].name;
                meta_elem.t               = p_tag->metas[k].t;
                meta_elem.v               = p_tag->metas[k].value;
                neu_json_encode_field(meta, &meta_elem, 1);
            }

            neu_json_elem_t meta_elem = { 0 };
            meta_elem.name            = p_tag->name;
            meta_elem.t               = NEU_JSON_OBJECT;
            meta_elem.v.val_object    = meta;
            neu_json_encode_field(metas, &meta_elem, 1);
        }

        p_tag++;
    }

    neu_json_elem_t resp_elems[] = {
        {
            .name         = "values",
            .t            = NEU_JSON_OBJECT,
            .v.val_object = values,
        },
        {
            .name         = "errors",
            .t            = NEU_JSON_OBJECT,
            .v.val_object = errors,

        },
        {
            .name         = "metas",
            .t            = NEU_JSON_OBJECT,
            .v.val_object = metas,

        },
    };

    ret = neu_json_encode_field(json_object, resp_elems,
                                NEU_JSON_ELEM_SIZE(resp_elems));
    return ret;
}

有没有官方的教程

没有相关的教程,改功能肯定是要了解代码的,多看看就能看懂。

好的,继续研究中 :thinking: