SSerial2mobile help, please

Hi all.

This will be my first message on this board, although I have been following the chatter for a while now :slight_smile:

I am writing because I have a question / problem related to understanding how a class is used (at least i guess that’s what i’m trying to find out)!

My question is:

I am using the library SSerial2Mobile, developed by Gustav Von Roth. Library can be found here: http://code.google.com/p/sserial2mobile/

The library works fine as long as the code is either called in the setup part of the program, or in the main loop of the program.

This is a problem because I want to initialize the function / class in the setup() function, and then call various functions in the main loop.

the example works fine:

#include <NewSoftSerial.h>
#include <SSerial2Mobile.h>

#define RXpin 6
#define TXpin 7 //blue

void setup() {
  Serial.begin(9600);
  SSerial2Mobile phone = SSerial2Mobile(RXpin,TXpin);
  
  Serial.print("Batt: ");
  Serial.print(phone.batt());
  Serial.println("%");
  
  Serial.print("RSSI: ");
  Serial.println(phone.rssi());
  
  phone.sendTxt("12345678","Lib SMS Test1");
  delay(3000);
  
}
void loop()
{
}

but If I want to use the phone.RSSI() command in the main loop, i get the error: ‘phone’ was not declared in this scope
the error makes perfect sense, as the ‘phone’ constructor is called in the setup routine, thus being a private member of that function.

on the oter hand, if I declare the
SSerial2Mobile phone = SSerial2Mobile(RXpin,TXpin);
before the setup() function, the program compiles just fine, but does not work:

#include <NewSoftSerial.h>
#include <SSerial2Mobile.h>

#define RXpin 6
#define TXpin 7 //blue

  SSerial2Mobile phone = SSerial2Mobile(RXpin,TXpin);

void setup() {
  Serial.begin(9600);

}
void loop()
{
  Serial.print("Batt: ");
  Serial.print(phone.batt());
  Serial.println("%");
  
  Serial.print("RSSI: ");
  Serial.println(phone.rssi());
  
  phone.sendTxt("12345678","Lib SMS Test1");
  delay(3000);
}

so what am i missing here… why can’t I make it work?

Hoping my ramblings make sense, and that there might be an answer out htere for me ;D

(PS. yes I know the last code example would in theory send me a SMS every 3 seconds :wink: )

The constructor for the SSerial2mobile class creates an instance of NewSoftSerial, and calls it's begin method. Since the Arduino hasn't finished initializing the hardware when the Sserial2mobile constructor is called, some of the necessary initialization fails.

The SSerial2mobile class really should have a begin method that does what the constructor does. The constructor should not be calling the NewSoftSerial::begin() method.

You could revise the SSerial2mobile class, and give it a begin method, that does what the constructor does.

Or, you could contact the SSerial2mobile class author to get it fixed.

Hi Paul.

Thanks for your reply.

I will have a look at how the NewSoftSerial library has been built, and then try to change the SSerial2Mobile accordingly.

Hopefully I'll be able to figure it out.

it would be really cool to get it working, so i can get my project to send me status Txt messages :)

Thanks, spumanti, for posting this question -- exactly the problem I was having -- and thanks PaulS for the answer, which fixed it. Specifically, here's what I changed in SSerial2Mobile.cpp:

Create a new member function, SSerial2Mobile::begin(), and move the call to _sSerial.begin, and the accompanying delay() statement, out of the constructor and into the new begin() function. Now I can instantiate a SSerial2Mobile object at the top of my sketch, call its begin() method from my setup() function, and use the object from my main loop().

Note that you also need to declare the new member function in SSerial2Mobile.h, like this: void begin();

And for anyone who hasn't modified Arduino libraries before, you need to delete SSerial2Mobile.o and restart the IDE to make your changes take effect.

Hi all,

Thanks for the post. I am having problems implementing the work around provided by oreanamatt. Not really a software guru. oreanamatt, could you share with me you modified SSerial2Mobile.cpp SSerial2Mobile.h as i am not having success at modifying to work with my system.

Thanks.

Has anyone had the problem SSerial2Mobile.h: no such file or directory 'void setup()':

Has anyone had the problem SSerial2Mobile.h: no such file or directory 'void setup()':

Anybody who tries to use that library, but hasn't installed it (or installed it in the proper place) will get that message.

yes,i have get the same error!

yes,i have get the same error!

Congratulations. Great job.