void costel() {
String message="";
String gcodex="";
String gcodey="";
char t;
int a;
String inceput= "<!DOCTYPE html><html><head><script>document.body.innerHTML ='';</script>";
inceput +="<meta name='viewport' content='width=device-width, initial-scale=1.0'></head><body><svg height='500' width='500'>";
inceput +="<g transform='scale(2)'><polyline points='";
String sfarsit ="' style='fill:white;stroke:red;stroke-width:.5' />";
sfarsit +="Sorry, your browser does not support inline SVG.</svg></body></html>";
String puncte="";
File f = SPIFFS.open("/test.nc", "r");
while(f.available()) {
t = f.read();
// G01 X123.456 Y567.890\n
message += t;
if(t=='X'){a=1;gcodex="";} //read line until 'X' (attention X high!!!)
if(t=='Y'){a=2;gcodey="";} //read line until 'Y' (attention Y high!!!)
if(t=='\n'){ //if line end
a=0;
puncte +=gcodex+','+gcodey+' ';
server.send(100, "text/html", inceput+puncte+sfarsit); //on any new line response to server with svg + new coordinate
process_string(message,message.length()); //send gcode line to gcode interpreter
message=""; //empty gcode string
}
if(a==1) if(t !='X' && t !=' ') gcodex +=t; //write svg coordonate without 'X' and space
if(a==2) if(t !='Y' && t !=' ') gcodey +=t; //write svg coordonate without 'X' and space
}
f.close();
server.send(200, "text/html", "ok" );
}
while(f.available()) {
So with this subrutine , read line by line and send to gcode interpreter.
Work fine!
But i can not interrupt this rutine after to finish read file!
Esp8266 not rispond at any web command until finish read file!
I need because in case is something wrong ... i not want wait until finish cut image for attend that module rispond again or
You can use a break statement to exit a while loop. Inside your loop, test for the condition that you wish to have interrupt, and if so, break. This will exit the while loop and continue processing with the code immediately following. There are other ways of doing it, but as most of the under 40 crowd are phobic against the use of GOTO, I'll leave the study of that up to you.
Don't attach a zip file, most will not download and extract it. Post your code as you have above or at leas the segment in question. As to how you do it, read #4, again.
void costel() {
String message="";
String gcodex="";
String gcodey="";
char t;
int a;
String inceput= "<!DOCTYPE html><html><head><script>document.body.innerHTML ='';</script>";
inceput +="<meta name='viewport' content='width=device-width, initial-scale=1.0'></head><body><svg height='500' width='500'>";
inceput +="<g transform='scale(2)'><polyline points='";
String sfarsit ="' style='fill:white;stroke:red;stroke-width:.5' />";
sfarsit +="Sorry, your browser does not support inline SVG.</svg></body></html>";
String puncte="";
File f = SPIFFS.open("/test.nc", "r");
while(f.available()) {
t = f.read();
// G01 X123.456 Y567.890\n
message += t;
if(t=='X'){a=1;gcodex="";} //read line until 'X' (attention X high!!!)
if(t=='Y'){a=2;gcodey="";} //read line until 'Y' (attention Y high!!!)
if(t=='\n'){ //if line end
a=0;
puncte +=gcodex+','+gcodey+' ';
server.send(100, "text/html", inceput+puncte+sfarsit); //on any new line response to server with svg + new coordinate
process_string(message,message.length()); //send gcode line to gcode interpreter
message=""; //empty gcode string
}
if(a==1) if(t !='X' && t !=' ') gcodex +=t; //write svg coordonate without 'X' and space
if(a==2) if(t !='Y' && t !=' ') gcodey +=t; //write svg coordonate without 'X' and space
}
f.close();
server.send(200, "text/html", "ok" );
}
So... when client get "costel" function ...
the function open gcode file and read line by line and send to gcode interpreter
when finished to read all lines ...close file and rispond with 200 for close connection
problem is that esp8266 not read another client messsage until not finish to read file and close
connection!
I think that i can not apply the "if" function here... maybe a test if client send a message in this time ... and if receive a message ...i can close file and connection
So, you need to define what event will happen outside from the while loop that will make you want to stop what you're doing. Maybe it's a button on pinx -> if(button attached to pinx has been pushed) break;
Place a test similar to this inside your loop for whatever condition(s) you need to cause the loop to abort. It could even be a timer, which is done often just in case there's and unidentified read error.
Forget that you are doing anything else. If your program was sitting around doing nothing, how would you know if the client has sent you a message? For example, if we are using Serial communications we constantly check if(Serial.available()) to see if there is incoming data. There must be some similar test you make to determine if there is a message from the client.
yes...someone know ... but not want did!
Anyway ... is not a close while ... because in this while is a "yield();" function
Without this "yield();" the esp8266 crash!
This "yield();" i read that is a function that read another incoming mesages from server or another things ... but for my program not happen!
Yielding
This is one of the most critical differences between the ESP8266 and a more classical Arduino microcontroller. The ESP8266 runs a lot of utility functions in the background – keeping WiFi connected, managing the TCP/IP stack, and performing other duties. Blocking these functions from running can cause the ESP8266 to crash and reset itself. To avoid these mysterious resets, avoid long, blocking loops in your sketch.
The amazing creators of the ESP8266 Arduino libraries also implemented a yield() function, which calls on the background functions to allow them to do their things.
If there is no event you need nothing. If there is an event, you know it. It's your code. You want someone to fabricate an event for you? Have you no idea what your own code does?
The program is hudge and i make tons of modifications !
The program work fine !
Only that need to wait until esp8266 finish to read file .
Any read line ...the motor spin for few millseconds or seconds.
But i have hundred of lines in program... so until read all lines and motors spin ...
maybe pass minutes ... in this time the esp8266 is blocking!!!
What part need put here?