Jump to content
Sign in to follow this  
lynkfs

bluetooth

Recommended Posts

How to connect webapp to a bluetooth enabled printer.

Basically there are 2 avenues to do that : a) going native and b) the web bluetooth api

Going native

This involves using PhoneGap or Cordova, plus installing a plugin to make the bluetooth capacities of the mobile target platform available in the js world.

I found this plugin on github, a cordova plugin, so used cordova rather than phonegap.

The install sequence for a clean install of everything looks something like

see https://cordova.apache.org/docs/en/latest/guide/cli/
  install node
  install npm
  install cordova : npm install -g cordova

install pre-requisites : see https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#requirements-and-support
  java development kit (jdk)
  gradle
  android studio / android sdk 

set environment and path variables
  JAVA_HOME
  ANDROID_HOME
  PATH

create app structure
  create app : cordova create bluetoothprinter com.smartmobilestudio.bluetoothprinter BluetoothPrinter

install plugin
  cordova plugin add https://github.com/srehanuddin/Cordova-Plugin-Bluetooth-Printer.git

create remainder of app
  add platform : cordova platform add android
  create SMS project
  copy SMS project output into the cordova app structure (www directory)
  build app : cordova build android

install apk file on android

Amazingly this all works out.

Some gotcha's :

- environment and path variables don't allow spaces, so for instance .../Program Files/... has to be shortened to .../Progra~1/...

- cordova now requires plugins to have their own package.json file. The selected plugin doesn't have that, so I had to download the git repository, create a package.json file and install the plugin from local (cordova plugin add cordova-plugin-bluetooth-printer --save --searchpath ../plugin)

- the SMS project needs these entries in its template index file

  <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
  <script type="text/javascript" charset="utf-8" src="BluetoothPrinter.js"></script>

and compile may end up in errors. However the cordova build process takes care of that and produces a viable apk file.

It is a bit of a process to go through, but works out well in the end.

 

Share this post


Link to post
Share on other sites

For this app I used the HOP-H58 bluetooth printer. It comes with bluetooth and usb connectivity, and even a socket for a cash drawer.

At an unbeatable price of $26 USD delivered (!), this gives me a mobile POS (invoice print) solution, where only the printer and a mobile phone is needed. 

Amazing.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×