[SOLVED] Sending string converted to uint8_t causes failed join request mDot

Home Forums mDot/xDot [SOLVED] Sending string converted to uint8_t causes failed join request mDot

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #23044
    Brad Rust
    Participant

    When placing an int into a uint8_t vector, the mDot joins and sends data to the conduit successfully. When I try the same with a string, even with only one letter, it fails.


    void dotHandler::sendData(std::vector<uint8_t> data)
    {
    logInfo("sending uplink with data = %d", data);
    send_data(data);
    if (deep_sleep)
    {
    // if going into deepsleep mode, save the session so we don't need to join again after waking up
    // not necessary if going into sleep mode since RAM is retained
    logInfo("saving network session to NVM");
    dot->saveNetworkSession();
    }
    sleep_wake_rtc_or_interrupt(deep_sleep);
    }

    void dotHandler::sendData(std::string s)
    {
    std::vector<uint8_t> vec(s.begin(), s.end());
    sendData(vec);
    }

    So this works:

    int counter = 0;
    sendData(counter++);

    And this does not as it fails to join:

    std::string s = "hello";
    sendData(s);

    Why would this be?

    edit: I’m using the dot_util from the mDot examples. that’s what the send_data function is

    #23052
    Brad Rust
    Participant

    Moving the vector declaration inside the while loop solved this issue.

    I either don’t have access to or cannot find the implementation of mDot::send(std::vector<uint8_t>, bool, bool) but am guessing this comes down to memory management.

    #23124
    Yi Wei
    Participant

    The sendData() function in the example calls the send() function inside mDot.h

    int32_t send(const std::vector<uint8_t>& data, const bool& blocking = true, const bool& highBw = false);

    So it only accepts vecotr<uint8_t> data. In C/C++ uint8_t and char occupy same memory space so you can convert your string to a char* to fit the function.

    Try this:
    ` char string_buffer[];
    //* Parse your data to string_buffer here */
    for (int i = 0; i < strlen(string_buffer); i++)
    {
    tx_data.push_back(((char*) string_buffer)[i]);
    }
    sendData(tx_data);
    `

    • This reply was modified 6 years, 11 months ago by Yi Wei.
    • This reply was modified 6 years, 11 months ago by Yi Wei.
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.