BluetoothSerial get wrong data

chiffa
Posts: 7
Joined: Thu Oct 15, 2020 3:22 pm

BluetoothSerial get wrong data

Postby chiffa » Fri Dec 01, 2023 1:27 pm

Hello. I use Wemos Lolin32 lite to communicate with nfc-reader, nfc-reader support usb and bluetooth serial ports.

I sent command to nfc-reader over usb and all work fine. Then I tried to send the same commands over bluetooth and get incorrect data (other command over bluetooth works fine).

Code: Select all


#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
#endif

BluetoothSerial SerialBT;

#define BT_DISCOVER_TIME  5000
esp_spp_sec_t sec_mask = ESP_SPP_SEC_NONE; // or ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE to request pincode confirmation
esp_spp_role_t role = ESP_SPP_ROLE_SLAVE; // or ESP_SPP_ROLE_MASTER

void setup() {

  if (! SerialBT.begin("myDevice", true) ) {
    Serial.println("========== serialBT failed!");
    abort();
  }

  SerialBT.setTimeout(10);

String sendData = "4d004E2117100a004880AE8000420000000001000000000000000804000000000009802312010005E7C6C72200000000000000000000000000000000000000000000000000000000000000000000000000FE";

char SendDataC[fullSendData.length() + 1];
	sendData .toCharArray(SendDataC, sendData .length() + 1);
	sendData = "";

	uint8_t sendData_Hex[strlen(SendDataC) / 2] = {};
	memset(sendData_Hex, 0, sizeof(sendData_Hex));


String btAnswer= "";

SerialBT.write(sendData_Hex, sizeof(sendData_Hex));

		while (SerialBT.available()) {
			
				
		byte b = SerialBT.read();
		
		String hexByte = convert.decimalToHexa(b);
		
		if (hexByte.length()==1)
		hexByte = "0"+hexByte;
		
		btAnswer+=hexByte;
		
	}
	
	Serial.println (btAnswer); 
	/*
	Get result: 2CC95FB6C4C633E7ED070E403F450E61111992A74EBF12C28D7DBC9E25274BE4B09C4E735B5F533E4D09F0CE790159A9D1C903F5B226E72480AEC33AD2B0E08CCAAC1AB29000D4
	
	Over USB get result: 4d0036241710000030012d2d77299f2701809f360206789f2608814d0bbe068357329f10120110a00003220000000000000000999900ff900091
	and it's correct
	*/
}

I change buffer to

Code: Select all

#define RX_QUEUE_SIZE 2048
#define TX_QUEUE_SIZE 512
If anyone know what can be trouble, please, help. Thanks!

Who is online

Users browsing this forum: No registered users and 45 guests