Skip to content
This repository has been archived by the owner on Dec 20, 2019. It is now read-only.

ollie doesn't connect with uuid #49

Open
codeNgamer opened this issue Jan 9, 2016 · 27 comments
Open

ollie doesn't connect with uuid #49

codeNgamer opened this issue Jan 9, 2016 · 27 comments

Comments

@codeNgamer
Copy link

I've got the following code which works for the most part, except that the callback is never called from
ollie.connect()

const bleAddress = "e7:40:98:2a:20:8d";
noble = Npm.require('noble');
sphero = Npm.require('sphero');
// Cylon = Npm.require('cylon');
// Npm.require('cylon-ble');

noble.on('stateChange', function(state) {
  if (state === 'poweredOn') {
    console.log("Scanning for ollie's in the area...");
    noble.startScanning();
  } else {
    noble.stopScanning();
  }
});

noble.on('discover', function(peripheral) {
  if(peripheral.address === bleAddress) {
    console.log('Found your ollie!');

    if(peripheral.connectable) {
      console.log('I can connect to it');
      console.log('Attempting to connect now');

      noble.stopScanning();
      console.dir('device uuid is: ' + peripheral.uuid);

      ollie = sphero(peripheral.uuid);

      ollie.connect(function() {
        console.log('connected!');
      });
      ollie.on('error', function() {
        console.log('error');
      })
    }else {
      console.log('Womp womp, I cant connect to it right now');
    }

  }
});
@deadprogram
Copy link
Contributor

Hi, @codeNgamer not sure why you are calling the Noble code directly, you do not need to do any of that when using sphero.js, it does it for you.

In fact, another thing that sphero.js does is to convert a BLE address for the format "e7:40:98:2a:20:8d" to that needed by noble "e740982a208d" to connect to an Ollie.

The code you should be using is something like:

var sphero = require("sphero"),
    ollie = sphero("e7:40:98:2a:20:8d"); // change BLE address accordingly

ollie.connect(function() {
  console.log('connected!');
});

That's it, unless I am missing something?

@codeNgamer
Copy link
Author

That's what I was doing at first, but it wasn't working. I forgot to mention that the above code block gets executed server-side on the meteor framework so i wasn't sure if there was something different in it's ecosystem causing it to not work. So I figured i'd search, find it, then try to connect but it still doesn't work. Strange thing is, noble connects just fine.

@deadprogram
Copy link
Contributor

Since sphero.js is also scanning using Noble, having your own code that scans cannot work well at the present time. Once solution I have been working on, is being able to pass an existing Noble device connection into sphero.js.

@codeNgamer
Copy link
Author

I figured that also, but using this code below doesn't work either. I'll just continue to investigate

var sphero = require("sphero"),
    ollie = sphero("e7:40:98:2a:20:8d"); // change BLE address accordingly

ollie.connect(function() {
  console.log('connected!');
});

@deadprogram
Copy link
Contributor

Does not work inside your Meteor app? Can you share a little more context of how you call this? Also what OS/Node version, please?

@codeNgamer
Copy link
Author

So i'm running it on osx/el capitan, meteor 1.2.1 which is based on node 0.10.40

@deadprogram
Copy link
Contributor

How are you calling the code from your Meteor app? Sorry if my questions seem silly, but I am not very familiar with Meteor, having only played with it a little when it first came out.

@codeNgamer
Copy link
Author

No that's fine. Basically, I pull all npm packages needed by the meteor project with the code below:

 Npm.depends({
  noble: '1.2.1',
  sphero: '0.6.0',
  spheron: '0.0.3',
  cylon: '1.2.0',
  'cylon-ble': '0.9.0',
  'cylon-ollie': '0.8.0',
});

then use the below code:

var sphero = require("sphero"),
    ollie = sphero("e7:40:98:2a:20:8d"); // change BLE address accordingly

ollie.connect(function() {
  console.log('connected!');
});

which is executed from a script loaded server side

@deadprogram
Copy link
Contributor

Hi, @codeNgamer

When using the latest release of sphero.js, you should be able to the the Noble peripheral from your code:

ollie = sphero(peripheral.uuid, {peripheral: peripheral});

Please give it a try!

@deadprogram
Copy link
Contributor

Hi, @codeNgamer did you have a chance to give a it try yet? Please let us know.

@codeNgamer
Copy link
Author

