Changing parameters through SMS API advice (SIM800L)

Thread Starter

zazas321

Joined Nov 29, 2015
891
Hello. I am using SIM800L module and for this project I need to be able to configure various program settings such as:

Delay time
Temperature_high
Temperature_low
and others....

First of all, I must configure the SIM800 modem to be able to receive SMS texts and route them to the USART:
Code:
void configure_sms_mode()
{
    SerialAT.println("AT+CMGF=1");
    modem.waitResponse();
    // 2ND OPTION 1 - save messages in buffer
    // 2nd option 2 - route messages to usart
    SerialAT.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
    modem.waitResponse();
    Serial.println("waiting for response complete");
}
In my void loop I can check what the sim800 modem is saying:
Code:
void loop()
{
    if (SerialAT.available()) {
      Serial.write(SerialAT.read());
    }
    if (Serial.available()) {
      SerialAT.write(Serial.read());
    }
}
The serial monitor output:

Code:
07:43:43.702 -> waiting for response complete
07:43:44.654 ->
07:43:44.654 -> Call Ready
07:43:45.401 ->
07:43:45.401 -> SMS Ready
07:43:50.677 ->
07:43:50.677 -> *PSUTTZ: 2021,7,23,4,43,49,"+12",1
07:43:50.677 ->
07:43:50.677 -> DST: 1
07:43:52.784 ->
07:43:52.784 -> *PSUTTZ: 2021,7,23,4,43,52,"+12",253
07:43:52.784 ->
07:43:52.784 -> DST: 253
07:43:52.784 ->
07:43:52.784 -> +CIEV: 10,"24601","Telia LT","Telia LT", 0, 0
The next step for me is to be able to store the messages to the buffer. That way, I can receive an SMS message and parse it how I want. I have developed a function to check whether there is Serial data available, if so, store the chars to the buffer one by one until the end of serial. However, it does not work as expected. It seems to work very unreliably. Could it be because that it detects null or end line characters and appends it to my array. And once my array detects null characters it thinks that its the end of this message? Please check the serial monitor below the read_SMS_data() function:

Code:
char full_message[50];
byte index5;


void read_SMS_data(){
    if(SerialAT.available() > 0){
        index5 = 0;
        while(SerialAT.available() > 0)
        {
            char inChar = SerialAT.read();
            full_message[index5] = inChar;
            index5++;

        }
        Serial.print("full message = ");
        Serial.println(full_message);
    }
}

Code:
07:50:28.142 -> waiting for response complete
07:50:29.121 -> full message =

07:50:29.121 -> full message =
07:50:29.121 ->
07:50:29.121 -> full message = C
07:50:29.121 -> full message = a
07:50:29.121 -> full message = l
07:50:29.121 -> full message = l
07:50:29.121 -> full message = 
07:50:29.121 -> full message = R
07:50:29.121 -> full message = eady
07:50:29.121 ->
07:50:29.872 -> full message =
ady
07:50:29.872 ->
07:50:29.872 -> full message =
07:50:29.872 -> ady
07:50:29.872 ->
07:50:29.872 -> full message = Sady
07:50:29.872 ->
07:50:29.872 -> full message = Mady
07:50:29.872 ->
07:50:29.872 -> full message = Sady
07:50:29.872 ->
07:50:29.872 -> full message =  ady
07:50:29.872 ->
07:50:29.872 -> full message = Ready
07:50:29.872 ->
07:50:29.872 -> full message =
07:50:29.872 -> ady
07:50:29.872 ->
07:50:33.606 -> full message =
07:50:33.606 -> ady
07:50:33.606 ->
07:50:33.606 -> full message =
07:50:33.606 ->
07:50:33.606 -> ady
07:50:33.606 ->
07:50:33.606 -> full message = *
07:50:33.606 -> ady
07:50:33.606 ->
07:50:33.606 -> full message = P
07:50:33.606 -> ady
07:50:33.606 ->
07:50:33.606 -> full message = S
07:50:33.606 -> ady
07:50:33.606 ->
07:50:33.606 -> full message = U
07:50:33.606 -> ady
07:50:33.606 ->
07:50:33.606 -> full message = TTZ:
07:50:33.606 ->
07:50:33.606 -> full message = 2021,7,23,4,50,32,"+12",1
07:50:33.606 -> full message =
07:50:33.606 ->
07:50:33.606 -> DST: 1
07:50:33.606 -> 50,32,"+12",1
07:50:35.566 -> full message =
07:50:35.566 ->
07:50:35.566 -> DST: 1
07:50:35.566 -> 50,32,"+12",1
07:50:35.566 -> full message =
07:50:35.566 ->
07:50:35.566 ->
07:50:35.566 -> DST: 1
07:50:35.566 -> 50,32,"+12",1
07:50:35.566 -> full message = *
07:50:35.566 ->
07:50:35.566 -> DST: 1
07:50:35.566 -> 50,32,"+12",1
07:50:35.566 -> full message = P
07:50:35.566 ->
07:50:35.566 -> DST: 1
07:50:35.566 -> 50,32,"+12",1
07:50:35.566 -> full message = SUTTZ: 2021,7,23,4,50,35,"+12",253
07:50:35.566 ->
07:50:35.566 -> DS
07:50:35.566 -> full message = T: 253
07:50:35.566 ->
07:50:35.566 -> +CIEV: 10,"24601","Telia LT","Telia LT", 0, 0
07:50:35.566 ->
Please suggest a way to solve this issue? How can I read messages properly and store them to the buffer in a proper way?
 
