Chat here about code rewrites, mods, etc... with respect to the github project https://github.com/esp8266/Arduino

Moderator: igrr

User avatar
By Mohammed Ubaid
#46410 Done... Completed it :)
Thank you Mr.Martin, you were right, a single serial port in esp8266, either connects to serial monitor or connects with arduino. I was doing both. Unplugged the USB cable and powered it independently. It works.

May be it will be useful for reference:

The arduino code I used is:
Code: Select all#include <SPI.h>       

char msg[1000];
int pPL=3,pPrL=4;

void setup() {
// initialize serial communications at 9600 bps:
Serial1.begin(9600);
}

void loop() {
sprintf(msg, "MMKBXX,MMCXXX,%d,%d,%d,%d",pPL,pPrL,0,0);
pPerL++;
Serial1.write(msg);
}


I am using Arduino mega, so I have 4 serial ports, I used TX1 and RX1.

On the NodeMCU Esp8266, I used the below code:
Code: Select all#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

char msg[1000];
int i=0;


// WiFi parameters
const char* ssid = "lenovo";
const char* password = "password";

IPAddress remoteIp(192, 168, 43, 55); // address to send UDP packe to
int Port = 7000;
int localPort = 7000;

WiFiUDP Udp;  // A UDP instance to let us send and receive packets over UDP

void setup(void)
{
// Start Serial
Serial.begin(9600);
// Connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Print the IP address
Serial.println(WiFi.localIP());
Serial.println(localPort);
Udp.begin(localPort);
}

void loop()
{
 
  if (Serial.available()) {
    int inByte = Serial.read();
    Serial.write(inByte);
    msg[i] = (char)inByte;
    if (inByte == '\r' or inByte == '\n' or i > (sizeof(msg) - 1)) {
      msg[i] = 0;
      i = 0;
      Serial.print("echo = ");
      Serial.println(msg);
    }
    else
      i++;
  }
    Udp.beginPacket(remoteIp,Port); //Send Answer to Network     
    Udp.write(msg);
    Udp.endPacket();
}


Your String decoding logic worked in the first go Mr. Martin, Thank you..!!!

With that done, I have one final issue.

My ESP8266 is disconnecting from the network after updating a little data.

Is this a module power supply issue?
It is even taking a long time to connect to wifi, like 15mins..!!!! :shock:

I am using a power supply chip (rated for upto 700mA) to supply both arduino and my esp8266..!!!!
Last edited by Mohammed Ubaid on Wed May 04, 2016 3:07 am, edited 1 time in total.
User avatar
By Mohammed Ubaid
#46465 I guess not a router issue, i created a wifi hotspot on my cell phone and on that I connected and i am sending data to my laptop which is also connected to my wifi hotspot..!!!

Thing is when i used UDP library, I am seeing this issue.

If i run just the code for connecting to wifi, the connection is stable.

While in sending data through udp, this is disconnecting