hey @deadprogram sorry for the late reply. I did try that, briefly though. it didn't work but i havent tested yet, been super busy at work. I'll drop feedback soon

@vr00n
Copy link

vr00n commented Feb 5, 2016

Having same issues unable to connect using uuid

@deadprogram
Copy link
Contributor

@b44p on OS X you use the UUID, on Linux you use the BLE address. Make sure you are entering the correct value as returned by the BLE scan using Noble.

@vr00n
Copy link

vr00n commented Feb 5, 2016

Thanks @deadprogram. I am on OSX and am using cylon-ble-scan to get the uuid. I get a 32 character string.
I then use the following code to connect and do something but nothing happens.
What am I missing here ?

var Cylon = require('cylon');

Cylon.robot({
  connections: {
    bluetooth: { adaptor: 'central', uuid: 'UUID', module: 'cylon-ble' }
  },

  devices: {
    ollie: { driver: 'ollie', module: 'cylon-sphero-ble' }
  },

  work: function(my) {
    my.ollie.color(0x00FFFF);

    after(500, function() {
      my.ollie.color(0xFF0000);
    });

    after(1000, function() {
      my.ollie.roll(60, 0);
    });

    after(2000, function() {
      my.ollie.roll(60, 180);
    });

    after(3000, function() {
      my.ollie.stop();
    });
  }
}).start();

@deadprogram
Copy link
Contributor

This may seem like a silly question, but you are using uuid: 'Your actual UUID here' in your code, right?

@vr00n
Copy link

vr00n commented Feb 5, 2016

Haha - you seem to know the pain of those brain farts too well it seems - but no - i made sure i plugged in my 32 character UUID that i refrain to disclose for an unfounded fear that my ollie could be hacked remotely

@deadprogram
Copy link
Contributor

Hi, @b44p seems like this would be more correctly an issue entered on https://github.com/hybridgroup/cylon-sphero-ble would you mind opening one on that repo?

@vr00n
Copy link

vr00n commented Feb 12, 2016

Hey @deadprogram - I realize that I am not putting the ollie into dev mode but according to this @peterainbow created cylon-ollie. He appears to say that there he updated https://github.com/peterainbow/cylon-ollie to programmatically turn dev mode on. Am i missing something here ?

@deadprogram
Copy link
Contributor

That is all auto handled by the current version of Sphero.js so no need.

@vr00n
Copy link

vr00n commented Feb 12, 2016

I was able to use advertisement_discovery and get Ollie's UUID and then do this. Does not work.

node ollie.js where ollie.js is below

var sphero = require("sphero"),
    ollie = sphero("c7:20:a1:85:fa:07"); // This my OLLIE

ollie.connect(function() {
  setInterval(function() {
    var direction = Math.floor(Math.random() * 360);
    ollie.roll(150, direction);
  }, 1000);
});

@deadprogram
Copy link
Contributor

Hi, @b44p shouldn't you be using the 32-char UUID instead of the BLE address in the code above, since you are on OSX? I booted up my OS X machine (still running Yosemite) installed the latest Sphero.js, and was able to run without troubles.

@vr00n
Copy link

vr00n commented Feb 13, 2016

Hey @deadprogram - tried both - no joy 👎
I am on El capitan - see my install log. Do you think maybe the [email protected] warning is causing issues ?

npm install sphero noble
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No README data
npm http GET https://registry.npmjs.org/sphero
npm http GET https://registry.npmjs.org/noble
npm http 304 https://registry.npmjs.org/sphero
npm http 304 https://registry.npmjs.org/noble
npm http GET https://registry.npmjs.org/browser-serialport
npm http GET https://registry.npmjs.org/xpc-connection
npm http GET https://registry.npmjs.org/debug
npm http GET https://registry.npmjs.org/bplist-parser
npm http GET https://registry.npmjs.org/bluetooth-hci-socket
npm http 304 https://registry.npmjs.org/bplist-parser
npm http 200 https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/xpc-connection
npm http 304 https://registry.npmjs.org/browser-serialport
npm http 304 https://registry.npmjs.org/bluetooth-hci-socket
npm WARN optional dep failed, continuing [email protected]
npm http GET https://registry.npmjs.org/nan
npm http GET https://registry.npmjs.org/ms
npm http 304 https://registry.npmjs.org/nan
npm http 304 https://registry.npmjs.org/ms

