this will be my first post since starting with Arduino a week ago
Right now im about to throw my stack out of the window..
Im trying to create an SMS gateway, for this im using Arduino Uno, Arduino Ethernet shield, and GPRS shield from Cooking hacks (Sim5218).
I want to start out making this as simple as possible, a webserver with two field where user enter number to sent to and the message.
Webserver works standalone.
Problem is when GPRS shield is stacked on top of it.
First SMS is always sent but after that it hangs when looking at it in serial monitor.
Below you can see the code, this is very basic and i only used examples from Arduino and cooking hacks.
By knowledge of programming is as basic as it comes, the some goes for electronics, even though i think this is really cool stuff.
Really appreciate if anyone could give me some input on this.
My problem is that for the first request made from webserver page, sends an sms and it works fine, but for the next request made it just freezes before it comes to calling function sendSms. Strange thing is that it isnt consistent so it stops in different places but always before sending sms function.
Maybe someone can see some really obvious coding error or some suggestions, anything is appreciated.
thanks
Attached a picture of my "stack", also the code as a txt file since i get an error of two long message?
Look at the documentation or schematics for the two shields. If you can't decipher them, post links (not to some stupid EBay seller that you bought them from; to the manufacturer's site).
Even if i knew this, is it possible to change pins?
It depends on which pins are in conflict. If, for example, both shields use the SPI pins FOR SPI, they can't, and don't need to be, changed. If one uses the SPI pins FOR SPI and the other uses them for switches, you have options.
Sounds great but i dont understand-
Is it wrong way of declaring variables?
Something about declaring amount of charactars? In the code i try to set it to "" after every sent sms.
Strings use dynamic memory allocation, re-allocating space for each character being added. That can leave holes in memory that are not contiguous. Suppose that you may need enough memory to allocate 100 bytes, but the memory that is available is in chunks of 67, 27, 82, and 90. 266 bytes available, but not contiguously, so the allocation fails.
What does your code do if the allocation fails?
The String class doesn't even provide a way for you to know that an allocation has failed.
On the 4th String declaration, why are you assigning readRequestString an initial value of "120"?
If you think that that is defining a maximum length for the String instance, then clearly you know how big the underlying string will be, so there is no reason to use a String at all.
Alright, i have to looka at this tomorrow when i get back home and have access to the arduino.
Why is set to 120 is because i thought that was a way of this parameter not to reserve more space that necessary.
I use it further down when looping through the header of the users request to the webserver. This is for checking the parameters send by the user in form and if there is an extra request (chrome favicon request).
As mentioned before i just patched together examples codes learning on the way, though sms gateway would be really cool sp it was a fun way of starting playing with arduino.
Serial.println("new client");
boolean currentLineIsBlank = true;// an http request ends with a blank line
while (client.connected()) {
if (client.available()) {
char c = client.read(); // read 1 byte (character) from client
//read char by char HTTP request
if (readRequestString.length() < 100) { //only reads 100 lines
readRequestString.concat(c); //store characters to string
Serial.print(c); //Print request header
}
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if ((c == '\n' && currentLineIsBlank) || readRequestString.indexOf("favicon")>0) {
if (readRequestString.indexOf("favicon")>0) {
}
else {
smsSendTo = getParameterValue(readRequestString,"recipientNumber");
smsMessage = getParameterValue(readRequestString,"sendText");
if (smsSendTo.length()>8){
//Serial.println("Calling sendSms");
sendSms2("",smsSendTo,smsMessage);
smsSendTo="";
smsMessage="";
readRequestString="";
}
}
Whats is a better variable type to use?
Maybe there is no need for having this limit but just read the whole header line instead.
Cant say that String sound to good to use when as you say using "dynamic memory allocation"?
When value is 120, an array of 18 characters is allocated, and the value is converted to a string (120 -> "120") and stored in the string that the String instance wraps.
Again, thanks for your help, but i cant get it to work.
in the main loop i have this part checking if user entered an recipient in the web form.
smsSendTo = getParameterValue(readRequestString,"recipientNumber");
smsMessage = getParameterValue(readRequestString,"sendText");
if (smsSendTo.length()>8){
//Serial.println("Calling sendSms");
Serial.println("before first delay");
delay(3000);
sendSms2("",smsSendTo,smsMessage);
Serial.println("before second delay");
delay(3000);
Serial.println("After second delay");
smsSendTo="";
smsMessage="";
readRequestString="";
}
So if i just reload this form without enter any data i can do this for as many times as i want without any problem.
When i enter recipient and message it is sent as it should, but the second time send function is called it just stops.
But if i for the second time empty the form so the function is not called it works.
And now i see that if i for every sms sent, i post an empty form it works. Seems like something is cleared out when running an empty request?