Giter Club home page Giter Club logo

Comments (15)

Velorexe avatar Velorexe commented on August 15, 2024

Hi @takeraparterer

Good that you were able to connect. After that you need to find the Characteristic that you want to write, read or subscribe to. If you have both the Service and Characteristic UUID, you can start to read or write data to your device.

Respectively, you'd use:

var command = new SubscribeToCharacterstic(device, service, characteristic, (byte[] data) => {
   Debug.WriteLine(data.length);
});

To subscribe

var command = new ReadFromCharacteristic(device, service, characteristic, (byte[] data) => {
   Debug.WriteLine(data.length);
});

To read

var command = new WriteToCharacteristic(device, service, characteristic, base64Message);

To write.

You'd then queue them up to the BleManager, like this:

BleManager.Instance.QueueCommand(command);

Which will execute the command. Do note, that the normal BleCommands take a short-hand UUID, which is the differentiating part in this UUID: 0000[short-hand-uuid]-0000-1000-8000-00805f9b34fb. If you're using complete custom UUID's, pass a true boolean to the commands as well.

from unity-android-bluetooth-low-energy.

takeraparterer avatar takeraparterer commented on August 15, 2024

Hi. What does subscribing exactly mean in this context? Is it needed? Thank you so much for the response by the way!

from unity-android-bluetooth-low-energy.

Velorexe avatar Velorexe commented on August 15, 2024

So within BLE you have a certain amount of actions you can do to get data or write data. These are Subscribing / Notifying, Writing and Reading. For now, these can only be done on Characteristic level. If you download a third party app like LightBlue, you can check what kind of Characteristics are available on the device that you're connecting to.

From there you can check on a Characteristic level what kind of action you can do on it. You'd then take that information and at the point where you've connected to the device, you'd queue up one of the commands that I mentioned in the previous comment.

from unity-android-bluetooth-low-energy.

jidkiiponosBOMJA avatar jidkiiponosBOMJA commented on August 15, 2024

Hello. What do all the parameters in the write command mean? (for example, the device from which the request is sent?) And is it necessary to use the abbreviated uuid? How can I shorten it?

from unity-android-bluetooth-low-energy.

Velorexe avatar Velorexe commented on August 15, 2024

Hi @jidkiiponosBOMJA

The WriteToCharacteristic command has two constructors, which only differ in the data parameter. The data you send will always be converted to Base64 and read from the .jar file as a byte array to the device.

The parameters are explained in the summaries on the constructors themselves, but I'll give a brief rundown:

  • deviceAddress: The MAC address of the device that you used to connect to the device with
  • serviceAddress: Either the shortened or full length UUID of the Service that you want to write to. Basically the service holds individual Characteristics and is used to label them together. If you're using a full-length then you'd pass true to the customGatt parameter.
  • characteristicAddress: Either the shortened or full length UUID of the Characteristic you want to connect to. If you're using a full-length then you'd pass true to the customGatt parameter.
  • data: either a string or a byte[]. In both cases, it'll be turned in to Base64 and send to the Android Java library.
  • customGatt: by default false, but indicates if both the serviceAddress and characteristicAddress are full length UUID's or short hands. true for full length, false (default) for short.

If your UUID's adhere to the standard 0000[short-hand-uuid]-0000-1000-8000-00805f9b34fb UUID template for BLE, then you can use the small part in the labeled [short-hand-uuid] part for the parameters of WriteToCharacteristic.

from unity-android-bluetooth-low-energy.

jidkiiponosBOMJA avatar jidkiiponosBOMJA commented on August 15, 2024

Can u give an example of using write command with customGate?(My arduino bluetooth ble module is HM-10)

from unity-android-bluetooth-low-energy.

Velorexe avatar Velorexe commented on August 15, 2024

Do you have an overview of the Characteristics available on your HM-10? That makes it easier to write such examples.
For now, I'll pick a generic address.

// 0x180F -> Battery Service
// 0x2A19 -> Battery Level [under Battery Service]
// Source: https://www.bluetooth.com/specifications/assigned-numbers/

var write = new WriteToCharacteristic(
    _deviceUUID,
// Service UUID
    "0000180f-0000-1000-8000-00805f9b34fb",
// Characteristic UUID
    "00002A19-0000-1000-8000-00805f9b34fb",
// Data
    new byte[] { 0x01 },
// Indicates that these are custom GATT UUID (though the example UUID's could be used with short-hand 16-bit UUID's)
    customGatt: true
);

