Git Product home page Git Product logo

Comments (5)

jiejieTop avatar jiejieTop commented on July 20, 2024

提供了动态设置write内存的API接口 mqtt_set_write_buf_size() ,调用即可,相关代码实现可以看代码

from mqttclient.

zpblog avatar zpblog commented on July 20, 2024

感谢,之前有使用 mqtt_set_write_buf_size() 尝试过,没生效,
刚按您说的看了一下代码,在mqttclient.c - mqtt_init()里面有段注释/*only malloc write buf and read buf when call mqtt_init function /
我现在按以下3步骤来做可以实现
platform_memory_free(client->mqtt_write_buf); //释放之前的
mqtt_set_write_buf_size(client, size); //配置需要的
client->mqtt_write_buf = (uint8_t
) platform_memory_alloc(client->mqtt_write_buf_size); //申请内存
不知道这样写是否可以?

另外在您那个在线代码生成里面 mqtt_set_write_buf_size() 也是在 调用mqtt_init()之后的 我一开始是参考的那个一直没成功是不是也是这个原因呢,请指正谢谢!

from mqttclient.

jiejieTop avatar jiejieTop commented on July 20, 2024

你看我最新的代码,可以切换到stable分支,可以动态去调整的,即使你知道怎么去申请、释放client内部的内存,但也请不要在外部操作,因为它是由client内部维护的。

static uint32_t mqtt_write_buf_malloc(mqtt_client_t* c, uint32_t size)
{
    MQTT_ROBUSTNESS_CHECK(c, 0);
    
    if (NULL != c->mqtt_write_buf)
        platform_memory_free(c->mqtt_write_buf);
    
    c->mqtt_write_buf_size = size;

    /* limit the size of the read buffer */
    if ((MQTT_MIN_PAYLOAD_SIZE >= c->mqtt_write_buf_size) || (MQTT_MAX_PAYLOAD_SIZE <= c->mqtt_write_buf_size))
        c->mqtt_write_buf_size = MQTT_DEFAULT_BUF_SIZE;
    
    c->mqtt_write_buf = (uint8_t*) platform_memory_alloc(c->mqtt_write_buf_size);
    
    if (NULL == c->mqtt_write_buf) {
        MQTT_LOG_E("%s:%d %s()... malloc write buf failed...", __FILE__, __LINE__, __FUNCTION__);
        RETURN_ERROR(MQTT_MEM_NOT_ENOUGH_ERROR);
    }
    return c->mqtt_write_buf_size;
}

uint32_t mqtt_set_write_buf_size(mqtt_client_t *c, uint32_t size) 
{ 
    return mqtt_write_buf_malloc(c, size);
}

from mqttclient.

zpblog avatar zpblog commented on July 20, 2024

好的,已经更新,
另外想请教一下,我把缓存已经设置足够的情况下,我的数据包一但超出 1MB ,就发送不成功,
调试发现板子貌似断网了,mqtt一直在重连,就一直卡着,ping板子也ping不通了
怀疑是有什么地方有1MB限制,然后超出了,内存溢出把网络搞挂了,
我找了lwip的配置,也尝试放大但都没有作用,请问还有哪边可以配置呢?
谢谢!

from mqttclient.

jiejieTop avatar jiejieTop commented on July 20, 2024

关于lwip的底层这个,你得排查一下了,可能是lwip本身限制了内存相关的问题(导致协议栈本身无法申请那么大的内存,也就没办法给你发出去),也可能是驱动的问题(发着发着数据驱动挂了,lwip也不能工作了)

from mqttclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.