PiCamera out of resources no matter what - python

I started trying the official test code;
from picamera import PiCamera
from time import sleep
camera = PiCamera()
camera.start_preview()
sleep(5)
camera.stop_preview()
And I got this error;
picamera.exc.PiCameraMMALError: Failed to enable connection: Out of resources
This is immediately after a reboot, no running scripts or processes, camera verified enabled in raspi-config via terminal and the Raspberry Pi Configuration app, and GPU memory increased to 256. I know the camera works because I can use the RPi Cam Web Interface and see the camera feed just fine (I uninstalled it afterwards to see if it was conflicting, which it apparently wasn't.) I've already updated and upgraded, and I can't run rpi_update even if I wanted to because it says "Invalid git hash specified" when I type "y" to proceed. I've reached the limit of troubleshooting, and reddit deletes my post instantly because the bot says I didn't research.
From the command prompt, I did some basic troubleshooting at the basic level. Copied directly from the console:
pi#raspberrypi:~ $ vcgencmd get_camera
supported=1 detected=1
pi#raspberrypi:~ $ raspistill -o image.jpg
mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
mmal: camera component couldn't be enabled
mmal: main: Failed to create camera component
mmal: Failed to run camera app. Please check for firmware updates
pi#raspberrypi:~ $

Related

adb shell input touchscreen tap is not working

I am trying to simulate tap and swipe gesture from adb to my android device. I've tried to run the following command
adb shell input tap 500 500 and adb shell input touchscreen tap 500 500 from windows command prompt. It is giving me the following error,
java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission
at android.os.Parcel.createException(Parcel.java:2074)
at android.os.Parcel.readException(Parcel.java:2042)
at android.os.Parcel.readException(Parcel.java:1990)
at android.hardware.input.IInputManager$Stub$Proxy.injectInputEvent(IInputManager.java:925)
at android.hardware.input.InputManager.injectInputEvent(InputManager.java:886)
at com.android.commands.input.Input.injectMotionEvent(Input.java:428)
at com.android.commands.input.Input.access$200(Input.java:41)
at com.android.commands.input.Input$InputTap.sendTap(Input.java:224)
at com.android.commands.input.Input$InputTap.run(Input.java:218)
at com.android.commands.input.Input.onRun(Input.java:108)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:56)
at com.android.commands.input.Input.main(Input.java:71)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:380)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.input.InputManagerService.injectInputEventInternal(InputManagerService.java:732)
at com.android.server.input.InputManagerService.injectInputEvent(InputManagerService.java:706)
at android.hardware.input.IInputManager$Stub.onTransact(IInputManager.java:422)
at android.os.Binder.execTransactInternal(Binder.java:1021)
at android.os.Binder.execTransact(Binder.java:994)
I've also tried to execute the same command from python script with the pure-python-adb package. The following is script I've exucted.
from ppadb.client import Client
adb = Client()
devices = adb.devices()
if len(devices) == 0:
print("No devices attached")
quit()
device = devices[0]
print(device)
device.shell('input touchscreen tap 700 1453')
I got the following output with no tap noticed on device and no error from the script.
<ppadb.device.Device object at 0x02B30E50>
Am I missing anything (Might be in developer's option setting for android)?
I am on windows 10 machine with adb version 1.0.41. And using an android device with Android 10 (Android Q) over a usb.
Look for a "USB debugging (Security Settings)" or something similar in your developer options in the debugging section -- This is where you grant ADB special permissions and allow input.
Best of luck; I hope you find it.
I tried this to tap a xy coordinate using adb command. Enabling the "USB debugging (Security Settings)" is worked for me. But the phone should connect to the internet inorder to enable the settings.
Thanks #Meer

PyQt4 or PyQt5 from framebuffer without X server

I'm trying to run a PyQt gui application from console on a Raspberry Pi 3.
Withough X11 server.
I tried xvfb-run python test.py but it did not work.
In the case of PyQt4, it outputs
"python: Fatal IO error 11 (Resource temporarily unavailable) on X server :99."
When I terminate the process.
In the case of PyQt5, it outputs
"libEGL warning: DRI2: failed to create any config
Cant find EGLConfig, returning null config
Unable to find an X11 visual which matches EGL config 0
Could not initialize OpenGL for RasterGLSurface, reverting to RasterSurface.
Unsupported screen depth: 8"
and then throws this when I kill the process
"The X11 connection broke (error 1). Did the X11 server die?"
I'm running raspian jessie
Any idea how to get this working ?

Python code for Bluetooth throws error after I had to reset the adapter

I was trying out bluetooth programming in python. It was working fine till yesterday. This morning, there was a power outage and for some reason, the bluetooth module got disabled and it could not be turned on. So, I did a sudo hciconfig hci0 reset and then turned it on. From that point onwards, the simplest of the programs are failing to execute. Take this one for example. It gets stuck at advertise_service in bluetooth module and throws the following error (FYI: virtualenv was not a problem here. The systemwide python also does the same thing).
Traceback (most recent call last):
File "bt.py", line 17, in <module>
advertise_service( server_sock, "SampleServer", service_id = uuid, service_classes = [ uuid, SERIAL_PORT_CLASS ], profiles = [ SERIAL_PORT_PROFILE ])
File "/home/machinename/.virtualenvs/py27/local/lib/python2.7/site-packages/bluetooth/bluez.py", line 242, in advertise_service
raise BluetoothError (str (e))
bluetooth.btcommon.BluetoothError: (2, 'No such file or directory')
Sometimes I got a different error when I compiled and reinstalled Bluez driver:
Traceback (most recent call last):
File "build/bdist.linux-x86_64/egg/bluetooth/bluez.py", line 268, in advertise_service
bluetooth.btcommon.BluetoothError: error no advertisable device.
But all of these worked like a charm before in that machine; in fact all of the program works just fine with my other ubuntu (14.04LTS) machine as I write this. I inspected the source code, and traced to a _bluetooth.so file - which is a compiled code, hence I couldn't figure out what to do anymore.
Any pointer will be highly appreciated.
This error is due to incompatibility issues with BlueZ 5 and SDP with bluetoothd
Fix for 15.10 and BlueZ 5
Make sure, running sdptool browse local gives following error:
Failed to connect to SDP server on FF:FF:FF:00:00:00: No such file or directory
As it turns out, the culprit is bluetoothd, the Bluetooth daemon. Using SDP with bluetoothd requires deprecated features for some silly reason, so to fix this, the daemon must be started in compatibility mode with bluetoothd -C (or bluetooth --compat).
Find location of bluetooth.service by:
systemctl status bluetooth.service
Then edit bluetooth.service and look for
ExecStart=/usr/libexec/bluetooth/bluetoothd
Append --compat at the end of this line, save, and then run
service bluetooth start
If all goes well, you should be able to successfully run
sudo sdptool browse local
Finally, reset the adapter:
sudo hciconfig -a hci0 reset
Things should work fine now
Old answer
Just to let people know, I believe the latest BlueZ build was somehow broken in my system. I downloaded, compiled and installed the 5.35 version, and nothing was working. I dialed down to 5.34, still same. I also noticed that the bluetooth adapter was going down automatically 3-4 minutes after enabling it using,
sudo hciconfig hci0 up # hci0 is the bt adapter
I used one usb bluetooth dongle to test. It did not go down automatically like the inbuilt adapter, but the problems persisted. Then I used apt-get to reinstall bluez,
apt-get install --reinstall bluez
and all of a sudden everything came back to normal.
To fix:
bluetooth.btcommon.BluetoothError: (2, 'No such file or directory')
You need to:
sudo nano /lib/systemd/system/bluetooth.service
Change from: ExecStart=/usr/lib/bluetooth/bluetoothd
To: ExecStart=/usr/lib/bluetooth/bluetoothd --compat
sudo systemctl daemon-reload
Again, as sidmeister mentioned,
Make sure, running sdptool browse local gives following error:
Failed to connect to SDP server on FF:FF:FF:00:00:00: No such file or directory
But,for those who are using initd system manager, its hard to find a solution if you want to execute sdp_rfcomm_server/client model and the terminal will keep on showing same error again and again.
So for init.d follow these steps:
Stop bluetooth first
$ /etc/init.d/bluetooth stop
Status check
$ /etc/init.d/bluetooth status
Run bluetooth in compatibility mode(don't forget ampersand,otherwise prompt won't turn up )
$ /usr/libexec/bluetooth/bluetoothd --compat&
start bluetooth again
$ /etc/init.d/bluetooth start
again try sdpbrowse
$ sdptool browse local
Things should work for you now.

Pygame.display.init() error: "No available video device", on VPS Server

I'm trying to run a pygame script on a vps server, and I'm receiving an error on the pygame.display.init().
Following the directions found here http://www.pygame.org/docs/ref/display.html#pygame.display.init and in other sources, I used all this configurations before the init():
os.environ["​​SDL_VIDEODRIVER"]="dummy"
os.environ["SDL_VIDEODRIVER"]="x11"
os.environ["SDL_VIDEODRIVER"]="dga"
os.environ["SDL_VIDEODRIVER"]="fbcon"
os.environ["SDL_VIDEODRIVER"]="directfb"
os.environ["SDL_VIDEODRIVER"]="ggi"
os.environ["SDL_VIDEODRIVER"]="vgl"
os.environ["SDL_VIDEODRIVER"]="svgalib"
os.environ["SDL_VIDEODRIVER"]="aalib"
So, the "dummy" option causes the script to go into a loop. Any other option give me the error:
<class 'pygame.error'>: No available video device
I have x11 installed. I'm calling the python script from a php file, so, I would expect the graphic output to go inside the browser, or, the "video device" to be set automatically as the user browser. Not happening.
Are you ssh'd into the vps server? Have you tried x forwarding, ssh -X user#server.com then when you run the script from the command line it should open on your window

Injecting uinput keypresses

I have Arch Linux ARM running on a Raspberry Pi. On boot, an X application is started (navit).
After system is booted, I ssh into it, and try the following python code:
from evdev import UInput, ecodes
inp = UInput()
inp.write(ecodes.EV_KEY, ecodes.KEY_UP, 1)
inp.write(ecode.EV_KEY, ecodes.KEY_UP, 0)
inp.syn()
The problem- the application which is started on boot does not receive this keypress.
The following does work from ssh session- application receives arrow up keypress.
DISPLAY=:0 xdotool key Up
uinput kernel module is loaded, Xorg configuration is left at defaults (hotplugging devices should be enabled- although, I cannot verify it).
dmesg shows that input device is registered:
[ 28.725976] input: py-evdev-uinput as /devices/virtual/input/input0
I alsso verified that the application I started is currently focused, by using:
DISPLAY=:0 xdotool getwindowfocus getwindowpid
Any ideas where to look next to debug this issue?
Turns out evdev module was not loaded. I though loading uinput module should suffice, but it's not.
I discovered it by noticing that the code did work when external keyboard was plugged in.

Categories