Hello, I have created this server to control Ender 3 using ESP32 Cam. I have an actual image from the printer(I can also do a timelapse), I can upload *.gcode files to a shared SD card and then print from it, and serial communication also works, except for one small problem. For commands like G28 for autohome there is no problem because the serial output from the printer is short, but in cases like M503 the output is long, something like that:
>>> M503
SENDING:M503
echo:; Linear Units:
echo: G21 ; (mm)
echo:; Temperature Units:
echo: M149 C ; Units in Celsius
echo:; Filament settings (Disabled):
echo: M200 S0 D1.75
echo:; Steps per unit:
echo: M92 X79.00 Y79.60 Z400.00 E102.80
echo:; Max feedrates (units/s):
echo: M203 X500.00 Y500.00 Z10.00 E60.00
echo:; Max Acceleration (units/s2):
echo: M201 X500.00 Y500.00 Z100.00 E5000.00
echo:; Acceleration (units/s2) (P<print-accel> R<retract-accel> T<travel-accel>):
echo: M204 P500.00 R1000.00 T500.00
echo:; Advanced (B<min_segment_time_us> S<min_feedrate> T<min_travel_feedrate> J<junc_dev>):
echo: M205 B20000.00 S0.00 T0.00 J0.08
echo:; Home offset:
echo: M206 X0.00 Y0.00 Z0.00
echo:; Auto Bed Leveling:
echo: M420 S0 Z40.00 ; Leveling OFF
echo: G29 W I0 J0 Z-0.38000
echo: G29 W I1 J0 Z-0.27500
echo: G29 W I2 J0 Z-0.14250
echo: G29 W I3 J0 Z-0.00250
echo: G29 W I4 J0 Z0.09000
echo: G29 W I0 J1 Z-0.34750
echo: G29 W I1 J1 Z-0.24000
echo: G29 W I2 J1 Z-0.11250
echo: G29 W I3 J1 Z0.02250
echo: G29 W I4 J1 Z-0.28250
echo: G29 W I0 J2 Z-0.33750
echo: G29 W I1 J2 Z-0.22000
echo: G29 W I2 J2 Z-0.08500
echo: G29 W I3 J2 Z0.04250
echo: G29 W I4 J2 Z0.15750
echo: G29 W I0 J3 Z-0.30250
echo: G29 W I1 J3 Z-0.20250
echo: G29 W I2 J3 Z-0.08500
echo: G29 W I3 J3 Z0.02000
echo: G29 W I4 J3 Z0.11750
echo: G29 W I0 J4 Z-0.32750
echo: G29 W I1 J4 Z-0.23000
echo: G29 W I2 J4 Z-0.13250
echo: G29 W I3 J4 Z-0.04500
echo: G29 W I4 J4 Z0.04750
echo:; Material heatup parameters:
echo: M145 S0 H150.00 B55.00 F0
echo: M145 S1 H240.00 B90.00 F0
echo:; Hotend PID:
echo: M301 P19.91 I1.30 D76.05
echo:; Z-Probe Offset:
echo: M851 X-70.00 Y-8.00 Z-1.96 ; (mm)
When sending M503, my esp32 webserver can only display a few lines from the beginning and then jumps to the end.
echo: M204 P500.00 R10851 X-70.00 Y-8.00 Z-1.96 ; (mm)
<travel-accel>):
echo:; Acceleration (units/s2) (P<print-accel> R<retract-accel>
echo: M201 X500.00 Y500.00 Z100.00 E5000.00
echo:; Max Acceleration (units/s2):
echo: M203 X500.00 Y500.00 Z10.00 E60.00
echo:; Max feedrates (units/s):
echo: M92 X79.00 Y79.60 Z400.00 E102.80
echo:; Steps per unit:
echo: M200 S0 D1.75
echo:; Filament settings (Disabled):
echo: M149 C ; Units in Celsius
echo:; Temperature Units:
echo: G21 ; (mm)
echo:; Linear Units:
$ M503
This is my code(only task SerialRx task on second core):
#include <Arduino.h>
#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include "FS.h"
#include "SD_MMC.h"
#include "SPI.h"
#include "esp_camera.h"
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
#include "driver/rtc_io.h"
TaskHandle_t SerialRx;
AsyncWebServer server(80);
//Define
void configESPCamera() {
}
void initMicroSDCard() {
}
void addToLogFile(String message) {
}
void takeNewPhoto(String path) {
}
void initWiFi() {
}
void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
}
void sendReversedLog(AsyncWebServerRequest *request) {
}
void setup() {
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
Serial.begin(115200);
initWiFi();
initMicroSDCard();
configESPCamera();
xTaskCreatePinnedToCore(
SerialRxFunction, /* Funkce úkolu. */
"SerialRx", /* Název úkolu. */
10000, /* Velikost zásobníku úkolu. */
NULL, /* Parametr úkolu. */
1, /* Priorita úkolu. */
&SerialRx, /* Ukazatel na úkol pro sledování vytvořeného úkolu. */
1);
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
};
server.begin();
}
void loop() {
String path = "/photos/image" + String(pictureCount) + ".jpg";
takeNewPhoto(path);
pictureCount++;
if (pictureCount == 2000) {
pictureCount = 0;
}
delay(delayTime);
}
#define BUFFER_SIZE 64
#define SERIAL_TIMEOUT 1000
void SerialRxFunction(void *pvParameters) {
char buffer[BUFFER_SIZE + 1];
int index = 0;
Serial.setTimeout(SERIAL_TIMEOUT);
for (;;) {
if (Serial.available() > 0) {
char incomingChar = Serial.read();
if (incomingChar != '\n' && index < BUFFER_SIZE) {
buffer[index++] = incomingChar;
} else {
buffer[index] = '\0';
logFile = SD_MMC.open("/logs/serial_log.txt", FILE_APPEND);
if (logFile) {
logFile.println(buffer);
logFile.close();
}
index = 0;
}
}
}
}

