How to setup wifi on raspberry pi with username and password on Android Things using adb shell - android-things

I have a raspberry pi running an older version of Android things that is capable of connecting to my wifi. I copied and inserted the wpa_supplicant file from that pi to another pi with an updated version of android things but the new pi is unable to connect to the wifi. Am I missing something here?

There is a guide on how to do this.
In the adb shell you can execute this command:
am startservice \
-n com.google.wifisetup/.WifiSetupService \
-a WifiSetupService.Connect \
-e ssid my-ssid \
-e passphrase my-passphrase

Related

How to connect to Remote X server with docker?

I'm trying to connect to the remote server with docker. Basically, I need a real physical display to run GUI tests. Now, the issue is that the server doesn't have a physical Monitor so I'm trying to use X Forwarding to be able to connect to my PC with Monitor.
So what I've done so far:
On the machine with Monitor.
1) $ touch /tmp/.docker.xauth
2) $ xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f /tmp/.docker.xauth nmerge -
3) rsync -aztP /tmp/.docker.xauth user#server_in_clouds:/tmp/.docker.xauth
4) echo $DISPLAY (returns :1)
On the machine in Cloud.
1) docker run --rm -v /tmp/.X11-unix:/tmp/.X11-unix -v /tmp/.docker.xauth:/tmp/.docker.xauth -e XAUTHORITY=/tmp/.docker.xauth --gpus=all -e DISPLAY=IP_OF_THE_MACHINE_WITH_MONITOR:1 -e NVIDIA_DRIVER_CAPABILITIES=all DOCKER_IMAGE xclock
After some time it says that it can't connect to the IP_OF_THE_MACHINE_WITH_MONITOR:1
Should I do anything else? I believe I'm missing something. Maybe it is not required to have a physical Monitor in centos in order to do so?

How to show GUI apps from docker desktop container on windows 11

From this article, it states that windows 11 natively supports running of X11 and wayland applications on wsl.
I tried to do the same through a docker container, settinng the environment variable DISPLAY="host.docker.internal:0.0", and running a gui application (like gedit). But instead I got this error:
Unable to init server: Could not connect: Connection refused
Gtk-WARNING **: 17:05:50.416: cannot open display: host.docker.internal:0.0
I stumbled upon your question while attempting the same thing as you are and acctually got it to work with aid of this blog post on Microsoft. I use a minimal Dockerfile based on Ubuntu and installs gedit:
FROM ubuntu:22.04
RUN apt update -y && apt install -y gedit
CMD ["gedit"]
Create the image the usual way, e.g. docker build . -t guitest:1.0
On the WSL command line, start it like this:
docker run -it -v /tmp/.X11-unix:/tmp/.X11-unix \
-v /mnt/wslg:/mnt/wslg \
-e DISPLAY \
-e WAYLAND_DISPLAY \
-e XDG_RUNTIME_DIR \
-e PULSE_SERVER \
guitest:1.0
I hope this is to good use for you as well.
This answer is heavily based on what chrillof has said. Thanks for the excellent start!
The critical things here for Docker Desktop users on Windows with WSL2 are that:
The container host (i.e. docker-desktop-data WSL2 distribution) does not have a /tmp/.X11-unix itself. This folder is actually found in the /mnt/host/wslg/.X11-unix folder on the docker-desktop distribution which translates to /run/desktop/mnt/host/wslg/.X11-unix when running containers.
There are no baked-in environment variables to assist you, so you need to specify the environment variables explicitly with these folders in mind.
I found this GitHub issue where someone had to manually set environment variables which allowed me to connect the dots between what others experience directly on WSL2 and chrillof's solution
Therefore, modifying chrillof's solution using PowerShell from the host, it looks more like:
docker run -it -v /run/desktop/mnt/host/wslg/.X11-unix:/tmp/.X11-unix `
-v /run/desktop/mnt/host/wslg:/mnt/wslg `
-e DISPLAY=:0 `
-e WAYLAND_DISPLAY=wayland-0 `
-e XDG_RUNTIME_DIR=/mnt/wslg/runtime-dir `
-e PULSE_SERVER=/mnt/wslg/PulseServer `
guitest:1.0
On my computer, it looks like
this (demo of WSLg X11)
To be clear, I have not checked if audio is functional or not, but this does allow you to avoid the installation of another X11 server if you already have WSL2 installed.