Last edited:

Thread Starter

zazas321

Joined Nov 29, 2015
891
I have decided to print ASCI values for each character maybe that would give me a clue what is happening. However, now I am even more unsure. It seems that by adding an additional print statement, the full message array is different from what it was before:
Code:
char full_message[50];
byte index5;

void read_SMS_data(){
    if(SerialAT.available() > 0){
        index5 = 0;
        while(SerialAT.available() > 0)
        {
            char inChar = SerialAT.read();
            Serial.print("ASCI character = ");
            Serial.println( inChar, DEC );
            full_message[index5] = inChar;
            index5++;
        }
        Serial.print("full message = ");
        Serial.println(full_message);
    }
}
Code:
07:56:54.838 -> waiting for response complete
07:56:55.868 -> ASCI character = 13
07:56:55.868 -> full message =

07:56:55.868 -> ASCI character = 10
07:56:55.868 -> full message =
07:56:55.868 ->
07:56:55.868 -> ASCI character = 67
07:56:55.868 -> full message = C
07:56:55.868 -> ASCI character = 97
07:56:55.868 -> ASCI character = 108
07:56:55.868 -> ASCI character = 108
07:56:55.868 -> ASCI character = 32
07:56:55.868 -> ASCI character = 82
07:56:55.868 -> ASCI character = 101
07:56:55.868 -> ASCI character = 97
07:56:55.868 -> ASCI character = 100
07:56:55.868 -> ASCI character = 121
07:56:55.868 -> ASCI character = 13
07:56:55.868 -> ASCI character = 10
07:56:55.868 -> full message = all Ready
07:56:55.868 ->
07:56:56.618 -> ASCI character = 13
07:56:56.618 -> full message =
ll Ready
07:56:56.618 ->
07:56:56.618 -> ASCI character = 10
07:56:56.618 -> full message =
07:56:56.618 -> ll Ready
07:56:56.618 ->
07:56:56.618 -> ASCI character = 83
07:56:56.618 -> full message = Sll Ready
07:56:56.618 ->
07:56:56.618 -> ASCI character = 77
07:56:56.618 -> ASCI character = 83
07:56:56.618 -> ASCI character = 32
07:56:56.618 -> ASCI character = 82
07:56:56.618 -> ASCI character = 101
07:56:56.618 -> ASCI character = 97
07:56:56.618 -> ASCI character = 100
07:56:56.618 -> ASCI character = 121
07:56:56.618 -> ASCI character = 13
07:56:56.618 -> ASCI character = 10
07:56:56.618 -> full message = MS Ready
07:56:56.618 ->
07:56:56.618 ->
07:57:01.539 -> ASCI character = 13
07:57:01.539 -> full message =
S Ready
07:57:01.539 ->
07:57:01.539 ->
07:57:01.539 -> ASCI character = 10
07:57:01.539 -> full message =
07:57:01.539 -> S Ready
07:57:01.539 ->
07:57:01.539 ->
07:57:01.539 -> ASCI character = 42
07:57:01.539 -> full message = *S Ready
07:57:01.539 ->
07:57:01.539 ->
07:57:01.539 -> ASCI character = 80
07:57:01.539 -> ASCI character = 83
07:57:01.539 -> ASCI character = 85
07:57:01.539 -> ASCI character = 84
07:57:01.539 -> ASCI character = 84
07:57:01.539 -> ASCI character = 90
07:57:01.539 -> ASCI character = 58
07:57:01.539 -> ASCI character = 32
07:57:01.539 -> ASCI character = 50
07:57:01.539 -> ASCI character = 48
07:57:01.539 -> ASCI character = 50
07:57:01.539 -> ASCI character = 49
07:57:01.539 -> ASCI character = 44
07:57:01.539 -> ASCI character = 55
07:57:01.539 -> ASCI character = 44
07:57:01.539 -> ASCI character = 50
07:57:01.539 -> ASCI character = 51
07:57:01.539 -> ASCI character = 44
07:57:01.586 -> ASCI character = 52
07:57:01.586 -> ASCI character = 44
07:57:01.586 -> ASCI character = 53
07:57:01.586 -> ASCI character = 55
07:57:01.586 -> ASCI character = 44
07:57:01.586 -> ASCI character = 48
07:57:01.586 -> ASCI character = 44
07:57:01.586 -> ASCI character = 34
07:57:01.586 -> ASCI character = 43
07:57:01.586 -> ASCI character = 49
07:57:01.586 -> ASCI character = 50
07:57:01.586 -> ASCI character = 34
07:57:01.586 -> ASCI character = 44
07:57:01.586 -> ASCI character = 49
07:57:01.586 -> ASCI character = 13
07:57:01.586 -> ASCI character = 10
07:57:01.586 -> ASCI character = 13
07:57:01.586 -> ASCI character = 10
07:57:01.586 -> ASCI character = 68
07:57:01.586 -> ASCI character = 83
07:57:01.586 -> ASCI character = 84
07:57:01.586 -> ASCI character = 58
07:57:01.586 -> ASCI character = 32
07:57:01.586 -> ASCI character = 49
07:57:01.586 -> ASCI character = 13
07:57:01.586 -> ASCI character = 10
07:57:01.586 -> full message = PSUTTZ: 2021,7,23,4,57,0,"+12",1
07:57:01.586 ->
07:57:01.586 -> DST: 1
07:57:01.586 ->
07:57:03.687 -> ASCI character = 13
07:57:03.687 -> full message =
SUTTZ: 2021,7,23,4,57,0,"+12",1
07:57:03.687 ->
07:57:03.687 -> DST: 1
07:57:03.687 ->
07:57:03.687 -> ASCI character = 10
07:57:03.687 -> full message =
07:57:03.687 -> SUTTZ: 2021,7,23,4,57,0,"+12",1
07:57:03.687 ->
07:57:03.687 -> DST: 1
07:57:03.687 ->
07:57:03.687 -> ASCI character = 42
07:57:03.687 -> ASCI character = 80
07:57:03.687 -> ASCI character = 83
07:57:03.687 -> ASCI character = 85
07:57:03.687 -> ASCI character = 84
07:57:03.687 -> ASCI character = 84
07:57:03.687 -> ASCI character = 90
07:57:03.687 -> ASCI character = 58
07:57:03.687 -> ASCI character = 32
07:57:03.687 -> ASCI character = 50
07:57:03.687 -> ASCI character = 48
07:57:03.687 -> ASCI character = 50
07:57:03.687 -> ASCI character = 49
07:57:03.687 -> ASCI character = 44
07:57:03.687 -> ASCI character = 55
07:57:03.687 -> ASCI character = 44
07:57:03.687 -> ASCI character = 50
07:57:03.733 -> ASCI character = 51
07:57:03.733 -> ASCI character = 44
07:57:03.733 -> ASCI character = 52
07:57:03.733 -> ASCI character = 44
07:57:03.733 -> ASCI character = 53
07:57:03.733 -> ASCI character = 55
07:57:03.733 -> ASCI character = 44
07:57:03.733 -> ASCI character = 51
07:57:03.733 -> ASCI character = 44
07:57:03.733 -> ASCI character = 34
07:57:03.733 -> ASCI character = 43
07:57:03.733 -> ASCI character = 49
07:57:03.733 -> ASCI character = 50
07:57:03.733 -> ASCI character = 34
07:57:03.733 -> ASCI character = 44
07:57:03.733 -> ASCI character = 50
07:57:03.733 -> ASCI character = 53
07:57:03.733 -> ASCI character = 51
07:57:03.733 -> ASCI character = 13
07:57:03.733 -> ASCI character = 10
07:57:03.733 -> ASCI character = 13
07:57:03.733 -> ASCI character = 10
07:57:03.733 -> ASCI character = 68
07:57:03.733 -> ASCI character = 83
07:57:03.778 -> ASCI character = 84
07:57:03.778 -> ASCI character = 58
07:57:03.778 -> ASCI character = 32
07:57:03.778 -> ASCI character = 50
07:57:03.778 -> ASCI character = 53
07:57:03.778 -> ASCI character = 51
07:57:03.778 -> ASCI character = 13
07:57:03.778 -> ASCI character = 10
07:57:03.778 -> ASCI character = 13
07:57:03.778 -> ASCI character = 10
07:57:03.778 -> ASCI character = 43
07:57:03.778 -> ASCI character = 67
07:57:03.778 -> ASCI character = 73
07:57:03.778 -> ASCI character = 69
07:57:03.778 -> ASCI character = 86
07:57:03.778 -> ASCI character = 58
07:57:03.778 -> ASCI character = 32
07:57:03.778 -> ASCI character = 49
07:57:03.778 -> ASCI character = 48
07:57:03.778 -> ASCI character = 44
07:57:03.778 -> ASCI character = 34
07:57:03.778 -> ASCI character = 50
07:57:03.778 -> ASCI character = 52
07:57:03.778 -> ASCI character = 54
07:57:03.778 -> ASCI character = 48
07:57:03.825 -> ASCI character = 49
07:57:03.825 -> ASCI character = 34
07:57:03.825 -> ASCI character = 44
07:57:03.825 -> ASCI character = 34
07:57:03.825 -> ASCI character = 84
07:57:03.825 -> ASCI character = 101
07:57:03.825 -> ASCI character = 108
07:57:03.825 -> ASCI character = 105
07:57:03.825 -> ASCI character = 97
07:57:03.825 -> ASCI character = 32
07:57:03.825 -> ASCI character = 76
07:57:03.825 -> ASCI character = 84
07:57:03.825 -> ASCI character = 34
07:57:03.825 -> ASCI character = 44
07:57:03.825 -> ASCI character = 34
07:57:03.825 -> ASCI character = 84
07:57:03.825 -> ASCI character = 101
07:57:03.825 -> ASCI character = 108
07:57:03.825 -> ASCI character = 105
07:57:03.825 -> ASCI character = 97
07:57:03.825 -> ASCI character = 32
07:57:03.825 -> ASCI character = 76
07:57:03.825 -> ASCI character = 84
07:57:03.825 -> ASCI character = 34
07:57:03.825 -> ASCI character = 44
07:57:03.825 -> ASCI character = 32
07:57:03.825 -> ASCI character = 48
07:57:03.825 -> ASCI character = 44
07:57:03.825 -> ASCI character = 32
07:57:03.825 -> ASCI character = 48
07:57:03.825 -> ASCI character = 13
07:57:03.825 -> ASCI character = 10
07:57:03.825 -> full message = *PSUTTZ: 2021,7,23,4,57,3,"+12",253
07:57:03.825 ->
07:57:03.825 -> DST: 253
07:57:03.825 ->
07:57:03.825 -> +CIEV: 10,"24601","Telia LT","Telia LT", 0, 0
07:57:03.825 -> ⸮
 
Top