Auto read new SMS

Adafruit cellular platform - SMS and IoT over celluar

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Vaas
 
Posts: 21
Joined: Mon Jun 26, 2017 5:10 am

Auto read new SMS

Post by Vaas »

Hello,

I try to make a function to auto read the SMS if the FONA received one.
Actually I try to acquire a SMS, in a 2 sec loop (cadenced by millis()) but it does not work.
I don't know how to read only NEW SMS ? Not all, not only one, but just if a new SMS is receive.

Has anyone ever tried to do this with the FONA ?

Thanks for the help :)

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Auto read new SMS

Post by adafruit_support_rick »

The FONA_SMS_Response example in the library shows how to do it

User avatar
Vaas
 
Posts: 21
Joined: Mon Jun 26, 2017 5:10 am

Re: Auto read new SMS

Post by Vaas »

Yes, my bad, sorry.
I successfully received SMS in my loop cadenced by millis().
I saw in the FONA library a function who start an interruption when a SMS is received. Do you have an example too ?

I saw here an example but we always check the pin, so it's not a real interruption:
https://learn.adafruit.com/open-sesame- ... k/software

Is it possible to make an event with the interrupt function in the FONA library ?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Auto read new SMS

Post by adafruit_support_rick »

We don't have any examples of this. But I think what you would do is to call fona.setSMSInterrupt(1); in setup. This will enable the Fona to trigger the ring interrupt (RI) line when an SMS is received. You would then attach an interrupt routine to the digital pin that Fona pin RI is attached to.

User avatar
Vaas
 
Posts: 21
Joined: Mon Jun 26, 2017 5:10 am

Re: Auto read new SMS

Post by Vaas »

The interrupt works, but I have another problem.
When I call my function to acquire new SMS (see below), it's working if I call it from my main loop. But when I call from the interrupt it is always stuck in : "Could not read #SMS"

Code: Select all

bool acquireSMS(void)
{
  char replybuffer[255];
  int8_t smsnum = fona.getNumSMS();
  bool acquireSuccess = false;

  if (smsnum < 0)
  {
    Serial.println(F("Could not read # SMS"));
    return false;
  }
  else
  {
    Serial.print(smsnum); 
    Serial.println(F(" SMS's on SIM card!"));
  }
  
  if (smsnum == 0)
    return;

  // there's an SMS!
  uint8_t n = 1;
  while (true)
  {
     uint16_t smslen;
     char sender[25];
     
     Serial.println(F("Reading SMS #")); Serial.println(n);
     uint8_t len = fona.readSMS(n, replybuffer, 250, &smslen); // pass in buffer and max len!
     
     // if the length is zero, its a special case where the index number is higher
     // so increase the max we'll look at!
     if (len == 0)
     {
        Serial.println(F("[empty slot]"));
        n++;
        continue;
     }

     // failed to get the sender?
     if (! fona.getSMSSender(n, sender, sizeof(sender)))
       sender[0] = 0;
      
     Serial.print(F("***** SMS #")); Serial.print(n);
     Serial.print(" ("); Serial.print(len); Serial.println(F(") bytes *****"));
     Serial.println(replybuffer);
    // acquireSuccess = processSMS(String(replybuffer));
     Serial.print(F("From: ")); Serial.println(sender);
     Serial.println(F("*****"));
     break;
  }  
  fona.deleteSMS(n);
  return acquireSuccess;
}

This is my interrupt code :

Code: Select all

void interruptSMS()
{
  // RI pin went low, SMS received?
  Serial.println(F("RI went low"));
  // Try to acquire a SMS
  if(acquireSMS())
    Serial.println(F("SMS action SUCCESS"));
  else
    Serial.println(F("SMS action FAIL"));
}
And the result in the console (the smsnum = -1):
Attachments
Interrupt.PNG
Interrupt.PNG (1.88 KiB) Viewed 390 times

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Auto read new SMS

Post by adafruit_support_rick »

Yeah, that won't work. First of all, you shouldn't be doing that much work in an ISR. They should be as fast as possible, since other interrupts will be blocked while you are processing your interrupt.

And that's the reason why this doesn't work. Software Serial depends on interrupts for receiving data. Since you are in an ISR, the response from the Fona is blocked. The call to getNumSMS times out instead, and returns a -1.

User avatar
Vaas
 
Posts: 21
Joined: Mon Jun 26, 2017 5:10 am

Re: Auto read new SMS

Post by Vaas »

Oh ok, I did not know the -1 meaning, I'll just change a flag in the ISR so, thanks you :)

User avatar
rishi_959
 
Posts: 3
Joined: Tue Jul 25, 2017 2:55 am

Re: Auto read new SMS

Post by rishi_959 »

Hi there! I 'm using SIM5320E GSM http://www.tinyosshop.com/3g-gprs-gsm-s ... o-sim5320e and I can't read the SMS using the FONA_SMS_Response.ino program. I have changed the Tx-2 and Rx-3 in the initailization but still can't read the SMS. But using the FONAtest.ino I'm able to send the SMS. Can you please help me?
My serial monitor response:
FONA SMS caller ID test
Initializing....(May take 3 seconds)
Attempting to open comm with ATs
---> AT
<--- OK
---> ATE0
<--- OK
---> ATE0
<--- OK
---> AT+CVHU=0
<--- OK
---> ATI
<--- Manufacturer: SIMCOM INCORPORATED
Model: SIMCOM_SIM5320E
Revision: SIM5320E_V1.5

+GCAP: +CGSM,+DS,+ES

OK

FONA is OK
---> AT+GSN
<--- 861311008040262

FONA Ready

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Auto read new SMS

Post by adafruit_support_rick »

That sketch doesn't work on the 3G. As I recall, I tried to get it working, but had no luck. I can have another look at it if I get a chance...

smgs
 
Posts: 194
Joined: Thu Dec 10, 2015 7:25 am

Re: Auto read new SMS

Post by smgs »

Might have to look at the library, if I get a minute later I'll have a look through the AT commands that the library is using to see why it isn't reading the messages in the slot and replying. This is the output from when I tried the sketch out.

Code: Select all

FONA SMS caller ID test
Initializing....(May take 3 seconds)
Attempting to open comm with ATs
	<--- 
	---> AT
...
	<--- START
	---> AT
...
	---> ATE0
...
	<--- OK
	---> AT+CVHU=0
	<--- +CPIN: READY
	---> ATI
	<--- Manufacturer: SIMCOM INCORPORATED
Model: SIMCOM_SIM5320E
Revision: SIM5320E_V1.5
IME: <Numbers>
+GCAP: +CGSM,+DS,+ES

OK

SMS DONE

FONA is OK
	---> AT+GSN
	<--- 861311004420013
SIM card IME: <numbers>
FONA Ready

PB DONE
⸮
START

+STIN: 25

+CPIN: READY

SMS DONE

PB DONE

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Auto read new SMS

Post by adafruit_support_rick »

I've fixed SMS on the 3G and the FONA_SMS_Response example. Get the latest version of the Fona library (1.3.3 or greater) and try it out!

Locked
Please be positive and constructive with your questions and comments.

Return to “FONA”