I am using some third party libraries for some third party hardware. The libraries communicate with the hardware over a serial connection. Using the libraries I send data over the serial interface to the hardware and get a response, which is stored in an array:
// This is the byte array declared in the third party libraries
// that stores data sent back from the external hardware
byte comm_buf[201];
/* I send data to hardware, comm_buf gets filled */
// Printing out the received data via a second serial line to which
// I have a serial monitor to see the data
for (int i = 0; i <= 50; i++) {
Serial.print(gsm.comm_buf[i]);
}
// This is printed via the second monitoring serial connection (without spaces)
13 10 43 67 82 69 71 58 32 48 44 51 13 10 13 10 79 75 13 10 00
// It is the decimal ascii codes for the following text
+CREG: 0,3
How can I convert a byte array into a format that I can evalute in code so I can perform an operation like the following pseudo code;
byte comm_buf[201];
/* I send data to hardware, comm_buf gets filled */
if (comm_buf[] == "CREG: 0,3" ) {
// do stuff here
}
Do I need to convert it to a string some how, or compare to another char array perhaps?
strcmp(com_buffer, "CREG: 0,3")?if (strcmp(gsm.comm_buf,"\r\n+CREG: 0,3\r\n\r\nOK\n")) {gives the errorinvalid conversion from 'byte*' to 'const char*'strcmp((const char *)comm_buf, "foobar")strcmp()expects two arguments of typeconst char *, but your array is of typebyte[]which decays intobyte *when passed to the function - and two pointers of which the base type is different (const char *andbyte *in your case) are incompatible types.