3D printer WIFI addon WITH ESP
If you don't have wifi in your printer you could connect another esp to serial port of your printer
Then use this code:
#include <ESP8266WiFi.h>
#include <WiFiServer.h>
#include <WiFiClient.h>
const int WIFI_STANDALONE_ACCESS_POINT_SERVER = 0;
const int WIFI_SERVER = 1;
const int WIFI_CLIENT = 2;
int PRINTER_WIFI_TYPE;
const char *ssid = "...";
const char *password = "wifi_password";
IPAddress serverIP(192,168,43,48); //server ip (the one that sends commands)
const int serverIPPort = 5556; //port
WiFiServer pserver(serverIPPort);
WiFiClient pclient;
bool cliconnected;
void setup()
{
cliconnected = false;
PRINTER_WIFI_TYPE = WIFI_CLIENT;//WIFI_STANDALONE_ACCESS_POINT_SERVER;
Serial.begin(115200); //set baudrate of printer serial
delay(1000);
Serial.println();
Serial.print("Configuring access point…");
if (PRINTER_WIFI_TYPE == WIFI_STANDALONE_ACCESS_POINT_SERVER)
{
WiFi.softAP(ssid, password);
WiFi.begin();
delay(10000);
pserver.begin();
}
if ( (PRINTER_WIFI_TYPE == WIFI_SERVER) || (PRINTER_WIFI_TYPE == WIFI_CLIENT) )
{
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) { delay(500); }
if (PRINTER_WIFI_TYPE == WIFI_SERVER) pserver.begin();
//if (PRINTER_WIFI_TYPE == WIFI_CLIENT) pclient.begin();
}
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
//server.on("/", handleRoot);
}
void loop()
{
String request = "";
if (PRINTER_WIFI_TYPE == WIFI_SERVER)
{
WiFiClient lclient = pserver.available();
//
if (!lclient)
return; else
{
request = lclient.readStringUntil('\r');
lclient.flush();
}
}
if ( (PRINTER_WIFI_TYPE == WIFI_CLIENT) && (!cliconnected) )
if (pclient.connect(serverIP, serverIPPort)) cliconnected = true;
if ( (PRINTER_WIFI_TYPE == WIFI_CLIENT) && (cliconnected) )
{
request = pclient.readStringUntil('\r');
pclient.flush();
}
if (request.length() > 2)
Serial.println(request);
}