Send Some special char with esp8266

I read spo2 module data from RX / TX port, it is ASCII data type and I want to send it via WIFI

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <SoftwareSerial.h>

SoftwareSerial mySer(12, 14);
char inData = '0';

// Set WiFi credentials
#define WIFI_SSID "TheOtherESP"
#define WIFI_PASS "flashmeifyoucan"

// UDP
WiFiUDP UDP;
IPAddress remote_IP(192, 168, 4, 1);
#define UDP_PORT 4210

void setup() {

  // Setup serial port
  Serial.begin(115200);
  mySer.begin(115200);
  Serial.println();

  // Begin WiFi
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  WiFi.mode(WIFI_STA);

  // Connecting to WiFi...
  Serial.print("Connecting to ");
  Serial.print(WIFI_SSID);
  // Loop continuously while WiFi is not connected
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(100);
    Serial.print(".");
  }

  // Connected to WiFi
  Serial.println();
  Serial.print("Connected! IP address: ");
  Serial.println(WiFi.localIP());

  // Begin UDP port
  UDP.begin(UDP_PORT);
  Serial.print("Opening UDP port ");
  Serial.println(UDP_PORT);

}

void loop() {

  // Read packet
  if (mySer.available()) {
    inData = mySer.read();
    Serial.print((char)inData);
    // Send Packet
    UDP.beginPacket(remote_IP, UDP_PORT);
    UDP.write(inData);
    UDP.endPacket();
    // delay(100);
  }
}

The printed data is as follows:

46 APR=680 BP⸮ OKA[⸮⸮ʲ-min=1930j}⸮⸮⸮1-	}⸮⸮⸮1⸮⸮=97 PR=9%46 APR=64AI벢⸮ OP⸮⸮⸮=2003 OP⸮⸮19-51 )⸮⸮⸮1846j}⸮⸮⸮1 Sop2=97 PR=94
 APR=65AI⸮=650
 OP⸮⸮뒂⸮⸮-_min=194-	}⸮⸮⸮⸮-	}⸮n=1756
⸮=97 PO%47 APR=679 BPR=669
 OP⸮⸮뒂⸮⸮-min=194-	}⸮⸮⸮1836 OKB[⸮⸮⸮⸮⸮ Sop2=97 PR APR=650 BPR=660
 ⸮⸮⸮뒂⸮⸮-_min=19-	}⸮⸮⸮1844 OK⸮⸮175م⸮Օ⸮ S=96 ⸮ APR=3AI62I}AI97
 EER*⸮Օ5⸮ APR=549 BPR⸮ EER%⸮ʺ
 So⸮96 PR=&%47 APR=630 
 OP⸮⸮⸮ʺ⸮-_min=1920 OKB_1803 O⸮⸮⸮늺⸮⸮ =96 PR=93%46

How can I send just data that contain Sop2=xx PR=xx ?

I think the first issue you need to solve is the serial data stream. Do you have a second UART on your device? Software Serial should be avoided as much as possible. Unless you are developing a ultra-cheap product with very large volumes, making you millions of dollars there is no need for that. Get a device with enough UARTs.

Once you have a clean stream of data you can investigate parsing the data. There are all kinds of way to do this. You basically search for the identifier and extract the data. You can do this character by character or fill a buffer and then use some functions for searching sub strings.

For example:

https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/indexof/
https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/startswith/

There is no way your software serial will run at 115200 baud rate. It will do 9600 reliably. Get a real UART.

When the esp board is turned on, if I using UART hardware, program not running and WiFi can not be connected to another board, I have to disconnect the jumper first from the pins and connect the jumper after connecting to WiFi, is it a way to solve it?

Can you provide some more information about your system? It is hard to give you advice without seeing what boards you have and how they are connected.
A schematic (hand drawn is OK) would be good and links to datasheets of non-Arduino devices.

the module is:Home Story LK88 Professional Series Pulse Fingertip Oximeter Pulse Oximeter - Home Story : Flipkart.com with 115200 baudrate

the code with hardware UART:

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>


// Set WiFi credentials
#define WIFI_SSID "TheOtherESP"
#define WIFI_PASS "flashmeifyoucan"

// UDP
WiFiUDP UDP;
IPAddress remote_IP(192, 168, 4, 1);
#define UDP_PORT 4210

void setup() {

  // Setup serial port
  Serial.begin(115200);
  Serial.println();

  // Begin WiFi
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  WiFi.mode(WIFI_STA);

  // Connecting to WiFi...
  Serial.print("Connecting to ");
  Serial.print(WIFI_SSID);
  // Loop continuously while WiFi is not connected
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(100);
    Serial.print(".");
  }

  // Connected to WiFi
  Serial.println();
  Serial.print("Connected! IP address: ");
  Serial.println(WiFi.localIP());

  // Begin UDP port
  UDP.begin(UDP_PORT);
  Serial.print("Opening UDP port ");
  Serial.println(UDP_PORT);

}

void loop() {

  // Read packet
  if (Serial.available()) {
   char inData = Serial.read();
    Serial.print(inData);
    // Send Packet
    UDP.beginPacket(remote_IP, UDP_PORT);
    UDP.write(inData);
    UDP.endPacket();
    // delay(100);
  }
}

OK. So, the pulse oximeter sends this serial data stream without any configuration. When you start the meter, you get the data. Am I right?

I had a look at some ESP-12F datasheet. It looks like you only have one UART.

However, if my first point is correct you can remove the connection from ESP-12F TX to Spo2 RX. Then you can connect the ESP-12F TX to your Serial Monitor. UARTs use an asynchronous protocol. That means transmit and receive are independent without a clock signal. Each side can just transmit whenever it wants. But the baudrate setting is the same for transmit and receive. Luckily, you can freely choose the setting for the Serial Monitor. So, we can match it to the baudrate required for the sensor.

Can you then create a simple sketch that will forward every character exactly as received and show the output of that?

void loop()
{
  if ( Serial.available() )
  {
    char c = Serial.read();
    Serial.write( c );
  }
}
1 Like

Thank you, It's work
Can you explain the reason for this? Why the module can not connect to WiFi in sync mode at startup

Can you show the output from the Spo2 module using the sketch above? Does still look as in post #1 or has the printout improved?

You only need two "half" hardware UARTs. Because you only have one UART and the direction is different for each case we can use the transmit and receive side for different functions. The receive side for the sensor and the transmit side for the Serial Monitor.

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.