Coder Social home page Coder Social logo

es-hw3's Introduction

HW3 BLE Central Programming

Modified from ble_scan_connect.py

Members

  • 毛楷維 b07901134
  • 涂銘洋 b07202031
  • 古振宏 b08901103

Codes added

class ScanDelegate(DefaultDelegate):
    def __init__(self):
        DefaultDelegate.__init__(self)
    def handleDiscovery(self, dev, isNewDev, isNewData):
        if isNewDev:
            print("Discovered device", dev.addr)
        elif isNewData:
            print("Received new data from", dev.addr)
    # Processing data of notifications from the server
    def handleNotification(self, cHandle, data): <--
        print("Received data: " + str(data))     <--
try :
    testService = dev.getServiceByUUID(UUID(0xfff0))
    for ch in testService.getCharacteristics():
        print(str(ch))

    ch = dev.getCharacteristics(uuid=UUID(0xfff1))[0]
    if (ch.supportsRead()):
        print(ch.read())

    cccd = ch.getDescriptors(forUUID=0x2902)[0] <--
    cccd.write(b"\x01\x00")                     <--
    print("Enabled notifications.")             <--
    print(cccd.read())                          <--

    while True:                                 <--
        if dev.waitForNotifications(1000):      <--
            print("Notify!")                    <--
        print("Waiting...")                     <--

sudo minicom -s

Configurations -> Serial port setup -> Serial Device : /dev/tty.usbserial-xxx (checked by ls /dev on terminal)

sudo minicom

Log in Raspberry Pi

Open iPhone app 'BLE scanner'

Configurations :

  • properties : READ WRITE NOTIFY
  • READ value
  • service UUID : FFF0
  • characteristic UUID : FFF1

Start advertising

Run sudo python ble_enableNotify.py on target

es-hw3's People

Contributors

mingyang-tu avatar hunglinnnnn avatar

Watchers

 avatar

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.