1. While sending the said string "Open: 1" from the Bluetooth, please send LF (Line Feed = 0x0A) as the terminating charcater.
2. Upload the following sketch in UNO and check that you have seen 1 on the OutputBox of the Serial Monitor.
while (Serial.available() > 0)
byte m = Serial.readBytesUntil('\n', myArray, 12);
unsigned int x1 = strtoul(myArray, &temPtr, 10);
byte x2 = strtoul(temPtr+5, &temPtr, 10);
Serial.println(x2, DEC); //shows: 1 or (0 to 255)
memset(myArray, 0x00, 12); //reset the array
Working Principle of strtoul() Function:
The function parses (read a character from a character type array and check if it is a digit) a string (array of characters) and stops at the non-digit character. The ASCII codes of the digits which have been parsed are converted into a numerical number which is saved in a variable. For example:
char myArray = “1234, 56, 78”;
unsigned int x1 = strtoul(myArray, &temPtr, 10); // x1 = 0x04D2
Serial.println(x1, DEC); //shows: 1234
The arg3 (= 10) says that the function looks for decimal digits in the array. The parsing stops at the first comma (,); there remains the sub-array/sub-string (, 56, 78) which will be parsed next to extract 56. Now, we need a pointer variable (*temPtr) to point the beginning of the sub-array. The arg2 (= &temPtr) passes to the pointer variable (temPtr) the address of the character where parsing has stopped and this mechanism allows the strtoul() function to locate the beginning of the sub-array.