2

I'm writing library for smart home arduino DIY project.
i want to use another library(not written by me).
here is the code:

boiler.cpp

#include "Boiler.h"
Boiler::Boiler(int pin)
{
 _pin = pin;
 dev.setDevice(_pin); // Set Device Output (on/off)
 turnOff();
}

boiler.h

#ifndef BOILER_H_
#define BOILER_H_
// include RF24 libs
#include "RF24.h"
#include "RF24Network.h"
#include "RF24Mesh.h"
#include <SPI.h>
// SmartHome Lib Includes
#include "Device.h"
#include "TimerOne.h"
#include "timeSet.h"
class Boiler 
{
 private:
 RF24 radio(7, 8);
 RF24Network network(radio);
 RF24Mesh mesh(radio, network);
 int _pin ;
 void timerIsr();
 void DrawSCR();
 public:
 .
 .
 .
 Boiler (int pin );
 void turnOn();
 void turnOff();
};

The problem is it's not compiling
the error I get is :
Boiler.h: 32:14: error: expected identifier before numeric constant
RF24 radio(7, 8)

What am i doing wrong? Thanks,

asked Apr 28, 2017 at 17:50
3
  • I've always had to put the includes of all "sub-libraries" in the main sketch. Commented Apr 28, 2017 at 18:51
  • But i wish to use it in the library... i only declare the boiler and takes care of the communication .... Commented Apr 28, 2017 at 19:20
  • You already asked this on SO. Don't cross post. Commented Apr 28, 2017 at 21:23

2 Answers 2

2

I Have found the answer (by mistake)
i have added the includes to Boiler.cpp file

#include "RF24.h"
#include "RF24Network.h"
#include "RF24Mesh.h"
#include <SPI.h>
.
.
.
#include "Boiler.h"
RF24 radio(7, 8); // Init RF24 Radio
RF24Network network(radio); // Init RF24 Network
RF24Mesh mesh(radio, network); // Init RF24 Mesh
Boiler::Boiler(int pin ,float Rev , String Last )
{
 _pin = pin;
 dev.setDevice(_pin); // Set Device Output (on/off)
 turnOff();
}
void Boiler::init( char nodeID)
{
 _nodeID = nodeID;
 // Connect to the mesh and set Node ID
 mesh.setNodeID(_nodeID);
 if (_DEBUG) Serial.println(F("Connecting to the mesh..."));
 mesh.begin();
 // init LCD and print init data on LCD
 myGLCD.InitLCD(60); // Init LCD 55 contrast
 myGLCD.setFont(SmallFont); // Set small font
 myGLCD.clrScr(); // clr screen
 myGLCD.print("Boiler Device",0,0); //Print init Data on screen
 myGLCD.print("Rev :" , 0 , 10);
 myGLCD.printNumF(_rev,1 ,35,10,'.',1,'0');
 myGLCD.print(_last,0,40);
 myGLCD.update(); // Update display
 turnOff();
}

and now it compiles ;-)

answered Apr 28, 2017 at 19:28
1

What am i doing wrong?

without seeing those includes, it is hard to tell.

I can say is that your original code, with the includes in boiler.h, is the right approach.

the revised code, which doesn't give you the error message, it not the right approach.

the issue is likely that the associated .h and .cpp files are incorrectly coded. unfortunately, without the actual code, it is hard to tell how and what the fixes should be.

answered Apr 28, 2017 at 23:18
2
  • you can see the library here: github.com/danhajduk/SmartHome Commented Apr 29, 2017 at 11:50
  • is it posible to declare public variable from method constractor? Commented Apr 29, 2017 at 12:13

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.