Code Monkey home page Code Monkey logo

khoih-prog / gsm_generic Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 7.0 1.3 MB

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.

License: GNU General Public License v3.0

C 34.07% C++ 65.71% Shell 0.22%
gsm gprs lte samd21 samd51 nrf52 gsm-modem rp2040 stm32 u-blox

gsm_generic's People

Contributors

khoih-prog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gsm_generic's Issues

SMS can send OUT but not receive

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); 
    } 
}

TOBY-L2 support issue

Arduino IDE version: 1.8.16
MCU board : Adafruit Feather M0 Adalogger
OS : Windows 10 20H2

Hi !
I tried to use the lib with a TOBY-L210 modem and it doesn't work well.

I used it on a Adafruit Feather M0 Adalogger with the SendSMS example.
I changed the the defines in order to select the Generic UBLOX modem and also selected the right serial ports
for both Debug and GSM.

Everything is working well with the LISA-U200 but as soon as I replace it with the TOBY-L210, nothing works.

The first obvious issue is the fact that the lib doesn't wait long enough for the modem to reboot because, for some
reason, my TOBY-L2 takes about 18 seconds to reboot (not absolutely sure that's normal but is seems like it is).

The second issue i found pretty quickly is that the TOBY-L2 modems does not support AT commands terminated
by both CR and LF for the reason that is written in the first note in the part 1.3.3 of the AT Commands Manual.

After kind of patching these two issues, the sketch seemed to begin correctly until it reached the AT+CMGF=1 command.
The modem's response to this command doesn't seem making any sense to me and it changes everytime.
After that response, the program gets stuck at this point.

At this point I'm kind of confused on what's going wrong.

Here is an example of console output (with debug level = 6) until the program gets stuck :


Starting SendSMS on SAMD_ZERO
GSM_Generic v1.6.1
[GSM] begin: UART baud = 9600
AT+CFUN=16
[GSM] begin: reset error
[GSM] GSM::begin: _gsmData._state = GSM_ERROR
Not connected
[GSM] begin: UART baud = 9600
AT+CFUN=16
AT+CFUN=16

OK
AT
AT

OK
AT
AT

OK
[GSM] begin: Check autosense
AT
AT

OK
[GSM] begin: Modem OK
AT+CPIN?
AT+CPIN?

+CPIN: SIM PIN

OK
AT+CPIN="0294"
AT+CPIN="0294"

OK
AT+CMGF=1
U*
|

An other example of weird response (note that, this time, the CMGF is ok but the next ccommand is f*cked up) :

AT+CMGF=1
AT+CMGF=1

OK
AT+UDCONF=1,1
URA"D1

I tried sending the AT+CMGF=1 command by hand using a serial terminal in a similar context (after sending
all the preceding commands) and I don't get this kind of weird response.

Do someone have an idea of what's happening ?
Is it intended to add proper support for TOBY modems ?

Add support for SIMCom LTE Module SIM7600E

Describe the solution you'd like
Dear contributors of GSM_Generic Repository. Thanks for your effort on creating and maintaining it. May I ask for an extension to support SIMCom LTE Module SIM7600E?
Many thanks in advance.

sync GSM Client's TCP connection's time server with esp32's onboard clock

Is your feature request related to a problem? Please describe.
configTime is a part of ESP32 core and relies on ESP32's own WiFI to be connected for it to work. When connecting over a GSM module, WiFi connections are not necessary, but that means that ESP32 can't use UDP on WiFi to sync with NTP, since wifi is not connected. Deepsleep or other time related modes wont work without onboard clock.

Describe the solution you'd like
Connect GSM Client's TCP connection to get the time from a TCP source (like the NIST daytime server) and then set the onboard clock manually based on the time returned.

Describe alternatives you've considered
using RTC module, isn't ideal
NTP AT command for the sim7000, in some cases, it may not be supported

Additional context
vshymanskyy/TinyGSM#357
Azure/azure-iot-sdk-c#1914
https://forum.arduino.cc/index.php?topic=88389.0
https://simcom.ee/documents/SIM7000E/SIM7000%20Series_AT%20Command%20Manual_V1.03.pdf

UBLOX LARA support

I am not sure if this is a bug or not supported case, here are the details.

I am using a custom board designed with MKR GSM 1400 in mind so for any purpose it is acting as the original MKR. The board works well with MKRGSM library and the original SARA-U201 module. however, when replacing the SARA with a UBLOX pin compatible LARA-R281 02B-00 module, I can't make it to work with GSM_Generic.

My end goal is to operate the LARA in LTE mode.

I have tested the hardware and it works fine, AT commands can be sent and even GSM Begin works using the original library so I believe the hardware is not the issue.

After trying several GSM_Generic examples I can only get to the point where the Serial says [GSM] begin: UART baud = 115200 and there it stops.

So I tested GSM_Generic on an original Arduino MKR GSM 1400 and got the following repeated output:

Starting GSMWebClient on SAMD MKRGSM1400
GSM_Generic v1.5.0
[GSM] begin: UART baud = 115200
AT+CFUN=16
[GSM] begin: reset error
[GSM] GSM::begin: _gsmData._state = GSM_ERROR
Not connected

I should add that the lib didn't work also on my custom board with SARA

Anyways thanks for the library and of course any hint is mostly appreciated.

Add PEM to DER converter tool to get certificates in HEX format

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when searching for a toll and still searching.
I had the problem to convert existing PEM certificates (keys also) to DER format. Thanks there are online web tools for it but it gives it all the time in DER file format which is encrypted. So, I have the problem to get the DER certs in HEX specially in uint8_t format.

Describe the solution you'd like
Maybe there is a tool (I am also searching for it) which can convert PEM -> DER -> uint8_t

Describe alternatives you've considered
DER -> uint8_t

I hope this feature will be added. I am currently searching for this kind of tool. When I find one, I will test it and give a feedback to it.

Lib fails to connect on MKR1400

Describe the bug

Testing on MKR 1400 fails:

Starting GSMScanNetworks on SAMD MKRGSM1400
GSM_Generic v1.4.0
GSM networks scanner
[GSM] begin: UART baud = 115200
AT+CFUN=16
[GSM] begin: reset error

Steps to Reproduce

Using the default network scanner with MKRGSM works.

Using the default network scanner with GSM_Generic fails.

Expected behavior

Connection to module and GSM networks reported.

Information

Please ensure to specify the following:

  • Arduino IDE version (e.g. 1.8.13) or Platform.io version

Platform IO 5.1.1 - 3.3.4

SAMD21 - MKR 1400

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.