NewSoftSerial.h errors

Hello all. I'm working on a project to send a text message from a cell phone that has a serial connection, using an arduino Nano. I'm getting error messages referencing to NewSoftSerial library I'm using. The sketch follows:

/*
 Example of SSerial2Mobile libary 

Sends a SMS and an email
The SMS phone number and the email address need to be changed to something valid. 

 created Jan 2010
 by Gustav von Roth 
*/

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

#define RXpin 10
#define TXpin 11 //blue

int returnVal=10;






void setup() {
  Serial.begin(9600);
  SSerial2Mobile phone = SSerial2Mobile(RXpin,TXpin);
  
  

  //returnVal=phone.isOK();
  //Serial.println(returnVal, DEC);
  //delay(3000);
  
  Serial.print("Batt: ");
  Serial.print(phone.batt());
  Serial.println("%");
  
  Serial.print("RSSI: ");
  Serial.println(phone.rssi());
  // Any RSSI over >=5 should be fine for SMS
  // SMS:  5
  // voice:  10
  // data:  20
  
  phone.sendTxt("+12125550125","Lib SMS Test1");
  delay(3000);
  phone.sendEmail("SSerial2Moble@example.com", "Lib email test1");
  delay(3000);
  
  
  
}
void loop(){}

The library file is:

/*
NewSoftSerial.h - Multi-instance software serial library
Copyright (c) 2006 David A. Mellis.  All rights reserved.
-- Interrupt-driven receive and other improvements by ladyada
-- Tuning, circular buffer, derivation from class Print,
   multi-instance support, porting to 8MHz processors,
   various optimizations, PROGMEM delay tables, inverse logic and 
   direct port writing by Mikal Hart

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

The latest version of this library can always be found at
http://arduiniana.org.
*/

#ifndef NewSoftSerial_h
#define NewSoftSerial_h

#include <inttypes.h>
#include "Print.h"

/******************************************************************************
* Definitions
******************************************************************************/

#define _NewSS_MAX_RX_BUFF 64 // RX buffer size
#define _NewSS_VERSION 10 // software version of this library
#ifndef GCC_VERSION
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif

class NewSoftSerial : public Print
{
private:
  // per object data
  uint8_t _receivePin;
  uint8_t _receiveBitMask;
  volatile uint8_t *_receivePortRegister;
  uint8_t _transmitBitMask;
  volatile uint8_t *_transmitPortRegister;

  uint16_t _rx_delay_centering;
  uint16_t _rx_delay_intrabit;
  uint16_t _rx_delay_stopbit;
  uint16_t _tx_delay;

  uint16_t _buffer_overflow:1;
  uint16_t _inverse_logic:1;

  // static data
  static char _receive_buffer[_NewSS_MAX_RX_BUFF]; 
  static volatile uint8_t _receive_buffer_tail;
  static volatile uint8_t _receive_buffer_head;
  static NewSoftSerial *active_object;

  // private methods
  void recv();
  bool activate();
  virtual void write(uint8_t byte);
  uint8_t rx_pin_read();
  void tx_pin_write(uint8_t pin_state);
  void setTX(uint8_t transmitPin);
  void setRX(uint8_t receivePin);

  // private static method for timing
  static inline void tunedDelay(uint16_t delay);

public:
  // public methods
  NewSoftSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false);
  ~NewSoftSerial();
  void begin(long speed);
  void end();
  int read();
  uint8_t available(void);
  bool active() { return this == active_object; }
  bool overflow() { bool ret = _buffer_overflow; _buffer_overflow = false; return ret; }
  static int library_version() { return _NewSS_VERSION; }
  static void enable_timer0(bool enable);
  void flush();

  // public only for easy access by interrupt handlers
  static inline void handle_interrupt();
};

// Arduino 0012 workaround
#undef int
#undef char
#undef long
#undef byte
#undef float
#undef abs
#undef round

#endif

The error messages are:

In file included from SSerial2Mobile_Example1.pde:11:
C:\Users\Scott Shirts\Documents\Arduino\libraries\NewSoftSerial/NewSoftSerial.h:71: error: conflicting return type specified for 'virtual void NewSoftSerial::write(uint8_t)'
C:\Downloads\Arduino\arduino-1.0.5-windows\arduino-1.0.5\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'

Since I don't really understand the error messages I've attempted to change things (such as remove 'virtual') in line 71 of the library file, but nothing I've tried works and at times aggravated the messages. I'd appreciate help in resolving the error messages and would like to understand why they are compiling errors.

