示例#1
0
    def do_connect(self, state):
        global device
        global AllDevices
        global isConnected

        if (device != -1 and isConnected is False):
            try:
                device = BLEDevice(SelectedDevice)
                print "DEBUG ..device initialized"
                AllDevices = ['Connected']
                isConnected = True
                self._smState = SMState.connected
            except:
                print "DEBUG: in exception block for connect"
                AllDevices = ['Not able to connect']
        elif (isConnected is True):
            self.promptWithCustomString(
                state, 'Already Connected to {0}'.format(device['name']))
        else:
            AllDevices = ['No Devices to Connect']
示例#2
0
 def connect(self):
     global bulb
     bulb = BLEDevice(self.bl.get())
示例#3
0
#!/usr/bin/env python
import sys, time
from bledevice import scanble, BLEDevice

# if len(sys.argv) != 2:
 #   print "Usage: python blecomm.py <ble address>"
 #   print "Scan devices are as follows:"
#    print scanble(timeout=3)
#    sys.exit(1)

def send_pkt(pkt):
    if pkt
        print pkt[1]
        print pkt[2]
        print(type(pkt))
        hm10.writecmd(vh, "y".encode('hex'))

    


hm10 = BLEDevice("A8:10:87:1B:62:B0")
while True:
    vh=hm10.getvaluehandle("ffe1")

    sniff(iface = 'veth4', prn = lambda x: send_pkt(x))
     

示例#4
0
文件: two_wheel.py 项目: GY-Cha/wb
import sys, time
import threading
import keyboard
import numpy as np

from bledevice import scanble, BLEDevice

Device1 = BLEDevice("DD:43:89:16:43:81")
Device2 = BLEDevice("F4:82:B3:50:ED:55")
Device1.writereq(0xd, '54524F5F0D0A')  #RUN_flag
Device1.notify()
Device2.writereq(0xd, '54524F5F0D0A')  #RUN_flag
Device2.notify()
Device1.writereq(0xd, '544443790D0A')  #FRONT
Device1.notify()
Device2.writereq(0xd, '544443790D0A')  #FRONT
Device2.notify()
desired = 0
flag = 1
now_velocity1 = 0
now_velocity2 = 0

STOP = 0
IDLE = 1
FWD = 2
LEFT = 3
RIGHT = 4
ROTATE = 6

direction1 = 1
direction2 = 1
示例#5
0
import sys, time
import threading
import keyboard
import numpy as np

from bledevice import scanble, BLEDevice
Device1 = BLEDevice("DD:43:89:16:43:81")
Device2 = BLEDevice("F4:82:B3:50:ED:55")
time.sleep(0.5)
sum_time = 0
mean_time = 0
count = 0

STOP = 0
MOVE_FWD = 1
MOVE_BWD = 2
MOVE_FWR_R = 10
MOVE_FWR_L = 11

MOVE_R = 3
MOVE_L = 4
IDLE = 9
F = 5
S = 6
Mon = 7
Moff = 8
keycode = ""


def print_key():
    print("hotkey press")
示例#6
0
文件: yeelight.py 项目: deepsrm/ble
 def connect(self):
     global bulb
     bulb = BLEDevice(self.bl.get())
     time.sleep(0.1)
     bulb.writereq(bulb.getvaluehandle(WRITE_CHAR_UUID), COMMAND_STX+AUTH_CMD+AUTH_ON+COMMAND_ETX*15)
示例#7
0
文件: test_22.py 项目: GY-Cha/wb
import sys, time
import threading
import keyboard
import numpy as np

from bledevice import scanble, BLEDevice
Device1 = BLEDevice("DD:43:89:16:43:81")
Device2 = BLEDevice("F4:82:B3:50:ED:55")

Device1.writereq(0xd, '545246680D0A')  #STOP_flag
Device2.writereq(0xd, '545246680D0A')  #STOP_flag
Device1.writereq(0xd, '54524F5F0D0A')  #RUN_flag
Device2.writereq(0xd, '54524F5F0D0A')  #RUN_flag
Device1.writereq(0xd, '544443790D0A')  #CW forward
Device2.writereq(0xd, '544443790D0A')  #CW forward
Device1.writereq(0xd, '54571E8B0D0A')  #5km/h
Device2.writereq(0xd, '54571E8B0D0A')  #5km/h
t = 0
toggle = 1
while 1:

    if t > 1:

        if toggle == 1:

            Device1.writereq(0xd, '544457650D0A')  #CCW backward
            Device2.writereq(0xd, '544457650D0A')  #CCW backward
            time.sleep(2)

        else:
            Device1.writereq(0xd, '544443790D0A')  #CCW forward