BleManager.Instance.QueueCommand(write);

from unity-android-bluetooth-low-energy.

jidkiiponosBOMJA avatar jidkiiponosBOMJA commented on August 15, 2024

Hi,thanks for answer.
I checked my HM-10 UUID:
0-02-05-2e31c9d987767521aa8a0f5efc58b50cbe7c42a2f151ed2c6fbffe2f88e980b5_4e939f60cfbe6b9a

In the Internet, I found which uuid corresponds to device name, service name and other. But when I entered these uuids, I got this code:

var write = new WriteToCharacteristic(
//Device UUID
"00002A00-0000-1000-8000-00805F9B34FB",
// Service UUID
"0000FFE0-0000-1000-8000-00805F9B34FB",
// Characteristic UUID
"0000FFE1-0000-1000-8000-00805F9B34FB",
// Data
new byte[] { 0x01},
// Indicates that these are custom GATT UUID (though the example UUID's could be used with short-hand 16-bit UUID's)
customGatt: true
//false-short,true-long
);
BleManager.Instance.QueueCommand(write);

(This code is'nt working ,it connect with scan button,but dont send commands)

Internet give me this:

image

ORANGE-Device UUID
GREEN-Service UUID
YELLOW-Characteristic UUID

Is this correct, or do these UUID belong to others?

from unity-android-bluetooth-low-energy.

Velorexe avatar Velorexe commented on August 15, 2024

Close, but not quite. Your Device isn't a UUID, it's a MAC address. My library will return a the found devices with their MAC address and name if it has one.

Also first the device has to be scanned, so the Android Java library has it cached. Then you have to connect to your device using it's MAC address (done through a button press in the example).

When the connection is successful, you can queue your commands to the BleManager.

Also as you can see for your Service and Characteristic addresses, they follow the same pattern as the standard UUID: 0000[short-hand-UUID]-0000-1000-8000-00805f9b34fb. So you could use FFE0 for the Service and FFE1 for the Characteristic, then leave customGatt as false.

from unity-android-bluetooth-low-energy.

jidkiiponosBOMJA avatar jidkiiponosBOMJA commented on August 15, 2024

Could you please match my data with the Write To Characteristic command? (I'm beginner in unity)

from unity-android-bluetooth-low-energy.

Velorexe avatar Velorexe commented on August 15, 2024

I'm not blaming the fact that I have to write this out on the original issue at hand (the lack of documentation). I recommend picking up some tutorials on C# / .NET and Unity to get familiar with it, but overall, keep practicing!

I'll write out the WriteToCharacteristic for you, but I don't know two parameters: the deviceAddress and the data. I don't know what you're going to send and I don't know the MAC address of your device.

var command = new WriteToCharacteristic(devieAddress, "FFE0", "FFE1", data);
BleManager.Instance.QueueCommand(command);

Again: this is only possible after you scanned for devices and connected to the one you want to send this command to.

from unity-android-bluetooth-low-energy.

jidkiiponosBOMJA avatar jidkiiponosBOMJA commented on August 15, 2024

Thanks a lot,it work!!!
image

Final code:
//(i put this code in my void(in "BleManager script"),he activates on "onClick")

var command = new WriteToCharacteristic("E0:62:34:D3:7A:64", "FFE0", "FFE1", "MESS"); BleManager.Instance.QueueCommand(command);

for other people:
1.
E0:62:34:D3:7A:64-MAC address of the device you want to connect to(u can find it in this app: https://play.google.com/store/apps/details?id=com.argonremote.bluetoothcontroller)
image
image

FFE0-service uuid-green square(check my photo in upper message)(app:
https://play.google.com/store/apps/details?id=com.macdom.ble.blescanner)
FFE0-characteristic uuid-yellow square(check my photo in upper message)(app;blescanner too)
image
(after connect u will see same,as my upper photo with squares)

"MESS"-your message

(i hope this messages will help other people)

from unity-android-bluetooth-low-energy.

jidkiiponosBOMJA avatar jidkiiponosBOMJA commented on August 15, 2024

good luck

from unity-android-bluetooth-low-energy.

Velorexe avatar Velorexe commented on August 15, 2024

@takeraparterer
Is your original question answered / solved? Else I'm gonna close the issue and you can re-open it if it's not.

from unity-android-bluetooth-low-energy.

takeraparterer avatar takeraparterer commented on August 15, 2024

@Velorexe go ahead and close it 👍

from unity-android-bluetooth-low-energy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.