UART sensor with Yun Rev 2

Hi!

I have a sensor that I would like to use with hardware serial on my Yun Rev2.

I have a code that is meant for Arduino Mega, and I just cant figure out how to use this with my Yun Rev2. Is it even possible? In this code the wiring is TX and TX from the sensor goes to TX3 and RX3 on the Mega board.

I dont need to print anything to serial monitor and I can upload code via WiFi. Which means maybe its possible?

I have tried to use Software Serial but it doesnt really work so good for some reason. It seems to be very slow and also sometimes gives really high numbers that doesnt make sense.

Here is the code:

//This code was written to be easy to understand.
//Modify this code as you see fit.
//This code will output data to the Arduino serial monitor.
//Type commands into the Arduino serial monitor to control the EZO-Co2 sensor.
//This code was written in the Arduino 1.8.9 IDE
//An Arduino MEGA was used to test this code.
//This code was last tested 6/2019



String inputstring = "";                              //a string to hold incoming data from the PC
String sensorstring = "";                             //a string to hold the data from the Atlas Scientific product
boolean input_string_complete = false;                //have we received all the data from the PC
boolean sensor_string_complete = false;               //have we received all the data from the Atlas Scientific product
int Co2;                                              //used to hold a integer number that is the Co2


void setup() {                                        //set up the hardware
  Serial.begin(9600);                                 //set baud rate for the hardware serial port_0 to 9600
  Serial3.begin(9600);                                //set baud rate for software serial port_3 to 9600
  inputstring.reserve(10);                            //set aside some bytes for receiving data from the PC
  sensorstring.reserve(30);                           //set aside some bytes for receiving data from Atlas Scientific product
}

void serialEvent() {                                  //if the hardware serial port_0 receives a char
  inputstring = Serial.readStringUntil(13);           //read the string until we see a <CR>
  input_string_complete = true;                       //set the flag used to tell if we have received a completed string from the PC
}


void serialEvent3() {                                 //if the hardware serial port_3 receives a char
  sensorstring = Serial3.readStringUntil(13);         //read the string until we see a <CR>
  sensor_string_complete = true;                      //set the flag used to tell if we have received a completed string from the PC
}


void loop() {                                         //here we go...


  if (input_string_complete == true) {                //if a string from the PC has been received in its entirety
    Serial3.print(inputstring);                       //send that string to the Atlas Scientific product
    Serial3.print('\r');                              //add a <CR> to the end of the string
    inputstring = "";                                 //clear the string
    input_string_complete = false;                    //reset the flag used to tell if we have received a completed string from the PC
  }


  if (sensor_string_complete == true) {               //if a string from the Atlas Scientific product has been received in its entirety
    Serial.println(sensorstring);                     //send that string to the PC's serial monitor
	/*                                                //uncomment this section to see how to convert the reading from a string to an int
      Co2 = sensorstring.toInt();                     //convert the string to a integer number so it can be evaluated by the Arduino
      if (Co2 >= 400) {                               //if the Co2 is greater than or equal to 400 ppm
        Serial.println("high");                       //print "high" this is demonstrating that the Arduino is evaluating the Co2 as a number and not as a string
      }
       if (Co2 <= 399) {                              //if the Co2 is less than or equal to 399 ppm
        Serial.println("low");                        //print "low" this is demonstrating that the Arduino is evaluating the Co2 as a number and not as a string
    }
*/    
  }
  sensorstring = "";                                   //clear the string:
  sensor_string_complete = false;                      //reset the flag used to tell if we have received a completed string from the Atlas Scientific product
  }