Beispiel #1
0
    def connect(self):
        # turn on bluetooth
        bluetoothctl("power", "on")
        bluetoothctl("discoverable", "yes")
        self.logger.debug("Bluetooth on")

        # display near by device
        '''
        nearby_devices = bluetooth.discover_devices(lookup_names=True)
        self.logger.info("Found {} devices.".format(len(nearby_devices)))

        for addr, name in nearby_devices:
            if "-hidemac" in sys.argv:
                self.logger.info("  {} - {}".format("**:**:**:**:**:**", name))
                self.logger.debug([addr, name])
            else:
                self.logger.info("  {} - {}".format(addr, name))
        '''

        port = 1
        # establish connection
        self.server_sock.bind(("", port))
        self.server_sock.listen(1)
        self.logger.debug("Sock listening to port %i", port)
        self.logger.info("Waiting for in coming connection...")
        self.client_sock, self.address = self.server_sock.accept()
        if "-hidemac" in sys.argv:
            self.logger.info("Accepted connection from %s",
                             ["**:**:**:**:**:**", self.address[1]])
            self.logger.debug(self.address)
        else:
            self.logger.info("Accepted connection from %s", self.address)
if __name__ == '__main__':

	logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filename='vg_servo.log', level=logging.INFO)

	pwm = Adafruit_PCA9685.PCA9685()
	pwm.set_pwm_freq(50)

	servo.initPosAll()
	print('All servos are in initial position')
	logging.info('All servos are in initial position')
	time.sleep(1)

	try:
		mac = "9C:AA:1B:A7:63:E5"
		bluetoothctl("connect", mac)
	except Exception as e:
		pass

	gamepad = InputDevice('/dev/input/event0')
	dev = gamepad
	vibrate_controller()

	vg_motor_control.setup()
	allowforward = True
	
	ultrsnc = threading.Thread(target=checkdist, args=())
	logging.info('checkdist thread started')
	ultrsnc.start()

	controllercheck()
def connectDevice(prevMAC, newMAC, stepDelay):
    if prevMAC is not None:
        bluetoothctl('disconnect', prevMAC)
        time.sleep(2*stepDelay)
    bluetoothctl('connect', newMAC)
    time.sleep(2*stepDelay)
def checkConnectionState(devMac):
    connectionInfo  = bluetoothctl('info',devMac)
    connectionState = False if str(connectionInfo.stdout).split('Connected:')[1].split('\\n')[0].strip() == 'no' else True
    return connectionState
data = {}
data['entity_id'] = 'media_player.living_room_main'
data['source'] = 'bluetooth'
payload = json.dumps(data)
post(url, data=payload, headers=headers)
# time.sleep(1)

# connect tinkerboard with soundbar by restarting bunch of bluetooth stuff
child = pexpect.spawn('systemctl restart bluetooth')
child.expect('Password:')  #sudo password
child.sendline(parameters.sudo_passw)
time.sleep(3)

cp = subprocess.run(["pulseaudio -k"], shell=True, stdout=subprocess.PIPE)
cp = subprocess.run(["pulseaudio --start"], shell=True, stdout=subprocess.PIPE)
bluetoothctl("agent", "off")
bluetoothctl("power", "off")
bluetoothctl("power", "on")
bluetoothctl("agent", "on")
# bluetoothctl("select","00:1A:7D:DA:71:14")
bluetoothctl(
    "select", "F0:03:8C:05:F0:DA"
)  #Get this address of your bluetooth adapter by running the commands on your host system 1) bluetoothctl 2) list
bluetoothctl(
    "disconnect", "94:E3:6D:61:59:72"
)  #Get the address of your bluetooth speaker by running the commands on your host system 1) bluetoothctl 2) "scan on" 3) devices
bluetoothctl("connect", "94:E3:6D:61:59:72")

## VLC stuff

# play a file added in /home/homeassistant/.homeassistant/www/ folder
Beispiel #6
0
def connect(mac_address):
    bluetoothctl("connect", mac_address)