daikini
Posts: 12
Joined: Mon Jul 23, 2012 2:06 am

Pi + Bluetooth + Node.js

Fri May 20, 2016 9:49 pm

Hi All,

After searching for a few days all over the web for info on interfacing pi/bluetooth with a website, I found this article:

https://arc.applause.com/2016/02/12/blu ... e-node-js/

I'm a HTML/CSS/PHP guy, and I don't know the first thing about Node.js. My goal is to be able to log connections (connect time, disconnect time, elapsed time) to the Pi (bluetooth USB) and display those on my home intranet. I've played around with "In/Out Board", which was written in python, but haven't had success in accessing the outputs to the Pi's web server (Apache).

Any thoughts?

With this new architecture from Bluetooth, I know it must be possible... assuming the devices are running it.

By the way, this new architecture was implemented in order to leverage Bluetooth further into the IoT (internet of things) space more forcefully. It has a LOT of potential.
Last edited by daikini on Fri May 20, 2016 10:24 pm, edited 1 time in total.

daikini
Posts: 12
Joined: Mon Jul 23, 2012 2:06 am

Re: Pi + Bluetooth + Node.js

Fri May 20, 2016 9:58 pm

Here's the actual article from Bluetooth (directly):

https://www.bluetooth.com/news/pressrel ... to-the-iot

And another article with more info: http://www.electronicsweekly.com/blogs/ ... n-2016-02/

By the way, they (Bluetooth) are using a RPi2b in their instructions on how to set this up in a home. Great reading!

daikini
Posts: 12
Joined: Mon Jul 23, 2012 2:06 am

Re: Pi + Bluetooth + Node.js

Sat May 21, 2016 3:38 pm

Bump! :mrgreen:

User avatar
Douglas6
Posts: 4874
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Pi + Bluetooth + Node.js

Sat May 21, 2016 4:37 pm

Not sure what you're asking. I haven't any experience with that framework, it looks interesting, please post your experiences. By the way, BLE uses very short connections, your idea of elapsed connection time won't make a lot of sense.

daikini
Posts: 12
Joined: Mon Jul 23, 2012 2:06 am

Re: Pi + Bluetooth + Node.js

Sat May 21, 2016 5:48 pm

Thanks for the post. I'm sure elapsed time could be a simple math function if it can't begin a timer, which is probably not just inefficient but also unnecessary.

Prior to getting this info from BT SIG, I successfully had In/Out Board working, but it's CLI only and in Python, which I haven't used before. Interfacing that with PHP and Pi's web server proved daunting. Enough so that I went searching for other solutions. That's when I found this from SIG. It looks promising for many, many smart home projects, including the one of like to work on.

daikini
Posts: 12
Joined: Mon Jul 23, 2012 2:06 am

Re: Pi + Bluetooth + Node.js

Sat May 21, 2016 11:57 pm

So, I've followed the instructions as outlined in the Quick Start Guide from SIG and after installing Node, I type

Code: Select all

node -v
I get

Code: Select all

Illegal Instruction
I'm stuck here for now... I posted on Github where there's an open issue for this: https://github.com/nodejs/node/issues/5495

Heater
Posts: 16092
Joined: Tue Jul 17, 2012 3:02 pm

Re: Pi + Bluetooth + Node.js

Sun May 22, 2016 8:49 am

Can you type the following command:

$ file $(which node)

You should see something like:

/usr/local/bin/node: ELF 32-bit LSB executable, ARM, EABI5 version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.26, BuildID[sha1]=4efddba0cb1893aa12d6e06dca07b64a48f7509c, not stripped

Note the bit about "ARM".

Edit: Forget all that the problem is answered on the github issue page linked above.
Memory in C++ is a leaky abstraction .

daikini
Posts: 12
Joined: Mon Jul 23, 2012 2:06 am

Re: Pi + Bluetooth + Node.js

Wed Jun 01, 2016 7:45 am

Thanks for your help! I was able to get Node installed on the Pi. Now, for next steps...

I get this after starting node:

pi@raspberrypi /gateway/gateway/navible $ node .
Server running at: http://raspberrypi:8000
Debug: internal, implementation, error
Error: connect ECONNREFUSED 127.0.0.1:8001
at Object.exports._errnoException (util.js:953:11)
at exports._exceptionWithHostPort (util.js:976:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1080:14)

daikini
Posts: 12
Joined: Mon Jul 23, 2012 2:06 am

Re: Pi + Bluetooth + Node.js

Thu Jun 02, 2016 11:43 pm

After looking into this a bit more, it seems that I should confirm whether the server is running on that port. I'll have a look at that and report back on progress.

briami
Posts: 4
Joined: Fri Jun 24, 2016 9:51 pm

Re: Pi + Bluetooth + Node.js

Fri Jun 24, 2016 9:53 pm

@daikini ...were you ever able to figure out this issue from your original post? I'm having the same problem as you and cannot figure out:
Error: connect ECONNREFUSED 127.0.0.1:8001
at Object.exports._errnoException (util.js:953:11)
at exports._exceptionWithHostPort (util.js:976:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1080:14)

daikini
Posts: 12
Joined: Mon Jul 23, 2012 2:06 am

Re: Pi + Bluetooth + Node.js

Sat Jun 25, 2016 10:19 pm

Hi @briami,

I have been looking at this again today and still no resolution. It starts off nicely with: Server running at: http://raspberrypi:8000

but, then it turns nasty with:

Debug: internal, implementation, error
Error: connect ECONNREFUSED 127.0.0.1:8001
at Object.exports._errnoException (util.js:953:11)
at exports._exceptionWithHostPort (util.js:976:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1080:14)

I'll let you know what I figure out. If you get there before me, please post back! :)

briami
Posts: 4
Joined: Fri Jun 24, 2016 9:51 pm

Re: Pi + Bluetooth + Node.js

Wed Jun 29, 2016 5:50 pm

@daikani...i think i figured it out...this worked for me at least...you need to open up 2 Terminal windows...in the first one, run your js file in the /gateway folder...this get's the BLE scanner up and running...then in the 2nd terminal window, run the js file in /navible...and then they should "talk" to eachother and you should not be getting that error anymore. let me know if that works for you! goodluck.

daikini
Posts: 12
Joined: Mon Jul 23, 2012 2:06 am

Re: Pi + Bluetooth + Node.js

Wed Jun 29, 2016 8:40 pm

Wow, how did you figure that out?

I'll give it a shot tonight.

Thanks!

briami
Posts: 4
Joined: Fri Jun 24, 2016 9:51 pm

Re: Pi + Bluetooth + Node.js

Thu Jun 30, 2016 5:50 pm

@daikini...figured it out through trial and error! hope it worked for you. if not, i'd be curious the new error you are getting.

daikini
Posts: 12
Joined: Mon Jul 23, 2012 2:06 am

Re: Pi + Bluetooth + Node.js

Fri Jul 01, 2016 5:15 am

Bummer...

I get the server running in the navible directory, but get errors in the gateway directory.

Code: Select all

/gateway $ node .
module.js:568
  return process.dlopen(module, path._makeLong(filename));
                 ^

Error: Module version mismatch. Expected 48, got 14.
    at Error (native)
    at Object.Module._extensions..node (module.js:568:18)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/gateway/gateway/gateway/node_modules/bluetooth-hci-socket/lib/native.js:3:15)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)

Return to “Other programming languages”