I've connected a LTE usb dongle at raspberry pi 4B which has raspbian buster 10.
I have created a initialization script which consists of the following :
modprobe qmi_wwan
echo 'xxxx xxxx' > /sys/bus/usb/drivers/qmi_wwan/new_id
ip link set dev wwan0 down
echo Y > /sys/class/net/wwan0/qmi/raw_ip
ip link set dev wwan0 up
qmicli --device=/dev/cdc-wdm0 --device-open-proxy --wds-start-network="ip-type=4,apn=apn" --client-no-release-cid
When I run it manually from the home directory
sudo ./init.sh
it works fine.
However when I try to run it as boot up script I always get the error :
couldn't create client for the 'wds' service: CID allocation failed in the CTL client: Transaction timed out
Firstly I tried to add the running of the script at the /etc/rc.local file.
Then I created a service to start up after boot up via systemd. The service file is basically the following:
[Unit]
Description=initialization script
After=remote-fs.target
After=syslog.target
[Service]
Type=simple
ExecStart=/bin/sh /home/pi/init.sh
User=root
[Install]
WantedBy=multi-user.target
I tried with or without User=root, I also tried After=network.target but in any case I get the above error.
I tried using the following service file suggestef by @Ingo bellow :
[Unit]
Description=initialization script
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/bin/sh /home/pi/init.sh
[Install]
WantedBy=multi-user.target
But then I got the error:
**Αpr 23 12:41:17 raspberrypi init.sh[418]: Cannot find device "wwan0"
Apr 23 12:41:17 raspberrypi init.sh[418]: /home/pi/init.sh: 6: /home/pi/init.sh: cannot create /sys/class/net/wwan0/qmi/raw_ip: Directory nonexi
Apr 23 12:41:17 raspberrypi init.sh[418]: Cannot find device "wwan0"
Apr 23 12:41:17 raspberrypi init.sh[418]: error: couldn't create QmiDevice: Couldn't query file info: Error when getting information for file “/dev/cdc-wdm0”:**
My assumption is that it doesn't recognize the ttyUSB on time but I don't know how to check it or fix it.
Does anyone knows what I'm doing wrong here ?