don / node-eddystone-beacon

Create an Eddystone Beacon using Node.js https://github.com/google/eddystone
Other
315 stars 48 forks source link

Failure to start beacon from crontab on reboot. #48

Open mike-pun opened 7 years ago

mike-pun commented 7 years ago

I have been working with a Raspberry Pi running Ubuntu Mate 16.04. I am doing a straight forward advertiseURL and the code works well when running from a bash file, either under nodejs or pm2. However when I try running the script in a crontab on @reboot, the beacon does not turn on. I have done a sudo setcap cap_net_raw+eip $(eval readlink -f which node) so that I can run without sudo.

I don't see where/how I can generate an error indicator or message to see what the problem is, so:

  1. How to verify if the advertiseURL has worked, that advertising has started, and to generate an exception if not?

  2. Any idea why the script would not work in a crontab?

mike-pun commented 7 years ago

Hi.. I have more information.. I now have this code:

const eddystoneBeacon = require('eddystone-beacon')
const bleno = require('bleno')

let options = {
    name: xxxx,
    txPowerLevel: -22,
    tlmCount: 2,
    tlmPeriod: 10
}

let url = 'https://xxxx.biz/' 

bleno.on('advertisingStart', function(err) {
  if (err) {
    throw err;
  }
  console.log('on -> advertisingStart');
})
bleno.on('stateChange', function(state,err) {
  if (err) {
    throw err;
  }
  console.log('on -> stateChange:' + state);
})
bleno.on('servicesSet', function(err) {
  if (err) {
    throw err;
  }
  console.log('on -> servicesSet');
})

console.info(`Turning on advertising ${url}`);
eddystoneBeacon.advertiseUrl(url, options);
console.info(`Turned on advertising ${url}`);

When I run this standalone in bash, I get:

Turning on advertising https://xxxx.biz/
Turned on advertising https://xxxx.biz/
on -> stateChange:poweredOn
on -> advertisingStart
/locol/lib/locol.pi.core/beaconOn.js:21
    throw err;
    ^

Error: Command Disallowed
    at Gap.onHciLeAdvertiseEnableSet (/locol/lib/locol.pi.core/node_modules/bleno/lib/hci-socket/gap.js:201:15)
    at emitOne (events.js:115:13)
    at Hci.emit (events.js:210:7)
    at Hci.processCmdCompleteEvent (/locol/lib/locol.pi.core/node_modules/bleno/lib/hci-socket/hci.js:542:10)
    at Hci.onSocketData (/locol/lib/locol.pi.core/node_modules/bleno/lib/hci-socket/hci.js:428:12)
    at emitOne (events.js:115:13)
    at BluetoothHciSocket.emit (events.js:210:7)

However, the beacon comes on properly. When I put in in crontab -e, I get:

Turning on advertising https://xxxx.biz/
Turned on advertising https://xxxx.biz/

And nothing else... There is no beacon being advertised...

Any help will be much appreciated... been struggling with this.

mike-pun commented 7 years ago

I found this: https://github.com/sandeepmistry/bleno/issues/136

which seem to describe the Command Disallowed problem with a bypass, but it does not seem to relate to the main problem of not being able to start beacon on reboot.

sandeepmistry commented 7 years ago

@mike-pun I would make sure the cron tab starts after the bluetooth adapter is up and bluetoothd is fully running.

locol-media-dev commented 7 years ago

The Cron does start. Other things are running. I tried putting in a time of about 20sec delay to see if it helps but no luck. How do I make sure that bluetoothd is fully running?