Sign In
New Member? Forgot Password?

Bluetooth Bytes Corona Plugin

This plugin allows you to scan for bluetooth devices, connect, send bytes and receive bytes.  Data send and received from the bluetooth device is converted from true bytes on the native platform to the lua numeric data type (a 32 bit integer) which the plugin treats as bytes.  The integers are always truncated to byte size (8 bits aka 0xff) and converted to bytes in the native code.

Demo

https://github.com/MeisterMichael/bluetoothbytes-demo

Platforms

This plugin only works for Android. (not simulator)

Functions

bt.init(listener)

-- handles all events

  • event.type==

    "discovery finished"

    -- returned when .search() is complete
  • event.type==

    "device found"

    -- device found on .search()
    • event.deviceName --(string) name of device found
    • event.deviceID --(string) mac address on android and UDID on iOS
    • event.deviceState --(string) state of device: "connected", "connecting", or "not connected"
  • event.type==

    "device paired"

    -- device paired with .connect()
    • event.deviceName --(string) name of device found
    • event.deviceID --(string) mac address on android and UDID on iOS
    • event.deviceState --(string) state of device: "connected", "connecting", or "not connected"
  • event.type==

    "device unpaired"

    • event.deviceName --(string) name of device found
    • event.deviceID --(string) mac address on android and UDID on iOS
    • event.deviceState --(string) state of device: "connected", "connecting", or "not connected"
  • event.type==

    "error"

    • event.error --(string) error message
  • event.type==

    "connected"

    -- connected to device
    • event.deviceName --(string) name of device found
    • event.deviceID --(string) mac address on android and UDID on iOS
    • event.deviceState --(string) state of device: "connected", "connecting", or "not connected"
  • event.type==

    "bytes"

    -- message received
    • event.bytes -- table array of integers
  • event.type==

    "connection error"

    • event.deviceName --(string) name of device found
    • event.deviceID --(string) mac address on android and UDID on iOS
    • event.deviceState --(string) state of device: "connected", "connecting", or "not connected"
    • event.error --(string) error message

bt.isEnabled()

-- returns boolean, if true bluetooth is enabled

bt.search()

-- search for bluetooth devices

bt.send(bytes, deviceID)

-- send message to devices (deviceID is only supported on iOS).  bytes is a table array of integers

bt.enable(enabled)

-- enable bluetooth (android only)

enabled(boolean) if true bluetooth will be enabled, if false bluetooth will be disabled

bt.connect(deviceID)

-- connect with with deviceID(string)

bt.disconnect(deviceID)

-- disconnect from device with deviceID(string)

bt.getDevices()

-- get configured devices, returns array with data in each table (only works on Android)

  • event.deviceName --(string) name of device found
  • event.deviceID --(string) mac address on android and UDID on iOS
  • event.deviceState --(string) returns "connected"

Build Settings

settings = { plugins={ ["plugin.bluetoothbytes"] ={publisherId = "com.spacekace",}, }, }