I am starting to write a library that needs to incorporate the painlessmesh library as its core function, essentially, a wrapper around it. I started putting it together but quickly hit a snag wrapping the painlessmesh lib. I know I am missing something in the declaration, just cant figure out what.
Any help would be great moving this on.
I have the following code:
myLib.h
#ifndef myLib_h
#define myLib_h
#include "Arduino.h"
struct libNode{
String deviceName;
String nodeName;
String Parameters;
};
class myLib
{
public:
myLib(libNode node);
//myLib(int node);
void beginMesh(String meshPrefix, String meshPassword, int meshPort);
void updateMesh();
private:
EscapeNode _node;
void receivedCallback(uint32_t from, String &msg);
//int _node;
};
#endif
and in my myLib.cpp
#include "Arduino.h"
#include "myLib.h"
#include "painlessMesh.h"
Scheduler userScheduler; // to control your personal task
painlessMesh mesh;
// Constructor
myLib::myLib(EscapeNode thisNode)
{
// Intialise the variable
_node = thisNode; //{"testDevice", "TestNode", "Parameter JSON String"};
// Start Up The Node
Serial.begin(115200);
//beginMesh();
}
void myLib::beginMesh(String MESH_PREFIX, String MESH_PASSWORD, int MESH_PORT) {
Serial.println('beginMesh');
Serial.println(MESH_PREFIX);
Serial.println(MESH_PASSWORD);
Serial.println(MESH_PORT);
//mesh.setDebugMsgTypes( ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on
mesh.setDebugMsgTypes(ERROR | STARTUP); // set before init() so that you can see startup messages
mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT);
mesh.onReceive (&myLib::receivedCallback);
//mesh.onNewConnection(&newConnectionCallback);
//mesh.onChangedConnections(&changedConnectionCallback);
//mesh.onNodeTimeAdjusted(&nodeTimeAdjustedCallback);
//userScheduler.addTask(taskSendMessage);
//taskSendMessage.enable();
}
I have a very simple test program:
#include <myLib.h>
void setup() {
// put your setup code here, to run once:
libNode node;
node.deviceName = "TestDevice";
node.nodeName = "TestNode";
node.Parameters = "{XXXXX}";
myLib thisNode = myLib(node);
#define MESH_PREFIX "xxxx"
#define MESH_PASSWORD "xxxx"
#define MESH_PORT 5555
thisNode.beginMesh(MESH_PREFIX , MESH_PASSWORD , 5555);
}
void loop() {
// put your main code here, to run repeatedly:
}
I get this error message when I try and compile:
d:UsersrichaDocumentsArduinolibrariesmyLibmyLib.cpp: In member function ‘void myLib::beginMesh(String, String, int)’:
d:UsersrichaDocumentsArduinolibrariesmyLibmyLib.cpp:39:51: error: no matching function for call to ‘painlessmesh::wifi::Mesh::onReceive(void (myLib::)(uint32_t, String&))’
mesh.onReceive (&myLib::receivedCallback);
^
In file included from d:UsersrichaDocumentsArduinolibrariesPainless_Meshsrc/painlessMeshSTA.h:6,
from d:UsersrichaDocumentsArduinolibrariesPainless_Meshsrc/painlessMesh.h:20,
from d:UsersrichaDocumentsArduinolibrariesmyLibmyLib.cpp:9:
d:UsersrichaDocumentsArduinolibrariesPainless_Meshsrc/painlessmesh/mesh.hpp:227:8: note: candidate: ‘void painlessmesh::Mesh::onReceive(painlessmesh::receivedCallback_t) [with T = painlessmesh::Connection; painlessmesh::receivedCallback_t = std::function<void(unsigned int, String&)>]’
void onReceive(receivedCallback_t onReceive) {
^~~~~~~~~
d:UsersrichaDocumentsArduinolibrariesPainless_Meshsrc/painlessmesh/mesh.hpp:227:8: note: no known conversion for argument 1 from ‘void (myLib::)(uint32_t, String&)’ {aka ‘void (myLib::*)(unsigned int, String&)’} to ‘painlessmesh::receivedCallback_t’ {aka ‘std::function<void(unsigned int, String&)>’}
exit status 1
Compilation error: exit status 1