Go Down

Topic: ESP8266(Flased with nodemcu) and Arduino Uno ! CODE WONT WORK HELP! (Read 5011 times) previous topic - next topic

Devashish

If I send these commands through the serial monitor everything works fine . But if I try it using the code below it just does't work and show errors and what not.




#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/index.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\")");
delay(3000);
 

}
void loop() // run over and over
{
   

  if (mySerial.available())
    Serial.print((char)mySerial.read());
  if (Serial.available())
   mySerial.write((char)Serial.read());
}
 

It just shows garbled information .Where am I going wrong?


Devashish

I have already been trying on 9600 . This is what I get on the serial monitor .


Goodnight moon!
¬,®XY·nn�Ñ¥r¢Å   ò
Þ¹¹z:�25ëË ¬®_XJ¸inP…å½*ûò¥RõËKÖÖ'KM--7.j¹sp8266 Lua; Windows NT 5.1)\r\n')
conn:send('\r\n')
stdin:1: '=' expected near 'Lua'
> þ

And these error messages keep changing as well everytime it runs . On 115200 its entirely garbled .

mart256

Arduino uno is 5v and esp8266 is 3v3. Maybe thats the problem, use voltage level shifter.

Riva

What do you get through serial when you first reset the ESP8266?

The commands your sending don't look like nodemcu api instructions so what modules have you got compiled with the core that use them?
Don't PM me for help as I will ignore it.

Arduino14


Chagrin

stdin:1: '=' expected near 'Lua'
That's a Lua syntax error; the semicolon needs to be escaped. Better yet just remove the entire "User-Agent:" line because it's not necessary anyway. Then remove the "Accept:" line as well.

Erni

Why do you use an Arduino to upload LUA code?

It is much easyer to use a dedicated upload tool like this:

http://www.esp8266.com/

It is just an example, there are more to chose from on the esp8266 forum.

Chagrin

Why do you use an Arduino to upload LUA code?
He's not writing files on the ESP8266 (the would prefix each line with file.writeline(..)). He's giving the module commands from the Arduino to do... whatever.

There are more efficient ways to do what he's doing but I don't see it as a problem.


Erni

Quote
He's not writing files on the ESP8266
Did I say that that ?

Quote
He's giving the module commands
I know, that is why I mentioned the LuaLoader where you can just copy/paste commands to the ESP8266, or you can upload Lua files as text-files.

I just think it is to complicate things to first write a sketch and upload to an Arduino to do such a task

electricalhobbyist

I also experience that problem. I also dont know how did I manage to solve mine. But I think it is beacuse of the number of characters you sent. I also used a <SoftwareSerial.h>. But in your code, you send all the data thru serial and what I did is i just send data to serial what is just necessary. I wanted to put the code here but its bit long so if you want to know how I did mine here is the link. I hope it helps and ignore if it dont. Thanks.
http://thinkingparts.blogspot.com/2015/08/home-automation-diy-version-internet_23.html

Go Up