Help ! Serial Monitor

Hi guys

I need to get the " Credit 1889 IRR " from the serial monitor and save it in a string.

So can anyone help me ?

Where did the data come from ?

Please post your full sketch

The easier you make it to read and copy the code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

I want to get my SIM card credit through the sim800 module and send it to my desired phone number.

I have no problem getting my SIM card credit, I just do not know how to save it in a string so I can send it to my desired phone number.

This is my code :point_down: :

#include <Sim800L.h>

#define RX  10
#define TX  11

Sim800L GSM(RX, TX);

String PhoneNumber = "+ZZ***********" ;

String ReceiveMessage ;

String SendMessage ;

void setup()
{

 Serial.begin(9600);

 GSM.begin(9600);

 Basic_Settings();

}

void loop()
{

 if(GSM.available())
 {

  ReceiveMessage = GSM.readStringUntil('\n');
  Serial.println(ReceiveMessage);

  if(ReceiveMessage == "Credit\r")
  {
  
   GSM.println("AT+CUSD=1,\"*141*1#\"");

   delay(1000);

   GSM.println("AT+CMGS=\"" + PhoneNumber + "\"\r");
   
   delay(1000);

   GSM.print(SendMessage);
   
   delay(1000);

   GSM.write(26);
      
  }   

 }

}

void Basic_Settings()
{

 GSM.println("AT");
 
 delay(1000);

 GSM.println("AT+CMGF=1");
 
 delay(1000);

 GSM.println("AT+CNMI=1,2,0,0,0");
 
 delay(1000);

 GSM.println("AT+CSMP=17,167,2,25\r");

}

It looks like you want to extract a sub String of ReceiveMessage. Is that right ?

No, see what this program does :

When someone sends the word credit to the SIM card in the module by phone, the module receives it and sends the SIM card credit receipt code, after the module sends the SIM card credit receipt code, the SIM card credit appears in the serial monitor, so i need to extract the SIM card credit from the serial monitor and save it in a string, so that I can send it to my desired phone number.

I hope you understand !

sounds like you want to "extract a sub Striing" like @UKHeliBob suggested.

you could use strstr() to locate the index of "credit" or "Credit" in the received string and other string functions to extract the sub-string

I deliberately rereferred to the "sub String" because ReceiveMessage is a String, to point @mstfa towards the substring() function

No still not really clear. The serial monitor is a part of the arduino IDE
running on your PC.

So your sentence "SIM card credit appears in the serial monitor, so i need to extract the SIM card credit from the serial monitor" would mean

make - somehow - a connection from the screen-area that shows the serial monitor to my phone.

PartOfComputerScreen(Showing the serial Monitor)------>---------Your-Phone.

That makes no sense at all.
This means you have to give a much more detailed description of your setup

If your microcontroller can send the credit to the serial monitor
The program of your microcontroller already has the credit.

Now it depends on which technical way you want to establish a connection to your phone.

As far as I know you can't buy cables that plug into the screen at one end and the other end of the cable plugs into your phone.

wireless will be - of course - much more comfortable.
What kind of wireless connections does your "phone" provide?
Is it a smartphone? If yes it has WiFi and Bluetooth.

So you need some kind of WiFi- or bluetooth-device to send the credit to the "phone".

If you want to send the credit as an SMS you have to expand your code for the already suggested extract substring and do the sending.

If english is not your native language and you have difficulties to express what you want in english. Use google-translate.

Write down a detailed description in your native language and let do google-translate the translation.

If you find this too exhausting go back using Alexa for ordering pizza.
I guess this will work.

As a general advice. If you have no idea what the code you have posted is doing. It is time to learn it. Expanding your program on what you want to do is more than adding a "cheatcode" of 64 characters in a single line of code.

If you you don't want to learn it. Ask in the Gigs and collaboration-forum if somebody wants to do all the programming for getting paid $20 to $50 per hour.

best regards Stefan

Thanks for your comment !

Yes, you are right ! so how can I extract the subString and just separate the credit and send it to the my desired phone number ?

Have you looked at the String substring() function ?

No :thinking:

Off you go then :grinning:

Your question is a hidden way of asking "post ready to use code"
I will NOT post ready to use code

To answer just as superficially as the superficial question is

you use the function substring to extract the credits and then you program all the AT-commands that will send a SMS to the right phone number.

End of superficially message.

best regards Stefan

I was able to do it, thank you very much :pray: !

So to give something back to the community post your working code.

You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

best regards Stefan

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.