title: Collect data from UART based on multiple terminating characters
body: <p>I am using an Arduino-like library on the WiFi module ESP8266. The code looks very much like Arduino.</p>
  
  <p>I am collecting data from UART and placing them into a buffer. Currently, the terminating character is <code>'\n'</code>. In other words, the stream of incoming data from the UART is stored in a buffer <code>command_buffer</code> and the end of this incoming data is identified by the <code>'\n'</code>. Here is the relevant code;</p>
  
  <pre><code>void onDataCallback(Stream&amp; stream, char arrivedChar, unsigned short availableCharsCount)
  {
      if (arrivedChar == '\n') // Lets show data!
      {
          Serial.println("&lt;New line received&gt;");
          while (stream.available())
          {
              char cur = stream.read();
              charReceived++;
              Serial.print(cur);
              command_buffer[index] = cur;
              buf_index++;
          }
      }
  }
  </code></pre>
  
  <p><code>onDataCallback()</code> is a callback function that gets called when incoming data is received from the UART. </p>
  
  <p>This is my problem. What if the terminating character is not a single character <code>'\n'</code>? What if it is made up of multiple binary characters like <code>&lt;0xFF&gt;&lt;0xFE&gt;&lt;0xFA&gt;</code>?</p>
  
  <p>The Arduino-like libraries comes from the SMING framework.
  <a href="https://github.com/SmingHub/Sming" rel="nofollow">https://github.com/SmingHub/Sming</a></p>