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
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.
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();
}
}