I tried to turn on / off the power of the USB port of Raspberry Pi.
Since I connected the Raspberry Pi and the smartphone via the Blynk server in previous article, I am operating the power supply from the smartphone side.
--Android smartphone
The whole picture of the above equipment is like this. It is an image that the smartphone and Raspberry Pi are connected in the same local area, and the Blynk server is connected to it. The Raspberry Pi and the USB-HUB / USB-FAN to be controlled this time are connected.
Since the following method uses Blynk, you need to install and connect Blynk on both your smartphone and Raspberry Pi.
Click here for how to do it. ↓↓↓ Connect your Raspberry Pi to your smartphone using Blynk
Since the script is difficult to handle in the initial setting, it is changed by referring to the following site.
http://blog.livedoor.jp/victory7com/archives/48432885.html
As a result, the relationship between the widget settings and the script on the Raspberry Pi side is as shown in the figure below (* The image is quoted from the same site).
On the smartphone side, select the pin associated with the widget and script for the Blynk project.
[Left] Tap the widget to open the widget settings [Middle] Since this is a button, tap it to select the pin to be linked when the button is pressed [Right] Select the pin type and pin number
pi@raspberrypi:~ $ sudo apt-get install libusb-dev
pi@raspberrypi:~ $ git clone https://github.com/codazoda/hub-ctrl.c
pi@raspberrypi:~ $ cd hub-ctrl.c
pi@raspberrypi:~/hub-ctrl.c $ gcc -O2 hub-ctrl.c -o hub-ctrl-armhf-static -lusb –static
pi@raspberrypi:~/hub-ctrl.c $ sudo cp hub-ctrl-armhf-static /usr/local/bin/hub-ctrl
The "lsusb" command returns the device connected to the USB port and its Bus and Device numbers. Since the USB-HUB is the operation target this time, check that the device name is "Genesys Logic".
pi@raspberrypi:~ $ lsusb
Bus 001 Device 005: ID 046d:c016 Logitech, Inc. Optical Wheel Mouse
Bus 001 Device 004: ID 05e3:0608 Genesys Logic, Inc. Hub
Bus 001 Device 006: ID 0424:7800 Standard Microsystems Corp.
Bus 001 Device 003: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 002: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Since the pin number was set to "V10" in the widget settings, the file name of the script is "V10".
pi@raspberrypi:~ $ sudo vi /home/pi/blynk/BLYNK_WRITE_V10.sh
The content of the script is like this.
/home/pi/blynk/BLYNK_WRITE_V10.sh
#!/bin/sh
HUB=`/usr/bin/lsusb -v 2>/dev/null | grep ^Bus | grep "Genesys Logic, Inc. Hub" | head -1`
BUS=`echo $HUB | awk '{print $2}'`
DEV=`echo $HUB | awk '{print $4}' | sed -e "s/\(.*\)\:/\1/p;d"`
for i in 1 2 3 4
do
/usr/local/bin/hub-ctrl -b $BUS -d $DEV -P $i -p 0
done
Now that you have a script that corresponds to the pin number specified in the widget, pressing a button on your smartphone will launch this script. As a result, you can turn on / off the power of the USB fan.
In the old version of Raspberry Pi, it was possible to control the power supply of the USB port of the main unit individually, but it became impossible because the version was upgraded.
It was said that a USB-HUB with "Per-port power switching" specifications could be controlled, but a HUB that supports it is not currently on sale. If it is ** BUFFALO BSH4AE12BK ** used this time, it is possible to control the power supply in units of USB-HUB **, so I decided to use this.
By creating the pin specified in the widget and the script associated with it, the script could be executed from the smartphone side. First of all, I understand the basics of how to move it, so next I would like to move it using a different widget.
――Part 3 Let's see the temperature / frequency / load status of the CPU ――Series Let's control the Raspberry Pi from a smartphone using the IoT service "Blynk" (Raspberry Pi blog) - http://blog.livedoor.jp/victory7com/archives/48432885.html --How to connect a USB fan to Raspberry Pi and control the USB port ON / OFF (Mushroom Times) - https://kinokotimes.com/2017/03/07/usb-control-method-by-raspberry-pi/ --Try controlling the power ON / OFF of the USB HUB from Linux (memo memo) - http://atotto.hatenadiary.jp/entry/linux-sugoi-usb-hub-power-ctrl --Turn on / off the power of the USB port on RaspberryPI 3 Model B (PC bird blog) - https://iot-plus.net/make/raspi/rpi3-blynk-shutdown/ --I installed a back camera and LCD monitor on the car: using GL-AR150 / OpenWRT, Amazon Dash Button, and a USB hub. - https://qiita.com/somainit/items/db4d8fe760e3fb88905f
Recommended Posts