[AlienPI]
New Raspberry Pi Zero setup
Download DietPi image and prepare Micro SD card
https://dietpi.com/ | https://dietpi.com/phpbb/viewtopic.php?p=9#p9
─────────────────────────────────────────────────────
DietPi v6.28.0 : 12:46 - Sa 18.01.2020
─────────────────────────────────────────────────────
- Device model : RPi Zero (armv6l)
- CPU temp : 36'C : 96'F (Cool runnings)
- LAN IP : 192.168.10.30 (eth0)
─────────────────────────────────────────────────────
DietPi Team : MichaIng (lead), Daniel Knight (founder)
Image : DietPi Core Team (pre-image: Raspbian Lite)
Web : https://DietPi.com | https://twitter.com/dietpi_
Patreon Legends : PINE64 community | oct8l
Donate : https://DietPi.com/#donate
DietPi Hosting : Powered by https://MyVirtualServer.com
dietpi-launcher : All the DietPi programs in one place.
dietpi-config : Feature rich configuration tool for your device.
dietpi-software : Select optimized software for installation.
htop : Resource monitor.
cpu : Shows CPU information and stats.
Setup NoIP
Execute dietpi-launcher
8 : Network Options: Misc
No-IP : [[Not Installed] Install No-IP now]
New configuration file '/usr/local/etc/no-ip2.conf' created.
Plug in 3g modem and wait some seconds ...
lsusb
Bus 001 Device 004: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter
Bus 001 Device 003: ID 05c6:1000 Qualcomm, Inc. Mass Storage Device
Bus 001 Device 002: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Install required software
sudo apt-get install ppp usb-modeswitch wvdial
Created symlink /etc/systemd/system/multi-user.target.wants/pppd-dns.service → /lib/systemd/system/pppd-dns.service.
You can retry the autodetection at any time by running "wvdialconf".
(Or you can create /etc/wvdial.conf yourself.)
Get the USB switching codes
We need to get the codes of the USB device in USB storage mode and USB modem mode.
Connect your USB modem and reboot the Raspberry PI without LAN or Wifi connection
Once rebooted open a terminal window and enter:
lsusb
- The output will look similar to the screenshot below. Your modem should be listed as one of the USB devices. Note the numbers in bold italics. These are the device vendor and product codes.
Bus 001 Device 004: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter
Bus 001 Device 003: ID 05c6:1000 Qualcomm, Inc. Mass Storage Device
Bus 001 Device 002: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
- Make a note of these numbers. In this case it is
05c6:1000
Switch the Mode from Mass Storage Device to 3G Modem
sudo usb_modeswitch -W -v 05c6 -p 1000 -K
Take all parameters from the command line
* usb_modeswitch: handle USB devices with multiple modes
* Version 2.5.2 (C) Josua Dietze 2017
* Based on libusb1/libusbx
! PLEASE REPORT NEW CONFIGURATIONS !
DefaultVendor= 0x05c6
DefaultProduct= 0x1000
StandardEject=1
Look for default devices ...
found USB ID 0bda:8153
found USB ID 05c6:1000
vendor ID matched
product ID matched
found USB ID 1a40:0101
found USB ID 1d6b:0002
Found devices in default mode (1)
Access device 003 on bus 001
Get the current device configuration ...
Current configuration number is 1
Use interface number 0
with class 8
Use endpoints 0x01 (out) and 0x81 (in)
USB description data (for identification)
-------------------------
Manufacturer: USBModem
Product: HSPA Data Card
Serial No.: 1234567890ABCDEF
-------------------------
Sending standard EJECT sequence
Looking for active drivers ...
OK, driver detached
Set up interface 0
Use endpoint 0x01 for message sending ...
Trying to send message 1 to endpoint 0x01 ...
OK, message successfully sent
Read the response to message 1 (CSW) ...
Response successfully read (13 bytes), status 0
Trying to send message 2 to endpoint 0x01 ...
OK, message successfully sent
Read the response to message 2 (CSW) ...
Response successfully read (13 bytes), status 0
Trying to send message 3 to endpoint 0x01 ...
OK, message successfully sent
Read the response to message 3 (CSW) ...
Response successfully read (13 bytes), status 0
Trying to send message 4 to endpoint 0x01 ...
OK, message successfully sent
Read the response to message 4 (CSW) ...
Response successfully read (13 bytes), status 1
Reset response endpoint 0x81
Reset message endpoint 0x01
-> Run lsusb to note any changes. Bye!
Check for changes by running lsusb again, if successful you should now see a new device ID as below:
lsusb
Bus 001 Device 004: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter
Bus 001 Device 005: ID 05c6:6000 Qualcomm, Inc. Siemens SG75
Bus 001 Device 002: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Now to make it switch automatically using Udev
Create a rule
nano /etc/udev/rules.d/05c6\:1000.rules
Put the following line into the empty file; It says if you see this USB device with these properties run the command we used above to switch modes from USB to 3G Modem:
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="05c6", ATTRS{idProduct}=="1000", RUN+="/usr/sbin/usb_modeswitch -W -v 05c6 -p 1000 -K"
Save the file and reboot.
Subsequent hot plugs should see the device attached as a USB 3G modem
Then connect to the internet:
wvdial 3g
Keep Internet connection always up:
A simple solution to this is CRON that runs the following script:
If WVDIAL is not running:
Run WVDIAL 3g
How to reset a USB device using a script:
The USB GSM modem does not always work properly. Sometimes it gets stuck. Sometimes on boot, usb_modswitch seems to just not get fired.
Create script
sudo nano
#! /bin/sh
# /usr/sbin/resetdevicebyauthorized
echo "Searching for $1"
devPath=`lsusb | grep $1 | sed -r 's/Bus ([0-9]{3}) Device ([0-9]{3}).*/bus\/usb\/\1\/\2/g;'`
Bus 001 Device 007: ID 05c6:6000 Qualcomm, Inc. Siemens SG75
echo "Found $1 @ $devPath"
echo "Searching for sysPath"
for sysPath in /sys/bus/usb/devices/*; do
echo "$sysPath/uevent"
devName=`cat "$sysPath/uevent" | grep $devPath`
#echo devName=$devName
if [ ! -z $devName ]
then
break
fi
done
if [ ! -z $devName ]
then
echo "Found $1 @ $sysPath, Resetting"
echo "echo 0 > $sysPath/authorized"
echo 0 > $sysPath/authorized
echo "echo 1 > $sysPath/authorized"
echo 1 > $sysPath/authorized
else
echo "Could not find $1"
fi
I want to change the script to be this:
If /dev/ttyUSB0 is not present:
If DevicePresent(12d1:1446):
ResetDevice(12d1:1446)
ElseIs DevicePresemt(12d1:1506)
ResetUSB(12d1:1506)
If WVDIAL is not running:
Run WVDIAL
lsusb
Obviously this is pseudo code, but I have the following lines that I need to string together but I can't figure out how:
This loads wvdial if it is not running:
#! /bin/sh
# /etc/init.d/wvdial
### BEGIN INIT INFO
# Provides: TheInternet
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Simple script to start a program at boot
# Description: A simple script from www.stuffaboutcode.com which will start / stop a program a boot / shutdown.
### END INIT INFO
# If you want a command to always run, put it here
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting GPRS Internet"
# run application you want to start
/sbin/start-stop-daemon --start --background --quiet --exec /usr/bin/wvdial internet
;;
stop)
echo "Stopping GPRS Internet"
# kill application you want to stop
/sbin/start-stop-daemon --stop --exec /usr/bin/wvdial
;;
*)
echo "Usage: /etc/init.d/noip {start|stop}"
exit 1
;;
esac
exit 0
This lets me find the /sys
path to a certain device:
for X in /sys/bus/usb/devices/*; do
echo "$X"
cat "$X/idVendor" 2>/dev/null
cat "$X/idProduct" 2>/dev/null
echo
done
And this resets a USB device if you know the correct /sys path:
echo 0 > /sys/bus/usb/devices/1-1.2.1.1/authorized
echo 1 > /sys/bus/usb/devices/1-1.2.1.1/authorized
So, I need to string the last 2 sections and a test to /dev/ttyUSB0
into a section that goes under the "If you want a command to always run. put it here" section
UPDATE 1
usbreset, although functioning, does not do the job. Only echo 0 the 1 into authroized
correctly simulates a device disconnect/reconnect.
This is what does the trick of booting the device or usb_modeswitch back into life. As such I've managed to cobble together this:
echo "Searching for $1"
devPath=`lsusb | grep $1 | sed -r 's/Bus ([0-9]{3}) Device ([0-9]{3}).*/bus\/usb\/\1\/\2/g;'`
echo "Found $1 @ $devPath"
echo "Searching for sysPath"
for sysPath in /sys/bus/usb/devices/*; do
echo "$sysPath/uevent"
devName=`cat "$sysPath/uevent" | grep $devPath`
#echo devName=$devName
if [ ! -z $devName ]
then
break
fi
done
if [ ! -z $devName ]
then
echo "Found $1 @ $sysPath, Resetting"
echo "echo 0 > $sysPath/authorized"
echo 0 > $sysPath/authorized
echo "echo 1 > $sysPath/authorized"
echo 1 > $sysPath/authorized
else
echo "Could not find $1"
fi
I think therefore all I have to do now is put this in the init.d script:
if ttyUSB0 not present
if 12d1:1446 present
/usr/sbin/resetdevicebyauthorized 12d1:1446
else if 12d1:1506 present
/usr/sbin/resetdevicebyauthorized 12d1:1506
fi
fi
Tips
Ever wanted to analyze the boot process? => "systemd-analyze -h"
Make a file executable
sudo chmod +x hello-world.sh