Hello,
I'm messing around with a SIM7600 cellular board and am trying to understand some code that I found for it on the internet. The board is working, in that I can send "AT+" type commands to it and can get the board to send an email to my phone. However, all of the code that I've found "hard-codes" the commands into the program. What I am trying to do is to understand how to use the Sprintf command in order to put the AT+ commands into variables (actually CONST char) and then call the variable.
Here is an example of a command that "works":
char aux_str[70];
const char smtp_server[ ] = "mail.smtp2go.com"; // SMTP server
const char smtp_port[ ] = "587"; // SMTP server port
sprintf(aux_str, "AT+SMTPSRV=\"%s\",%s", smtp_server, smtp_port);
Serial.println(aux_str);
I get the following on the Arduino Com Port:
AT+SMTPSRV="mail.smtp2go.com",587 which is actually what I want to be printed to the display.
However the way I want to do it is to put the "AT+SMTPSRV=" string into a CONST CHAR, something like:
atPlusSmtpSrv[ ] = "AT+SMTPSRV=";
I've tried this a bunch of different ways including all of the following:
``
sprintf(aux_str, atPlusSmtpSrv "%s",%s", smtp_server, smtp_port);
sprintf(aux_str, atPlusSmtpSrv, smtp_server, smtp_port);
sprintf(aux_str, atPlusSmtpSrv "%s" %s", smtp_server, smtp_port);
sprintf(aux_str, atPlusSmtpSrv "%s",%s", smtp_server, smtp_port);
This one comes the closest:
`sprintf(aux_str, "atPlusSmtpSrv \"%s\",%s", smtp_server, smtp_port);`
However, it produces the following result:
atPlusSmtpSrv "mail.smtp2go.com",587
My problem is that I can't find an sprintf syntax explanations that are relevant to my situation.
Here's what I think I know:
1. "aux_str" is the array into which the "assembled string" will be placed, and will be displayed on the com terminal via the Serial.println command
2. Sprintf properly assembles the "AT+SMTPSRV=" string, the "mail.smtp2go.com" string, and the "587" from the variable "SMTP_Port".
3. It seems to me that several variations (listed above) that I've tried should work. However, each of them has its own problem, whether the problem is a failure to complete the "aux_str" assembly or failure to grab the actual AT+ command from the variable and then append the server and port data to it.
I'm sure I'm missing something here and would appreciate it if someone would point out what is likely to be obvious. I'd also appreciate it if you might point me to a reasonably thorough explanation of sprintf.
Thanks in advance.,
Robert