Giter Site home page Giter Site logo

Comments (9)

david-cermak avatar david-cermak commented on June 8, 2024

Ad1) need to add a urc handler, a planned feature for modem_v1.2. This library also supports it, but it involves using some advanced c++ API: you can check this example:

ESP_LOGI(TAG, "Adding URC handler");
dce->set_on_read(handle_urc);
} else {
ESP_LOGI(TAG, "URC removed");
dce->set_on_read(nullptr);

Ad2) You can also create a custom command or handler in this library. For example:

    std::string output;
    auto ret = dce->command("at+cpbf=\"user\"\r", [&output](uint8_t *data, size_t len) {
        std::string_view response((char *) data, len);
        if (response.find("OK") != std::string::npos) {
            output = response;
            return command_result::OK;
        }
        return command_result::TIMEOUT;
    }, 1000);

Maybe the default esp_modem_at() command should return everything, not just the last line (but I believe this per line tokenization is useful in most cases, as it filters out potential echo's and garbage).

from esp-protocols.

JB-DX avatar JB-DX commented on June 8, 2024

Thanks for your suggestions!
My app is written in C, I can't convert it to C++
How can I set_on_read() from C? dce->set_on_read() obviously does not compile.

Yes I also was thinking that esp_modem_at() would return everything, but your concerns are valid too.
For multiline reponses esp_modem_at() either needs the additional parameter accept_multi_line
or a separate function esp_modem_at_multiline() so esp_modem_at() can be left unchanged.

from esp-protocols.

david-cermak avatar david-cermak commented on June 8, 2024

I'm sorry, I don't really have a good suggestion for C right now (other than create a custom DCE as in the console example and wrap it in C-API)

dce->set_on_read() obviously does not compile.

It does compile in that example, but as said above -- uses some C++ magic to conveniently override set_on_read() in

void set_on_read(esp_modem::got_line_cb on_read_cb)
{
if (on_read_cb == nullptr) {
handling_urc = false;
handle_urc = nullptr;
dte->on_read(nullptr);
return;
}
handle_urc = std::move(on_read_cb);
dte->on_read([this](uint8_t *data, size_t len) {
this->handle_data(data, len);
return command_result::TIMEOUT;
});
handling_urc = true;
}

For multiline reponses esp_modem_at() either needs the additional parameter accept_multi_line separate function esp_modem_at_multiline() so esp_modem_at() can be left unchanged.

Yes, I'd probably add a new function, as you proposed, which could be used more universally. I would also remove the trailing \r here, so the new function could be used to send any kind of characters, e.g. the +++:

std::string at_command = cmd + "\r";
return generic_get_string(t, at_command, out, timeout);

from esp-protocols.

JB-DX avatar JB-DX commented on June 8, 2024

I managed to add a esp_modem_set_read_cb() in C and that works.
When will v1.2 available?

Another problem:
How can I reconnect to PPP ? I'm using SIM800.
After an established connection I call esp_modem_set_mode(dce, ESP_MODEM_MODE_COMMAND)
and later on (it can be hours later)
esp_modem_set_mode(dce, ESP_MODEM_MODE_DATA);

But that results just in a "User interrupted event" and it doesn't get connected.

The SIM800 sends:

CONNECT
~ÿ}#À!}!}!} }2}"}&} }*} } }#}$À#}'}"}(}"Uƒ~~ÿ}#À!}#}$} }*}"}&} }*} } t"~~ÿ}#À!}!}"} }.}"}&} }*} } }'}"}(}"ÐÓ~~ÿ}#À!}"}%} }4}"}&} }*} } }%}&áÏFˆ}'}"}(}"}=}(~~€!����À¨þþHÌ~~€!����-��àB~~ÿ�À!���…r~
NO CARRIER

A similar question right at the first connection-try after reset:
If it can't get a PPP connection because the provider has no capacity, I get IP_EVENT_PPP_LOST_IP
How can I start a retry? Setting ESP_MODEM_MODE_DATA doesn't work.
Do I have to destroy and re-create the DCE each time? That sounds a bit awkward.

from esp-protocols.

JB-DX avatar JB-DX commented on June 8, 2024

Now I got it running. The reason was the missing APN

from esp-protocols.

david-cermak avatar david-cermak commented on June 8, 2024

Thanks for the update!

When will v1.2 available?

I'm currently getting ready for v1.1, should be available next week or so,.
Version v1.2 would add a few features, so I think it should be ready sometime in Feb/March. As for the URC handler, its not a big change and I think I could get it working after the 1.1 release.

from esp-protocols.

david-cermak avatar david-cermak commented on June 8, 2024

Closing, as I think all questions have been answered. Please reopen or create new issues if it's not the case.

from esp-protocols.

mettz avatar mettz commented on June 8, 2024

Sorry @JB-DX, I have your same issue regarding the URC handler and set_read_cb stuff and I can't convert my app to c++, too. Could you please share your esp_modem_set_read_cb function implementation? Because I'm not able to make mine work

from esp-protocols.

JB-DX avatar JB-DX commented on June 8, 2024

I assumed that the URC handler would have been implemented by now, but I can't find it.

in esp_modem_c_api.cpp I added this:

extern "C" esp_err_t esp_modem_set_read_cb(esp_modem_dce_t *dce_wrap, esp_modem_terminal_read_cbt read_cb)
{
    if (dce_wrap == nullptr || dce_wrap->dce == nullptr || dce_wrap->dte == nullptr) {
        return ESP_ERR_INVALID_ARG;
    }
    if (read_cb) {
        dce_wrap->dte->on_read([read_cb](uint8_t *line, size_t leng) {
           read_cb(line, leng);
            return command_result::TIMEOUT;  
        });
    } else {
        dce_wrap->dte->on_read(nullptr);
    }
    return ESP_OK;
}

and in esp_modem_c_api_types.h add this:
esp_err_t esp_modem_set_read_cb(esp_modem_dce_t *dce_wrap, esp_modem_terminal_read_cbt read_cb);

from esp-protocols.

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.