khoih-prog / GSM_Generic

Enables GSM/GRPS network connection using the GSM/GPRS modules. Use this library to make/receive voice calls, to send and receive SMS using Generic GSM/GPRS modules, such as u-blox SARA-U201 module.This library also allows you to connect to internet through the GPRS networks. You can either use Web Clients and Servers.
GNU General Public License v3.0
16 stars 7 forks source link

SMS can send OUT but not receive #2

Closed avonree closed 3 years ago

avonree commented 3 years ago

Describe the bug

Existing sketch using MKRGSM.h sends/receives SMS. New lib has SMS OUT being received (by iphone) but INCOMING sms are not received.

Steps to Reproduce

Expected behavior

Actual behavior

Information

CODE below

// sms testing with new lib 
// change these depending on provider, SIM
const char GPRS_APN[]      = "hologram";
const char PINNUMBER[]     = "";
const char GPRS_LOGIN[]    = "";
const char GPRS_PASSWORD[] = "";

// #include "defines.h"    //  new 03.26 GSM info.  Used new GSM library. Dont include MKRGSM
// unsigned long baudRateSerialGSM  = 115200;

#include <MKRGSM.h>
GSM gsmAccess;  // (true);      // (true) enables debugger?
GSM_SMS sms;                    // For sending/receiving SMS
GSMLocation location;           // For location of boat (only avail via SMS command)
GPRS gprs;                      // data over connection
GSMScanner carrier;             // carrier and signal level (avail on SMS command and if lcd)

char senderNumber[20] = "+19058157009";    // input cell number +<areacoce><number> format for send

char stringOne[121];  

int checkSerial() {
  int c;
  String sTwo = "";
  int retval = 0;  // default to none

  if (sms.available()) {
    sms.remoteNumber(senderNumber, 20);
    Serial.print("sms avail");
    Serial.print(senderNumber);
    if (sms.peek() == '#') {
      Serial.println("Discarded SMS");
      sms.flush();
      return -1;
    }

    // Read message bytes and print them

    while ((c = sms.read()) != -1) {
      sTwo += char(c);
    }
    // Parse sTwo
    retval = 1;
    if (sTwo.equalsIgnoreCase("hello")) retval = 2;
    Serial.println(sTwo);
  }
  sms.flush();

  return retval;
}

void send_an_sms(char *outString) {
  int smsStatus;
  bool connected = false;
  Serial.print("DBG-sendsms: senderNumber = [");
  Serial.print(senderNumber);
  Serial.print(" ");
  Serial.print(outString);
  Serial.println("]");

  if (outString != "") { /// not null
      smsStatus = sms.beginSMS(senderNumber);
      sms.print(outString);
      sms.endSMS();
      Serial.print("..endSMS.done.");
  } 
}

bool connectGSM() {
  // copied from github and modified to fit.
  // https://github.com/arduino-libraries/MKRGSM/issues/66
  gprs.setTimeout(180000);
  gsmAccess.setTimeout(180000);

  boolean connected = false;
  while (!connected) {
    Serial.print("connectGSM:Begin GSM Access....");
    // swap out for testing new MKR GSM LIB 
    // if ((gsmAccess.begin(baudRateSerialGSM, PINNUMBER) == GSM_READY) &&
    if ((gsmAccess.begin() == GSM_READY) &&
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
      connected = true;
      Serial.println("... Success CR:");
      Serial.println(carrier.getCurrentCarrier());  
    }
    else {
      Serial.println("...failed - Not connected");
      delay(1000);
    }
  }
  return connected;
}

void setup() {

    Serial.begin(115200);   // 9600 

    while (!Serial) {
      ; // wait for serial port to connect. Needed for native USB port only
    }

    bool gsmConnected = connectGSM();
    Serial.print("GSM initialized and");
    if (gsmConnected) {
      Serial.println(" connected.");
      }
    else {
      Serial.println(" FAILED to connect. Please Re-start.");
    }

}

