gitbls / sdm

Raspberry Pi SD Card Image Manager
MIT License
465 stars 48 forks source link

Configure gsm/lte modem interface to start on boot #255

Closed thk686 closed 1 month ago

thk686 commented 1 month ago

I am trying to get NetworkManager to bring up a modem when the pi boots. I have a script that will configure and bring up the interface if I run it after logging in. But I can't get it to come up automatically. I have tried it as a oneshot service and in 0piboot. Once I manually run the script, the interface does come up automatically on reboot.

#!/bin/bash

# Currently, this script is installed in /etc/sdm/0piboot

# Path to the configuration file
CONFIG_FILE="/etc/biosense/setup-modem.conf"

# Function to read APN from the configuration file
read_apn() {
    local apn=""
    if [ -f "$CONFIG_FILE" ]; then
        apn=$(grep -i 'apn' "$CONFIG_FILE" | awk -F'=' '{print $2}' | xargs) # Extract APN value
    fi
    echo "$apn"
}

# Detect the modem interface (e.g., wwan0)
modem_iface=$(nmcli dev status | grep gsm | awk '{print $1}')

# Read APN from the configuration file
APN=$(read_apn)

if [ -n "$modem_iface" ]; then
    if [ -n "$APN" ]; then
        nmcli c add type gsm ifname "$modem_iface" con-name lte connection.interface-name "$modem_iface" gsm.apn "$APN" ipv4.method auto &&
            echo "Added LTE modem connection with APN: $APN" ||
            echo "Failed to add LTE modem connection with APN: $APN"
    else
        nmcli c add type gsm ifname "$modem_iface" con-name lte connection.interface-name "$modem_iface" ipv4.method auto &&
            echo "Added LTE modem connection without APN" ||
            echo "Failed to add LTE modem connection without APN"
    fi

    nmcli c modify lte connection.autoconnect yes &&
        echo "Set LTE connection to autoconnect" ||
        echo "Failed to set LTE connection to autoconnect"
else
    echo "No modem network interface found."
fi
gitbls commented 1 month ago

In order to be run during sdm FirstBoot, scripts in /etc/sdm/0piboot need to be named 0*-*.sh

Does your script conform to this naming?

If so, what do you find in the system journal as output from running the script?

thk686 commented 1 month ago

Naming is correct. I will look at the journal output. Thanks.

On Thu, Sep 19, 2024 at 8:11 AM Benn @.***> wrote:

In order to be run during sdm FirstBoot, scripts in /etc/sdm/0piboot need to be named 0-.sh

Does your script conform to this naming?

If so, what do you find in the system journal as output from running the script?

— Reply to this email directly, view it on GitHub https://github.com/gitbls/sdm/issues/255#issuecomment-2360948217, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEQXSM4TECAIB3MZK3RFGLZXLEQBAVCNFSM6AAAAABOPHWBSCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNRQHE2DQMRRG4 . You are receiving this because you authored the thread.Message ID: @.***>

-- Timothy H. Keitt www keittlab org

gitbls commented 1 month ago

Closing since you have presumably resolved this. Pls re-open if more assistance needed. Thx.

thk686 commented 1 month ago

Yes we fixed. Network manager handles this well although we need to reboot once for some reason. Thanks for all your help with sdm.Sent from my iPhoneOn Oct 5, 2024, at 1:46 PM, Benn @.***> wrote: Closing since you have presumably resolved this. Pls re-open if more assistance needed. Thx.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>