> [email protected] install /Users/vivi/node_modules/noble/node_modules/xpc-connection
> node-gyp rebuild

  CXX(target) Release/obj.target/binding/src/XpcConnection.o
  SOLINK_MODULE(target) Release/binding.node
  SOLINK_MODULE(target) Release/binding.node: Finished
npm WARN unmet dependency /Users/vivi/node_modules/cylon-ollie requires cylon-ble@'~0.8.0' but will load
npm WARN unmet dependency /Users/vivi/node_modules/cylon-ble,
npm WARN unmet dependency which is version 0.10.1
[email protected] ../../../../node_modules/sphero
└── [email protected]

[email protected] ../../../../node_modules/noble
├── [email protected]
├── [email protected] ([email protected])
└── [email protected] ([email protected])
var sphero = require("sphero"),
    ollie = sphero("964da49affdd4ee6a123e934a076097f"); // This my OLLIE

ollie.connect(function() {
  setInterval(function() {
    var direction = Math.floor(Math.random() * 360);
    ollie.roll(150, direction);
  }, 1000);
});

@deadprogram
Copy link
Contributor

I will install El Capitan and dig in further...

@vr00n
Copy link

vr00n commented Feb 15, 2016

Thank you kind sir

@deadprogram
Copy link
Contributor

Hi, @b44p still researching on this. Another question: what exact Mac do you have? Including the specific Bluetooth adaptor, please.

@vr00n
Copy link

vr00n commented Mar 3, 2016

argh sorry for the late response - Im using 2 macs

MAC1

Model Name: iMac
Processor Name: Intel Core i5
Processor Speed: 3.4 GHz
Number of Processors: 1
Total Number of Cores: 4
L2 Cache (per Core): 256 KB
L3 Cache: 6 MB
Memory: 32 GB

> Apple Bluetooth Software Version: 4.4.3f4 16616
Hardware, Features, and Settings:
Bluetooth Low Energy Supported: Yes
Handoff Supported: Yes
Instant Hot Spot Supported: Yes
Manufacturer: Broadcom
Transport: USB
Chipset: 20702B0
Firmware Version: v112 c9036
Bluetooth Power: On
Discoverable: Off
Connectable: Yes
Auto Seek Pointing: On
Remote wake: On
Vendor ID: 0x05AC
Product ID: 0x828D
HCI Version: 0x6
HCI Revision: 0x234C
LMP Version: 0x6
LMP Subversion: 0x4170
Device Type (Major): Computer
Device Type (Complete): Mac Desktop
Composite Class Of Device: 0x380104
Device Class (Major): 0x01
Device Class (Minor): 0x01
Service Class: 0x1C0
Auto Seek Keyboard: On

MAC 2

Model Name: MacBook Air
Model Identifier: MacBookAir6,2
Processor Name: Intel Core i5
Processor Speed: 1.3 GHz
Number of Processors: 1
Total Number of Cores: 2
L2 Cache (per Core): 256 KB
L3 Cache: 3 MB
Memory: 8 GB
Boot ROM Version: MBA61.0099.B21
SMC Version (system): 2.13f15

> Apple Bluetooth Software Version: 4.4.3f4 16616
Hardware, Features, and Settings:
Name: Varun’s MacBook Air
Bluetooth Low Energy Supported: Yes
Handoff Supported: Yes
Instant Hot Spot Supported: Yes
Manufacturer: Broadcom
Transport: USB
Chipset: 20702B0
Firmware Version: v112 c9037
Bluetooth Power: On
Discoverable: On
Connectable: Yes
Auto Seek Pointing: On
Remote wake: On
Vendor ID: 0x05AC
Product ID: 0x828F
HCI Version: 0x6
HCI Revision: 0x234D
LMP Version: 0x6
LMP Subversion: 0x4170
Device Type (Major): Computer
Device Type (Complete): Mac Portable
Composite Class Of Device: 0x38010C
Device Class (Major): 0x01
Device Class (Minor): 0x03
Service Class: 0x1C0
Auto Seek Keyboard: On

@deadprogram
Copy link
Contributor

The bluetooth-hci-socket warning is just telling you "this optional module is not being installed". If you were installing on Linux or Windows, that module would be installed, but you would see a warning for xpc-connection not being installed, since xpc-connection is Mac-only.

@b44p we have an issue open on Noble itself here: noble/noble#340 you might want to chime in.

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

No branches or pull requests

3 participants