I can't find Bluetooth devices using Bleak and asyncio - python-3.x

I am building a project using gopro camera i found that there is free API from GoPro it self, i followed the tutorial how to use BLE. so to try if everything is working i used this simple program to find bluetooth device but nothing happing it found nothing.
i am using python3.10
i am using mac m1
my bluetooth is open
import bleak
from bleak import BleakScanner
async def main():
devices = await BleakScanner.discover()
for d in devices:
print(d,"yes i found it")
asyncio.run(main())```

The problem might be related to the fact that Bleakscanner.discover() finishes before the advertisement from the GoPro. As per the description that is given in the example you followed from the documentation, it only scans for 5 seconds before stopping. I suggest you use the next example and play with the sleep time to see if you have any success at all.

Could also be caused by a bug fixed in OS X 12.3 - see
https://bleak.readthedocs.io/en/latest/troubleshooting.html#no-devices-found-when-scanning-on-macos-12

Related

Facing issue with Camera in Xamarin iOS 13 [duplicate]

Android emulators can simulate Camera device (see screenshot)
For example I can test how my video recording module works:
What about iOS-Simulators? When I try to run my app which uses camera I get the next error
Thread 5: Fatal error: Unexpectedly found nil while unwrapping an Optional value
at line
let videoDeviceInput = try AVCaptureDeviceInput(device: defaultVideoDevice!)
so no simulated devices are available for iOS-Simulators?
According to Apple documentation, using camera with Simulator is not supported:
The following hardware is not supported in Simulator:
Ambient light sensor
Audio input, except for using Siri by choosing Hardware > Siri.
Barometer
Bluetooth
Camera
Motion support (accelerometer and gyroscope)
Proximity sensor
There is one known workaround which could be useful sometimes: https://github.com/YuigaWada/iCimulator
But it does not work with 3-rd party libs like WebRTC though...

How to discover a device quickly with BlueZero?

I have an Ubuntu PC that I want to connect to an advertising microcontroller (nrf52840) using python.
They connect just fine when the PC has already discovered the microcontroller using a command line tool like bluetoothctl. The issue is when the devices are interacting for the first time.
According to the Bluezero docs it seems like nearby_discovery() is just the function for the job. The issue is unless I set the timeout to be absurdly long, like ~45 seconds, the Central cannot be created because it hasn't been discovered.
The steps I'm taking now:
from bluezero import adapter, central
dongles = adapter.list_adapters()
dongle = adapter.Adapter(dongles[0])
dongle.nearby_discovery(timeout=45)
myCentral = central.Central(adapter_addr=dongle.address, device_addr="AA:BB:CC:DD:EE:FF")
Is there a more reliable way to discover/connect to new devices?
For what it's worth, bluetoothctl scan on seems to discover devices almost immediately.
The solution turned out to be unrelated to bluezero. I'm using JTAG to grab the MAC address and that function resets the CPU on the board, meaning that it took around 30 seconds to reboot and start advertising again. Thank you for the responses
There shouldn't be any significant time difference between Bluezero and bluetoothctl to discover a device as they are making the same API calls to bluetoothd.
Once a device is in the known list in BlueZ, then because BlueZ ignores "duplicates", it doesn't report a device very frequently in the scan results.
This is what leads to most scripts I've seen not using the nearby_discovery() because once your device is in the known list, you can connect to it without discovery.
In bluetoothctl you can type devices to get the list. In Bluezero there is not a tidy option to do this (Just not something I have thought of providing previously). If you wanted to do a test to see if the device you want to connect to is already in the list then below is my initial thought:
from bluezero import dbus_tools
def known_devices():
"""Get a list of devices Bluez already knows about"""
device_list = []
mng_objs = dbus_tools.get_managed_objects()
for path in mng_objs:
address = mng_objs[path].get('org.bluez.Device1', {}).get('Address')
if address:
device_list.append(str(address))
return device_list
def is_known_device(mac_addr):
"""Is the given Bluetooth address already a known device"""
found_devices = known_devices()
return mac_addr in found_devices
print(f'Device list: {known_devices()}')
look_list = ['DC:DB:16:6B:8C:5F', 'DC:DB:16:6B:8C:xx']
for look_up in look_list:
print(f'{look_up} is known? {is_known_device(look_up)}')
In my testing I got the following output:
Device list: ['DC:DB:16:6B:8C:5F', 'DE:82:35:E7:43:BE']
DC:DB:16:6B:8C:5F is known? True
DC:DB:16:6B:8C:xx is known? False

rfid-rc522 Tag is not read

I am using the instructions of https://pimylifeup.com/raspberry-pi-rfid-rc522/ to learn how to read my rfid-rc522.
I installed all the things needed, and cloned from git all the files. I connected accordingly and double checked the wire.
The code in Write.py is
#!/usr/bin/env python
import RPi.GPIO as GPIO
import SimpleMFRC522
reader = SimpleMFRC522.SimpleMFRC522()
try:
text = raw_input('New data:')
print("Now place your tag to write")
reader.write(text)
print("Written")
finally:
GPIO.cleanup()
When I run it- The result stops after "Now place your tag to write" and nothing happens when I place my tag. Any help please? What's wrong here? The module gives red light meaning it is connected. Is it really connected? How do I know? Please help.
Edit: My title and tags were wrong in this question due to already saved data. I edited. :)
It can be multiple reasons why your reader is not retrieving any data:
The RFID cards that you are providing to the reader are not supported by the ISO 14443: Mifare Classic, 4K. (Some DesFire, etc...) are the cards you want to try. Source: https://en.wikipedia.org/wiki/ISO/IEC_14443
The MFRC522 is not receiving enough input voltage. Try to increase from 3.3V to 4V. I have tried with 5V months and the reader is still running perfectly, but be cautious. The safe range in NXP is from 2.5V to 3.6V. Source: https://www.nxp.com/docs/en/data-sheet/MFRC522.pdf
The library you are using does not support IRQ (Interruption Request). This means the process of reading UIDs is high CPU consuming and low in performance. Try to use this popular library which supports interruptions: https://github.com/ondryaso/pi-rc522 . You will need to connect another wire from the IRQ pin in the MFRC522 to one GPIO pin in the Raspberry that is free and supports reading/writing operations.
Check if SPI interfaces are enable in Raspbian. Open a terminal and run:
ls -l /dev/spi
Lastly, it could be that your reader is broken. Some chinese versions do not work as they should do. Maybe you should buy another one and try more luck.
I suppose you have connected all cables in the correct way between the MFRC522 and the Raspberry Pi. Check that again.

How to poll for GPIO interrupts in python?

I need to poll for interrupts on a GPIO pin using python 2.7, and I wonder if there are any native functions or libraries to help me do that?
When searching for anything like this I find a lot about Raspberry Pi, but that is not what I need.
Is this doable?
It will be greate if you post what you already tried so we can help.
I did it like this
while 1:
events = po.poll(30000)
if not events:
print ('TIMEOUT!')
for fd, flag in events:
# check what's been done with os.lseek and os.read
This code is based on How do I wait for interrupts in different languages? question.
Whole code was done as a simple game for emebeded system on Raspberry PI and is available here

Java ME AudioSamples do not work on Ubuntu

I'm using Ubuntu 11.04 and trying to import Sun Wireless Toolkit 2.5.2 audio sample project in NetBeans 6.9. On Windows this works, while on Ubuntu, when running the sample midlet code, it does not make any sound, even not playing a simple tone.
After player.start() nothing happens, checking player.getMediaTime() gets always 0, and finally attempt to stop = player.stop() will not return the call at all.
I've searched all over the place. This post seems to report an answer for a potentially similar problem when using FreeTTs:
FreeTTS no audio linux ubuntu - no errors
the suggested workaround involves modifying/replacing the player class in com.sun.speech.freetts.audio packages. I wonder how to find the corresponding class that causes the lock in my case.
Probably it's easier to drop Ubuntu and use Windows VM for development, but at least I'd like to try. Maybe there is a simple solution.
Updated: Any type of player plays well on my Ubuntu box. Also I tried to use different non-me code, such as JLayer or Jorbis based players, even Java sound API. All work. It's just somewhere in the Java ME style player where it breaks down.

Resources