Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem writing value to characteristic #16

Open
asaladino opened this issue Jul 5, 2021 · 0 comments
Open

Problem writing value to characteristic #16

asaladino opened this issue Jul 5, 2021 · 0 comments

Comments

@asaladino
Copy link

I created an iOS app peripheral and I am trying to create a java/kotlin cli app write data to the peripheral. The kotlin cli app can see the iOS app as a peripheral but whenever I call manager.getCharacteristicGovernor(url) the characteristic is never ready. Would you be able to look at my code and see if I am missing something?

import org.sputnikdev.bluetooth.manager.CharacteristicGovernor
import org.sputnikdev.bluetooth.manager.impl.BluetoothManagerBuilder

object BmSendTest {

    private val serviceId = "56a7c54d-fd39-4efe-9e10-4d832fa64b6f".toUpperCase()
    private val characteristic = "3348f88a-4972-4125-a6fb-6c70ef459e4d".toUpperCase()

    private val SEND_VALUE = "43966666".encodeToByteArray()

    @JvmStatic
    private fun sendValue(governor: CharacteristicGovernor): Boolean {
        println("sending: $SEND_VALUE")
        return governor.write(SEND_VALUE)
    }

    @Throws(Exception::class)
    @JvmStatic
    fun main(args: Array<String>) {
        println("Starting BLE Requests")
        val manager = BluetoothManagerBuilder()
            .withTinyBTransport(true)
            .withBlueGigaTransport("^*.$")
            .withIgnoreTransportInitErrors(true)
            .withDiscovering(true)
            .withRediscover(true)
            .build()

        manager.addDeviceDiscoveryListener { discoveredDevice ->
            if (discoveredDevice.displayName == "iOS Peripheral") {
                val d = manager.getDeviceGovernor(discoveredDevice.url)
                d.connectionControl = true
                println(
                    "=== Device: ${d.displayName}," +
                            " isOnline: ${d.isOnline}," +
                            " isAuthenticated: ${d.isAuthenticated}," +
                            " isBleEnabled: ${d.isBleEnabled}," +
                            " isBlocked: ${d.isBlocked}," +
                            " isConnected: ${d.isConnected}," +
                            " isServicesResolved: ${d.isServicesResolved}," +
                            " isReady:${d.isReady}"
                )
                val url = discoveredDevice.url.copyWith(serviceId, characteristic)
                println(url)
                // ISSUE: characteristic is never ready.
                manager.getCharacteristicGovernor(url).whenReady(BmSendTest::sendValue)
            }
        }
        manager.start(true)
    }
}

Console output:

Starting BLE Requests

(process:49679): GLib-CRITICAL **: 10:20:00.860: g_variant_iter_loop: assertion 'first_time || format_string == GVSI(iter)->loop_format' failed

(process:49679): GLib-CRITICAL **: 10:20:00.860: g_variant_iter_free: assertion 'is_valid_heap_iter (iter)' failed
=== Device: iOS Peripheral, isOnline: false, isAuthenticated: false, isBleEnabled: true, isBlocked: false, isConnected: false, isServicesResolved: false, isReady:true
tinyb:/XX:XX:XX:XX:XX:XX/57:50:6A:3B:53:0A/56a7c54d-fd39-4efe-9e10-4d832fa64b6f/3348f88a-4972-4125-a6fb-6c70ef459e4d
=== Device: iOS Peripheral, isOnline: true, isAuthenticated: false, isBleEnabled: true, isBlocked: false, isConnected: true, isServicesResolved: false, isReady:true
tinyb:/XX:XX:XX:XX:XX:XX/57:50:6A:3B:53:0A/56a7c54d-fd39-4efe-9e10-4d832fa64b6f/3348f88a-4972-4125-a6fb-6c70ef459e4d

I'm running this on manjaro and eventually raspbian.

Changes I've tried to resolve the issue:

  • Tried jdk's 14, 13, 11
  • Tried running with sudo.

I was able to perform a test write to the peripheral using LightBlue https://punchthrough.com/lightblue/

Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant