From 225a0d2264f408eb9245c2656b6b77473d9f8fab Mon Sep 17 00:00:00 2001 From: Andrey Egorov Date: Mon, 29 Jul 2024 14:11:38 +0300 Subject: [PATCH] Added APN parse. --- api/modem/internet/ic.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/api/modem/internet/ic.go b/api/modem/internet/ic.go index fdad76a..52005ec 100644 --- a/api/modem/internet/ic.go +++ b/api/modem/internet/ic.go @@ -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)