docker: Error response from daemon: error gathering device information while adding custom device "/dev/video0": no such file or directory [duplicate]

I'm not sure that this is even possible, but is there a way to access my camera inside docker container? I'm not using external camera but built-in in my mac.
I'm not sure that the flag volume (-v) is the best practice to do so.
According to the github of jfrazelle, docker engineer who wrote many Dockerfile and docker run for many graphical app such as chromium, skype, spotify, and so on, the flag and argument you should use is --device /dev/video0.
For quick test(tested on ubuntu), below code should give supported frame resolution of cameras:-
docker run --rm -it --entrypoint /bin/bash --device /dev/video0 jrottenberg/ffmpeg
ffmpeg -f video4linux2 -list_formats all -i /dev/video0
You can try to forward your webcam device using -v flag
Something like
sudo docker run -d -p 55555:22 --privileged -v /dev/video0:/dev/video0 testimage
To list all devices attached to USB use lsusb ; to list all devices attached to PCI use lspci
On MacOS, it can be a bit tricky:
Install legacy docker virtualization engine for Docker Desktop on Mac (which uses Oracle Virtual Box)
Install Virtual Box
Install Virtual Box Extension pack
Install Docker Toolbox (reading this is strongly recommended & backuping your /usr/local/bin/docker* before is also recommended)
Ensure that /usr/local/bin/docker and /usr/local/bin/docker-compose link to Docker Desktop binaries (/Applications/Docker.app/Contents/Resources), and not Docker Toolbox
Test everything is still working: docker ps -a and docker images should display what you already had in Docker Desktop, docker-machine ls should not raise an error
brew install socat
brew install xquartz
Setting: XQuartz Preferences > Security > check allow all (Allow connections from network clients)
defaults write org.macosforge.xquartz.X11 enable_iglx -bool true
IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
xhost + $IP
docker-machine create -d virtualbox --virtualbox-cpu-count=4 --virtualbox-memory=4096 --virtualbox-disk-size=1000000 --virtualbox-boot2docker-url https://github.com/gzupark/boot2docker-webcam-mac/releases/download/18.06.1-ce-usb/boot2docker.iso default
docker-machine stop default
Open Virtual Box app & configure the VirtualBox VM that has just been created with docker-machine
Display > Video memory (max)
Display > Acceleration > Enable 3D acceleration (check)
Ports > USB > Enable USB controller (check) > USB 2.0 (select)
Shared folders > Add > Folder Path = / & Folder name = host-root
Reboot macOS
Open a terminal (T1), and type
open -a XQuartz
If it does not open another terminal, focus XQuartz app, and Applications > Terminal
Now a new terminal is opened (T2)
On T2: socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
if it complains about "Address already in use", check with lsof -i tcp:6000 that owning process is X11.bin, otherwise kill owning process and try running socat again (always on T2)
On T1 again
IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
xhost + $IP
docker-machine start default
eval $(docker-machine env default)
vboxmanage list webcams
Identify in the list your webcam (eg mine was .1)
vboxmanage controlvm default webcam attach .1
(You may need to open VirtualBox again, double click on your VM, which will open a view of your system, and then Devices > Webcam > <select your camera>)
You should now be able to access your camera in a container.
Test XQuartz with
docker run --rm -it -e DISPLAY=$IP:0 gns3/xeyes
Test camera with
docker run --rm -it -e DISPLAY=$IP:0 --device=/dev/video0:/dev/video0 -v /tmp/.X11-unix:/tmp/.X11-unix ubuntu
apt update && apt install -y streamer
streamer -f jpeg -o image.jpeg
Tip
Shutdown your greedy VM process with: VBoxManage controlvm thevm acpipowerbutton
Big thanks to:
https://github.com/GzuPark/boot2docker-webcam-mac
https://medium.com/#jijupax/connect-the-webcam-to-docker-on-mac-or-windows-51d894c44468
https://askubuntu.com/a/106773
https://apple.stackexchange.com/a/277029
Additional notes:
https://apple.stackexchange.com/a/277029
https://docs.docker.com/docker-for-mac/docker-toolbox/#docker-toolbox-and-docker-desktop-coexistence
https://docs.docker.com/docker-for-mac/docker-toolbox/

How to use mosquitto_pub to publsih the topic/message with specific time interval on the mqtt server?

