How to code GSM-GPS Click Sim808 using STM32F446RE?

Yes , I tried it out again and found that it is now working, it’s now capable of giving me the actual location . But I have been trying to use the functions to send sms but not working.

I’m still checking it up to see how I can use the SMS function.

Good day Sir, please I have tried something out here using the AT command. It says successful but I don’t receive any message. I believe I miss some code . Find it below please

#include "mbed.h"

#define   GSM_DEFAULT_BAUD_RATE   115200

UARTSerial *_serial;
ATCmdParser *_parser;

DigitalOut RST(D3, 1);  //POWERKEY
DigitalIn AN(D4);       //STAT

int main()
{
    printf("\nATCmdParser");
    
    printf("Trying to power up the module!\n");
    while (AN.read() == 0)
    {   
        printf("Trying to power up!\n");
        RST.write(0);
        wait(1.5);
        RST.write(1);
        wait(2);
    }
    printf("Modul is powered!\n");
    
    _serial = new UARTSerial(D8, D2, GSM_DEFAULT_BAUD_RATE);
    _parser = new ATCmdParser(_serial);
    _parser->debug_on( 1 );
    _parser->set_delimiter( "\r\n" );  
    
    _parser->send("AT+CMGF=1"); 
    wait(1);
    _parser->send("AT+CSMP?");     
    
    while (1){
     
     wait(2); 
    _parser->send(" AT+CMGS='+233556128170'> Hello Wrld <Ctrl+Z>"); 
    
    
    if( _parser->recv("OK")){
        printf("\nATCmdParser: Message was sent successfully");
    } else { 
        printf("\nATCmdParser: Message was not sent");        
    }
    wait(3);
        
    }      
}

Sir please, Kindly find attached the link to all files of the above code. I have tried to used some of the SMS handling function to send the SMS but still not working. I’m sure I’m missing something, could you please check and see how we can go about the GSM using those SMS functions in the library ?
By the way the GPS is working .
GSM-GPS code

Thanks a lot .

Just try to send it in sequence like here.

"AT+CSCS=\"GSM\""
"AT+CMGF=1"
"AT+CMGS=\"sim_number\"\n Hello"

I already check it but you need a correct sequence of functions. And I not found an documentation for that.
The library probably is rework of this one.

BR, Jan

I don’t know how far you are right now, but for easeally play with AT commands you can try code bellow.

Code
#include "mbed.h"

#define   GSM_DEFAULT_BAUD_RATE   115200

UARTSerial *_serial;
ATCmdParser *_parser;

DigitalOut RST(D3, 1);  //POWERKEY
DigitalIn AN(D4);       //STAT

int main()
{
    printf("\nATCmdParser");
    
    printf("Trying to power up the module!\n");
    while (AN.read() == 0)
    {   
        printf("Trying to power up!\n");
        RST.write(0);
        wait(1.5);
        RST.write(1);
        wait(2);
    }
    printf("Modul is powered!\n");
    
    _serial = new UARTSerial(D8, D2, GSM_DEFAULT_BAUD_RATE);
    _parser = new ATCmdParser(_serial);
    _parser->debug_on( 1 );
    _parser->set_delimiter( "\r\n" );  
    
    char inBuffer[50],response[200];
    while(1){
        scanf("%s[^\n]",inBuffer);
        _parser->send("%s",inBuffer);
        _parser->read(response, sizeof(response));
        printf("Response: %s\n",response);
        memset (inBuffer,0,sizeof(inBuffer));
        memset (response,0,sizeof(response));
    }   
}

With this code you can try to type some At commands via PC terminal and you are receiving response in a moment.So you will not need recompile the program for every change in At commands sequence or settings.

BR, Jan

Hello Sir
I do appreciate your help, I have been trying over and over to send the SMS but with no good response. Wanted to try more possibilities before coming back to you again.

Thanks a lot , will try out your code as well.
Will surely come back :sweat_smile: .

Thanks SIR .

