简体   繁体   中英

reading data from stm32 on esp8266

im sending via uart data from stm32 like this:

sprintf(buffer, "%d %d %d %d %d %d %d %d %d %d %d %f;", (int32_t)ir_average, (int32_t)red_average, (int32_t)dcFilterIRresult, (int32_t)dcFilterRedresult, (int32_t)chebyshevResult2, (int32_t)elipticResult2, (int32_t)wyjscie, (int32_t)bpm_up, (int32_t)fftbmp, (int32_t)currentSaO2Value, (int32_t)spo2Calib, temp); 
HAL_UART_Transmit(&huart4, buffer, 100, 1000);

how should i read it from esp8266 side in arduino ide? maybe i should do it differently? i wanted to send a packet od data and split it after reading full packet on esp8266

Generally in arduino you read using Serial.read() which returns char. Form a string out of it.

    String resp;
    char   _char;
    while(Serial.available()){
        _char =  Serial.read();
        resp += _char;
    }

to convert it to int use .toInt()

to separate individual numbers use .indexOf

To read bytes from the UART in arduino IDE: Serial.read() (in a loop) or Serial.ReadString().

Generally speaking, prefer using snprintf to sprintf to avoid buffer overflows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM