-->
Page 1 of 5

Simple TCP Connection Library for ESP8266 on Arduino

PostPosted: Fri Sep 26, 2014 10:06 am
by Akexorcist
I've coding a library for ESP8266 on Arduino. I think It's will be useful for anyone who want to use this module with easy coding.

It's have only TCP Connection now. I didn't yet coding it to supported web server or http connection. (Soon) If you have any feedback about my library, please tell me :D

This library is include
• Open AP command (I forced it to WPA_WPA2_PSK authentication)
• Connect to Any AP command
• Open TCP Server and Client
• Send a message between modules
• Auto reconnect when connection isn't success
• Debugging with another serial port (If your board have more than 1 channel)

https://github.com/INEXTH/Arduino-ESP8266_libs

A sample project from this library (Thai language)

Re: Simple TCP Connection Library for ESP8266 on Arduino

PostPosted: Sat Sep 27, 2014 5:12 am
by reaper7
@Akexorcist - very good job!
many tnx!

Re: Simple TCP Connection Library for ESP8266 on Arduino

PostPosted: Sat Sep 27, 2014 6:06 am
by Samighi11
Akexorcist wrote:I've coding a library for ESP8266 on Arduino. I think It's will be useful for anyone who want to use this module with easy coding.

It's have only TCP Connection now. I didn't yet coding it to supported web server or http connection. (Soon) If you have any feedback about my library, please tell me :D

This library is include
• Open AP command (I forced it to WPA_WPA2_PSK authentication)
• Connect to Any AP command
• Open TCP Server and Client
• Send a message between modules
• Auto reconnect when connection isn't success
• Debugging with another serial port (If your board have more than 1 channel)

https://github.com/INEXTH/Arduino-ESP8266_libs

A sample project from this library (Thai language)
http://www.youtube.com/watch?v=86dubCzFvd0



here is the part I can't get to work consistently (almost there). Many command do not return online like items.

Code: Select allString ESP8266_TCP::readData() {
    String data = "";
    while(available() > 0) {
        char r = serial->read();
        if (r == '\n') {
            return data;
        } else if(r == '\r') {
        } else {
            data += r; 
        }
    }
}



I am CWLAP, RST and a few others (I have not address +IPD yet) return multiple lines. I would like to merge the library I am working on with many others, just need some ideas on how serial read (and wait) are being handled. (not this is WIP and the "20" tries is just a test). it appears to work fast and clean, getting the expected results (WIP)

Code: Select allString  ESP8266::sendAndWait(String AT_Command, char *AT_Response, uint16_t wait) {
        serial.println(AT_Command);
        Serial.println("Sending " + AT_Command);
        String str = "";
        unsigned long time1 = millis();
        for (int i=0;i<20;i++) {
           while (Serial1.available()) {
                  str = str + serial.readString();                 
        }
        if (str.indexOf(AT_Response) == -1)
           delay(300);
        else
           break;
       }
       Serial.print("Serial port returned" + str);
   
        if (str.indexOf(AT_Response) == -1)
           return "Not OK";
        else
          return "OK";
}

Re: Simple TCP Connection Library for ESP8266 on Arduino

PostPosted: Sat Sep 27, 2014 11:44 am
by RichardS
What we should be doing here is first, making AT+ command **ALL** behave the same... and then when writing drivers say for Arduino, then its a know command + response, we should work on a common command set and response.....

Maybe this should be a complete sub forum on its own, that command and response section?

Richard.