@@ -662,7 +662,11 @@ void p2p_enumDir(FsFile* tdir, String path) {
662
662
file.getName (f_name, max_characters);
663
663
// filename = String(f_name);
664
664
String filename = String (f_name);
665
- Serial.println (filename);
665
+ Serial.print (filename);
666
+ Serial.print (" \r " );
667
+
668
+ Serial.flush ();
669
+ Serial.readStringUntil (' \r ' );
666
670
667
671
if (file.isDir ()) {
668
672
@@ -764,12 +768,12 @@ WiFiServer p2p_server(888);
764
768
bool webMode = true ;
765
769
766
770
IPAddress ip (192 , 168 , 1 , 1 );
767
- IPAddress gateway (192 , 168 , 4 , 1 );
771
+ IPAddress gateway (192 , 168 , 1 , 1 );
768
772
IPAddress subnet (255 , 255 , 255 , 0 );
769
773
770
774
void p2pRecieverMode () {
771
-
772
-
775
+ Serial. print ( " cp1 " );
776
+ Serial. print ( ' \r ' );
773
777
WiFi.mode (WIFI_AP);
774
778
WiFi.setOutputPower (0 );
775
779
WiFi.softAPConfig (ip, gateway, subnet);
@@ -785,50 +789,88 @@ void p2pRecieverMode() {
785
789
}*/
786
790
787
791
p2p_server.begin ();
788
-
792
+ Serial.print (" cp2" );
793
+ Serial.print (' \r ' );
789
794
WiFiClient client = p2p_server.available (); // Проверка подключения клиента
790
795
while (!client) {
791
796
delay (100 );
792
797
}
793
798
while (!client.available ()) { // Ожидание запроса клиента
794
799
delay (1 );
795
800
}
801
+ Serial.print (" cp3" );
802
+ Serial.print (' \r ' );
796
803
client.setTimeout (100000 );
797
804
String filename = client.readStringUntil (' \r ' ); // filename
798
805
filename.trim ();
799
- if (!filename.startsWith (" /" )) filename = " /" + filename;
806
+ if (!filename.startsWith (" /" ))
807
+ filename = " /" + filename;
808
+ Serial.print (" cp4" );
809
+ Serial.print (' \r ' );
800
810
811
+ Serial.print (filename);
812
+ Serial.print (' \r ' );
801
813
String request2 = client.readStringUntil (' \r ' ); // size
802
814
request2.trim ();
803
815
auto size = request2.toInt ();
804
- client.flush ();
816
+ Serial.print (size);
817
+ Serial.print (' \r ' );
818
+ // client.flush();
819
+ // Initialize the SD.
820
+ my_DEV_Module_Init ();
821
+ bool goodInited = true ;
822
+ if (!sd.begin (SD_CONFIG)) {
823
+ sd.initErrorHalt (&Serial);
824
+ goodInited = false ;
825
+ }
826
+ Serial.print (" cp5" );
827
+ Serial.print (' \r ' );
828
+
805
829
file = sd.open (filename, MFILE_WRITE);
806
- Serial.println (" max" );
807
- int crntsz = 0 ;
808
- Serial.println (size);
809
- // while (client.available()) {
830
+ Serial.print (" cp6" );
831
+ Serial.print (' \r ' );
810
832
for (long ii = 0 ; ii < size; ii++) {
811
833
file.write (client.read ());
812
-
813
- if (ii % 1000 == 0 )
814
- Serial.println (crntsz);
834
+ if (ii % 1000 == 0 ) {
835
+ float vv = ii / size;
836
+ Serial.print ((int )(100 * vv));
837
+ Serial.print (' \r ' );
838
+ }
815
839
}
840
+
816
841
file.close ();
842
+ Serial.print (" end" );
843
+ Serial.print (' \r ' );
817
844
WiFi.mode (WIFI_OFF); // TURN OFF WIFI
818
845
WiFi.forceSleepBegin ();
819
846
ESP.deepSleep (0 );
820
847
}
821
848
822
849
void p2pSenderMode () {
823
850
webMode = false ;
824
- Serial.println (" files" );
851
+ Serial.print (" files" );
852
+ Serial.print (" \r " );
853
+
825
854
Serial.flush ();
855
+ my_DEV_Module_Init ();
856
+ // Initialize the SD.
857
+ bool goodInited = true ;
858
+ if (!sd.begin (SD_CONFIG)) {
859
+ sd.initErrorHalt (&Serial);
860
+ goodInited = false ;
861
+ }
862
+
826
863
if (!dir.open (" /" )) {
827
864
error (" dir.open failed" );
828
865
}
829
866
p2p_enumDir (&dir, " /" );
830
- Serial.println (" <finish>" );
867
+
868
+
869
+ Serial.print (" <finish>" );
870
+ Serial.print (" \r " );
871
+
831
872
Serial.flush ();
873
+ Serial.readStringUntil (' \r ' );
832
874
String dPath = " /1.cb" ;
833
875
Serial.setTimeout (100000 );
834
876
while (true ) {
@@ -837,23 +879,37 @@ void p2pSenderMode() {
837
879
}
838
880
839
881
String teststr = Serial.readStringUntil (' \r ' ); // read until timeout
840
- teststr.trim (); // remove any \r \n whitespace at the end of the String
882
+
883
+ Serial.print (" ack" );
884
+ Serial.print (" \r " );
885
+ Serial.flush ();
886
+ teststr.trim (); // remove any \r \n whitespace at the end of the String
841
887
if (teststr == " <select>" ) {
842
888
843
889
dPath = Serial.readStringUntil (' \r ' ); // read until timeout
890
+ Serial.print (" ack" );
891
+ Serial.print (" \r " );
892
+ Serial.flush ();
844
893
dPath.trim ();
845
894
break ;
846
895
} else {
847
896
}
848
897
}
849
-
898
+ delay (500 );
899
+ Serial.print (" cp1" );
900
+ Serial.print (" \r " );
901
+ Serial.flush ();
902
+ delay (500 );
850
903
WiFi.setOutputPower (0 );
851
904
WiFi.mode (WIFI_STA);
852
905
WiFi.begin (p2p_ssid, p2p_password);
853
906
while (WiFi.status () != WL_CONNECTED) {
854
907
delay (500 );
855
908
}
856
-
909
+ Serial.print (" cp2" );
910
+ Serial.print (" \r " );
911
+ Serial.flush ();
912
+ delay (500 );
857
913
WiFiClient client;
858
914
if (!client.connect (ip, 888 )) {
859
915
// return client;sleep?
@@ -864,25 +920,46 @@ void p2pSenderMode() {
864
920
}
865
921
// send file name
866
922
// send data
923
+ Serial.print (" cp3" );
924
+ Serial.print (" \r " );
925
+ Serial.flush ();
926
+ delay (500 );
927
+
928
+
929
+ if (!dPath.startsWith (" /" ))
930
+ dPath = " /" + dPath;
867
931
868
932
client.print (dPath);
869
933
client.print (' \r ' );
934
+ client.flush ();
935
+
936
+ Serial.print (dPath);
937
+ Serial.print (" \r " );
938
+ Serial.flush ();
939
+ delay (500 );
870
940
file = sd.open (dPath, MFILE_READ);
871
941
// Serial.println("max");
872
942
873
- auto sz = file.size ();
943
+ auto sz = file.size ();
944
+ client.print (sz);
945
+ client.print (' \r ' );
946
+ client.flush ();
874
947
for (long i = 0 ; i < sz; i++) {
875
948
client.write (file.read ());
876
- if (i % 1000 == 0 ) {
877
- float vv = i / sz;
949
+ if (i % 10000 == 0 ) {
950
+ float vv = i / ( float ) sz;
878
951
Serial.print ((int )(100 * vv));
879
- client.print (' \r ' );
952
+ Serial.print (' \r ' );
953
+ Serial.flush ();
880
954
}
881
955
}
882
- client. print ( " end " );
883
- client. print ( ' \r ' );
884
- file. close ();
956
+ file. close ( );
957
+
958
+
885
959
WiFi.mode (WIFI_OFF); // TURN OFF WIFI
960
+ Serial.print (" end" );
961
+ Serial.print (' \r ' );
962
+ Serial.flush ();
886
963
WiFi.forceSleepBegin ();
887
964
ESP.deepSleep (0 );
888
965
}
@@ -944,9 +1021,8 @@ void setup() {
944
1021
yield ();
945
1022
}
946
1023
947
- while (Serial.available () == 0 ) {}
948
- String teststr = Serial.readString (); // read until timeout
949
- teststr.trim (); // remove any \r \n whitespace at the end of the String
1024
+ String teststr = Serial.readStringUntil (' \r ' ); // read until timeout
1025
+ teststr.trim (); // remove any \r \n whitespace at the end of the String
950
1026
if (teststr == " web" ) {
951
1027
break ;
952
1028
}
0 commit comments