Thanks - Scotty

Where did you get the library from ?

Try using the SoftwareSerial library that is installed with the Arduino IDE. The code that you posted is 5 years old and things have moved on since then.

Hello Scott,
Could you also post the SSerial2Mobile.h library file? regards,

p

SSerial2Mobile.h:

/*
  SSerial2Mobile.h - Software serial to Mobile phone library   
  Copyright (c) 2008 Gustav von Roth.  All right reserved.
  SSerial2Mobile@vonroth.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

// #$Id: SSerial2Mobile.h,v 1.3 2009/05/04 23:32:23 gvonroth Exp $

#ifndef SSerial2Mobile_h
#define SSerial2Mobile_h
 
//#include "WConstants.h"
#include "Arduino.h"
#include <NewSoftSerial.h>

 
class SSerial2Mobile {
 
     public:
           SSerial2Mobile(int rx, int tx);
           void println(const char[]); 
           void off(void);
	   void on(void);
	   void reset(void);
	   void sendTxt(const char number[],const char msg[]);
	   void sendEmail(const char emailAddr[],const char msg[]);

           int isOK();
           int wait4OK();
           int batt();
           int rssi();

     private:
           NewSoftSerial _sSerial;
           void readline(void);
           uint32_t parsedecimal(char *str);
     
};
 
#endif

Try using the SoftwareSerial library that is installed with the Arduino IDE

Thanks for the tip. I changed the instances of NewSoftSerial to SoftwareSerial in the sketch and the SSerial2Mobile library and that did clear up the errors I was getting. I also found #include <SoftwareSerial.h> commented out in the SSerial2Mobule.cpp file and uncommented that.

The errors I'm getting now seem minor but nonrtheless they are errors:

C:\Users\Scott Shirts\Documents\Arduino\libraries\SSerial2Mobile\SSerial2Mobile.cpp:45: error: expected initializer before 'SSerial2Mobile'
C:\Users\Scott Shirts\Documents\Arduino\libraries\SSerial2Mobile\SSerial2Mobile.cpp: In member function 'void SSerial2Mobile::sendTxt(const char*, const char*)':
C:\Users\Scott Shirts\Documents\Arduino\libraries\SSerial2Mobile\SSerial2Mobile.cpp:86: error: 'BYTE' was not declared in this scope
C:\Users\Scott Shirts\Documents\Arduino\libraries\SSerial2Mobile\SSerial2Mobile.cpp: In member function 'void SSerial2Mobile::sendEmail(const char*, const char*)':
C:\Users\Scott Shirts\Documents\Arduino\libraries\SSerial2Mobile\SSerial2Mobile.cpp:104: error: 'BYTE' was not declared in this scope

Near the top of the SSerial2Mobile.cpp file below, I added BYTE as a global variable first with a type byte and the as a char. Neither worked. Any advice?

/*
  SSerial2Mobile.cpp - Software serial to Mobile phone library 
  Copyright (c) 2008 Gustav von Roth.  All right reserved.
  SSerial2Mobile@vonroth.com

    This program is free software: you can redistribute it and/or modify
 uy(PHONE_DELAY_AFTER_SENDING_COMMAND_VALUE);nder the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

// #$Id: SSerial2Mobile.cpp,v 1.6 2009/05/04 23:40:05 gvonroth Exp gvonroth $

//this is only here to grab the constant for BYTE which is 0
#include "HardwareSerial.h"

#include "Arduino.h"

#include "ATT.h"
#include "MOT-C168i.h"

//extern "C" {
	 #include <SoftwareSerial.h>
//}

#include "SSerial2Mobile.h"

// some global vars for reciving data
#define BUFFSIZ 90 // plenty big
char buffer[BUFFSIZ];
char *parseptr;
char buffidx;

 
SSerial2Mobile::SSerial2Mobile(int rx, int tx): _sSerial(rx, tx)
{
	  pinMode(rx, INPUT);
          pinMode(tx, OUTPUT);

	_sSerial.begin(PHONE_SERIAL_SPEED);delay(PHONE_DELAY_AFTER_SENDING_COMMAND_VALUE);
	
}

void SSerial2Mobile::println(const char c[])
{
	_sSerial.println(c);
}

void SSerial2Mobile::off(void)
{
	println(PHONE_TURN_OFF_COMMAND);
}

void SSerial2Mobile::on(void)
{
        println(PHONE_TURN_ON_COMMAND);
}

void SSerial2Mobile::reset(void)
{
        println(PHONE_RESET_COMMAND);delay(PHONE_DELAY_AFTER_SENDING_COMMAND_VALUE);
}

void SSerial2Mobile::sendTxt(const char number[],const char msg[])
{
	_sSerial.println(PHONE_SET_SMS_TXT_MODE_COMMAND);
	delay(PHONE_DELAY_AFTER_SENDING_COMMAND_VALUE);
	_sSerial.print(PHONE_SEND_MSG);
	_sSerial.print("\"");
	_sSerial.print(number);
	_sSerial.print("\"");
	_sSerial.println();
	delay(PHONE_DELAY_AFTER_SENDING_COMMAND_VALUE);
	_sSerial.print(msg);
	// dec 26 is a <CTRL Z>
	_sSerial.println(26, BYTE);
	delay(PHONE_DELAY_AFTER_SENDING_COMMAND_VALUE);
}

void SSerial2Mobile::sendEmail(const char emailAddr[],const char msg[])
{
        _sSerial.println(PHONE_SET_SMS_TXT_MODE_COMMAND);
        delay(PHONE_DELAY_AFTER_SENDING_COMMAND_VALUE);
        _sSerial.print(PHONE_SEND_MSG);
        _sSerial.print("\"");
        _sSerial.print(CARRIER_EMAIL_GATEWAY_NUMBER);
        _sSerial.print("\"");
        _sSerial.println();
        delay(PHONE_DELAY_AFTER_SENDING_COMMAND_VALUE);
	 _sSerial.print(emailAddr);
	 _sSerial.print(" ");
        _sSerial.print(msg);
        // dec 26 is a <CTRL Z>
        _sSerial.println(26, BYTE);
	delay(PHONE_DELAY_AFTER_SENDING_COMMAND_VALUE);
}

//############     Stuff relating to reciving  ##########################

int SSerial2Mobile::isOK() {
     _sSerial.println("AT");
     delay(PHONE_DELAY_AFTER_SENDING_COMMAND_VALUE);
     return wait4OK();
}

int SSerial2Mobile::wait4OK() {
  int returnVal=0;
  
  while(_sSerial.available())  {
       readline();
       if (strncmp(buffer, "OK",2) == 0) {
          returnVal=1;
       } else  {
	 returnVal=-1;
       }
  }
        return returnVal;
}


int SSerial2Mobile::batt() {
 _sSerial.flush();
  _sSerial.println(PHONE_BATT_CHARGE_CHECK_COMMAND);
  delay(PHONE_DELAY_AFTER_SENDING_COMMAND_VALUE);
  while(_sSerial.available())  {
       readline();
       if (strncmp(buffer, "+CBC: ",6) == 0) {
         parseptr = buffer;
         parseptr = strchr(parseptr, ',') + 1;
         return parsedecimal(parseptr);
       }
  }
  return -2;
}


int SSerial2Mobile::rssi() {
  _sSerial.println(PHONE_SIGNAL_STRENGTH_CHECK_COMMAND);
  delay(PHONE_DELAY_AFTER_SENDING_COMMAND_VALUE);
  while(_sSerial.available())  {
       readline();
       if (strncmp(buffer, "+CSQ: ,",6) == 0) {
         parseptr = buffer;
         parseptr = strchr(parseptr, ' ') + 1;
         return parsedecimal(parseptr);
       }
  }
  return -2;
}



void SSerial2Mobile::readline(void) {
  char c;
  
  buffidx = 0; // start at begninning
  while (1) {
      c=_sSerial.read();
      if (c == -1)
        continue;
     // Serial.print(c);
      if (c == '\n')
        continue;
      if ((buffidx == BUFFSIZ-1) || (c == '\r')) {
        buffer[buffidx] = 0;
        return;
      }
      buffer[buffidx++]= c;
  }
}

uint32_t SSerial2Mobile::parsedecimal(char *str) {
  uint32_t d = 0;
  
  while (str[0] != 0) {
   if ((str[0] > '9') || (str[0] < '0'))
     return d;
   d *= 10;
   d += str[0] - '0';
   str++;
  }
  return d;
}
  • Scotty

Looks like yet more problems caused by using an old library,
Replace _sSerial.println(26, BYTE);with

	_sSerial.write(26);
	_sSerial.println();

and replace#include "Arduino.h"with#include <Arduino.h>