Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8087279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:43:37+00:00 2026-06-05T18:43:37+00:00

I am trying to add some error detection to a script that is used

  • 0

I am trying to add some error detection to a script that is used to send SMS messages from our surveillance system. Most of the time it works like a charm but in some rare cases it stops sending the messages and we have no idea why.

We haven’t been able to reproduce the error so I’m wondering if anyone out there has had a similar problem. Below is the code that send the message and below that an idea I had that might be able to catch the error.

Here is the code that sends the message:

sub sendsms {
  my ($number,$msg) = @_;
  my $store = undef;
  my $status = undef;
  $msg =~ tr/\\[\]_'^~\{\}\|/\/\(\)\-"??\(\)!/; # \ -> /, [ -> (, ] -> ), ...., strippa út [ ] _ ' ^ ~ { } | \
  $msg =~ tr/\xe1\xe9\xed\xf3\xfa\xfd\xf0\xfe\xe6\xf6\xc1\xc9\xcd\xd3\xda\xdd\xd0\xde\xc6\xd6/aeiouydtaoAEIOUYDTAO/;
  for (my $i = 0; $i < length($msg); $i++) {
    substr($msg,$i,1) = '_' if (ord(substr($msg,$i,1)) < 0x20 || ord(substr($msg,$i,1)) > 0x7f);
  }
  my $s = substr($msg,0,$maxlen);
  RETRY: for (my $t = 0; $t < 5; $t++) {
    eval {
      put('AT+CMGD='.($next_store+1), 'OK');
      put('AT+CSCA="'.$sca.'",145', 'OK');
      put('AT+CMGF=1', 'OK');
      put('AT+CMGW="'.$number.'",145', '>');
      put($s, '>');
      my $a = put("\x{1a}", undef);
      print "a = '$a'\n" if ($verbose);
      if ($a =~ /\+CMGW: ([0-9]*)/) {
        $store = $1;
        last RETRY;
      }
     };
    if ($@) {
      print "ERROR: attempt $t: $@\n";
    }
    sleep 2*($t+1);
  }
  if (defined $store) {
    print "Message store $store\n" if ($verbose);
    put('AT+CMSS='.$store.',"'.$number.'",145',undef);
    $next_store = (($store - 1) + 1) % $stores;
  }
  else {
    die "Message not stored";
  }
}

The put function:

sub put {
  my ($cmd,$expect) = @_;
  print "Sending command '$cmd' expecting '$expect'\n" if ($verbose);
  $modem->atsend($cmd."\r\n") || die "FAILED send\n";
  my $a = $modem->answer();
  die "Failed '$cmd' expected '$expect' got '$a'\n" if (defined $expect && !($a =~ /$expect/));
  return $a;
}

Like I said earlier this works 99% of the time. The error seems to be that the messages are written to the store but never sent.

My idea:

eval {'$status = AT+CPAS'};
if (defined $status and ($status == '+CPAS: 1' or $status == '+CPAS: 2')){
    print "Modem returned an error status: ".$status;
    flush_stores();
    sendsms('+xxxxxxxxxx', 'There is an error in the 3G modem');
}

Flush function:

sub flush_stores {
   for (my $i = 0; $i < $stores; $i++) {
      put('AT+CMGD='.($i+1), 'OK');
   }
}

Will this work?

If not, what will?

Gísli

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:43:39+00:00Added an answer on June 5, 2026 at 6:43 pm

    This seems to have been a hardware problem. We have replaced the 3G modem and SIM card and it’s all working smoothly for now. It would be interesting to know if there is any way to detect these kinds of failures.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting the following error when trying to add some data from myXml.xml to
I'm trying to add some error checking inside my PHP script. Is it valid
I was trying to add some custom error messages to a form like this
I'm trying to add some text to a listBox in a form, from another
I've been trying to add some selected items from a multi-select listbox on my
I'm trying to add some code in a presentation made with LaTex. I used
I'm trying to add some extended error codes to the event log but I
I am trying to add some existing functionality to a site that uses jQuery
I'm trying to add some contacts from an xml file which have been serialize
I am trying to add some administration scripts to a Zend Framework project, that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.