void loop() {
    // send some message via SMS
    strcpy(stringOne,"TEST OUT GOING");
    send_an_sms(stringOne);

    // check to see if anything on SMS
    Serial.print("Msg OUT send, now looping to see if receive anything");
    while (1) {
        int smsThere = checkSerial();  // checks if anything incoming
        Serial.print(smsThere);
        if (smsThere) {
          Serial.println("Got Something INCOMING !");
          Serial.print(" Val = ");
          Serial.print(smsThere);
          if (smsThere ==2) Serial.println(" Got an Hello!");   
        }
        delay(1000); 
    } 
}
khoih-prog commented 3 years ago

Hi @avonree

Thanks a lots for your impressive and informative bug report / description, which have been helping me a lots to find out and fix the bug.

The new release will be published by tomorrow and your contribution is appreciated. and will be noted.


Release v1.3.0

  1. Fix SMS receive bug
  2. Add ThingStream MQTTS (using PubSubClient) support. Check U-BLOX NINA B302 + GSM ACCESSING THINGSTREAM.IO (SSL)
khoih-prog commented 3 years ago

Hi @avonree

Thanks for your contribution which has been noted in Contributions and Thanks

The new GSM_Generic v1.3.0 has been published to fix the issue also with many more features

Please test and inform if the bug has been totally fixed. Impressive bug report from you will be always appreciated.


Major Release v1.3.0

  1. Fix SMS receive bug.
  2. Add option to load Root Certs only when necessary for SSL.
  3. Add ThingStream MQTT(S) support and example.
  4. Add UDP functions to permit specify host
  5. Add GSM_LOGATDEBUG macro to help debug AT-command related functions
  6. Add support to SoftwareSerial
  7. Fully tested on u-blox SARA-G350 modem and nRF52-based NINA_B302_ublox board
avonree commented 3 years ago

Great, thanks you. Just tested, working fine and dandy. Receiving sms ! I havent tested any other items as yet. The debug level 5 is really nice too !

j

On Wed, Mar 31, 2021 at 10:10 PM Khoi Hoang @.***> wrote:

Hi @avonree https://github.com/avonree

Thanks for your contribution which has been noted in Contributions and Thanks https://github.com/khoih-prog/GSM_Generic#contributions-and-thanks

The new GSM_Generic v1.3.0 https://github.com/khoih-prog/GSM_Generic/releases/tag/v1.3.0 has been published to fix the issue and also add many ore features

Please test and inform if the bug has been totally fixed. Impressive bug report from you will be always appreciated.

Major Release v1.3.0

  1. Fix SMS receive bug.
  2. Add option to load Root Certs only when necessary for SSL.
  3. Add ThingStream MQTT(S) support and example.
  4. Add UDP functions to permit specify host
  5. Add GSM_LOGATDEBUG macro to help debug AT-command related functions
  6. Add support to SoftwareSerial
  7. Fully tested on u-blox SARA-G350 modem and nRF52-based NINA_B302_ublox board

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/khoih-prog/GSM_Generic/issues/2#issuecomment-811585930, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATOQYXND2G7I6G3F6GV4BPTTGPIYFANCNFSM42E46BLA .

--


J.Egan 905 815 7009 (c)

khoih-prog commented 3 years ago

Thanks a lot. Glad to know it's OK now. More tests and bug reports are highly appreciated. Are you using MKRGSM 1400 board?

avonree commented 3 years ago

Yes, MKRGSM 1400. Currently on a proto board with a DHT1 temp/rh, a 5vdc-dc buck converter (from 12v), a few voltage dividers, timer circuit for low power management. Just doing up some fritzing. And lots of packaging/prep

On Wed, Mar 31, 2021 at 10:53 PM Khoi Hoang @.***> wrote:

Thanks a lot. Glad to know it's OK now. More tests and bug reports are highly appreciated. Are you using MKRGSM 1400 board?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/khoih-prog/GSM_Generic/issues/2#issuecomment-811599533, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATOQYXPLADSQMWSIVTGKT3DTGPNYDANCNFSM42E46BLA .

--


J.Egan 905 815 7009 (c)