示例#8
0
文件: yeelight.py 项目: last2003/ble
 def connect(self):
     global bulb
     bulb = BLEDevice(self.bl.get())
     time.sleep(0.1)
     bulb.writereq(bulb.getvaluehandle(WRITE_CHAR_UUID),
                   COMMAND_STX + AUTH_CMD + AUTH_ON + COMMAND_ETX * 15)
示例#9
0
文件: blecomm.py 项目: last2003/ble
#!/usr/bin/env python
import sys, time
from bledevice import scanble, BLEDevice

if len(sys.argv) != 2:
    print "Usage: python blecomm.py <ble address>"
    print "Scan devices are as follows:"
    print scanble(timeout=3)
    sys.exit(1)

hm10 = BLEDevice(sys.argv[1])
while True:
    vh = hm10.getvaluehandle("ffe1")
    hm10.writecmd(vh, "test\r\n".encode('hex'))
    data = hm10.notify()
    if data is not None:
        print "Received: ", data
    time.sleep(1)
示例#10
0
#!/usr/bin/env python
import sys, time
from bledevice import scanble, BLEDevice

if len(sys.argv) != 2:
    print "Usage: python blecomm.py <ble address>"
    print "Scan devices are as follows:"
    print scanble(timeout=3)
    sys.exit(1)

hm10 = BLEDevice(sys.argv[1])
while True:
    vh = hm10.getvaluehandle("ffe1")
    hm10.writecmd(vh, "test\r\n".encode("hex"))
    data = hm10.notify()
    if data is not None:
        print "Received: ", data
    time.sleep(1)
示例#11
0
def wheel_com_init():
    global Device1, Device2
    Device1 = BLEDevice("DD:43:89:16:43:81")  #right wheel
    Device2 = BLEDevice("F4:82:B3:50:ED:55")  #left  wheel
    Device1.writereq(0xd, '54524F5F0D0A')  #RUN_flag
    Device1.notify()
    Device2.writereq(0xd, '54524F5F0D0A')  #RUN_flag
    Device2.notify()
    Device1.writereq(0xd, '544443790D0A')  #FRONT
    Device1.notify()
    Device2.writereq(0xd, '544443790D0A')  #FRONT
    Device2.notify()

    desired_speed1(10)
    desired_speed2(10)

    time.sleep(2)
    desired_speed1(0)
    desired_speed2(0)
    global state
    state = STOP
示例#12
0
文件: test2.py 项目: GY-Cha/wb
import sys, time
from bledevice import scanble, BLEDevice
Device1 = BLEDevice("DD:43:89:16:43:81")
Device2 = BLEDevice("F4:82:B3:50:ED:55")


def data_ON(Device1, Device2):
    Device1.writereq(0xd, '545457550D0A')  #RUN_flag
    Device2.writereq(0xd, '545457550D0A')  #RUN_flag


def data_OFF(Device1, Device2):
    Device1.writereq(0xd, '545446660D0A')  #RUN_flag
    Device2.writereq(0xd, '545446660D0A')  #RUN_flag


def motor_OFF(Device1, Device2):
    Device1.writereq(0xd, '545246680D0A')  #RUN_flag
    Device2.writereq(0xd, '545246680D0A')  #RUN_flag


def motor_ON(Device1, Device2):
    Device1.writereq(0xd, '54524F5F0D0A')  #RUN_flag
    Device2.writereq(0xd, '54524F5F0D0A')  #RUN_flag


def M_FWD(Device1, Device2, direciton):
    #motor_ON()
    print("M_FWD")

    if direction == -1:
示例#13
0
#!/usr/bin/python3
import sys, time
from bledevice import scanble, BLEDevice

if len(sys.argv) != 2:
    print("Usage: python blecomm.py <ble address>")
    print("Scan devices are as follows:")
    print(scanble(timeout=3))
    sys.exit(1)

hm10 = BLEDevice(sys.argv[1])
while True:
    #vh=hm10.getvaluehandle("ffe1")
    #hm10.writecmd(vh, "hello\r\n".encode('hex'))
    vh = hm10.getvaluehandle(b"0000ffe1")
    hm10.writecmd(vh, bytes("test\r\n".encode('utf-8')).hex())
    data = hm10.notify()
    if data is not None:
        print("Received: ", data)
    time.sleep(1)
示例#14
0
import sys, time
import threading
import keyboard
import numpy as np

from bledevice import scanble, BLEDevice
Device2 = BLEDevice("F4:82:B3:50:ED:55")
Device2.writereq(0xd, '54524F5F0D0A')  #RUN_flag

desired = 0
flag = 1
now_velocity = 0


def M_FWD():
    global now_velocity
    if now_velocity < 16:
        now_velocity = 16
    now_velocity = now_velocity + 1
    return now_velocity


def M_BWD():
    global now_velocity
    if now_velocity < 16:
        now_velocity = 16
    now_velocity = now_velocity - 1
    return now_velocity


def M_STOP():