I wanted to know if there is any code to check if a sim800L successfully sends a text message. I will need this code so that every time my sim800L sends a text message successfully it would light up a LED light. I am also using a nodemcu-32S as my microcontroller and Arduino IDE.
here is my code for sending a text message
Serial.println(customKey);
Serial.println("SENDING CONFIRMATION TEXT");
sim800.print("AT+CMGF=1\r");
delay(1000);
sim800.print("AT+CMGS=\""+PHONE+"\"\r");
delay(1000);
sim800.print("Completed");
sim800.print(",");
sim800.print(orderID);
delay(100);
sim800.write(0x1A);
delay(1000);
Serial.println("SMS Sent Successfully.");
See AT command manual (found it online, I don't have the device myself) at chapter 4.2.5 AT+CMGS - it looks like it should response, incl. whenever it succeeded.
Related
My purpose was to send SMS using GSM SIM800L coreboard and Arduino UNO. Here is the code
#include <SoftwareSerial.h>
//Create a software serial object to communicate with SIM800L
SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2
void setup()
{
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(115200);
//Begin serial communication with Arduino and SIM800L
mySerial.begin(115200);
Serial.println("Initializing...");
delay(1000);
mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
updateSerial();
mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
updateSerial();
mySerial.println("AT+CMGS=\"+ZZxxxxxxxxx\"");//change ZZ with country code and xxxxxxxxxxx with phone number to sms
updateSerial();
mySerial.print("TEST"); //text content
updateSerial();
mySerial.write(26);
}
void loop()
{
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(mySerial.available())
{
Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
}
}
And here is the serial monitor output
22:31:19.430 -> Initializing...
However, when I run the code, I get the text message to my mobile phone, but I can't see any AT commands in the serial monitor. It only outputs "Initializing..." .
All the connections and baud rates are okay, checked a thousand times. Has connected 2A, 4.4v power supply to the GSM coreboard and shorten the wires, and sho No bad soldering joints. GSM module red led flash per 3 seconds. And again, I'm getting the text message to my phone. So that means the problem is with the Arduino serial monitor or code, not in the hardware. I need to see AT commands because I need to put more commands through the serial monitor, I tried typing and click send, But it's not showing anything. Any assistance you can provide would be greatly appreciated.
Your logic is reversed in the updateSerial() function.
Actually, you are sending the AT command over mySerial at the setup function, then you need to wait for the answer to come in that object mySerial.
So, you should do the while (!mySerial.available()) ; to be able to read something from it. Once this loop ends, you can read from mySerial.
However, you want to forward it to the serial monitor so, you also need to check if the Serial is available to be written to, that is why you also waits for it, resulting in the while (!mySerial.available() || !Serial.available()) ;.
Once you are sure both serials are available, you can read from one and write what you just read into the other one: Serial.Write(mySerial.read()).
Also, I do not see any need for the mySerial.write(Serial.read()) call, because the Serial is being used just to forward what you are receiving from the SIM800L, thus, you could simply remove that part.
Thus, the correction of your function would result in this:
void updateSerial()
{
delay(500);
while (!mySerial.available() || !Serial.available())
;
Serial.write(mySerial.read());
}
So, with this, everything you receive from the SIM800L is forwarded to the serial monitor.
#include <SoftwareSerial.h>
//SIM800 TX is connected to Arduino D8
#define SIM800_TX_PIN 8
//SIM800 RX is connected to Arduino D7
#define SIM800_RX_PIN 7
//Create software serial object to communicate with SIM800
SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);
void setup() {
//Begin serial comunication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
while(!Serial);
//Being serial communication with Arduino and SIM800
serialSIM800.begin(9600);
Serial.println("Setup Complete!");
//serialSIM800.println("AT+CSPN?\r\n");
//serialSIM800.println("AT+EXUNSOL=\"SQ\",1\r\n");
//serialSIM800.println("AT");
//delay(1000);
//Send SMS
Serial.println("Sending Text...");
delay(1000);
serialSIM800.print("AT+CMGF=1\r");
serialSIM800.print("AT+CMGS=\"0781xxxxxxx\"\r");
delay(200);
//Send SMS content
serialSIM800.print("TEST");
serialSIM800.print("\r");
delay(500);
//Send Ctrl+Z / ESC to denote SMS message is complete
serialSIM800.print((char)26);
delay(100);
serialSIM800.println();
delay(500);
Serial.println("SMS Sent!");
delay(500);
}
void loop() {
//Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor
if(serialSIM800.available()){
Serial.write(serialSIM800.read());
}
//Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800
if(Serial.available()){
serialSIM800.write(Serial.read());
}
}
The code above when uploaded runs generate no errors but no SMS received.
serial mode displays the following;-
Setup Complete!
Sending Text...
SMS Sent!
AT+CMGF=1
AT+CMGS="0781xxxxxxx"
OK
TEST
Call Ready
obviously I send the text to my mobile that's available tried the country code option also. I haven't been able to find anything that helps online as yet and was hoping someone can point me in the right direction.
Thanks
Okay, found the answer, the code is fine.
Checked the power at 4.1V which is fine
So with the above code I needed to make sure that I pressed and held the Reset button on the mini board until the sim800L led went from fast flashing to slow flashing, then the text was generated and sent to the number programmed.
As I am new to this, I couldn't find clear guidance anywhere that explained this, so was scratching my head a little.
Now to the next step.
I have been working on sending SMS to multiple recipients through AT commands. I have been modifying the code that I attached to this post.
Last night I got to know from this site here that we ought to use the AT+CMSS in order to send multiple sms. And that it sends message from the sms storage area in sim. I tried through this way:
gsm.print("AT+CMGF=1\r");
delay(100);
gsm.println("AT + CMSS=3,\"*********\"");
gsm.println("AT + CMSS=3,\"***********\"");
gsm.println("AT + CMSS=3,\"**********\"");
delay(100);
gsm.println((char)26);
delay(100);
gsm.println();
delay(5000);
gsmpower();
It's working for me but only sending message to the first number. Can you please suggest me the way to use AT+CMSS command?
I would like to know if there is anything like GCM for arduino.
I'm working on a project where I need to send push notifications to the arduino connected with WiFi shield. Arduino then will do some action based on the notification it gets or sync up with the server data.
Any advice on how I need to proceed would be helpful.
Thank you.
Yes you can send push notification to Arduino. There are multiple ways from where you can send push notification to Arduino.
I am using push notification from Parse.com.To send push notification from Parse just register with Parse.com and create account there.
Once you create account,you can send push notification from Parse dashboard.
To receive notification on Arduino you need to write sketch on Arduino, following is sketch for help.
Include Parse library to make sure following code will work.
/***************************************************************************************************************************
setup function
****************************************************************************************************************************/
void setup() {
Bridge.begin();
Serial.begin(9600);
while (!Serial);
Parse.begin("***E0uUjQkMa7nj5D5BALvzegzfyVNSG22BD2FJ", "umPSsggp5JgMFmSHfloewW5oixlM5ibt9LBS***");
// In this example, we associate this device with a pre-generated installation
Parse.getInstallationId();
Parse.startPushService();
}//setup function block
void loop() {
if (Parse.pushAvailable()) {
Serial.println("Start push");
ParsePush push = Parse.nextPush();
// Print whole JSON body
String message = push.getJSONBody();
// Serial.print("New push message size: ");
// Serial.println(message.length());
// Serial.print("New push message content: ");
Serial.println(message);
// Do something with the push
// IMPORTANT, close your push message
push.close();
checkStatus(message);
Serial.println("End Push");
}//if push notification block
} //loop
You can read documentation here https://parse.com/docs/arduino/guide#push-notifications.
I hope this will help.
You would have to run an HTTP server on the wifi shield which accepts requests, then send such a request from your outside system (command line on your desktop, IFTTT recipe, etc.)
I'm assuming this is one of the older 8bit Arduinos (since you mention the wifishield rather than something like the Yun with a Linux partition), so you will need to write a http server sketch on the Arduino.
Here is tutorial for a simple HTTP server with the wifi shield from arduino.cc
https://www.arduino.cc/en/Tutorial/WiFiWebServer
i have trouble with my SIM900A GSM
i can send one SMS successfully ("arrived in less than one minute")
but when i send another SMS after first one (delay more than one minute "it's not for bulk purpose") the second message take about 15 minutes or more to arrive to destination device.
in the same time i'm sending sms my phone to the same destination it's arrive directly all sim-card from the same operator
i have powered the gsm with 5v,2A power so i have no power problem.
any suggestion will be great
i'm using arduino
this my code :
Serial3.println("AT+CMGF=1");
delay(1000);
Serial3.println("AT+CMGS=\"+96279XXXXXX\"");
delay(1500);
Serial3.println("my message");
delay(1000);
Serial3.println((char)26);
delay(1000);
Serial3.println();
delay(5000);
It seems that it is an issue related to network. Try switching to another network.
As far as the modem accepts your request for sending sms and replies back with +CMGS response including the a number, it has performed its job well.
SMS are not meant to be a real time communication and operators delay them due to several reasons.