how to connect the Esp32 wifi to the connect ramps 1.4 ?

hello, I have connected the ESP32-38 PIN, to the ramps 1.4 instead of the bluetoch. to give you connectivity via Wi-Fi.

In this code, the esp32 module is connected to my home 
router and I can do it with my pc. I don't know how I should do
to flow as it should be... with the repeater host, it connects, but the protocol is
not well established so that they understand each other...


/*
 WiFi Web Server



 If the IP address of your shield is yourAddress:
 http://yourAddress/H turns the LED on
 http://yourAddress/L turns it off

 This example is written for a network using WPA encryption. For
 WEP or WPA, change the Wifi.begin() call accordingly.

 Circuit:
 * WiFi shield attached


 created for arduino 25 Nov 2012
 by Tom Igoe

ported for sparkfun esp32
31.01.2017 by Jan Hendrik Berlin
 
 */

#include <WiFi.h>

const char* ssid     = "printer 3d";
const char* password = "123456";

WiFiServer server(80);

void setup()
{
    Serial.begin(115200);


    delay(10);

    // We start by connecting to a WiFi network

    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }

    Serial.println("");
    Serial.println("WiFi connected.");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
    
    server.begin();

}

int value = 0;

void loop(){
 WiFiClient client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,
   // Serial.println("New Client.");           // print a message out the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {   
       if (Serial.available()) {

       client.print(Serial.read());
        // Serial.write("hola");
        }
      
      // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        //char c = client.read();             // read a byte, then

       Serial.write(client.read());

      }

 
      
    }
    // close the connection:
    client.stop();
   // Serial.println("Client Disconnected.");
  }
}





Comments

  • This works with TP/IP connection or Telnet connection in host. Enter ip and port required.

    It is essential that the esp32 just puts the data through to firmware and returns results 1:1. No interference no protocol addition especially no web browser protocol (http) on that port. Any other communication with tcp/ip is not supported.
  • edited May 2022
    Hello, I have tried in different ways and I cannot establish the connection correctly via wifi-esp32. any ideas?
    
    When it connects, I can see that repetier-host correctly sends the data to the esp32-wifi, I see it through the serial port of the Esp32. Photo 1
    
    https://ibb.co/Csk94LM    
    
    When it sent data over serial , relayed over wifi, the repetier-host captured correctly. photo 2
    
    … I do not know what I'm doing wrong. Help -___-   https://ibb.co/Ry7M83L

    #include <WiFi.h>

    const char* ssid     = "wifi";
    const char* password = "123456";

    WiFiServer server(8080);

    void setup()
    {
        Serial.begin(115200);
       // pinMode(5, OUTPUT);      // set the LED pin mode

        delay(10);

        // We start by connecting to a WiFi network

        Serial.println();
        Serial.println();
        Serial.print("Connecting to ");
        Serial.println(ssid);

        WiFi.begin(ssid, password);

        while (WiFi.status() != WL_CONNECTED) {
            delay(500);
            Serial.print(".");
        }

        Serial.println("");
        Serial.println("WiFi connected.");
        Serial.println("IP address: ");
        Serial.println(WiFi.localIP());
        
        server.begin();

    }



    size_t len=0;
    size_t len2=0;

    byte sbuf[128];
    byte sbuf2[128];

    void loop(){
     WiFiClient client = server.available();   // listen for incoming clients

      if (client) {                             // if you get a client,
        while (client.connected()) {            // loop while the client's connected
          if (client.available()) {             // if there's bytes to read from the client,
            len = client.available();
             client.readBytes(sbuf, len);
             Serial.write(sbuf,len);
             
          }

          if (Serial.available()) {
            len2 = Serial.available();
            Serial.readBytes(sbuf2, len2);
            client.write(sbuf2, len2);
           

          }

        }   
       client.stop();  
    }
    }




  • What does the "WiFi.h" library d? http or just tcp connection? As said it must be a plain tcp connection and port 8080 sounds like http. Also the loop looks much like it just answers a http request, that is not the kind of connection you need for communication with host/server.
  • edited May 2022
    EUREKA WORKS!!
    
    I ONLY NEEDED A SECOND SERIAL PORT. IT SEEMS TO BE IN COMPLICT WITH DEFAUT.



    #include <WiFi.h>

    const char* ssid = "777";
    const char* password = "777";

    WiFiServer server(8080);


    #define RXD2 16
    #define TXD2 17


    void setup()
    {
    Serial.begin(115200);
    Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);

    delay(10);

    // We start by connecting to a WiFi network

    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    }

    Serial.println("");
    Serial.println("WiFi connected.");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());

    server.begin();

    }



    size_t len=0;
    size_t len2=0;
    byte sbuf[128];
    byte sbuf2[128];



    void loop(){
    WiFiClient client = server.available(); // listen for incoming clients

    if (client) { // if you get a client,
    while (client.connected()) { // loop while the client's connected
    if (client.available()) { // if there's bytes to read from the client,
    len = client.available();
    client.readBytes(sbuf, len);
    Serial2.write(sbuf,len);

    }

    if (Serial2.available()) {
    len2 = Serial2.available();
    Serial2.readBytes(sbuf2, len2);
    client.write(sbuf2, len2);


    }

    }
    client.stop();
    }
    }


  • Great it works. Just do not understand what the first serial is used for. Client talks with host/server and Serial2 with printer firmware. But what is serial used for? Surely not firmware as it is not correct format. Looks like some monitoring serial you could connect with for debugging, but otherwise not required.
Sign In or Register to comment.