Developing Custom Applications with our Plugable PS-BTAPS1 Bluetooth Switch

BTAPS1 Sample App Running on Fedora 21
Our new Plugable PS-BTAPS1 is perfect for many different home automation projects, however, we understand that our Android and iOS apps may not fit the bill for every project, and we wanted to provide a way for hobbyists and programmers to develop custom applications that are able to interact with the device. We have for you today some instructions and sample code on how to trigger the device’s on and off functionality from a custom application. More information on how to perform more advanced functions, such as using the built-in timer, will be forthcoming at a later date.

The PS-BTAPS1 uses Bluetooth’s very simple Serial Port Profile for communication. All that is required to talk to the device is an open RFCOMM connection and then the right payload to be sent to trigger the device’s desired functionality.

There are two different payloads necessary for turning the device’s switch on and off:
0xCCAA03010101 will tell the BT-APS1 to flick its internal switch to ON.
0xCCAA03010100 will tell it to do the opposite, and switch to OFF.

To make this somewhat simpler to understand, we are providing a sample application written in Python 2.7. The code for the application can be found below:

All that is required to run the application is Python 2.7 and the PyBluez module, which can be downloaded here.

This sample application has a simple command line interface for making your PS-BTAPS1 switch on or off.

python btaps.py 00:00:00:00:00:00 on
python btaps.py 00:00:00:00:00:00 off

Replace 00:00:00:00:00:00 with your PS-BTAPS1’s Bluetooth Address. You can easily find your device’s Bluetooth Address like so:

Windows:
Go to Control Panel -> Devices and Printers -> Right Click on your paired Plugable PS-BTAPS1(It should be listed as “Plugable”) -> Properties -> Bluetooth Tab -> Unique Identifier

Linux:
Open a terminal and run:

hcitool scan

This code has been tested under Fedora 21 and Windows 8.1. It should run on older versions of Windows and Linux without issues. Unfortunately, this sample code will not work under OS X due to lack of support in PyBluez. Mac OS X applications should still be possible using OS X native Bluetooth APIs.

More information on programming the Plugable PS-BTAPS1 should follow early in the new year. We can’t wait to see what cool and interesting projects are developed by the community!

3 comments on “Developing Custom Applications with our Plugable PS-BTAPS1 Bluetooth Switch”

  1. Patrick Reply

    I’m trying to do something similar but using C# and the 32Feet.Net library.
    The following is the start of my test code:
    InTheHand.Net.Sockets.BluetoothClient bc = new InTheHand.Net.Sockets.BluetoothClient();
    InTheHand.Net.Sockets.BluetoothDeviceInfo[] devices = bc.DiscoverDevices(8);
    InTheHand.Net.Sockets.BluetoothDeviceInfo device = devices[0]; // Plugable device is the only one returned.
    bc.Connect(device.DeviceAddress, InTheHand.Net.Bluetooth.BluetoothService.GenericAudio);
    The last line fails (times out) with the exception:
    “A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 8CDE5221333D:0000120300001000800000805f9b34fb”
    I wasn’t sure what the second parameter for the Connect call should be and there are a lot of choices. I have tried at least 8 of them and they all give the same failure. Any clue what this “Service Class Id” should be (it’s a Guid apparently).

    • Ivan Fossa Ferrari Ivan Fossa Ferrari Reply

      Patrick,

      Forgive me, for I am not at all familiar with the 32Feet.Net library, but it looks like you are trying to create a GenericAudio connection with the BTAPS? You should be making a serial connection with the device.

      Sincerely,
      Ivan
      Plugable Technologies

  2. Patrick Reply

    I tried bc.Connect(device.DeviceAddress, InTheHand.Net.Bluetooth.BluetoothService.SerialPort); as well and that also failed.

Leave a Reply