-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReFlowSystem.ino
1979 lines (1767 loc) · 65.7 KB
/
ReFlowSystem.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* HOT PLATE CODE - base source from My Circuits 2023, SD comunication is based on code of David Bird 2018
Upgrades by zeroTM - https://github.com/w4b-zero
SD + Configfile CONFIG.TXT (if not on SD=auto create configfile)
SD + Second Curve Temp File (for Debugmode)
+SSD1306 Status and infos
WebServer + Activ-Status
WebServer + ask before delete File
WebServer + editable Configfile
WebServer + stop running ReFlow
WebServer + System Restart
+Configfile AccessPoint or Stationmode
+Configfile APssid/APpassword STAssid/STApassword
+Configfile Debugmode On/Off (to use second Curve Temp File!)
+Configfile CURVE.TXT DCURVE.TXT
Default Config:
Wlanmode = AccessPoint
APssid = reflowserver
APpassword = 12345678
USE MAX6675 Temp Sensor!
Requiered libraries:
ESP32WebServer - https://github.com/Pedroalbuquerque/ESP32WebServer download and place in your Libraries folder
SSD1306 - Adafruit_SSD1306 + Adafruit_GFX Arduino-Library
MAX6675 - GyverMAX6675 Arduino-Library
************************
* Original Source Info *
************************
Information from David Birds original code - not from My Circuits contribution (with my contribution/simplification to the code do whatever you wish, just mention us!):
Part of the SD software, the ideas and concepts is Copyright (c) David Bird 2018. All rights to this software are reserved.
Any redistribution or reproduction of any part or all of the contents in any form is prohibited other than the following:
1. You may print or download to a local hard disk extracts for your personal and non-commercial use only.
2. You may copy the content to individual third parties for their personal use, but only if you acknowledge the author David Bird as the source of the material.
3. You may not, except with my express written permission, distribute or commercially exploit the content.
4. You may not transmit it or store it in any other website or other form of electronic retrieval system for commercial purposes.
The above copyright ('as annotated') notice and this permission notice shall be included in all copies or substantial portions of the Software and where the
software use is visible to an end-user.
THE SOFTWARE IS PROVIDED "AS IS" FOR PRIVATE USE ONLY, IT IS NOT FOR COMMERCIAL USE IN WHOLE OR PART OR CONCEPT. FOR PERSONAL USE IT IS SUPPLIED WITHOUT WARRANTY
OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
See more at http://www.dsbird.org.uk
*/
//int cTest = 1; // Fast Temp to debug
int cTest = 0; // Normal Temp
int debugsrc = 0;
//Web ESP32 + SD
#include <WiFi.h> //Built-in
#include <ESP32WebServer.h> //https://github.com/Pedroalbuquerque/ESP32WebServer download and place in your Libraries folder
#include <ESPmDNS.h>
#include <SD.h>
#include <SPI.h>
//Hot Plate
#include <Wire.h>
#include <GyverMAX6675.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define servername "reflowserver" //Define the name to your server...
String sName = "ReFlow System";
String refreshSite = "";
int startCommand = 0;
String refreshStatus = "";
#include "CSS.h" //Includes headers of the web and de style file
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define SSD1306_NO_SPLASH
/* VARIABLES SERVER + SD */
String pageReflowStatus = "";
#define SD_pin 5
#define CLK_PIN 17 // Пин SCK
#define DATA_PIN 16 // Пин SO
#define CS_PIN 15 // Пин CS
String CONFIGfile = "/CONFIG.TXT";
String wlanmode = "ap";
String ssid = "";
String password = "";
String apssid = "reflowserver";
String appassword = "12345678";
String newconfig = "no";
bool SD_present = false; //Controls if the SD card is present or not
String fileName0 = "/CURVE.TXT"; //File name to save the data
String fileName1 = "/DCURVE.TXT"; //File name to save the data
String fDEBUG = "/DEBUG.TXT"; //File name to save the data
String fName = ""; //File name to save the data
String img_download = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAsgAAALIBa5Ro4AAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAJ6SURBVFiF7ZfPi01xGMY/zwz5NdMYDWFW7NyykBKJ/GZI8geoyUZ+LCmrsaBslGIzdmPMbDQLNAtCikiJxhjJQpEIRUrDDDPzWHyP6cyZO/fec85VFp56u6dzvu/7PN9z3/f9vgfbJA04BDwHRgGntD5gfrG4xUwR4TgknQeOAJ+ATuAzlWMfUIhEbLT9taxHYudrol1cBmZUuouY/xVgEBgBHgB15XxqEnq2Rr+nbA+n2Hkcb4FWYDVwVdLMUouTApYAH233ZyQHwHYXIY82AT2SplcqQHmIEyLagWPALqBbUm2xddOqRRjhO9Aoqdb2qO0zkuqBNmBQ0n4nsj75BvLiMbAAOCBJALZPAGcJeXFukkciizuAD2mzP+Y/C3hGqKTXwMOY/ekpR0tVQS7Y/kHI/jZgABiK2T1CiW6J++TKAUkNhFp/FxMxCJycYn1f8l7eJLwALAQ2ZA2Q9y+YG1lmVLsK/gv4ewIU0CVpXYk1BUmXJM2rugDCObEK6JW0sgj5UuAmsD1FzMoF2B4jHNffgOuSlsXIm4FbQB2ww/aXqguIRLyJRIiw28VAQ3S9CNht+0mamKkbke0XklqA20BzdHsE2Gv7btp4marA9iNgDzBMOGBabfdmiZW5Fdu+I2kz0JiVPJeASMT9PP7wDzSism9AUg1h3F6fMnY/sM32UC4Btsck9QDvUwoYKEdeTMAYMGl6td1J+ErKi9qIYxzJHHgJNElaWwWyCYhadQF4NeFBYqhcDvwCbgBNWYfTIsNqPXCR0DNayn2cHgdOE5rMNaDivj4F5hCaVj3QbvvgBL6kgEjETuAwsAKYnVPAT+Ap0GG7O/nwN3kByObnvXUsAAAAAElFTkSuQmCC";
String img_upload = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAsQAAALEBxi1JjQAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAANfSURBVFiFxddfiNVVEMDxz+j2x9ywwMVKIfsDUlGRVhhFFFFZD0VaQYFhZgURQeBLCulLhCzBRlRYSom0ZYkFvViZglBYmWAhQSEswRYWRkKKW+r08Dt393q96717F2vgcO9v5pzz+86cc2bOT2bKTDgHqzGIbLMdxcraHJ20yEwRMRFf4WK8hW+0J69gKpZl5ottjjleivf3F49uHAs9Bgps4plOItBVOGbjp8z8ogMf3sH76IuIQ5m5ZiyDawBn4Y8OXg4yszciurG6QPSPFaBT+QuTC8SKiJiMdQXio3YmmDBOgH4sjIgZBWIp1mBDRMz7LwDWYggDETEQEQO4G6djU0TMbDXBuJYgM/fh6oi4GTcgiqkbyzFTdVJODUAdyHZsrz1HxHkFoKWMdwnGLf87wKhLEBGzcOso5n2Z+eEpBcBiPDmK7beI2JaZf9YrI6ILl+G6ojqjJUHJ6X3Y0UkuV+38xdiJw46vlkN4F7e0qgUnSKmQZ7fgn4WXMQfr8GoBGcCVJRJ3YltEbMTCzDzcVgTwmvbuBHswp0WUHlLVmi/R0+w+0Ie5mTm3LgLTcM0onk9XpdxPcU9mDtWN68IVmbm7IaLT8TX2ZOYdLSPQwqP1xaMLGvQTVKU58USTcfOK7d529sCDmN/ENBEL8Ehm/tJgW40Hyv/XI+JAZm6oc3ZzRKzFSxHxcWYeO1ki6sKZTdocHMEHDcC9eBRvFtUbWB8RdzXM249LShv7EuA97GrQLcMxLDIS5kmqk3EQN9X1nVL6zs/MjlLxDHxb5/lEvIBnM/Ptun6Jx7AFK4aVmQewV3VMh/dAjgHgd5UXtQmPRkR3Zh5s7JiZRyJiAaY1mKZgPyPFaBCXR0SrxAO7jKTa2otOeHk9RGYO1p4j4kL0qI7kMMAnqovpynK5bAUwMyJ62oBtJtfjb+ymLEFmfh8RS9GLJRHxw0kmmFR+V+Dpsbw5Ik7Dc9hSS17DeSAz+yJiM25XZbqTyV48FRGbMnNrg+1HfK7yslGW41LcN6zpsAJOwGf4GbPbHPMw/sGS4/SdAJQJp2JH8fR5dI3SrwcbVR+yqxrtUTp1JGVNV6n2wn7Vzq6V46tUp+Va/IpF2eTTb1wAdSDn43HchotwLr5TJayd2JiZh5qN/RfT7gbtXn6VVAAAAABJRU5ErkJggg==";
String img_delete = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAADsAAAA7AF5KHG9AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAd9JREFUWIW9lr9KA0EQxn8JCqKQCAH/Bgu1sPBPrSApFC3zAL6EorWFpVZ5CEF8FVuxsIyCTWJIMCLRXCx2DzZze8luLpeB5ciX73a+m5mdHfCzC6AG9GJWDTj32TDjwd0CXoAf4COGswzMaO6rjxAXK6O+sjKAU9GcsuumUxasAGwD0wLf088icByzX9HgtsV/v8AzUB8k6EoT43KcdHWAyzjnu0A3Refh6gI7odOsIeBA/E7LstpXREBjAs4jvsxjmAH2gdmUnTeBp5R9uJutEZ0BNyn5uwbuTcDWB1rAekoCmhKwVf2bBQtQR0habwAeWPD3QepCKxA9uydAyYIfAYcWvAScWvCCiwCAL/HiKipdgcDn9TKxQHOLApetGYhvPDJUOeAP+HYQ39bcnMCrPgJkHeT1s+UgIOTkBW6rLW8BkSq2WMhJJECGKwynjwCZgrFEIEkKxlIDE0uBJIfh9IlAohTIcI0jAtYuGCegTf98kDQCn6jm5iwA+kOWNALW8A8TYKYh6SmwnoBhAkzVSfvASBGYSApsA4ntpSVgDlgQnDWiH7GIuiFXDMxpDpC2Sf91WkfdhibWIHp1d1BVb2IbowgAeCQ6VPiuh1GdgxrR71BV7Ou4CtwyZMz/B6vd494SzA63AAAAAElFTkSuQmCC";
File file;
File dataCurve;
File okCurve;
File isDEBUG;
/* SERVER */
ESP32WebServer server(80);
//Adafruit_MLX90614 mlx = Adafruit_MLX90614(); //IR Temperature sensor
GyverMAX6675<CLK_PIN, DATA_PIN, CS_PIN> sens;
float targetTemp = 0; //Track the target temperature in each time - Target Temperature
float temp = 0.00; //Temperature from the sensor - Current Temperature
char tempstr[20]; //Temperature from the sensor - Current Temperature
int ledStatus = LOW; //Rele state
int i = 0; //Variable for tracking the rele state
int tAs = 0; //Variable for tracking the rele state
int down = 0; //Relative Time delay for the rele
int extraTemp = 1; //Time delay for the rele in seconds - Compensation Temperature
int start = 0; //Tracks the push of the botton
int currentMillis = 0; //Current milliseconds
unsigned long ssdPreviousMillis = 0; // Store the time of the last LED toggle
int digitalButton = 0; //Web interface start
int firstTime = 1; //Tracks the first start
int reflowon = 0;
// the number of the LED pin
const int ledPinOrange = 2; //Rele
const int ledPinWhite = 13; //On
const int ledPinGreen = 14; //Hot plate cycle
const int ledPinRed = 12; //Plate hot
const int button = 26; //Push button
void setup()
{
Serial.begin(9600);
pinMode(19, INPUT_PULLUP);
pinMode(ledPinWhite, OUTPUT);
pinMode(ledPinGreen, OUTPUT);
pinMode(ledPinOrange, OUTPUT);
pinMode(ledPinRed, OUTPUT);
pinMode(button, INPUT_PULLUP);
digitalWrite(ledPinGreen, LOW);
digitalWrite(ledPinWhite, LOW);
digitalWrite(ledPinOrange, LOW);
digitalWrite(ledPinRed, LOW);
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
// delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
display.drawLine(0, 0, 127, 0, SSD1306_WHITE); //top line
display.drawLine(0, 63, 127, 63, SSD1306_WHITE); //bottom line
display.drawLine(0, 0, 0, 63, SSD1306_WHITE); //left line
display.drawLine(127, 0, 127, 63, SSD1306_WHITE); // right line
display.display(); // Update screen with each newly-drawn line
display.cp437(true);
display.setTextSize(1);
// display.setTextColor(SSD1306_WHITE);
// display.setCursor(0,0); // Start at top-left corner
//debugtest();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0); // Start at top-left corner
drawCentreText("REFLOW",62 ,5 ); //Center on Display
drawCentreText("PLATE V1.0",62 ,25 ); //Center on Display
//123456789012345678901 size1
//1234567890 size2
//1234567 size3
display.setCursor(0,0); // Start at top-left corner
drawCentreText("by zero",62 ,45 ); //Center on Display
display.setCursor(102,43); // Start at top-left corner
display.setTextSize(1);
display.println(F("TM"));
display.display();
Serial.println("*********************");
Serial.println("* REFLOW PLATE V1.0 *");
Serial.println("* by zeroTM *");
Serial.println("*********************");
// Serial.println("");
delay(2000); // Pause for 5 seconds
// Clear the buffer
display.clearDisplay();
display.drawLine(0, 0, 127, 0, SSD1306_WHITE); //top line
display.drawLine(0, 63, 127, 63, SSD1306_WHITE); //bottom line
display.drawLine(0, 0, 0, 63, SSD1306_WHITE); //left line
display.drawLine(127, 0, 127, 63, SSD1306_WHITE); // right line
display.drawLine(105, 0, 105, 63, SSD1306_WHITE); // v-trenner
display.drawLine(0, 41, 105, 41, SSD1306_WHITE); // h-trenner
display.display(); // Update screen with each newly-drawn line
// textarea
// display.setCursor(4,4); // Start at top-left corner
// display.println(F("System ready!"));
// display.setCursor(4,17); // Start at top-left corner
// display.println(F("Press Button"));
// display.setCursor(4,28); // Start at top-left corner
// display.println(F("to Start!"));
display.setCursor(0,0); // Start at top-left corner
display.setTextSize(1);
//drawCentreText("\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB",48 ,4 ); //Center on Display
drawCentreText("System start",50 ,17 ); //Center on Display
//drawCentreText("\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB",48 ,29 ); //Center on Display
//display.display();
Serial.println("- System start");
// temp area
display.setTextSize(2);
display.setCursor(0,0); // Start at top-left corner
display.setCursor(6,45);
display.print("220.00");
display.print("\xF8");
display.print("C");
// reflow sign
// display.setTextSize(3);
// display.setCursor(0,0); // Start at top-left corner
// display.setCursor(109,2);
// display.print("\xF7");
reflowOn();
// relay sign
// display.setTextSize(3);
// display.setCursor(0,0); // Start at top-left corner
// display.setCursor(109,17);
// display.print("\x07");
relaySignOn();
// hot plate sign
// display.setTextSize(3);
// display.setCursor(0,0); // Start at top-left corner
// display.setCursor(109,38);
// display.print("\x13");
plateHot();
display.setTextSize(1);
display.display();
delay(1000); // Pause for 5 seconds
clearSign1();
clearSign2();
clearSign3();
clearTextArea();
display.setTextColor(SSD1306_WHITE);
clearTempArea();
display.setTextSize(2);
display.setCursor(0,0); // Start at top-left corner
display.setCursor(6,45);
dtostrf (temp, 6, 2, tempstr);
drawCentreText(tempstr,39 ,45 ); //Center on Display
display.setTextSize(1);
display.display();
display.setCursor(0,0);
drawCentreText("check LEDs",50 ,17 ); //Center on Display
display.display();
Serial.print("- check LEDs ");
checkLeds(); //Nice Led pattern
//mlx.begin(); //IR Temperature sensor
// wait for MAX chip to stabilize
//delay(500);
//SD
if (!SD.begin(SD_pin))
{
//Serial.println(F("Card failed or not present, no SD Card data logging possible..."));
Serial.println("F SD-Card Error or not present, use Standart Temp Data!");
SD_present = false;
clearTextArea();
display.setCursor(0,0); // Start at top-left corner
drawCentreText("SD-Card Err!",50 ,4 ); //Center on Display
drawCentreText("use Standart",50 ,17 ); //Center on Display
drawCentreText("Temp Data!",50 ,29 ); //Center on Display
display.display(); // Update screen with each newly-drawn rectangle
delay(1000);
}
else
{
read_file_info();
//Serial.println(F("Card initialised... file access enabled..."));
SD_present = true;
//isDEBUG = SD.open(fDEBUG);
if(debugsrc == 1){
cTest = 1;
Serial.println("!! DEBUG Mode ");
Serial.println("!! "+fileName1+" wird genutzt!");
}
else {cTest = 0;}
if (cTest == 0){
okCurve = SD.open(fileName0);
fName = fileName0;
}
if (cTest == 1){
okCurve = SD.open(fileName1);
fName = fileName1;
}
clearTextArea();
display.setCursor(0,0); // Start at top-left corner
drawCentreText("SD-Card OK!",50 ,4 ); //Center on Display
String useCfile = "use "+fName;
if (okCurve){
if (cTest == 0){
drawCentreText(useCfile.c_str(),50 ,17 ); //Center on Display
drawCentreText("from SD-Card",50 ,29 ); //Center on Display
Serial.println("- SD-Card OK, "+useCfile+" from SD-Card!");
}
if (cTest == 1){
drawCentreText(useCfile.c_str(),50 ,17 ); //Center on Display
drawCentreText("from SD-Card",50 ,29 ); //Center on Display
Serial.println("- SD-Card OK, "+useCfile+" from SD-Card!");
}
}
else {
Serial.println("- SD-Card OK, File not found! use default Data");
drawCentreText("File not found!",50 ,17 ); //Center on Display
drawCentreText("use default Data",50 ,29 ); //Center on Display
}
display.display(); // Update screen with each newly-drawn rectangle
delay(2000);
}
if (wlanmode == "station"){
//SERVER
// WiFi.softAP("MyCircuits", "12345678"); //Network and password for the access point genereted by ESP32
Serial.print("- Connecting to Router: ");
Serial.println(ssid);
clearTextArea();
display.setCursor(0,0); // Start at top-left corner
drawCentreText("Connecting",50 ,4 ); //Center on Display
drawCentreText("to",50 ,17 ); //Center on Display
drawCentreText("Router",50 ,29 ); //Center on Display
display.display(); // Update screen with each newly-drawn rectangle
WiFi.begin(ssid, password);
Serial.print("- ");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print("*");
}
// Print local IP address and start web server
Serial.println("");
Serial.println("- WiFi connected.");
Serial.print("- IP address: ");
Serial.println(WiFi.localIP());
//const char* ipWifi = WiFi.localIP().toString().c_str() ;
clearTextArea();
display.setCursor(0,0); // Start at top-left corner
drawCentreText("WiFi connected",50 ,4 ); //Center on Display
drawCentreText("IP address",50 ,17 ); //Center on Display
drawCentreText(WiFi.localIP().toString().c_str(),50 ,29 ); //Center on Display
display.display(); // Update screen with each newly-drawn rectangle
delay(1000);
}
else {
//SERVER
Serial.print("- Starting Accesspoint: ");
Serial.println(apssid);
Serial.print("Password: ");
Serial.println(appassword);
clearTextArea();
display.setCursor(0,0); // Start at top-left corner
drawCentreText("Starting",50 ,4 ); //Center on Display
drawCentreText("the",50 ,17 ); //Center on Display
drawCentreText("Accesspoint",50 ,29 ); //Center on Display
display.display(); // Update screen with each newly-drawn rectangle
WiFi.softAP(apssid, appassword); //Network and password for the access point genereted by ESP32
// WiFi.begin(ssid, password);
// Serial.print("- ");
// while (WiFi.status() != WL_CONNECTED) {
// delay(500);
// Serial.print("*");
// }
// Print local IP address and start web server
// Serial.println("");
Serial.println("- AP Started");
Serial.print("- IP address: ");
IPAddress myIP = WiFi.softAPIP();
Serial.println(myIP);
//const char* ipWifi = WiFi.localIP().toString().c_str() ;
clearTextArea();
display.setCursor(0,0); // Start at top-left corner
drawCentreText("AP started",50 ,4 ); //Center on Display
drawCentreText("IP address",50 ,17 ); //Center on Display
drawCentreText(myIP.toString().c_str(),50 ,29 ); //Center on Display
display.display(); // Update screen with each newly-drawn rectangle
delay(1000);
}
if (!MDNS.begin(servername))
{
Serial.println(F("Error setting up MDNS responder!"));
ESP.restart();
}
/********* Server Commands **********/
// server.on("/", SD_dir);
server.on("/", startCycle);
server.on("/files", SD_dir);
server.on("/fileDel", fileDel);
server.on("/upload", File_Upload);
server.on("/fupload", HTTP_POST,[](){ server.send(200);}, handleFileUpload);
server.on("/config", editconfig);
server.on("/wconfig", writeconfig);
server.on("/rfcommand", ReFlowCommand);
server.on("/newstart", newstart);
server.on("/gonewstart", gonewstart);
server.begin();
Serial.println("- HTTP server started");
Serial.print("- Servername: ");
Serial.println(servername);
clearTextArea();
display.setCursor(0,0); // Start at top-left corner
drawCentreText("HTTP server",50 ,4 ); //Center on Display
drawCentreText("started",50 ,17 ); //Center on Display
//drawCentreText(WiFi.localIP(),48 ,29 ); //Center on Display
display.display(); // Update screen with each newly-drawn rectangle
delay(1000);
clearTextArea();
display.setCursor(0,0); // Start at top-left corner
drawCentreText("System ready!",50 ,4 ); //Center on Display
drawCentreText("Press Button",50 ,17 ); //Center on Display
drawCentreText("to Start!",50 ,29 ); //Center on Display
Serial.println("************************");
Serial.println("- System ready!");
Serial.println("- Press Button to Start!");
Serial.println("************************");
///clearTempArea();
//clearSign1();
//clearSign2();
// relay sign
// display.setTextSize(3);
// display.setCursor(109,17);
// display.print("\x09");
// display.setTextSize(1);
// display.display();
//clearSign3();
}
void loop()
{
while (start == 0)
{
server.handleClient(); //Listen for client connections
// temp = sens.getTemp(); //Obtain IR temperature
reflowon = 0;
if (digitalRead(button) == 0 || digitalButton == 1)
{
start = 1;
if (digitalRead(button) == 0){
Serial.println("Button pressed!");
}
else {
Serial.println("Webinterface Start!");
}
Serial.println("Reflowing started!");
Serial.println("!!! WARNING !!! - PLATE IS HOT!!!");
clearTextArea();
drawCentreText("Reflowing...",50 ,4 ); //Center on Display
drawCentreText("!!WARNING!!",50 ,17 ); //Center on Display
drawCentreText("!PLATE VERY HOT!",50 ,29 ); //Center on Display
// display.display(); // Update screen with each newly-drawn rectangle
reflowOn();
reflowon = 1;
}
currentMillis = millis();
// ssdCurrentMillis = millis();
firstTime = 1;
temp = sens.getTemp(); //Obtain IR temperature
//HOT - Red
ssdTemp();
if (temp>39.99)
{
digitalWrite(ledPinRed, HIGH);
Serial.print("! Plate is HOT!!! Temp:");
Serial.println(temp);
plateHot();
//delay(1000); //Step every 1 second
}
else if (temp > 38)
{
if (reflowon == 0){
digitalWrite(ledPinRed, LOW);
Serial.print("- READY! PLATE IS COLD!");
Serial.println(temp);
plateCold();
clearTextArea();
drawCentreText("READY!",50 ,4 ); //Center on Display
drawCentreText("------",50 ,17 ); //Center on Display
drawCentreText("PLATE IS COLD!",50 ,29 ); //Center on Display
display.display(); // Update screen with each newly-drawn rectangle
delay(5000); //Step every 1 second
tAs=1;
}
}
else if (temp<37)
{
digitalWrite(ledPinRed, LOW);
if (reflowon == 0){
if(tAs == 1){
clearTextArea();
display.setCursor(0,0); // Start at top-left corner
drawCentreText("System ready!",50 ,4 ); //Center on Display
drawCentreText("Press Button",50 ,17 ); //Center on Display
drawCentreText("to Start!",50 ,29 ); //Center on Display
display.display(); // Update screen with each newly-drawn rectangle
Serial.println("************************");
Serial.println("- System ready!");
Serial.println("- Press Button to Start!");
Serial.println("************************");
tAs=0;
}
}
}
delay(250); //Step every 1/4 second
}
while (start==1)
{
server.handleClient(); //Listen for client connections
if (firstTime==1)
{
firstTime = 0;
if (cTest == 0){
dataCurve = SD.open(fileName0);
}
if (cTest == 1){
dataCurve = SD.open(fileName1);
}
}
// temp = mlx.readObjectTempC(); //Obtain IR temperature
temp = sens.getTemp(); //Obtain IR temperature
if (!dataCurve)
{
checkTemp (); //Gets current cycle temperature
}
else
{
String row = dataCurve.readStringUntil('\n');
reflowon = 0;
if (row.indexOf("e") >= 0) //until "end"
{
targetTemp = 0;
start = 0;
digitalButton = 0;
digitalWrite(ledPinGreen, LOW);
reflowon = 0;
// Serial.println("end detected");
Serial.println("*******************************");
Serial.println("- Reflow finish!");
Serial.println("! WAIT UNTIL THE PLATE IS COLD!");
Serial.println("*******************************");
clearTextArea();
drawCentreText("Reflow finish!",50 ,4 ); //Center on Display
drawCentreText("WAIT UNTIL THE",50 ,17 ); //Center on Display
drawCentreText("PLATE IS COLD!",50 ,29 ); //Center on Display
reflowOff();
}
else
{
targetTemp = row.toFloat();
digitalWrite(ledPinGreen, HIGH);
reflowon = 1;
}
}
downCheck(); //Definition for the relay delay
//HOT - Red
if (temp>39.99)
{
digitalWrite(ledPinRed, HIGH);
if (reflowon == 0){
Serial.print("! Plate is HOT!!! Temp:");
Serial.println(temp);
}
if (reflowon == 1){
Serial.print("! Plate is HOT!!! ");
}
plateHot();
}
else if (temp > 38)
{
if (reflowon == 0){
digitalWrite(ledPinRed, LOW);
Serial.print("- READY! PLATE IS COLD!");
Serial.println(temp);
plateCold();
clearTextArea();
drawCentreText("READY!",50 ,4 ); //Center on Display
drawCentreText("------",50 ,17 ); //Center on Display
drawCentreText("PLATE IS COLD!",50 ,29 ); //Center on Display
display.display(); // Update screen with each newly-drawn rectangle
delay(5000); //Step every 1 second
tAs=1;
reflowon = 0;
}
if (reflowon == 1){
Serial.print("- Plate is COLD. ");
}
}
else if (temp<38)
{
if (reflowon == 1){
Serial.print("- Plate is COLD. ");
}
}
else if (temp<37)
{
digitalWrite(ledPinRed, LOW);
if (reflowon == 0){
if(tAs == 1){
clearTextArea();
display.setCursor(0,0); // Start at top-left corner
drawCentreText("System ready!",50 ,4 ); //Center on Display
drawCentreText("Press Button",50 ,17 ); //Center on Display
drawCentreText("to Start!",50 ,29 ); //Center on Display
display.display(); // Update screen with each newly-drawn rectangle
Serial.println("************************");
Serial.println("- System ready!");
Serial.println("- Press Button to Start!");
Serial.println("************************");
tAs=0;
}
}
if (reflowon == 1){
Serial.print("- Plate is COLD. ");
}
}
Serial.print("TargetTemp:");
Serial.print(targetTemp);
Serial.print(", Temp:");
Serial.print(temp);
// temp area
clearTempArea();
display.setTextSize(2);
display.setCursor(0,0); // Start at top-left corner
display.setCursor(6,45);
dtostrf (temp, 6, 2, tempstr);
drawCentreText(tempstr,39 ,45 ); //Center on Display
display.setTextSize(1);
display.display();
if(temp<(targetTemp-extraTemp)) //Rele ON
{
ledStatus = HIGH;
i = 10; //Rele State
relaySignOn();
}
else //Rele OFF
{
ledStatus = LOW;
i = 0; //Rele State
clearSign2();
}
digitalWrite(ledPinOrange, ledStatus); //Rele control
//Serial.println("???????????????????????????????????");
Serial.print(", Relay:O");
if(i == 10) //Rele ON
{
Serial.print("n");
} else {
Serial.print("ff");
}
Serial.print(", extraTemp:");
Serial.println(extraTemp*10); //Compensation Temperature * 10
//Serial.println("???????????????????????????????????");
delay(250); //Step every 1/4 second
}
//delay(250); //Step every 1/4 second
}
void ssdTemp() //default reflow curve - If there is no CURVE.TXT still works...
{
unsigned long ssdCurrentMillis = millis(); // Get the current time
if (ssdCurrentMillis - ssdPreviousMillis >= 1000)
{
temp = sens.getTemp(); //Obtain IR temperature
// temp area
clearTempArea();
display.setTextSize(2);
display.setCursor(0,0); // Start at top-left corner
display.setCursor(6,45);
dtostrf (temp, 6, 2, tempstr);
drawCentreText(tempstr,39 ,45 ); //Center on Display
display.setTextSize(1);
display.display();
ssdPreviousMillis = ssdCurrentMillis;
}
}
void checkLeds()
{
digitalWrite(ledPinWhite, HIGH);
Serial.print("*");
delay(300);
digitalWrite(ledPinGreen, HIGH);
reflowOn();
display.display();
Serial.print("*");
delay(300);
digitalWrite(ledPinOrange, HIGH);
relaySignOn();
display.display();
Serial.print("*");
delay(300);
digitalWrite(ledPinRed, HIGH);
plateHot();
display.display();
Serial.print("*");
delay(300);
digitalWrite(ledPinRed, LOW);
clearSign1();
display.display();
Serial.print("*");
delay(300);
digitalWrite(ledPinOrange, LOW);
clearSign2();
display.display();
Serial.print("*");
delay(300);
digitalWrite(ledPinGreen, LOW);
clearSign3();
display.display();
Serial.print("*");
delay(1000);
display.setTextSize(1);
display.display();
Serial.println(" OK");
}
void downCheck() //Rele delay calculation - little twisted but seems to make the job
{
temp = sens.getTemp(); //Obtain IR temperature
if (temp<targetTemp && ledStatus == HIGH ) //needs to go up
{
down = down - 1; //need to continue
}
else if (temp<targetTemp && ledStatus == LOW )
{
down = down + 1; //need to continue
}
else if (temp>targetTemp && ledStatus == LOW )
{
down = down - 1; //need to continue
}
else //(temp>targetTemp && ds == 255 )
{
down = down + 5; //need to continue
}
if (down<0)
{
if (down < -200)
{
down = -200;
}
extraTemp = -down/20; //converts to seconds
}
else
{
extraTemp = 1;
}
}
void checkTemp () //default reflow curve - If there is no CURVE.TXT still works...
{
if (millis()<=75000+currentMillis)
{
targetTemp = 2.00*(millis()-currentMillis)/1000.00;
digitalWrite(ledPinGreen, HIGH);
}
else if (millis()<=155000+currentMillis)
{
targetTemp = 150;
}
else if (millis()<=190000+currentMillis)
{
targetTemp = 150.00+2.00*(millis()-155000-currentMillis)/1000.00;
}
else if (millis()<=230000+currentMillis)
{
targetTemp = 220;
}
else
{
targetTemp = 0;
digitalWrite(ledPinGreen, LOW);
start = 0;
Serial.println("*******************************");
Serial.println("- Reflow finish!");
Serial.println("! WAIT UNTIL THE PLATE IS COLD!");
Serial.println("*******************************");
clearTextArea();
drawCentreText("Reflow finish!",50 ,4 ); //Center on Display
drawCentreText("WAIT UNTIL THE",50 ,17 ); //Center on Display
drawCentreText("PLATE IS COLD!",50 ,29 ); //Center on Display
reflowOff();
}
}
/********* FUNCTIONS **********/
//Download a file from the SD, it is called in void SD_dir()
void SD_file_download(String filename)
{
if (SD_present)
{
File download = SD.open("/"+filename);
if (download)
{
server.sendHeader("Content-Type", "text/text");
server.sendHeader("Content-Disposition", "attachment; filename="+filename);
server.sendHeader("Connection", "close");
server.streamFile(download, "application/octet-stream");
download.close();
} else ReportFileNotPresent("download");
} else ReportSDNotPresent();
}
//Upload a file to the SD
void File_Upload()
{
sName = "File Upload";
refreshSite = "";
refreshStatus = "";
append_page_header();
if(start==0){
pageReflowStatus = "<span style='color:green'><b>Off</b></span>";
}
if(start==1){
pageReflowStatus = "<span style='color:red'><b>On</b></span>";
}
webpage += F("<div class='inhalt'>");
webpage += refreshStatus;
webpage += F("<p class='status'>");
webpage += pageReflowStatus;
webpage += F("</p ><br>");
webpage += F("<h3>Select File to Upload</h3>");
webpage += F("<FORM action='/fupload' method='post' enctype='multipart/form-data'>");
webpage += F("<input class='buttons' style='width:25%' type='file' name='fupload' id = 'fupload' value=''>");
webpage += F("<button class='buttons' style='width:10%' type='submit'><img src='");
webpage += img_upload;
webpage += F("' width='32' height='32'></button><br><br>");
webpage += F("<a href='/files'>Back to File System</a><br><br>");
webpage += F("<a href='/'>to Startsite</a><br><br>");
webpage += F("</div>");
append_page_footer();
server.send(200, "text/html",webpage);
}
//Handles the file upload a file to the SD
File UploadFile;
//Upload a new file to the Filing system
void handleFileUpload()
{
HTTPUpload& uploadfile = server.upload(); //See https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer/srcv
//For further information on 'status' structure, there are other reasons such as a failed transfer that could be used
if(uploadfile.status == UPLOAD_FILE_START)
{
String filename = uploadfile.filename;
if(!filename.startsWith("/")) filename = "/"+filename;
Serial.print("Upload File Name: "); Serial.println(filename);
SD.remove(filename); //Remove a previous version, otherwise data is appended the file again
UploadFile = SD.open(filename, FILE_WRITE); //Open the file for writing in SD (create it, if doesn't exist)
filename = String();
}
else if (uploadfile.status == UPLOAD_FILE_WRITE)
{
if(UploadFile) UploadFile.write(uploadfile.buf, uploadfile.currentSize); // Write the received bytes to the file
}
else if (uploadfile.status == UPLOAD_FILE_END)
{
if(UploadFile) //If the file was successfully created
{
UploadFile.close(); //Close the file again
Serial.print("Upload Size: "); Serial.println(uploadfile.totalSize);
webpage = "";
sName = "File Upload - successfull!";
webpage += refreshStatus;
refreshSite = "";
refreshStatus = "";
append_page_header();
if(start==0){
pageReflowStatus = "<span style='color:green'><b>Off</b></span>";
}
if(start==1){
pageReflowStatus = "<span style='color:red'><b>On</b></span>";
}
webpage += F("<div class='inhalt'>");
webpage += F("<p class='status'>");
webpage += pageReflowStatus;
webpage += F("</p ><br>");
webpage += F("<h3>File was successfully uploaded</h3>");
webpage += F("<p class='status1'>Uploaded File Name: "); webpage += uploadfile.filename+"</p >";
webpage += F("<p class='status1'>File Size: "); webpage += file_size(uploadfile.totalSize) + "</p ><br><br>";
webpage += F("<a href='/files'>Back to File System</a><br><br>");
webpage += F("<a href='/'>to Startsite</a><br><br>");
webpage += F("</div>");
append_page_footer();
server.send(200,"text/html",webpage);
}
else
{
ReportCouldNotCreateFile("upload");
}
}
}
void editconfig()
{
sName = "System Config";
refreshSite = "";
refreshStatus = "";
append_page_header();
if(start==0){
pageReflowStatus = "<span style='color:green'><b>Off</b></span>";
}
if(start==1){
pageReflowStatus = "<span style='color:red'><b>On</b></span>";
}
webpage += F("<div class='inhalt'>");
webpage += refreshStatus;
webpage += F("<p class='status'>");
webpage += pageReflowStatus;
webpage += F("</p >");
String cfile = fileName0.substring(1);
String dcfile = fileName1.substring(1);
webpage += F("<h3>ReFlowServer System Config</h3>");
webpage += F("<FORM action='/wconfig' method='post' enctype='multipart/form-data'>");
webpage += "<table align='center'><tr><th>Name</th><th>Value</th><th>Default</th></tr>";
webpage += "<tr><td>Wlanmode: </td><td><select name='wlanmode' id='wlanmode'>";
webpage += " <option value='station'";
if (wlanmode == "station"){webpage += "selected ";}
webpage += " >Station</option>";
webpage += " <option value='ap'";