2017-07-20 15 views
-1

nodeMCUで実行するプロジェクトでESP8266WiFiMeshライブラリを使用しています。ライブラリで提供されている例がArdunino inoファイルにある場合はうまく動作しますが、それをC++のcppファイルに書き直すと問題が発生します。 Mesh :: Meshでは、ESP8266WiFiMeshクラスのインスタンスを作成するときに、chipIdとコールバックの2つのパラメータを提供します。私は数日のために苦労していると私は、任意の解決策を見つけることができませんでしたコールバック関数(manageRequest)コードを書き直す際に未解決のオーバーロードされた関数タイプC++

<unresolved overloaded function type> to std::function<String(String)> 

を提供するときに私が取得

エラー。

私が使用している元のサンプルコードは次のとおりです。 https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFiMesh/examples/HelloMesh/HelloMesh.ino

Mesh.cpp:

#include "Mesh.h" 
#include <ESP8266WiFi.h> 
#include <ESP8266WiFiMesh.h> 

unsigned int request_i = 0; 
unsigned int response_i = 0; 

Mesh::Mesh() { 
    /* Create the mesh node object */ 
    /* Here I'm getting Unresolved overloaded function when providing manageRequest function (callback) */ 
    ESP8266WiFiMesh mesh_node = ESP8266WiFiMesh(ESP.getChipId(), manageRequest); 

    /* Create the utils node object */ 
    utilsy = new Utils(); 

#ifdef DEBUG 
    Serial.println("Setting up mesh node..."); 
#endif 

    /* Initialize the mesh node */ 
    mesh_node.begin(); 
} 

/** 
* Callback for when other nodes send you data 
* 
* @request The string received from another node in the mesh 
* @response The string to send back to the other node 
*/ 
String Mesh::manageRequest(String request) { 

    /* Split request */ 
    String requestedTo = utilsy->getDelimitedValues(request, '.', 0); 
    String requestedFrom = utilsy->getDelimitedValues(request, '.', 1); 
    const char *cstr = requestedFrom.c_str(); 
    String requestedMessage = utilsy->getDelimitedValues(request, '.', 2); 
    String requestedState = utilsy->getDelimitedValues(request, '.', 3); 

#ifdef DEBUG 
    /* Print out received message */ 
    Serial.print("Requested from: " + requestedFrom); 
    Serial.print("\tMessage: " + requestedMessage); 
    Serial.println("\tRequested state: " + requestedState); 
#endif 

    /* return a string to send back */ 
    char response[60]; 
    //TODO should send back with same message and giving proper state [0,1] whether LED turned on/off 
    sprintf(response, "%s.%d.%d.%d", cstr, ESP.getChipId(), response_i++, 1); 
    return response; 
} 

答えて

0

あなたの関数は、クラスメソッドであるため、コードは動作しませんが、あなたは適切な結果を得るためにstd::bindを使用することができます。

ESP8266WiFiMesh mesh_node = ESP8266WiFiMesh(
    ESP.getChipId(), 
    std::bind(&Mesh::manageRequest, this, std::placeholders::_1)); 
+0

それが実際に解決問題。ありがとうございました。 – damianrudzinski

関連する問題