happycodelucky / rocket-nuimo-node

Nuimo Control device discovery, connection manager, and interface control for Node.js
MIT License
12 stars 4 forks source link

Nuimo not found without device_id #9

Open oschade opened 3 years ago

oschade commented 3 years ago

Thank you for your work!

I tried your lib today, but sadly, my nuimo was not found. I can find my device (name: "Nuimo") with noble on my windows machine, using the advertising example of noble from https://github.com/noble/noble/blob/master/examples/advertisement-discovery.js

But in your script, noble found no devices at all:

file: dist/discovery/discovery.js

 startDiscoverySession(options) {
        // Initial discovery requires events to be registered
        if (this.managerDiscoveryState === device_discovery_state_1.DeviceDiscoveryState.Initial) {
            // TODO: Should we account for BT initialization for timeouts?
            this.initializeBluetooth();
            noble.on('discover', (peripheral) => {
               console.log("THIS MESSAGE NEVER LOGGED") // <-----------------------------------------------------------
                const isNuimoDevice = (peripheral.advertisement.localName === 'Nuimo');
                if (isNuimoDevice) {
               [... ]

I do not know exactly the meaning of "DEVICE_ID" in your example. So I leave it undefined:

// Uncomment to search for only your device
// ENTER DEVICE_ID to discover only a particular device
const DEVICE_ID: string | undefined = undefined

/**
 * Main application entry point
 */
async function main() {
  const device = await connectToDevice(DEVICE_ID)

  // Create a custom Glyph
  // Nuimo Control has a 9x9 LED display, but you only need to create what you need
  // and use `GlyphAlignment` to align the glyph on display
  const glyph = Glyph.fromString([
    '  *  ',
    ' *** ',
    ' *** ',
    ' *** ',
    '*****',
    '** **',
    '* * *',
  ])

  // Display the glyph for 5 seconds
  device.displayGlyph(glyph, {
    alignment: GlyphAlignment.Center, // Center align (default)
    brightness: 1, // Display brightness
    transition: DisplayTransition.CrossFade, // Fade in/out
    timeoutMs: 5000, // Timeout after 5 seconds
  })
}

// Boot strap async function
bootstrap(main)

the console logs "Waiting for device..." at least. I read a bit of your code. Maybe you forgot to run the method noble.startScanning() when no devide_id was specified?

Thank you.

Oliver

happycodelucky commented 3 years ago

Hey Oliver, I recently change this code to remove a deprecated function. I could have broken it. You can use the prior release it should work just fine

On Wed, Jan 13, 2021 at 7:50 AM oschade notifications@github.com wrote:

Thank you for your work!

I tried your lib today, but sadly, my nuimo was not found. I can find my device (name: "Nuimo") with noble on my windows machine, using the advertising example of noble from

https://github.com/noble/noble/blob/master/examples/advertisement-discovery.js

But in your script, noble found no devices at all:

file: dist/discovery/discovery.js

startDiscoverySession(options) { // Initial discovery requires events to be registered if (this.managerDiscoveryState === device_discovery_state_1.DeviceDiscoveryState.Initial) { // TODO: Should we account for BT initialization for timeouts? this.initializeBluetooth(); noble.on('discover', (peripheral) => { console.log("THIS MESSAGE NEVER LOGGED") // <----------------------------------------------------------- const isNuimoDevice = (peripheral.advertisement.localName === 'Nuimo'); if (isNuimoDevice) { [... ]

I do not know exactly the meaning of "DEVICE_ID" in your example. So I leave it undefined:

// Uncomment to search for only your device // ENTER DEVICE_ID to discover only a particular device const DEVICE_ID: string | undefined = undefined

/**

  • Main application entry point */ async function main() { const device = await connectToDevice(DEVICE_ID)

    // Create a custom Glyph // Nuimo Control has a 9x9 LED display, but you only need to create what you need // and use GlyphAlignment to align the glyph on display const glyph = Glyph.fromString([ ' * ', ' ', ' ', ' * ', '***', ' ', ' *', ])

    // Display the glyph for 5 seconds device.displayGlyph(glyph, { alignment: GlyphAlignment.Center, // Center align (default) brightness: 1, // Display brightness transition: DisplayTransition.CrossFade, // Fade in/out timeoutMs: 5000, // Timeout after 5 seconds }) }

// Boot strap async function bootstrap(main)

the console logs "Waiting for device..." at least. I read a bit of your code. Maybe you forgot to run the method noble.startScanning() when no devide_id was specified?

Thank you.

Oliver

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/happycodelucky/rocket-nuimo-node/issues/9, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABCAEHPQYZICLK3IQRB3GLSZW6K5ANCNFSM4WBAFPQQ .

oschade commented 3 years ago

I try to use version "0.5.1", but with no success. I noticed you use the package "@abandonware/noble" instead of "noble". I tried this package with the same version you used and this example code works flawless on my windows machine:


import noble from '@abandonware/noble'

noble.on('stateChange', function (state) {
  if (state === 'poweredOn') {
    noble.startScanning()
  } else {
    noble.stopScanning()
  }
})

noble.on('discover', function (peripheral) {
  console.log(
    `peripheral discovered (${peripheral.id} with address <${peripheral.address}, ${peripheral.addressType}>,` +
      ` connectable ${peripheral.connectable},` +
      ` RSSI ${peripheral.rssi}:`
  )
  console.log('\thello my local name is:')
  console.log(`\t\t${peripheral.advertisement.localName}`)
  console.log(
    '\tcan I interest you in any of the following advertised services:'
  )
  console.log(`\t\t${JSON.stringify(peripheral.advertisement.serviceUuids)}`)

  const serviceData = peripheral.advertisement.serviceData
  if (serviceData && serviceData.length) {
    console.log('\there is my service data:')
    for (const i in serviceData) {
      console.log(
        `\t\t${JSON.stringify(serviceData[i].uuid)}: ${JSON.stringify(
          serviceData[i].data.toString('hex')
        )}`
      )
    }
  }
  if (peripheral.advertisement.manufacturerData) {
    console.log('\there is my manufacturer data:')
    console.log(
      `\t\t${JSON.stringify(
        peripheral.advertisement.manufacturerData.toString('hex')
      )}`
    )
  }
  if (peripheral.advertisement.txPowerLevel !== undefined) {
    console.log('\tmy TX power level is:')
    console.log(`\t\t${peripheral.advertisement.txPowerLevel}`)
  }

  console.log()
})

In the meantime, I tried your lib with my rpi3 and it works fine, so I think the problem is in the library.

happycodelucky commented 3 years ago

Thanks for letting me know. I don't have access to Windows so this is not tested. @abandonware takes over packages that no longer receive updates. There must be something broken in there.

If you are using yarn instead of npm you can override the version of noble used in package.json

happycodelucky commented 3 years ago

I've published a couple of versions since these messages. Do you mind giving it another try?

oschade commented 3 years ago

Still the same behaviour =(