Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Arduino IDE运行Lua脚本?(使用Arduino uno板作为ESP8266的串行提供程序)_Lua_Arduino_Wifi_Esp8266_Nodemcu - Fatal编程技术网

如何使用Arduino IDE运行Lua脚本?(使用Arduino uno板作为ESP8266的串行提供程序)

如何使用Arduino IDE运行Lua脚本?(使用Arduino uno板作为ESP8266的串行提供程序),lua,arduino,wifi,esp8266,nodemcu,Lua,Arduino,Wifi,Esp8266,Nodemcu,(我是微控制器的新手,只是一个中级程序员) 如果我通过串行监视器发送这些命令,一切正常。但是,如果我尝试使用下面的代码,它就是不工作,并显示错误和什么 #include <SoftwareSerial.h> SoftwareSerial mySerial(2, 4); // RX, TX void setup() { // Open serial communications and wait for port to open: Serial.begin(96

(我是微控制器的新手,只是一个中级程序员)

如果我通过串行监视器发送这些命令,一切正常。但是,如果我尝试使用下面的代码,它就是不工作,并显示错误和什么

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 4); // RX, TX

void setup()  
{
    // Open serial communications and wait for port to open:
    Serial.begin(9600);
    Serial.println("Goodnight moon!");

    // set the data rate for the SoftwareSerial port
    mySerial.begin(9600);
    mySerial.println("conn=net.createConnection(net.TCP, 0)");
    mySerial.println("conn:on('receive', function(conn, payload) print(payload) end)"); 
    mySerial.println("conn:connect(80,'50.87.151.128')");
    mySerial.println("conn:send('GET /devashishproject/time.php HTTP/1.1\\r\\n')");
    mySerial.println("conn:send('Host: kartikkhattar.com\\r\\n')");
    mySerial.println("conn:send('Accept: */*\\r\\n')"); 
    mySerial.println("conn:send('User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\\r\\n')");
    mySerial.println("conn:send('\\r\\n')");
}
void loop() // run over and over
{
    if (mySerial.available())
        Serial.print((char)mySerial.read());
    if (Serial.available())
        mySerial.write((char)Serial.read());
}
#包括
软件系列mySerial(2,4);//接收,发送
无效设置()
{
//打开串行通信并等待端口打开:
Serial.begin(9600);
连载。println(“晚安,月亮!”);
//设置软件串行端口的数据速率
mySerial.begin(9600);
println(“conn=net.createConnection(net.TCP,0)”;
println(“conn:on('receive',function(conn,payload)print(payload)end)”;
println(“conn:connect(80,'50.87.151.128')”;
println(“conn:send('GET/devashishproject/time.php HTTP/1.1\\r\\n');
println(“conn:send('Host:kartikkhatar.com\\r\\n');
println(“conn:send('Accept://*\\r\\n');
println(“conn:send('User-Agent:Mozilla/4.0(兼容;esp8266 Lua;Windows NT 5.1)\\r\\n');
println(“连接:发送('\\r\\n')”);
}
void loop()//反复运行
{
if(mySerial.available())
Serial.print((char)mySerial.read());
if(Serial.available())
mySerial.write((char)Serial.read());
}

它只是显示了乱七八糟的信息。我哪里做错了?它必须做电源吗?但是当通过串行监视器输入这些命令时,它工作正常吗?为什么我把它放在上面这样的代码中就不起作用了?

对不起,但是。。。该代码使用硬件串行通信。。如果将ESP连接到0和1以外的管脚上,则应使用注释掉的行中的SoftwareSerial库。另一方面,如果您使用的是串行硬件,则应能正常工作。您仍然可以看到发送的命令,因为它们与串行适配器位于同一行,但是您看不到答案(它们位于错误的行)。无论如何,它应该能工作。是的,ESP引脚连接到电路板上的第0和第1引脚。我似乎无法让它发挥作用。我希望能够看到它在串行监视器上得到的任何响应。我想知道我是否弄乱了引号。@Devashishkhatar您应该转义字符串中的引号,类C语言将字符串连接在一起,因此“this”“that”与“this”“that”相同。由于您正在打印Lua代码,因此在Lua字符串的字符串中使用单引号将不会出现难看的转义。我刚刚更新了问题中的代码,这就是我一直尝试运行的代码。即使使用SoftwareSerial.h库(使用插脚2和4作为软件串行),甚至用单引号替换双引号,我也无法使它工作。我做错了什么?对不起,但是。。。该代码使用硬件串行通信。。如果将ESP连接到0和1以外的管脚上,则应使用注释掉的行中的SoftwareSerial库。另一方面,如果您使用的是串行硬件,则应能正常工作。您仍然可以看到发送的命令,因为它们与串行适配器位于同一行,但是您看不到答案(它们位于错误的行)。无论如何,它应该能工作。是的,ESP引脚连接到电路板上的第0和第1引脚。我似乎无法让它发挥作用。我希望能够看到它在串行监视器上得到的任何响应。我想知道我是否弄乱了引号。@Devashishkhatar您应该转义字符串中的引号,类C语言将字符串连接在一起,因此“this”“that”与“this”“that”相同。由于您正在打印Lua代码,因此在Lua字符串的字符串中使用单引号将不会出现难看的转义。我刚刚更新了问题中的代码,这就是我一直尝试运行的代码。即使使用SoftwareSerial.h库(使用插脚2和4作为软件串行),甚至用单引号替换双引号,我也无法使它工作。我做错了什么?