Added APN parse.
This commit is contained in:
parent
2eb21228e3
commit
225a0d2264
@ -74,7 +74,7 @@ func (c *conn) ensurePackage(pname string) error {
|
||||
// c.logger.Println("Installing", pname, "package...")
|
||||
// resp, err := exec.Command("apt-get", "install", pname).Output()
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("execute install cmd: %w", err)
|
||||
// return fmt.Errorf("execute install cmd: %w", err)
|
||||
// }
|
||||
// c.logger.Println(resp)
|
||||
// c.logger.Println("\x1b[38;2;255;0;0mComplete\x1b[38;2;255;255;255m")
|
||||
@ -110,14 +110,28 @@ func (c *conn) checkReqs() error {
|
||||
|
||||
func (c *conn) ConfigurePPP() error {
|
||||
// Get provider name and its APN
|
||||
// AT+CSPN
|
||||
provider := ""
|
||||
resp, err := c.port.Send("AT+CSPN?")
|
||||
if err != nil {
|
||||
return fmt.Errorf("AT+CSPN? request: %w", err)
|
||||
}
|
||||
if !resp.Check() {
|
||||
return fmt.Errorf("failed to check SIM provider")
|
||||
}
|
||||
strs := strings.Split(string(resp), "\"")
|
||||
if len(strs) < 3 {
|
||||
return fmt.Errorf("parse AT+CSPN response: %s", string(resp))
|
||||
}
|
||||
provider := strs[1]
|
||||
apn := apns[provider]
|
||||
if apn == "" {
|
||||
return fmt.Errorf("no apn for provider: %s", provider)
|
||||
}
|
||||
|
||||
// Make config
|
||||
c.logger.Printf("Config values: %s, %s, %d", apn, c.port.GetName(), c.port.GetBaudrate())
|
||||
config := fmt.Sprintf(pppConfig, apn, c.port.GetName(), c.port.GetBaudrate())
|
||||
|
||||
// Write to file
|
||||
f, err := os.OpenFile("etc/ppp/pears/"+pppConfigName, os.O_CREATE, 0666)
|
||||
if err != nil {
|
||||
return fmt.Errorf("open ppp config file %w", err)
|
||||
|
Loading…
Reference in New Issue
Block a user