Semi debugged sms.

This commit is contained in:
Andrey Egorov
2024-07-29 18:53:55 +03:00
parent 1b741c7dab
commit d05e2205d6
4 changed files with 19 additions and 15 deletions

View File

@ -44,17 +44,19 @@ func (d *dialer) Init() error {
}
func (d *dialer) Send(number, msg string) error {
cmd := fmt.Sprintf("AT+CMGS=\"%s\"\r%s%c", number, msg, 26)
if resp, err := d.port.Send(cmd); err != nil || !resp.Check() {
if err != nil {
return fmt.Errorf("AT+CGMS= request: %w", err)
}
if errCode, err := GetError(resp.Bytes()); err != nil {
return fmt.Errorf("failed to send with SMS error: %s", DecodeError(errCode))
}
return fmt.Errorf("failed to send SMS")
d.port.Send(fmt.Sprintf("AT+CMGS=\"%s\"", number)) // Because it will throw error
resp, err := d.port.RawSend(fmt.Sprintf("%s\x1A", msg)); // Add additional \r\n because there is not supposed to be
if err != nil {
return fmt.Errorf("message request: %w", err)
}
return nil
if at.Resp(resp).Check() {
return nil
}
errCode, err := GetError([]byte(resp))
if err != nil {
return fmt.Errorf("send sms failed and failed to get error: %w", err)
}
return fmt.Errorf("failed to send with SMS error: %d - %s", errCode, DecodeError(errCode))
}
// Reads all new messages