我正在使用ESP8266创建一个mesh网络,这里我使用两个ESP-01作为客户端,nodemcu作为服务器。
我也在使用painlessMesh库。它工作得很好,我把这些值作为JSON发送给服务器。但问题是,现在我必须连接到本地WiFi连接,才能将这些数据发布到nodered。无痛网格可以创建一个mqtt网桥来将这些数据传输到mqtt客户端,但是它必须与WiFi路由器在同一个通道上。我试过了,但似乎有点复杂。
是否有任何方法可以终止上述mesh任务,并使用Arduino的WiFi库连接到internet。
 // Prototype for the msg received from other nodes
 void receivedCallback( uint32_t from, String &msg );
// create a task instance to send msg to client nodes
Task logServerTask(10000, TASK_FOREVER, []() {
   DynamicJsonBuffer jsonBuffer;
   JsonObject& msg = jsonBuffer.createObject();
   msg["server"] = "logServer";
   msg["nodeId"] = mesh.getNodeId();
   String str;
   msg.printTo(str);
   mesh.sendBroadcast(str);
   Serial.printf("\n");
   });
void setup() {
   Serial.begin(115200);
     mesh.setDebugMsgTypes( ERROR | CONNECTION | S_TIME );  // set before 
      init() 
     //initialise the mesh
      mesh.init( MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT, 
      WIFI_AP_STA, 6 );
      mesh.onReceive(&receivedCallback);
      mesh.stationManual(STATION_SSID, STATION_PASSWORD);
      mesh.setHostname(HOSTNAME);
      client.setClient(wifiClient);
      client.setServer(mqtt_server,1883);
      mesh.onNewConnection([](size_t nodeId) {
      Serial.printf("New Connection %u\n", nodeId);
    });
     mesh.onDroppedConnection([](size_t nodeId) {
     Serial.printf("Dropped Connection %u\n", nodeId);
    });
     // Add the task to the your scheduler
       userScheduler.addTask(logServerTask);
       logServerTask.enable();
     }
  void loop() {
      userScheduler.execute(); // it will run mesh scheduler as well
      mesh.update();
      client.loop();
      while(!client.connected()){
          if(client.connect("ESP8266Client123456789")){
          client.subscribe("thermalValues");
          client.subscribe("thermalValues1");
    }
      else{
       Serial.print("failed,rc=");
       Serial.println(client.state());
       delay(500);
    }   
  }
 }
//callback to the received messages from different nodes
void receivedCallback( uint32_t from, String &msg ) {
  //callback received
 }https://stackoverflow.com/questions/52754285
复制相似问题