After developing for two weeks non-stop, I came to the very last annoyance before finishing my project.
I'm trying to make a device that responds on incoming SMSes by forwarding the message (an array of chars) to another person.
I can't pinpoint the problem, whether I wrongly chose pointers/vartypes or some other conflict.
Please correct me if I'm wrong!:
Because I learned that I cannot pass a string/char variable to a function, I decided to create a publicly shared class object (called mzg), to allow myself write messages as needed. This is done by calling the WrapAndSend-routine. It gets the information from getLocation, but when it's supposed to send the message, all I read is this:
>
Which means that the message, although the object SMS.mzg (or this->mzg) contains the message, it doesn't 'print' it to the NSS port.
Sometimes, after changing some code around, I only receive the first character of the fetched string.
Have been trying over a week now and it seems that it's taking the life out of me. Can anyone help me on this issue?
Kind regards
Royale
main
void WrapAndSend() {
SMS.mzg = getLocation();
Serial.print("The mzg");
Serial.println(SMS.mzg);
SMS.sendSMS("+12345678900");
delay(1500);
iterbuf(0); // Get Response from mobile
}
char * getLocation() {
//Some thingies here
return locationcode;
}
hilo.h
#ifndef hilo_h
#define hilo_h
#include <NewSoftSerial.h>
#include <WProgram.h>
class hilo
{
NewSoftSerial GSM; // Works like a charm btw!!
public:
// some methods
void sendSMS(char *receiver);
char *mzg;
private:
char *_receiver;
Here is a test you can do:
after
GSM.print(_receiver);
Add
Serial.print(_receiver);
If you can't see the string on the serial monitor you may find it easier to debug your code using the serial monitor and move back to NSS when you have it working.
Perhaps your format is not correct. Are you sure about that carriage return. Try sending a complete hard coded message bypassing your class code, this will help you check that the message format to the GSM modem is ok.
Wait a sec. Could it be that NSS doesn't handle print requests like this?:
GSM.print(34**,BYTE**); Naaah, don't think so, since I've been able to succesfully send messages with the same set of commands.
Update: It doesn't work hardcoded either. When sending commands only using my sendCmd routine, it doesn't show up on the modem monitor (as above.) However, when using Serial.print, it works just fine :-/
AlphaBeta:
Alot of garbage between the code, don't mind
void getLocation() { //const char *getLocation() {
int k;
inString = ""; // From the Wstring library
SMS.sendCmd("AT+CMGR=1");
iterbuf(1); // reads modem - option 1 = only SMS header
inString= MySMS;
if (inString.contains("+1234567890")) {
SMS.sendCmd("AT+CMGR=1");
iterbuf(2); // reads modem - option 2 = read SMS body and is stored to 'MySMS' (from Pstring library)
k=0;
for (k=0; k<13; k++) {
locationcode[k] = MySMS[k];
}
locationcode[k+1] = '0';
}
Serial.println("Here's substring");
Serial.println(locationcode);
inString ="";
}
It's hard to see exactly what is happening. Can you post the minimal test sketch that sends a hard coded message through NSS. Ideally, this test would only print a hard coded string using NSS without going through any of your class code. If the problem persists then you know its not any of your class code.
It seems that, for some reason, the variable needs to be streamed to the modem port, as if it being a literal text.
I used Mikal's Streaming library to get this baby going like this:
Can you explain the difference between GSM.print and the Streaming operation as above?
And another thing: I keep an eye on the RAM by printing the free space in my Serial monitor. Before it GSM.sendZ(var), it had 250 bytes left. After it send the message, I only had '1023' bytes left, which means stack overflow, right? Any reason why this operation uses a lot of RAM space? Especially concerning the fact that Mikal states that it doesn't consume resources. http://arduiniana.org/libraries/streaming/
Geez, wasted a week to get this done. Thank you for your help till now and thanks in advance for the remaining questions.
Well, I have small routine in my main (loop) that checks how much RAM memory is left. This to check if I still enough memory for variables & performance.
So everytime I call I perform function (e.g. getLocation, sendSMS, sendCmd etc.), I also let my board check how much RAM is left.
Now, here's a copy of my Serial monitor:
OK (<--- RESPONSE OF: SMS.sendCmd("AT");
218 (<---- THIS IS LEFTOVER MEMORY)
Here's substring (<--- RESPONSE OF: getLocation();
10425 12eiok
218 (<---- THIS IS LEFTOVER MEMORY)
OK (<--- RESPONSE OF: SMS.sendZ(locationcode);
1023 (<--- UH OH, WE START RECOUNTING)
This is the routine
int availableMemory()
{
int size = 1024;
byte *buf;
while ((buf = (byte *) malloc(--size)) == NULL);
free(buf);
return size;
}
My guess is that the string library you are using is not releasing memory. You could try replacing the string code with a static character array big enough to hold your longest string to see if that is the cause.
Well mem, I cleaned up some more variables. I freed up about 200 bytes of valuable space.
BUT
Running the code again gives me the same symptom: The memory counter suddenly drops to 1023.
It's really keen on this number. No matter how much space i free up additionaly, the available memory drops excessively. Giving me a reason to think that there's a problem. And this started ever since I used 'endl'