Esempio n. 1
0
    def connect(self):
        #UUID where temp is stored
        #	tempc_uuid = UUID(0x0021)
        tempc_uuid = UUID(0x2221)
        self.isBTNOK = 1

        #connection...
        while not self._stopevent.isSet() and self.isBTNOK:
            try:
                #			print("Connection...")
                #my bluefruit address
                self.p = Peripheral("EE:1B:17:8F:A4:5D", "random")
                #EE:1B:17:8F:A4:5D
                #    			print("OK!\ngetCharacteristics")
                #for ch in self.p.getCharacteristics():
                #	print str(ch)
                self.cht = self.p.getCharacteristics(uuid=tempc_uuid)[0]
                #			print("Done!")
                self.isBTNOK = 0

            except BTLEException as e:
                #			print "CONNECT - BTLEException : {0}".format(e)
                self.disconnect()

            except:
                #			print 'CONNECT - Other error! ',sys.exc_info()[0]
                self.disconnect()

            #wait 3 second before try again
            if (not self._stopevent.isSet()):
                self._stopevent.wait(3)
Esempio n. 2
0
 def runDoCycle(self):
     ##        self.player.set_mrl(MRL)
     ##        self.player.play()
     print("cerco di connettermi")
     per = Peripheral("d7:84:e7:e2:87:68")
     #per.setDelegate( MyDelegate() )
     print("connessione avvenuta")
     GObject.timeout_add(3000, self.doCycle, per)
Esempio n. 3
0
 def connect(self):
     try:
         self.peripheral = Peripheral(self.macAddress, addrType='random')
     except BTLEException:
         return False
     try:
         self.enableNotifications()
         self.peripheral.setDelegate(NuimoDelegate())
     except BTLEException:
         self.peripheral.disconnect()
         self.peripheral = None
         return False
     return True
Esempio n. 4
0
def ble_init():
    print('Scanning...')
    scanner = Scanner().withDelegate(ScanDelegate())
    devices = scanner.scan(10.0)
    for dev in devices:
        print("Device %s (%s), RSSI=%d dB" %
              (dev.addr, dev.addrType, dev.rssi))
        for (adtype, desc, value) in dev.getScanData():
            print("  %s = %s" % (desc, value))
    print('Querying...')
    try:
        p = Peripheral(BLE1_MAC_ADDR, "random", 0)
    except:
        print(
            "Check device on or does it throw an BTLEException exception from BLE constructor? "
        )

    try:
        c = p.getCharacteristics(uuid="BD6664C8941DCBA806E1AA75F7D44BAC")[0]
        #c = p.getCharacteristics(uuid="1814")[0]
    except:
        print("getCharacteristics Error")
Esempio n. 5
0
def startCycle():
    print("cerco di connettermi")
    per = Peripheral("d7:84:e7:e2:87:68")
    per.setDelegate(MyDelegate())
    print("connessione avvenuta")
    GObject.timeout_add(7000, doCycle, per)
Esempio n. 6
0
import binascii
import struct
import time
from bluepy.bluepy.btle import UUID, Peripheral

# Message constants
MSG_LOCK = 0x10
MSG_UNLOCK = 0x11
MSG_STATE_REQ = 0x12

# Define read and write UUIDs
read_uuid = UUID(0x2221)
write_uuid = UUID(0x2222)

# Create a connection to the RFduino
p = Peripheral("F9:D8:C2:B9:77:E9", "random")

try:

    # Create handles for read and write characteristics
    w_ch = p.getCharacteristics(uuid=write_uuid)[0]
    r_ch = p.getCharacteristics(uuid=read_uuid)[0]

    # If we can, continuously send lock and unlock requests
    if (r_ch.supportsRead()):
        while 1:

            # Tell the Lockitron to lock
            msg = struct.pack('i', MSG_LOCK)
            print "Writing: " + str(msg)
            w_ch.write(msg)
Esempio n. 7
0
from bluepy.bluepy.btle import UUID, Peripheral

p = Peripheral("28:84:fa:97:0f:f8")
svc = p.getServiceByUUID(uuid="2B1DA6DE-9C29-4D6C-A930-B990EA2F12BB")

ch = svc.getCharacteristics(uuid="7F855F82-9378-4508-A3D2-CD989104AF22")[0]
ch.write()

while 1:
    if p.waitForNotifications(1.0):
        continue

    print "waiting"
Esempio n. 8
0
import struct
import time
from bluepy.bluepy.btle import UUID, Peripheral

temp_uuid = UUID(0x2221)

p = Peripheral("xx:xx:xx:xx:xx:xx", "random")

try:
    ch = p.getCharacteristics(uuid=temp_uuid)[0]
    if (ch.supportsRead()):
        while 1:
            val = binascii.b2a_hex(ch.read())
            val = binascii.unhexlify(val)
            val = struct.unpack('f', val)[0]
            print str(val) + " deg C"
            time.sleep(1)

finally:
    p.disconnect()
import binascii
import struct
import time
from bluepy.bluepy.btle import UUID, Peripheral
 
temp_uuid = UUID(0x2221)
 
p = Peripheral("00:A0:50:18:1D:10", "random")
 
try:
    ch = p.getCharacteristics(uuid=temp_uuid)[0]
    if (ch.supportsRead()):
        while 1:
            val = binascii.b2a_hex(ch.read())
            val = binascii.unhexlify(val)
            val = struct.unpack('f', val)[0]
            print str(val) + " deg C"
            time.sleep(1)
 
finally:
    p.disconnect()