Good day Sir
Trust you are doing good .
Please I have written this code below. The SMS part runned well when the sim808 was detected but , haven’t received any message. So I decided to check the status of the network, and found out that my sim card does not really connect to the network. Is there a way to activate the sim card so it connects to the network ?

if(SIM808Success == 1) {
pc.printf(“\nSIM808 detected successfully…\n”);

    int n = gps.getNetworkStatus();
    
      pc.printf("N: %zu", n);
    
    
      
    // send an SMS!
    char sendto[21], message[141];   
    sendto[21] = '+233239520891';   
    message[141] = 'Hey Sam';           
    printf("\n Send to ...");       
    pc.printf(sendto);
    pc.printf("Type out one-line message (140 char): ");
    pc.printf(message);
    if (!gps.sendSMS(sendto, message)) {
      pc.printf("Failed");
    } else {
      pc.printf("Sent!");
    }
    
}

THANK YOU .

Hi there,

and what an error code did you received?

I am also not sure the part above is ok. It maybe is more efficient something like below.

char sendto[] = "+233239520891";
char message[] = "Hey Sam";
// or
char sendto[21] ;
memcpy ( sendto, "+233239520891", strlen("+233239520891")+1 );
char message[144];
memcpy ( message, "Hey Sam", strlen("Hey Sam")+1 );


BR, Jan

Thanks Sir , I’m gonna try it out …

Since the code worked but did not receive any message, I decided to check the status of the network and I got 4 and later 2 from this code line pc.printf(“N: %zu”, n); So per arduino code below (which is part of one of the link you gave me )

if (n == 0) Serial.println(F(“Not registered”));
if (n == 1) Serial.println(F(“Registered (home)”));
if (n == 2) Serial.println(F(“Not registered (searching)”));
if (n == 3) Serial.println(F(“Denied”));
if (n == 4) Serial.println(F(“Unknown”));
if (n == 5) Serial.println(F(“Registered roaming”));
break;

4 : Means Unknown and 2: Not registered . So I concluded that my SIM CARD is not connecting to network . So was wondering if we there is a way to activate it B4 I can send my message.

Hello,

datasheet of AT commands, page 91 contains description of CREG AT commad. That is the command what the getNetworkStatus() (line 203) uses.

2 Not registered, but MT is currently searching a new
operator to register to

description of your source is similar, the important word can be searching

So from my point of view, you need to give it more time to establish the connection.

Replace this

int n = gps.getNetworkStatus();
pc.printf("N: %zu", n);

with something like this or similar

pc.printf(“Network status...\n”);
while((int n =  gps.getNetworkStatus()) != 1 )
{
   if (n == 0) pc.printf(“Not registered\n”);
   if (n == 1) pc.printf(“Registered (home) \n”);
   if (n == 2) pc.printf(“Not registered (searching)\n”);
   if (n == 3) pc.printf(“Denied\n”);
   if (n == 4) pc.printf(“Unknown\n”);
   if (n == 5) pc.printf(“Registered roaming\n”);
   wait(1);
}

Also if your SIM is protected with a PIN code then you need also gps.unlockSIM(char *pin); for unlock.

BR, Jan

Hello Sir , please it has finally worked , yesterday when I tried it . And that is exactly what you said , I gave it time to establish the connection then I used the SendSMS function to send the message and it was successful. I’m very grateful SIR for everything you have done. Thanks a million

But still not yet finished :sweat_smile: , Want now to retrieve missed calls numbers :sweat_smile: . that is the next challenge currently.
Will keep you inform please

Thanks again Sir .

Good day Sir , please trust you are doing good . Please do you have any idea of how I can convert unint_16 to char data type?

Thanks in advance …

BR, Jan

Ooh ok , thank you Sir .
So what will be the result if we print out the variable hi ? And what does variable lo becomes ? We don’t use it anymore ? . Still wondering how the conversion takes place with all these variable ?
Or which one of the variable can be considered as the real converted value of our unint16_t variable ?

Please come to the relevant topic, your new one.

BR, Jan

Ok Sir . Sorry for this …