I'm trying to send a USSD string with Arduino/SIM900 module.
This is my code:
mySerial.println("AT+CMGF=0");
delay(100);
mySerial.println("AT+CUSD=1,\"*123#\"");
delay(10000);
if (mySerial.available() >0)
{
while(mySerial.available() > 0)
{
incoming_char=mySerial.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char);
}
}
the problem is that, the response is truncated.
If I try to remove the row
mySerial.println("AT+CMGF=0");
the response is more long but always truncated
How to resolve the problem?
Thanks a lot
Related
Hi I have used esp8266 module http client example and my code is exactly like the sample code.
This is a part of my code:
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = http.getString();
if(payload=="text") {
digitalWrite(LED_BUILTIN, HIGH);
} else {
digitalWrite(LED_BUILTIN, LOW);
}
}
}
I can't compare my variable with my text and the LED_BUILTIN is always on. I am sure it can get the text of the http client page because I can send it to Arduino nano with softwareserial.
Actually when i want to send it to arduino nano it gives me an error : no matching function for call to HardwareSerial::write(String&)
i could fix the error with this sample code
String mystring= http.getString();
char* buf = (char*) malloc(sizeof(char)*myString.length()+1);
myString.toCharArray(buf, myString.length()+1);
Serial.write(buf);
free(buf);
but esp8266 module can't compare payload with my text
If the LED was turned on, then the compare method was definitely work. Try to send different String from the server, your LED should be turned off. And also, when you got problems like this, try to print the "payload" to the serial monitor. At least, you could figure it out where the faulty is.
hope this help.
I'm trying to make an HTTP request with an ESP8266 and the ESP8266HTTPClient library. I have a request in the loop() function that makes a request every 5 seconds which works 100% flawlessly. However, I also have an interrupt setup like so:
void interrupt() {
if(WiFiMulti.run() == WL_CONNECTED) {
Serial.println("Knock!");
HTTPClient http;
knockhttp.begin(http_address + "/knock");
int httpCode = http.GET();
if(httpCode > 0) {
Serial.println(http.getString());
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
}
This fails. I get a "connection refused" Error every time the interrupt triggers. It's connecting to the same server as the request in the loop, just a different path.
Okay, I fixed it.
For some reason, HTTP requests with the ESP8266HTTPClient library do not work within interrupts, so here's the solution I came up with that worked:
Set some boolean flag in the interrupt.
Check that flag in the main loop
Perform the HTTP request in the main loop when the flag matches
Reset the flag.
Hope this helps anyone else that comes across the same strange problem.
I am quite rusty when it comes to Serial ports. I want to send an AT command to a GSM/ GPRS shield connected to my Arduino UNO. The AT command I want to pass in particular is the command to get a networks signal strength.
I am using the SIM900 and SoftwareSerial library to send the command as the GSM library does not compile correctly for me. Meaning I have to use the SoftwareSerial library.
I have this example code from the SIM900 library working that relies on reading inputs from the serial monitor to carry out commands but I need it to be automated and the command to be passed in hardcoded. In this example code, the place of interest is the simplehwread() method.
#include "SIM900.h"
#include <SoftwareSerial.h>
int numdata;
char inSerial[40];
int i=0;
void setup()
{
//Serial connection.
Serial.begin(9600);
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(9600))
Serial.println("\nstatus=READY");
else Serial.println("\nstatus=IDLE");
};
void loop()
{
//Read for new byte on serial hardware,
//and write them on NewSoftSerial.
serialhwread();
//Read for new byte on NewSoftSerial.
serialswread();
};
void serialhwread()
{
i=0;
if (Serial.available() > 0) {
while (Serial.available() > 0) {
inSerial[i]=(Serial.read());
delay(10);
i++;
}
inSerial[i]='\0';
if(!strcmp(inSerial,"/END")) {
Serial.println("_");
inSerial[0]=0x1a;
inSerial[1]='\0';
gsm.SimpleWriteln(inSerial);
}
//Send a saved AT command using serial port.
if(!strcmp(inSerial,"TEST")) {
Serial.println("SIGNAL QUALITY");
gsm.SimpleWriteln("AT+CSQ");
} else {
Serial.println(inSerial);
gsm.SimpleWriteln(inSerial);
}
inSerial[0]='\0';
}
}
void serialswread()
{
gsm.SimpleRead();
}
No matter how I modify this code, the command does not get passed in and response displayed while the method here does it but not the way I want it to be done. i.e Direct input. Could anyone assist here?
i have dealt with exactly this scenario at a company with a cellular radio on board. there are many status signals that come over and if not dealt with appropriately these status flags from the cell modem will be lost
you need to look at the data sheets associated with your cell modem and its protocol so you know what flags to watch for at the various steps taken along the way from configuration, to eventual connection to cellular service.
multi-threaded coding techniques must be followed as well.
keep in mind that the comm channel is not ideal and there WILL be failures. provided your coding techniques are sound and you follow protocol requirements, then it should work.
Ron
Boise, ID
I'm working on a project that has to turn a pump off upon sending an sms to the microcontroller. This code below has to be able to read and download the message so it can turn the pump off but it is not working. Can someone please check the code and let me know the problem. The microcontroller used is atmega32 and the software to program it is atmel studio 6.1.
while(1)
{
//check_sensor();
/*uint8_t x=0;
while(GSMWaitForMsg(&id)!=GSM_OK)
{
if(x)
{
LCDWriteStringXY(10,3,"%3"); //LOVE SYMBOL TILL MSG COMES CHECK MYUTILS.H
x=0;
}
else
{
LCDWriteStringXY(10,3,"%4"); //ARROW TO SHOW MESSAGE DOWNLOAD
x=1;
}
}
LCDWriteStringXY(10,3,"%2");
_delay_ms(1000);
//function to read message
char msg[300];
int8_t r=GSMReadMsg(id,msg); //ID=NUMBER MSg=MESSAGE OA=THE REPLY
if(r==GSM_OK)
{
if(strcasecmp(msg,"STOP")==0) // checking if message read is stop
{
PORTC|=(1<<PC7);
LCDClear();
LCDWriteStringXY(0,1,"PUMP TURNED OFF"); // displaying on the lcd screen
RelayOff(); // turning the relay off
_delay_ms(2000);
goto comehomeboy; // going back to home
}
}
}
The message received for GSM module (on UART of controller) are merely ASCII characters.Mostly there is no NULL(\0) appended to the data.
For strcasecmp() function you need NULL terminated strings as Input.
Please make sure 'msg' array is terminated with NULL.
I Am using Arduino UNO and SIM900A module for GSM + ARDUINO based communication.I used following code to call a specific number but nothing happens,
void setup()
{
Serial.begin(9600);
delay(10000);
}
void loop()
{
Serial.println("ATDTxxxxxxxxxx;"); //where xxxxxxxxxx is a 10 digit mobile number
delay(30000); // wait 20 seconds.
Serial.println("ATH"); // end call
do // remove this loop at your peril
{
delay(1);
}
while (1>0);
}
whereas when i used ATDTxxxxxxxxxx; in minicom while communicating with SIM900A module, i was able to call(AS ATDxxxxxxxxxx was giving No carrier error, so i used " ; ").Similr is the case with Sending message. I am getting "+CMS ERROR: 302" while i am using
AT+ CMGF=1
AT+CMGS="Mobno." //after this i get the error.
I am not able to send the message through minicom + SIM900A GSM module and i want to test it with Arduino.I think i am having some problem with settings of SIM or either module.I even tried to reset the settings of SIM , but nothing worked out.
First of all: never, never ever use delay instead of proper waiting by parsing the actual response given by the modem. And you must read back the responses given by the modem and wait for the final result code before proceeding to the next command. See this answer and this answer for more details (especially regarding proper AT+CMGS handling).
A list of all the CMS ERRORs are defined in 27.005 in the section 3.2.5 Message Service Failure Result Code +CMS ERROR. Does your subscription allow sending SMS (most likely, but just to be sure check this. Test sending an sms using this sim inserted into another mobile phone)? What message storage are you using? Are you sure the gsm module supports text mode?
I solve the problem just use this code:
void setup()
{
Serial.begin(9600);
delay(10000);
}
void loop()
{
Serial.println("ATD+60148266823;"); //where xxxxxxxxxx is a 10 digit mobile number
delay(30000); // wait 20 seconds.
Serial.println("ATH"); // end call
do // remove this loop at your peril
{
delay(1);
} while (1>0);
}
void setup(){
Serial.begin(9600);
}
void loop(){
Serial.println("AT");
delay(500);
Serial.print("ATD");
Serial.println("99XXXXXXX8;");
delay(20000);
Serial.println("ATH");
}