Git Product home page Git Product logo

nimbluez's Introduction

NimBluez

Modules for access to system Bluetooth resources for the Nim programming language.

Use nimbluez/bluetooth module for cross-platform discovery and managing Bluetooth devices and services.

For cross-platform low-level sockets interface implementation use nimbluez/bluetoothnativesockets.

You can find wrappers for BlueZ in nimbluez/bluez folder. For Microsoft Bluetooth protocol stack wrappers look at nimbluez/msbt.

Installation

To install using Nimble run the following:

$ nimble install nimbluez

Linux

You may need to install libbluetooth-dev, if you see error could not load: libbluetooth.so on application start.

# for Ubuntu
 sudo apt install libbluetooth-dev

Examples

# Simple discovery example.  
import nimbluez/bluetooth

echo "All visible remote devices:"
for remoteDevice in getRemoteDevices():
  echo remoteDevice.address, " - ", remoteDevice.name
# Simple server example.
# Attention! This code does not contain error handling.
import nimbluez/bluetoothnativesockets

var serverSocket = newBluetoothNativeSocket(SOCK_STREAM, BTPROTO_RFCOMM)
var name = getRfcommAddr(RfcommPort(1))
discard bindAddr(serverSocket,
                 cast[ptr SockAddr](addr(name)),
                 sizeof(name).SockLen)
discard serverSocket.listen()
var
  clientName = getRfcommAddr()
  clientNameLen = sizeof(clientName).SockLen
var clientSocket = accept(serverSocket,
                          cast[ptr SockAddr](addr(clientName)),
                          addr(clientNameLen))
var message: string = ""
message.setLen(1000)
let recvLen = clientSocket.recv(cstring(message), cint(message.len), cint(0))
message.setLen(recvLen)
echo message
clientSocket.close()
serverSocket.close()
# Simple client example.
# Attention! This code does not contain error handling.
import nimbluez/bluetoothnativesockets

var socket = newBluetoothNativeSocket(SOCK_STREAM, BTPROTO_RFCOMM)
var name = getRfcommAddr(RfcommPort(1), "00:02:72:0F:5C:87")
discard connect(socket, cast[ptr SockAddr](addr(name)), sizeof(name).SockLen)
var message = "Hi there!"
discard send(socket, cstring(message), cint(message.len), cint(0))
socket.close()

For more examples look at examples folder.

nimbluez's People

Contributors

electric-blue avatar ruan-pysoft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nimbluez's Issues

Error: undeclared identifier: 'expr'

When I try to build Example code with nimbluez library, I find this error:

~/.nimble/pkgs/nimbluez-0.1.1/nimbluez/bluez/ioctl.nim(54, 28) Error: undeclared identifier: 'expr'

Mac OSX support?

The library says cross-platform, but mentions support for Bluez and Ms Bluetooth. Are there any plans to support Mac?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.