cc2uart

    0.0.3 • Public • Published

    cc2uart -- node-cc2540

    node.js support for the TI CC2540 UART service. The CC2540 is programmable so there is no guarantee this works with all boards with the CC2540 chip.

    This module is built on noble so it should work where ever noble works.

    See also nrfuart if using the nRF8001 or nRF51822 chip.

    Tested configurations

    A USB to Bluetooth 4.0 gadget similar to this is required to add BLE support to systems without Bluetooth 4.0/BLE hardware.

    Laptop running Ubuntu Linux 14.04

    Laptop running Ubuntu 14.04 <-> BLE <-> CC2540 <-> Arduino Uno
    

    Ubuntu 14.04 includes bluez 4.101 which is sufficient for this module. Install the following packages before installing cc2uart.

    sudo apt-get install bluetooth bluez-utils libbluetooth-dev

    Raspberry Pi running Raspbian Linux

    The tested device is a Raspberry Pi Model B running a fresh installation of Raspian release 2015-02-16. Be sure to do the usual post-installation steps such as "sudo apt-get update", "sudo apt-get upgrade", and "sudo raspi-config".

    The next step is to install node.js. The version of node.js in the Raspian repo is too old so install a recent version.

    wget http://node-arm.herokuapp.com/node_0.10.36_armhf.deb
    sudo dpkg -i node_0.10.36_armhf.deb

    Install bluez 4.99 from the Raspian repo. Testing has shown this version works with BLE and noble. This is much easier and faster than install bluez 5.x from source code.

    sudo apt-get install bluez bluez-tools libbluetooth-dev

    If bluez 4.99 does not work, remove it then install bluez 5.x as described below. Remember, do the next block of commands only if BLE is not working.

    sudo apt-get remove bluez bluez-tools libbluetooth-dev
    # Reference: http://www.elinux.org/RPi_Bluetooth_LE 
    sudo apt-get install libdbus-1-dev libdbus-glib-1-dev libglib2.0-dev \
    libical-dev libreadline-dev libudev-dev libusb-dev make
    mkdir bluez
    cd bluez
    wget https://www.kernel.org/pub/linux/bluetooth/bluez-5.28.tar.xz
    tar xf bluez-5.28.tar.xz
    cd bluez-5.28
    ./configure --disable-systemd --enable-library
    # The next step takes a long time. 
    make
    sudo make install
    sudo hciconfig hci0 up

    Install this module

    npm install cc2uart 

    Use this module

    This program sends a test pattern and displays anything that comes back.

    var cc2uart = require('cc2uart');
     
    cc2uart.discoverAll(function(ble_uart) {
        // enable disconnect notifications
        ble_uart.on('disconnect', function() {
            console.log('disconnected!');
        });
     
        // connect and setup
        ble_uart.connectAndSetup(function() {
            var writeCount = 0;
     
            console.log('connected!');
     
            ble_uart.readSystemId(function(sysID) {
                console.log('System ID:', sysID);
            });
     
            ble_uart.on('data', function(data) {
                console.log('received:', data.toString());
            });
     
            setInterval(function() {
                var TESTPATT = 'Hello world! ' + writeCount.toString();
                ble_uart.write(TESTPATT, function() {
                    console.log('data sent:', TESTPATT);
                    writeCount++;
                });
            }, 3000);
        });
    });

    Install

    npm i cc2uart

    DownloadsWeekly Downloads

    2

    Version

    0.0.3

    License

    MIT

    Last publish

    Collaborators

    • bbx10node