Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

SMS can send OUT but not receive #2

Closed
avonree opened this issue Mar 31, 2021 · 5 comments
Closed

SMS can send OUT but not receive #2

avonree opened this issue Mar 31, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@avonree
Copy link

avonree commented Mar 31, 2021

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

  • Comment out MKRGSM.h and use provided defines.h file
  • defines.h file has 2 lines uncommented, required to make connect to GSM to be successful
    (code snippet below, but these are the two lines)
    #define UBLOX_USING_RESET_PIN true
    #define UBLOX_USING_LOW_POWER_MODE true
  • defaults in defines.h dont require changing as they are for the MKRGSM U201 UBLOX.
  • addition of baudRateSerialGSM to set baud rate per example provided
  • modify gsmAccess.begin per example to include baudRateSerialGSM and PINNUMBER
  • (PINNUMBER is null in my code as am using Hologram SIM)

Expected behavior

  • expect to send an SMS and be able to receive an SMS
  • existing working code sends/receives

Actual behavior

  • send OUT works as previously
  • receive (sms.available()) always returns a 0 (should return a non zero value when text is ready to be sms.read()
  • existing code sends/receives, so not a hardware issue
  • existing code send/receives from iphone or hologram 'messaging' so likely not a provider issue
  • when swap back to existing code (comment out defines, uncomment mkr, adjust gsmAccess) then texts previously sent to mkr for testing are then received (likely as provider buffers)

Information

  • using existing IDE or beta - same results
  • MKRGSM UBLOX SARA U201
  • hologram SIM (to test, will need a MKRGSM and a SIM (and account with provider, SIM active, etc)

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
Copy link
Owner

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
Copy link
Owner

khoih-prog commented Apr 1, 2021

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

@khoih-prog khoih-prog added the bug Something isn't working label Apr 1, 2021
@avonree
Copy link
Author

avonree commented Apr 1, 2021 via email

@khoih-prog
Copy link
Owner

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
Copy link
Author

avonree commented Apr 1, 2021 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants