Esp8266 and Nano two way serial communication - Solved

Solved
Arduino Code

//Serial two way communication Arduino/Esp 8266
// Webpage toggles Arduino Led 13  - And -
// Arduino, every 10 seconds sends a new count to show on webpage.

//  Connect GND from the Arduino to GND on the ESP8266
//  Arduino pin TBD below and voltage divider at ESP8266 RX for 5v to 3.3 reduction
//  Pull ESP8266 CH_PD HIGH
//  When Flashing ESP with lua code
//     1) Close Serial Monitor at all times
//     2) Load a blank sketch to arduino, Void Setup() and Void Loop() only
//     3) Next connect RX to RX, TX to TX (yes really)
//     4) Update your router ID and Password in lua code. Upload the init.lua code via arduino board , I use LuaLoader.
//     5) Restart the ESP8266 and click LuaLoader "GET IP" for the web IP you will use later.
//     6) Remove Esp/Nano RX/TX connections or this sketch won't upload
//     7) Upload this sketch to the Nano
//     8) Now connect RX to TX and TX to RX as you would expect.
//     9) restart both Esp and Nano
//     10) Can also get the ESP IP off your router list if you forgot to get it in step 5.
//     11) Connect to ESP webpage IP.

int LIGHT_RELAY_PIN = 13;
long previousMillis = 0;

void setup()
{
  pinMode(LIGHT_RELAY_PIN, OUTPUT);
  Serial.begin(9600);     // communication with the host computer

}

void loop()
{
  // listen for communication from the ESP8266 and update LED 13
  if ( Serial.available() > 0 )   {
    String varStr, valStr, s = "";
    s = Serial.readString();


    // ----------- Variable / Value "String" pair from website ----------------------
    varStr = s.substring(0, s.indexOf("="));
    varStr.trim();
    valStr = s.substring(s.indexOf("=") + 1 , s.length());
    valStr.trim();

    if (varStr == "toggleLed13On" && valStr == "true") {
      lightOn();
    }

    if (varStr == "toggleLed13Off" && valStr == "true") {
      lightOff();
    }
    varStr  = "";
    valStr  = "";
    s = "";
  }



  if (millis() - previousMillis > 10000) {
    static int i;
    i++;
    previousMillis = millis();
    //EspSerial.println("cmd(1)");
    Serial.print("count = ");
    Serial.print(i);
    Serial.print('\n');
  }

}


void lightOn() {
  digitalWrite(LIGHT_RELAY_PIN, HIGH);
  delay(5);
  Serial.println("lightStatus = \"ON\"");
  Serial.print('\n');
}

void lightOff() {
  digitalWrite(LIGHT_RELAY_PIN, LOW);
  //  To send String info back to the Esp escape quotes \ like sample below and new line.
  delay(5);
  Serial.println("lightStatus = \"Off\"");
  Serial.print('\n');
}


[code]

LUA Code
[code]

wifi.setmode(wifi.STATION)
wifi.sta.config("Your SSID","Your Password")

lightStatus = "Waiting"
count = "Waiting"

srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
    conn:on("receive", function(client,request)
        local buf = "";
        local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
        if(method == nil)then
            _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
        end
        local _GET = {}
        if (vars ~= nil)then
            for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
                _GET[k] = v
            end
        end

        local _on,_off = "",""
          
       if(_GET.pin == "toggleLed13Off")then
        print("toggleLed13Off = true")
        lightStatus = "OFF"
       elseif(_GET.pin == "toggleLed13On")then
        print("toggleLed13On = true")
        lightStatus = "ON"
       end
      
        buf = buf.."<!DOCTYPE HTML>"
        buf = buf.."<html>"
        buf = buf.."<head>"
        buf = buf.."<META name=\"description\" content=\"ESP8266\">"
        buf = buf.."<META http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">"
        buf = buf.."<META http-equiv=\"Pragma\" content=\"no-cache\">"
        buf = buf.."<META HTTP-equiv=\"Cache-Control\" content=\"no-cache\">"
        buf = buf.."<META HTTP-EQUIV=\"Expires\" CONTENT=\"Mon, 06 Jan 1990 00:00:01 GMT\">"

        buf = buf.."<title>Arduino / ESP8266 Web Server</title>"
        buf = buf.."</head>"
        buf = buf.."<body>"
      
        buf = buf.."<h1> ESP8266 Web Server</h1>
"
        buf = buf.." IP Address :" .. tostring(wifi.sta.getip()) .. "

"
        --buf = buf.."<p><a href=\"\"><button>Refresh Page</button></a>&nbsp
"
        buf = buf.." Nano LED 13 Status is :" .. lightStatus .. "
"
        buf = buf.." Nano to ESP Count is:" .. count .. " 
"

        -- Arduino Led 13 light toggle   
        buf = buf.."<p><a href=\"?pin=toggleLed13On\"><button>Light On</button></a>&nbsp"
        buf = buf.."<p><a href=\"?pin=toggleLed13Off\"><button>Light Off</button></a>&nbsp"
                                                
        buf = buf.."</body>"
        buf = buf.."</html>"
                             
                             

        client:send(buf);
        client:close();
        collectgarbage();
    end)
end)


-- setup UART for receiving data
-- parameters uart.setup( UART-id, baud, databits, parity, stopbits, echo )
uart.setup(0,9600,8,0,1)
// this doesn't work  
   Serial.println(cmd(123));

What do you think it is supposed to do?

The only reference to cmd() is the lua function, which isn't running on the Arduino.

When Lua receives the cmd() function

Where is that Lua code running? NOT on an Arduino.

joe494:
Lua code is running on the esp8266 not the Arduino

I could have sworn this was the Arduino forum.