mesh network using esp8266 with arduino

Hi,

I am using arduino mega 2560 and esp8266mod for my application . I successfully made esp8266 as AP and also use TCP stack with arduino. Now I want to make mesh network using 4 esp8266 in which one is root and one is end device and others are just passing node.For that I already tried Hellomesh code which is listed in esp8266 examples. but I can't understand that how to use that examples in arduino to make mesh network? I also searched and use espressif sdk but i can't find interesting. I also use some other examples but they are not meant for "Mesh" network. Please suggest some links or sample code by which I can build mesh network.

Hi, here I got a code for 2 ESP comunication each other as stand alone

-- CODIGO CLIENTE 
wifi.setmode(wifi.STATION)                  -- Modo Station
wifi.sta.config("bamboklat","12345678")     -- Conectando a la red
wifi.sta.connect() 


tmr.alarm(1, 1000, 1, function()            --Que intente cada 1 seg
    if wifi.sta.getip()== nil then      
        print("IP no disponible, a la espera...") 
    else 
        tmr.stop(1)                         -- Desabilitamos la alarm
        print("Configuracion hecha, IP: "..wifi.sta.getip())
    end 
end)

tmr.alarm(2, 4000, 1, function()            --cada 3 seg que envíe
    if (wifi.sta.getip() ~= nil) then       --por si pierde conexion 
        sk = net.createConnection(net.TCP, 0)  
        sk:connect(80, "192.168.4.1")           -- server ESP IP
        
        sk:on("connection", function(sk) 
        sk:send("123456789")
        print("Mensaje enviado") end )
        
        sk:on("receive", function(sk, Datadeentrada)
        print("Data recibida: " .. Datadeentrada) 
        sk:close() end) 
    else
        print("no connection...")
    end
end)

Server

-- CODE FOR SERVER ESP
wifi.setmode(wifi.STATIONAP)
cfg={}
cfg.ssid="bamboklat" 
cfg.pwd="12345678"
wifi.ap.config(cfg)

wifi.sta.config("telecentro","bamboklat")     -- Conectando a la red
wifi.sta.connect() 

tmr.alarm(1, 1000, 1, function()            --Que intente cada 1 seg
    if wifi.sta.getip()== nil then      
        print("IP no disponible, a la espera...") 
    else 
        tmr.stop(1)                         -- Desabilitamos la alarm
        print("Configuracion hecha, IP: "..wifi.sta.getip())
    end 
end)

--server
server = net.createServer(net.TCP) 
server:listen(80, function(conn)
        conn:on("receive", function(conn, Datadeentrada) 
        print("received: " .. Datadeentrada)
        
        fragm = string.sub(Datadeentrada, 1, 2)
        print(fragm)
        a = tonumber(fragm)
        print(a)
        b=a+3
        print(b)  --Corroboramos si efectiamente b es un numero
                  -- igual al fragm + 3  
        message = "Recibido OK"
        conn:send(message)
        print("enviado: " .. message)
        message = nil  --libramos RAM
    end) 
    --conn:on("sent", function(conn) 
   --end)
end)

For me its kicking fine, do not take the code seriusly, since it was my first code that worked. hope it helps.

here an aplication of sending data to thingspeak sending the comands from arduino Tx Rx, is kicking for me, I had plenty of troubleshotting with AT commands:

#include "DHT.h"  //Añadimos la libreria con la cual trabaja nuestro sensor
#define DHTPIN 7     // Indicamos el pin donde conectaremos la patilla data de nuestro sensor
#define DHTTYPE DHT11   // DHT 11 / DHT 22  (AM2302) / DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);  



#include <SoftwareSerial.h>
#define SSID "telecentro"
#define PASS "bamboklat"
#define DST_IP "184.106.153.149" //ThingSpeak.com  
SoftwareSerial dbgSerial(2, 3); // RX, TX

String GET = "GET /update?key=BOV5P6CY9WUBKG4K&1=";  //BOV5P6CY9WUBKG4K

//https://api.thingspeak.com/update?key=MV24V850YRMH98YR&field1=0

boolean flag_resp=false;
boolean flag_wifi=false;
boolean connected=false;

void setup()
{
  dht.begin();                

  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  Serial.setTimeout(5000);
  dbgSerial.begin(9600); //can't be faster than 19200 for softserial
  dbgSerial.println("ESP8266 Demo");

  //Ciclara hasta que responde, generalmente 3 o 4 veces

  do
  {
    Serial.println("node.restart()");
    //Serial.println("AT+RST");
    delay(1000);

    if(Serial.find("NodeMCU"))
    { 
      flag_resp= true;
      dbgSerial.println("Module is ready");
    }
    else
    { 
      flag_resp= false;
      dbgSerial.println("Module have no response.");
    }

  }
  while(flag_resp== false);


  delay(200);                

  //connect to the wifi
  
  for(int i=0;i<5;i++)
  {    
    //Conexion a la red
    if(connectWiFi())
    {
      connected = true;
      break;
    }
  }

  if (!connected){
    dbgSerial.println("No logra coectarse a la red wifi");
  }            //queda colgado si no se conecta a la pagina

}

void loop()
{ 
  if(connected == true){

    int h = dht.readHumidity();  
    int t = dht.readTemperature(); 

    Serial.println("conn=net.createConnection(net.TCP, 0)");
    delay(250);
    Serial.println("conn:on(\"receive\",function(conn, payload) print(payload) end)");
    delay(250);
    Serial.println("conn:connect(80,'184.106.153.149')");
    delay(250);
    Serial.println("conn:send(\"" + GET + String(t) + "&2=" + String(h) + " HTTP/1.1\\r\\n\") ");
    delay(250);
    Serial.println("conn:send(\"Host: api.thingspeak.com\\r\\n\") ");
    delay(250);
    Serial.println("conn:send(\"Accept: */*\\r\\n\")");
    delay(250);
    Serial.println("conn:send(\"User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\\r\\n\")");
    delay(250);
    Serial.println("conn:send(\"\\r\\n\")");
    delay(250);
    Serial.println("conn:on(\"sent\",function(conn) print(\"Closing connection\") conn:close() end)");
    delay(250);
    //Serial.println("conn:on(\"disconnection\", function(conn) print(\"Got disconnection...\") end)");
    /*              //Avoid Java conflicks on line Serial.println("conn:send(\"Accept: ....
   */
    //Serial.find("+IPD");
    while (Serial.available())
    {
      char c = Serial.read();
      dbgSerial.write(c);
      if(c=='\r') dbgSerial.print('\n');
    }
    dbgSerial.println("  ====");

    delay(5000);
  }

}


boolean connectWiFi()
{
  Serial.println("print(wifi.setmode(wifi.STATION))");
  Serial.println("print(wifi.sta.config(\"telecentro\",\"bamboklat\"))");
  Serial.println("print(wifi.sta.getip())");
  delay(200);

  if(Serial.find(">"))
  { 
    flag_wifi= true;
    dbgSerial.println("OK, Connected to WiFi");
    return true;
  }
  else
  { 
    flag_wifi= false;
    dbgSerial.println("Can not connect to the WiFi");
    return false;
  }
}