I am working on Raspberry Pi with os "Raspbian GNU/Linux 8 (jessie)".Now what i am trying is to send the simple message from my raspberry pi to the mqtt server which i have created on the "api.cloudmqtt.com". I am able to send (from raspberry pi to my server) and Receive (from server to my raspberry pi)
with the following Commands
1.
pi#RevPi100102:~ $ mosquitto_pub -h "farmer.cloudmqtt.com" -p "18989" -u "obvrnnss" -P "xxxxxxxxx" -t "Test check" -m "Hello from RevPi"
2.
pi#RevPi100102:~ $ mosquitto_sub -h "farmer.cloudmqtt.com" -p "18989" -u "obvrnnss" -P "xxxxxxxxx" -t "Test check"
After this i tried to send the same message to server using the -r and for this i took help from link for mosquitto_pub
pi#RevPi100102:~ $ mosquitto_pub -h "farmer.cloudmqtt.com" -p "18989" -u "obvrnnss" -P "xxxxxxxxxx" -t "Test check" -m "Hello from RevPi" -r --repeat-delay "2"
I am getting the following error,
Error: Unknown option '--repeat-delay'.
Can someone help me to find where i am going wrong and how to use the command -r and --repeat-delay.I am not expertise in Linux commands.
Firstly the -r flag is not the short version of --repeat or --repeat-delay
From the mosquitto_pub doc
-r,
--retain
If retain is given, the message will be retained as a "last known good" value on the broker. See mqtt(7) for more information.
To get repeating messages you need to use the --repeat flag. This can then be combined with the --repeat-delay flag to set the time between each message being published.
Secondly, the repeat functionality is new, it was only added at version 1.6 of mosquitto. You not said what version you are using but if it is the default that ships with raspbian then it is unlikely you have this feature.

SSH agent forwarding to Docker Alpine container from Mac OS

Okay so for several projects I need to access my private repositories, so I'd like to forward the host's SSH Agent to the container to allow retrieving from these private repositories. Eventually I would like to implement this in docker-compose.
I've found a lot of answers and solutions pointing to something like this:
docker run --rm -t -i \
-v $SSH_AUTH_SOCK:/ssh-agent \
-e SSH_AUTH_SOCK=/ssh-agent \
alpine:3.6 sh
But when I run ssh-add -l inside there (after making sure openssh is installed)
I get the following error:
Error connecting to agent: Connection refused
Also tried this within my docker compose setup but it doesn't seem to work like it should.
Due to most posts and solutions being several years old I hope someone can help me with accurate up-to-date info.
According to this issue you can forward your macOS ssh-agent to your docker container by adding -v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock -e SSH_AUTH_SOCK="/run/host-services/ssh-auth.sock" options to your docker run command, e.g.
docker run --rm -it \
-v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock \
-e SSH_AUTH_SOCK="/run/host-services/ssh-auth.sock" \
docker_image
You can mount files, but not sockets - sharing sockets between MacOS through the hypervisor into docker containers is something that isn't supported yet. Various bug reports and acknowledgements exist, and some day it should work.
So in the meantime, you need to have something that forwards network traffic between the container and MacOS. One of the solutions that people point out is docker-ssh-agent-forward.
A different solution would be to run ssh-agent in a container and to access that from MacOS and the other containers - it's probably a bit more invasive but works. A solution is docker-ssh-agent.
Add keys to the launchd managed ssh-agent:
SSH_AUTH_SOCK=`launchctl getenv SSH_AUTH_SOCK` ssh-add
Forward the launchd managed ssh-agent to docker container:
docker run --rm -it \
-v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock:ro \
-e SSH_AUTH_SOCK="/run/host-services/ssh-auth.sock" \
image ssh hosts
The mount option and SSH_AUTH_SOCK value in container are all magic constants, do not change them.
launchctl getenv SSH_AUTH_SOCK may output empty string on iTerm2 3.2+ due to the bug. The work around is one of:
A portable way for newer OS (>=10.13 i.e. macOS High Sierra) is launchctl asuser $UID launchctl getenv SSH_AUTH_SOCK, or
For older OS, in iTerm2 > Prefs > Advanced, turn on "Enable multi-server daemon", or
For older OS, in iTerm2 > Prefs > Advanced, turn off "Allow sessions to survive logging out and back in".
NOTE: if the launchctl problem cannot work round, there is another way to forwarding ssh agent via stdio tunnel.

Resources