remove a line break

Hello Everyone,

my device is sending hex number to my arduino : {43,4f,66,66}, so if i print it : 43 4f 66 66

can i remove the line break? ( 434f6666)?

Thanks.

renadi160691: Hello Everyone,

my device is sending hex number to my arduino : {43,4f,66,66}, so if i print it : 43 4f 66 66

can i remove the line break? ( 434f6666)?

Are you sure the line break is coming from your mysterious "device" and not caused by how you are printing it to the Serial monitor? How about a link to the device and properly posted code?

the device is an energy meter, using serial serial monitor it will send 01 04 04 43 4E 66 66 25 9D , but i only use the 43 4E 66 66.
Then after i receive the hex number , i publish it to my mqtt server.

The code :
#include <SoftwareSerial.h>
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
#define X2 1024

byte mac = { 0x90, 0xA2, 0xDA, 0x0E, 0xA1, 0x1B };
byte server = { 192, 168, 0, 10 };
byte ip = { 192, 168, 0, 15 };

void callback(char* topic, byte* payload, unsigned int length) {

}

EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);

#define rxPin 0
#define txPin 1
byte req= {0x01, 0x04, 0x00, 0x10, 0x00, 0x02, 0x70, 0x0E};
byte req2 = 04;
byte inByte = 0;

void setup()
{
Serial.begin(1200, SERIAL_8E1);
pinMode(txPin, OUTPUT);
pinMode(rxPin, INPUT);
Serial.write(req, 8);

Ethernet.begin(mac, ip);
if (client.connect(“arduinoClient”))
{
client.publish(“outTopic”,“ENERGY_METER_CONNECTED”);
}

}

void loop()
{

Serial.write(req, 8);
delay(500);

{
while (Serial.available()>0)

{
for (int x =0; x < 9 ; x++)
{
int inbyte ;
char message_buff[9];
String str;
inByte = Serial.read() ;

if (x > 2 && x < 7 )
{
str = String(inByte,HEX) ;
str.toCharArray(message_buff, 9);
client.publish(“outTopic”,message_buff);
}
}
}
}
client.publish(“outTopic”,"---------");
delay(9000);

}

The result is in the picture :

i’ve tried to replace it by using str.replace("\n"," "); , but it doesn’t work.
And it published :

43
43
43
43

instead :

43434343

any idea? thanks.

renadi160691: the device is an energy meter, using serial serial monitor it will send 01 04 04 43 4E 66 66 25 9D , but i only use the 43 4E 66 66. Then after i receive the hex number , i publish it to my mqtt server.

The code :

Serial.write(req, 8); delay(500);

I don't get it. You better read the link about "properly posted code" above.