Jump to content
RobertWoodruff

Anyone tried to use AT+CLASS= on the HC-05 Bluetooth module?

Recommended Posts

Has anyone figured out how to translate the value supplied to the HC-05 Bluetooth module's AT+CLASS= command to the value that is retrieved on the far end from the Bluetooth device connection?

 

I can find explanations of how the individual bits of a standard BT 32 bit class value are to be interpreted. But I cannot figure out how to encode that value in the HC-05's AT+CLASS= command nor how any value set there translates to the value picked up when doing the BT paring on the far end.

 

For example, if pairing with an Android the Java code on the Android to retrieve the class is something like

 

BluetoothClass bluetoothClass = btDevice.getBluetoothClass();
int deviceClass = bluetoothClass.getDeviceClass();
int majorDeviceclass = bluetoothClass.getMajorDeviceClass();

 

Does anyone know how to encode class values in AT+CLASS= on the HC-05 and how they are translated into values on the other end?

 

For example, say the Android was looking for deviceClass to be 99. What would be placed in the AT+CLASS= command to the HC-05 so that 99 was seen by the Android? (I know it is not AT+CLASS=99).

 

Thank you,
 

Share this post


Link to post
Share on other sites

A quick web search (duck duck go: at command set +class "HC-05") turned up a bit of docs (on slideshare) that mentions it.  From what I read (not the whole thing) it looks like many of the parameters are in hex for many of the commands.  The next entry in the document, for example shows that for "AT+IAC=<PARAM>" that the default value is 9e8b33.

 

So I'd try converting 99 to hex (63) and sending:

 

AT+CLASS=63

 

(Note: I'd've put in a link to the documentation, but as a new member here, I didn't want to run the risk of being marked a spambot due to having an offsite URL in a short reply.)

 

Hope that gets you going!

 

UPDATE:  I just read the appendix in the above document, and it contains an appendix that appears to be a description of the class field.  It says that it's a 32 bit field, and shows various tables describing what the bits mean in various instances.  (It's rather more complex than I'd've thought, as there are about 6 pages containing nine tables covering subsections of the 32 bit number.  Kind of interesting.)

Share this post


Link to post
Share on other sites

Hi Roboticus,

 

You are correct,  the parameter values to AT+CLASS= are hex numbers. There is a overview in the Bluetooth spec about formatting and interpreting the 32 bit class value (CoD). I am not going to learn all that now but have learned enough to carry forward with this application.

 

Here is a translation between what is sent to the AT command and what is seen on the Android side

 

/* Android Java code segment */

BluetoothClass bluetoothClass = btDevice.getBluetoothClass();
int deviceClass = bluetoothClass.getDeviceClass();
int majorDeviceclass = bluetoothClass.getMajorDeviceClass();

 

Apparently the default in the HC-05 is that lowest two bits of whatever hex value is sent to AT+CLASS= are set to 0 by the time it can be picked up on the Android side by deviceClass = bluetoothClass.getDeviceClass(); The majorDeviceclass is coming in at 0x100.

 

Here are a few test cases I tried

 

AT value(hex, binary)                deviceClass          majorDeviceClass  

128, 0001 0010 1000      0x128          0x100

129, 0001 0010 1001      0x128          0x100

12A, 0001 0010 1010      0x128          0x100

12B, 0001 0010 1011      0x128          0x100

12C, 0001 0010 1100      0x12C          0x100

12D, 0001 0010 1101      0x12C          0x100

 

There are also web sites where you can enter the characteristics of your BT device and it will generate a CoD (class of device) hex number for you.

 

Hope this info is useful to someone out there.

 

Thank you,

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...