Redirect function output from serial monitor to character variable

I’m doing a project using the DYIRDaikin.h DYIRDaikin.h library, it has a void function called .description() that prints 7 lines to the serial monitor. I would like to be able to have those 7 lines stored in a char array so I can publish them on the device webpage.

I tried in multiple ways using the Serial.read() to read the data from the serial monitor but without success. I’m starting to question if it’s actually possible.

Can someone help me?

Please post a sketch showing what you tried and describe the problems

not really

void DYIRDaikin::description()
{
	//Serial.print(F("\r\n==send buffer==\r\n"));
	//Serial.print(F("Power:"));
	//Serial.print(getPower(),DEC);
	//Serial.println();
	//Serial.print(F("Mode:"));
	//Serial.print(getMode(),DEC);
	//Serial.println();
	//Serial.print(F("Fan:"));
	//Serial.print(getFan(),DEC);
	//Serial.println();
	//Serial.print(F("Temperature:"));
	//Serial.print(getTemp(),DEC);
	//Serial.println();
	//Serial.print(F("Swing:"));
	//Serial.print(getSwing(),DEC);
	//Serial.println();
	//Serial.print(F("SwingLR:"));
	//Serial.print(getSwingLR(),DEC);
	//Serial.println();
	_irrecv.descriptionARC(daikin + (sizeof(unsigned char)*8));
}

Reading back from the serial output is not a good idea, and would be difficult to do. It is not possible to actually read back from the serial monitor.

You can rewrite the function to save the text into a char array, but a better way (particularly if you are short of ram) is to pass a structure to the function so that it can save the data that needs to be printed, then generate the print statements later when you publish to the webpage. All of the functions being called in the print() statements return uint8_t, so that would not take much memory to implement.

I'm not an expert but I found the void DYIRDaikinRecv::descriptionARC(uint8_t *recvData) function in the DYIRDaikinRecv.cppv file that has the same syntax (and errors) that appear on the serial monitor:

    DYIRDAIKIN_DEBUG_PRINT(F("\r\n===\r\n"));
	DYIRDAIKIN_DEBUG_PRINT(F("Power:"));
	DYIRDAIKIN_DEBUG_PRINT(powerState,DEC);
	DYIRDAIKIN_DEBUG_PRINTLN();
	DYIRDAIKIN_DEBUG_PRINT(F("Mode:"));
	DYIRDAIKIN_DEBUG_PRINT(mode,DEC);
	if (mode == 0) {
		DYIRDAIKIN_DEBUG_PRINT(F(" (FAN"));
	}
	if (mode == 1) {
		DYIRDAIKIN_DEBUG_PRINT(F(" (COOL"));
	}
	if (mode == 2) {
		DYIRDAIKIN_DEBUG_PRINT(F(" (DRY"));
	}
	if (mode == 3) {
		DYIRDAIKIN_DEBUG_PRINT(F(" (HEAT"));
	}
	if (mode == 4) {
		DYIRDAIKIN_DEBUG_PRINT(F(" (AUTO"));
	}

	DYIRDAIKIN_DEBUG_PRINTLN();
	DYIRDAIKIN_DEBUG_PRINT("Fan:");
	DYIRDAIKIN_DEBUG_PRINT(fan,DEC);
	DYIRDAIKIN_DEBUG_PRINTLN();
	DYIRDAIKIN_DEBUG_PRINT("Temperature:");
	DYIRDAIKIN_DEBUG_PRINT(temperature,DEC);
	DYIRDAIKIN_DEBUG_PRINTLN();
	DYIRDAIKIN_DEBUG_PRINT("Swing:");
	DYIRDAIKIN_DEBUG_PRINT(swing,DEC);
	DYIRDAIKIN_DEBUG_PRINTLN();
	DYIRDAIKIN_DEBUG_PRINT("SwingLR:");
	DYIRDAIKIN_DEBUG_PRINT(swingLR,DEC);
	DYIRDAIKIN_DEBUG_PRINTLN();

If getting the data from the serial monitor it's too complicate I will give it a try but since I haven't done anything similar before I'm afraid I'm going to break the functionality of the library but we'll see

It is not complicate, I would say it just impossible.

I moved your topic to an appropriate forum category @Katoz.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

After quite a few problems I managed to get the function to return a char matrix with all that I needed.

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