Fórum témák

» Több friss téma
Fórum » Arduino
A klónok CH340 Soros-USB illesztőjének drivere (Letöltés)
Lapozás: OK   511 / 854
(#) eSDi válasza trickentrack hozzászólására (») Feb 2, 2019 /
 
Az elvileg kell. De a rajz hibás! Használd a arduino hivatalos kapcsolásait. Az Aref-ről a kondi a GND-re megy és elég egy 100nF is.
(#) kapu48 válasza trickentrack hozzászólására (») Feb 3, 2019 /
 
A tápfessz szűrése kimaradt! Kel az GND és 5V közé 100n és legalább 10u szűrés!
(#) trickentrack válasza eSDi hozzászólására (») Feb 4, 2019 / 1
 
Elkészítettem a gyári kapcsolás alapján!
Szerintetek így jó lesz?
(#) Skori hozzászólása Feb 11, 2019 /
 
Kitöltési tényezőt szeretnék mérni arduinoval (MEGA2560 esetleg Nano), 1kHz körüli pwm jelen.
Mi erre a jó megoldás?
Az egyik lehetőség amire gondoltam: RC szűrő majd A/D konverterrel mérek.
Timer-t felhasználva megoldható-e ügyesebben?
A hozzászólás módosítva: Feb 11, 2019
(#) Kovidivi válasza Skori hozzászólására (») Feb 11, 2019 /
 
Igen. Timer-t használj, vagy a pulsein() fv-t. Nagyon hasznos!
A hozzászólás módosítva: Feb 11, 2019
(#) tbarath válasza Skori hozzászólására (») Feb 11, 2019 /
 
Szerintem ha nem digitalRead-et használsz, hanem közvetlen olvasod a portot, akkor a 1 kHz környékét még lehetne is mérni
(#) Skori válasza Kovidivi hozzászólására (») Feb 11, 2019 /
 
Köszönöm, a pulsein() szimpatikusnak tűnik, mindjárt kipróbálom.
(#) Vacok hozzászólása Feb 11, 2019 /
 
Sziasztok!
Fordulatszámmérőhöz szeretnék atmega328 IC-vel meghajtani 20 ledet multiplex üzemmódban. Nos a ledek meghajtására a kódot sikerült megalkotni, ami önállóan működik ugyan loop-ban, de ha folytatom a kód megírását (gombok beolvasása, hőmérséklet, és fordulatszám értékének számolása), akkor az egész elkezd villogni, halványabban világítani. Próbáltam a Timer1-et használni a ledek "meghajtására" de akkor meg az egész loop-ban lévő kód leáll.
Hogy lehetne a ledeket villogás nélkül üzemeltetni úgy, hogy a kód többi része is működik?
(#) Kovidivi válasza tbarath hozzászólására (») Feb 11, 2019 /
 
Többet is lehet. A határ olyan 2MHz környékén van. 16MHz-es kvarccal 8 órajel alatt lehet a kimenet állapotát olvasni, és a timer aktuális értékét menteni (előosztó nélkül). Vannak frekvenciamérő Arduino-k, azoknak a határfrekvenciáját érdemes megnézni, 1MHz tuti meg van.
Olyat találtam ami 2MHz-ig mér.
A hozzászólás módosítva: Feb 11, 2019
(#) sargarigo válasza Vacok hozzászólására (») Feb 12, 2019 /
 
Több módszer is létezik. Az egyik az, ha bele lehet még nyúlni a hw-be. Ekkor egy puffer ic-t kell használni, ami addig tartja a kimenetét, amíg át nem írod (latch a kulcsszó). Közben tetszőleges kódot futtathatsz, akár le is állíthatod. Programozásilag ez a legegyszerűbb, de hozzá kell nyúlni a vashoz.

Ha ez valamiért nem megy, akkor nehezebb ügy, mert gondoskodnod kell róla, hogy a megfelelő időben mindenképpen megtörténjen a frissítés. Ha sok mindent csinálsz, akkor ez SOKKAL nehezebb feladat.
Például a loop csak egy egyszerű ciklus, ami meghívja a frissítést, majd a egymás után a többi feladatot. Feltétel, hogy minden feladat nagyon gyorsan lefusson, lehetőleg mindig ugyanannyi idő alatt.

Kirakhatod a frissítést megszakításba, de akkor ott kell odafigyelni, hogy annak is megvannak a trükkjei.

Végül az egészet kiszervezheted megszakításokba, ez már ugye a mélyvíz. Cserébe ha már elindult, akkor pontos a cucc. Lődd be hogy melyik utat választod, aztán innen tudsz tovább menni!

Szerk: Ja, és a legfontosabb, hogy a delay-t minden formában felejtsd el! Az garantáltan hazavágja.
A hozzászólás módosítva: Feb 12, 2019
(#) david10 hozzászólása Feb 13, 2019 /
 
Sziasztok, léteznek-e olyan fordulatszám mérő szenzorok, amik valamilyen kommunikációs protokollal (pl. SPI/I2C/RS485 stb) tudnak kommunikálni egy mikrokontrollerrel?
Erre azért lenne szükségem, mert olyan környezetben lesz a szenzor használva, ahol nincs lehetőség valós időben továbbítani az átlagos szenzor által kiadott jelet.
Tudnék a szenzorra tenni mikrokontrollert, de ha nem muszáj, akkor nem akarok.
A választ előre is köszönöm!
(#) Kera_Will válasza david10 hozzászólására (») Feb 13, 2019 /
 
Valamikor 20 éve olyan fordulatszám mérő pickup-ot is szereltem aminek a pickup része önállóan táplálta az LCD kijelzőt és a benne lévő mérőművet is.
Ez egy viszonylag nagy 2 - 3 méteres lendkerék lyukai felett volt rögzítve.
A kijelző a motor másik végén kb 15 méterrel arrébb volt.Oda egy árnyékolt vezeték ment a pickup-től.
(#) Vacok válasza sargarigo hozzászólására (») Feb 13, 2019 /
 
Sajnos a vas már nem módosítható. A programot úgy írom, hogy delay egyáltalán ne vagy csak delayMicrosecods legyen benne az is minimális késleltetéssel. Amúgy már sikerült a problémát megoldani. Van a ledek mellett egy TM1637 7 szegmenses led kijelző is az MCU-ra kapcsolva, amit egy header fájl segítségével vezéreltem, és abban volt egy delay (100) sor. Amióta nem a header vezérli a kijelzőt, hanem a loop-ban a program, ami csak 5-5 usec késleltetést tartalmaz azóta a villogás is megszűnt és mindkét kijelzés békésen működik egymás mellett valamint a többi egyéb funkció is.
(#) sitto hozzászólása Feb 13, 2019 /
 
Sziasztok!

ESP32 programozásával kapcsolatban lenne szükségem egy kis segítségre.
Már van egy működő kódom és ezt szeretném kiegészíteni webes felülettel.
Ehhez találtam is egy működő példát amit elkezdtem belepakolni a saját kódomba, persze ott már nem működik.
Ami nekem nagyom furcsa, hogy a minta kódban a
  1. void setup(void){

rész végéről hiányzik egy
  1. }
zárójel, de a kód mégis működik.
Kvázi a
  1. void loop(void){
  2.  
  3.   server.handleClient(); // Listen for client connections
  4.  
  5. }


a setup szakaszon belül van, de setup nincs lezárva.
Nálam ez nem így van, a setup és a loop résznek is van eleje/ vége, próbáltam elhagyni de nem segített.

Miért működhet így a minta?

  1. /*  Version 4
  2.  *  
  3.  *  ESP32/ESP8266 example of downloading and uploading a file  or to the device's Filing System, including Directory and Streaming of files.
  4.  *  
  5.  This software, the ideas and concepts is Copyright (c) David Bird 2019. All rights to this software are reserved.
  6.  
  7.  Any redistribution or reproduction of any part or all of the contents in any form is prohibited other than the following:
  8.  1. You may print or download to a local hard disk extracts for your personal and non-commercial use only.
  9.  2. You may copy the content to indivi third parties for their personal use, but only if you acknowledge the author David Bird as the source of the material.
  10.  3. You may not, except with my express written permission, distribute or commercially exploit the content.
  11.  4. You may not transmit it or store it in any other website or other form of electronic retrieval system for commercial purposes.
  12.  
  13.  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
  14.  software use is visible to an end-user.
  15.  
  16.  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
  17.  OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18.  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
  19.  , OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20.  *
  21. */
  22. #ifdef ESP8266
  23.   #include <ESP8266WiFi.h>       // Built-in
  24.   #include <ESP8266WebServer.h>  // Built-in
  25. #else
  26.   #include <WiFi.h>              // Built-in
  27.   #include <WebServer.h>
  28.   #include "SPIFFS.h"
  29. #endif
  30.  
  31. #define ServerVersion "1.0"
  32. String  webpage = "";
  33. bool    SPIFFS_present = false;
  34.  
  35. const char ssid[]     = "****";
  36. const char password[] = "*****";
  37.  
  38. #include "FS.h"
  39. #include "CSS.h"
  40. #include <SPI.h>
  41.  
  42. #ifdef ESP8266
  43.   ESP8266WebServer server(80);
  44. #else
  45.   WebServer server(80);
  46. #endif
  47.  
  48. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  49. void setup(void){
  50.   Serial.begin(115200);
  51.  
  52.   WiFi.begin(ssid,password);
  53.   while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
  54.     delay(250); Serial.print('.');
  55.   }
  56.   Serial.println("\nConnected to "+WiFi.SSID()+" Use IP address: "+WiFi.localIP().toString()); // Report which SSID and IP is in use
  57.   #ifdef ESP8266
  58.   if (!SPIFFS.begin()) {
  59.   #else
  60.   if (!SPIFFS.begin(true)) {
  61.   #endif  
  62.     Serial.println("SPIFFS initialisation failed...");
  63.     SPIFFS_present = false;
  64.   }
  65.   else
  66.   {
  67.     Serial.println(F("SPIFFS initialised... file access enabled..."));
  68.     SPIFFS_present = true;
  69.   }
  70.   //----------------------------------------------------------------------  
  71.   ///////////////////////////// Server Commands
  72.   server.on("/",         HomePage);
  73.   server.on("/download", File_Download);
  74.   server.on("/upload",   File_Upload);
  75.   server.on("/fupload",  HTTP_POST,[](){ server.send(200);}, handleFileUpload);
  76.   server.on("/stream",   File_Stream);
  77.   server.on("/delete",   File_Delete);
  78.   server.on("/dir",      SPIFFS_dir);
  79.  
  80.   ///////////////////////////// End of Request commands
  81.   server.begin();
  82.   Serial.println("HTTP server started");
  83. }
  84. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  85. void loop(void){
  86.   server.handleClient(); // Listen for client connections
  87. }
  88.  
  89. // All supporting functions  here...
  90. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  91. void HomePage(){
  92.   SendHTML_Header();
  93.   webpage += F("<a href='/download'><button>Download</button></a>");
  94.   webpage += F("<a href='/upload'><button>Upload</button></a>");
  95.   webpage += F("<a href='/stream'><button>Stream</button></a>");
  96.   webpage += F("<a href='/delete'><button>Delete</button></a>");
  97.   webpage += F("<a href='/dir'><button>Directory</button></a>");
  98.   append_page_footer();
  99.   SendHTML_Content();
  100.   SendHTML_Stop(); // Stop is needed because no content length was sent
  101. }
  102. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  103. void File_Download(){ // This gets called twice, the first pass s the input, the second pass then processes the command line arguments
  104.   if (server.args() > 0 ) { // Arguments were received
  105.     if (server.hasArg("download")) DownloadFile(server.arg(0));
  106.   }
  107.   else Input("Enter filename to download","download","download");
  108. }
  109. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  110. void DownloadFile(String filename){
  111.   if (SPIFFS_present) {
  112.     File download = SPIFFS.open("/"+filename,  "r");
  113.     if (download) {
  114.       server.sendHeader("Content-Type", "text/text");
  115.       server.sendHeader("Content-Disposition", "attachment; filename="+filename);
  116.       server.sendHeader("Connection", "close");
  117.       server.streamFile(download, "application/octet-stream");
  118.       download.close();
  119.     } else ReportFileNotPresent("download");
  120.   } else ReportSPIFFSNotPresent();
  121. }
  122. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  123. void File_Upload(){
  124.   append_page_header();
  125.   webpage += F("<h3> File to Upload</h3>");
  126.   webpage += F("<FORM action='/fupload' method='post' enctype='multipart/form-data'>");
  127.   webpage += F("<input class='buttons' style='width:40%' type='file' name='fupload' id = 'fupload' value=''><br>");
  128.   webpage += F("<br><button class='buttons' style='width:10%' type='submit'>Upload File</button><br>");
  129.   webpage += F("<a href='/'>[Back]</a><br><br>");
  130.   append_page_footer();
  131.   server.send(200, "text/html",webpage);
  132. }
  133. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  134. File UploadFile;
  135. void handleFileUpload(){ // upload a new file to the Filing system
  136.   HTTPUpload& uploadfile = server.upload(); // See https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266Web...r/srcv
  137.                                             // For further information on 'status' structure, there are other reasons such as a failed transfer that could be used
  138.   if(uploadfile.status == UPLOAD_FILE_START)
  139.   {
  140.     String filename = uploadfile.filename;
  141.     if(!filename.startsWith("/")) filename = "/"+filename;
  142.     Serial.print("Upload File Name: "); Serial.println(filename);
  143.     SPIFFS.remove(filename);                  // Remove a previous version, otherwise data is appended the file again
  144.     UploadFile = SPIFFS.open(filename, "w");  // Open the file for writing in SPIFFS (create it, if doesn't exist)
  145.   }
  146.   else if (uploadfile.status == UPLOAD_FILE_WRITE)
  147.   {
  148.     if(UploadFile) UploadFile.write(uploadfile.buf, uploadfile.currentSize); // Write the received bytes to the file
  149.   }
  150.   else if (uploadfile.status == UPLOAD_FILE_END)
  151.   {
  152.     if(UploadFile)          // If the file was successfully created
  153.     {                                    
  154.       UploadFile.close();   // Close the file again
  155.       Serial.print("Upload Size: "); Serial.println(uploadfile.totalSize);
  156.       webpage = "";
  157.       append_page_header();
  158.       webpage += F("<h3>File was successfully uploaded</h3>");
  159.       webpage += F("<h2>Uploaded File Name: "); webpage += uploadfile.filename+"</h2>";
  160.       webpage += F("<h2>File Size: "); webpage += file_size(uploadfile.totalSize) + "</h2><br>";
  161.       append_page_footer();
  162.       server.send(200,"text/html",webpage);
  163.     }
  164.     else
  165.     {
  166.       ReportCouldNotCreateFile("upload");
  167.     }
  168.   }
  169. }
  170. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  171. #ifdef ESP32
  172. void SPIFFS_dir(){
  173.   if (SPIFFS_present) {
  174.     File root = SPIFFS.open("/");
  175.     if (root) {
  176.       root.rewindDirectory();
  177.       SendHTML_Header();
  178.       webpage += F("<h3 class='rcorners_m'>SD Card Contents</h3><br>");
  179.       webpage += F("<table align='center'>");
  180.       webpage += F("<tr><th>Name/Type</th><th style='width:20%'>Type File/Dir</th><th>File Size</th></tr>");
  181.       printDirectory("/",0);
  182.       webpage += F("</table>");
  183.       SendHTML_Content();
  184.       root.close();
  185.     }
  186.     else
  187.     {
  188.       SendHTML_Header();
  189.       webpage += F("<h3>No Files Found</h3>");
  190.     }
  191.     append_page_footer();
  192.     SendHTML_Content();
  193.     SendHTML_Stop();   // Stop is needed because no content length was sent
  194.   } else ReportSPIFFSNotPresent();
  195. }
  196. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  197. void printDirectory(const char * dirname, uint8_t levels){
  198.   File root = SPIFFS.open(dirname);
  199.   if(!root){
  200.     return;
  201.   }
  202.   if(!root.isDirectory()){
  203.     return;
  204.   }
  205.   File file = root.openNextFile();
  206.   while(file){
  207.     if (webpage.length() > 1000) {
  208.       SendHTML_Content();
  209.     }
  210.     if(file.isDirectory()){
  211.       webpage += "<tr><td>"+String(file.isDirectory()?"Dir":"File")+"</td><td>"+String(file.name())+"</td><td></td></tr>";
  212.       printDirectory(file.name(), levels-1);
  213.     }
  214.     else
  215.     {
  216.       webpage += "<tr><td>"+String(file.name())+"</td>";
  217.       webpage += "<td>"+String(file.isDirectory()?"Dir":"File")+"</td>";
  218.       int bytes = file.size();
  219.       String fsize = "";
  220.       if (bytes < 1024)                     fsize = String(bytes)+" B";
  221.       else if(bytes < (1024 * 1024))        fsize = String(bytes/1024.0,3)+" KB";
  222.       else if(bytes < (1024 * 1024 * 1024)) fsize = String(bytes/1024.0/1024.0,3)+" MB";
  223.       else                                  fsize = String(bytes/1024.0/1024.0/1024.0,3)+" GB";
  224.       webpage += "<td>"+fsize+"</td></tr>";
  225.     }
  226.     file = root.openNextFile();
  227.   }
  228.   file.close();
  229. }
  230. #endif
  231. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  232. #ifdef ESP8266
  233. void SPIFFS_dir(){
  234.   String str;
  235.   if (SPIFFS_present) {
  236.     Dir dir = SPIFFS.openDir("/");
  237.     SendHTML_Header();
  238.     webpage += F("<h3 class='rcorners_m'>SPIFFS Card Contents</h3><br>");
  239.     webpage += F("<table align='center'>");
  240.     webpage += F("<tr><th>Name/Type</th><th style='width:40%'>File Size</th></tr>");
  241.     while (dir.next()) {
  242.       Serial.print(dir.fileName());
  243.       webpage += "<tr><td>"+String(dir.fileName())+"</td>";
  244.       str  = dir.fileName();
  245.       str += " / ";
  246.       if(dir.fileSize()) {
  247.         File f = dir.openFile("r");
  248.         Serial.println(f.size());
  249.         int bytes = f.size();
  250.         String fsize = "";
  251.         if (bytes < 1024)                     fsize = String(bytes)+" B";
  252.         else if(bytes < (1024 * 1024))        fsize = String(bytes/1024.0,3)+" KB";
  253.         else if(bytes < (1024 * 1024 * 1024)) fsize = String(bytes/1024.0/1024.0,3)+" MB";
  254.         else                                  fsize = String(bytes/1024.0/1024.0/1024.0,3)+" GB";
  255.         webpage += "<td>"+fsize+"</td></tr>";
  256.         f.close();
  257.       }
  258.       str += String(dir.fileSize());
  259.       str += "\r\n";
  260.       Serial.println(str);
  261.     }
  262.     webpage += F("</table>");
  263.     SendHTML_Content();
  264.     append_page_footer();
  265.     SendHTML_Content();
  266.     SendHTML_Stop();   // Stop is needed because no content length was sent
  267.   } else ReportSPIFFSNotPresent();
  268. }
  269. #endif
  270. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  271. void File_Stream(){
  272.   if (server.args() > 0 ) { // Arguments were received
  273.     if (server.hasArg("stream")) SPIFFS_file_stream(server.arg(0));
  274.   }
  275.   else Input("Enter a File to Stream","stream","stream");
  276. }
  277. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  278. void SPIFFS_file_stream(String filename) {
  279.   if (SPIFFS_present) {
  280.     File dataFile = SPIFFS.open("/"+filename,  "r"); // Now read data  SPIFFS Card
  281.     if (dataFile) {
  282.       if (dataFile.available()) { // If data is available and present
  283.         String dataType = "application/octet-stream";
  284.         if (server.streamFile(dataFile, dataType) != dataFile.size()) {Serial.print(F("Sent less data than expected!")); }
  285.       }
  286.       dataFile.close(); // close the file:
  287.     } else ReportFileNotPresent("Cstream");
  288.   } else ReportSPIFFSNotPresent();
  289. }  
  290. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  291. void File_Delete(){
  292.   if (server.args() > 0 ) { // Arguments were received
  293.     if (server.hasArg("delete")) SPIFFS_file_delete(server.arg(0));
  294.   }
  295.   else Input(" a File to Delete","delete","delete");
  296. }
  297. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  298. void SPIFFS_file_delete(String filename) { // Delete the file
  299.   if (SPIFFS_present) {
  300.     SendHTML_Header();
  301.     File dataFile = SPIFFS.open("/"+filename, "r"); // Now read data  SPIFFS Card
  302.     if (dataFile)
  303.     {
  304.       if (SPIFFS.remove("/"+filename)) {
  305.         Serial.println(F("File deleted successfully"));
  306.         webpage += "<h3>File '"+filename+"' has been erased</h3>";
  307.         webpage += F("<a href='/delete'>[Back]</a><br><br>");
  308.       }
  309.       else
  310.       {
  311.         webpage += F("<h3>File was not deleted - error</h3>");
  312.         webpage += F("<a href='delete'>[Back]</a><br><br>");
  313.       }
  314.     } else ReportFileNotPresent("delete");
  315.     append_page_footer();
  316.     SendHTML_Content();
  317.     SendHTML_Stop();
  318.   } else ReportSPIFFSNotPresent();
  319. }
  320. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  321. void SendHTML_Header(){
  322.   server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
  323.   server.sendHeader("Pragma", "no-cache");
  324.   server.sendHeader("Expires", "-1");
  325.   server.setContentLength(CONTENT_LENGTH_UNKNOWN);
  326.   server.send(200, "text/html", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
  327.   append_page_header();
  328.   server.sendContent(webpage);
  329.   webpage = "";
  330. }
  331. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  332. void SendHTML_Content(){
  333.   server.sendContent(webpage);
  334.   webpage = "";
  335. }
  336. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  337. void SendHTML_Stop(){
  338.   server.sendContent("");
  339.   server.client().stop(); // Stop is needed because no content length was sent
  340. }
  341. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  342. void Input(String heading1, String command, String arg_calling_name){
  343.   SendHTML_Header();
  344.   webpage += F("<h3>"); webpage += heading1 + "</h3>";
  345.   webpage += F("<FORM action='/"); webpage += command + "' method='post'>"; // Must match the calling argument e.g. '/chart' calls '/chart' after ion but with arguments!
  346.   webpage += F("<input type='text' name='"); webpage += arg_calling_name; webpage += F("' value=''><br>");
  347.   webpage += F("<type='submit' name='"); webpage += arg_calling_name; webpage += F("' value=''><br><br>");
  348.   webpage += F("<a href='/'>[Back]</a><br><br>");
  349.   append_page_footer();
  350.   SendHTML_Content();
  351.   SendHTML_Stop();
  352. }
  353. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  354. void ReportSPIFFSNotPresent(){
  355.   SendHTML_Header();
  356.   webpage += F("<h3>No SPIFFS Card present</h3>");
  357.   webpage += F("<a href='/'>[Back]</a><br><br>");
  358.   append_page_footer();
  359.   SendHTML_Content();
  360.   SendHTML_Stop();
  361. }
  362. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  363. void ReportFileNotPresent(String target){
  364.   SendHTML_Header();
  365.   webpage += F("<h3>File does not exist</h3>");
  366.   webpage += F("<a href='/"); webpage += target + "'>[Back]</a><br><br>";
  367.   append_page_footer();
  368.   SendHTML_Content();
  369.   SendHTML_Stop();
  370. }
  371. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  372. void ReportCouldNotCreateFile(String target){
  373.   SendHTML_Header();
  374.   webpage += F("<h3>Could Not Create Uploaded File (write-protected?)</h3>");
  375.   webpage += F("<a href='/"); webpage += target + "'>[Back]</a><br><br>";
  376.   append_page_footer();
  377.   SendHTML_Content();
  378.   SendHTML_Stop();
  379. }
  380. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  381. String file_size(int bytes){
  382.   String fsize = "";
  383.   if (bytes < 1024)                 fsize = String(bytes)+" B";
  384.   else if(bytes < (1024*1024))      fsize = String(bytes/1024.0,3)+" KB";
  385.   else if(bytes < (1024*1024*1024)) fsize = String(bytes/1024.0/1024.0,3)+" MB";
  386.   else                              fsize = String(bytes/1024.0/1024.0/1024.0,3)+" GB";
  387.   return fsize;
  388. }


  1. void append_page_header() {
  2.   webpage  = F("<!DOCTYPE html><html>");
  3.   webpage += F("<head>");
  4.   webpage += F("<title>File Server</title>"); // NOTE: 1em = 16px
  5.   webpage += F("<meta name='viewport' content='user-scalable=yes,initial-scale=1.0,width=device-width'>");
  6.   webpage += F("<style>");
  7.   webpage += F("body{max-width:65%;margin:0 auto;font-family:arial;font-size:105%;text-align:center;color:blue;background-color:#F7F2Fd;}");
  8.   webpage += F("ul{list-style-type:none;margin:0.1em;padding:0;border-radius:0.375em;overflow:hidden;background-color:#dcade6;font-size:1em;}");
  9.   webpage += F("li{float:left;border-radius:0.375em;border-right:0.06em solid #bbb;}last-child {border-right:none;font-size:85%}");
  10.   webpage += F("li a{display: block;border-radius:0.375em;padding:0.44em 0.44em;text-decoration:none;font-size:85%}");
  11.   webpage += F("li a:hover{background-color:#EAE3EA;border-radius:0.375em;font-size:85%}");
  12.   webpage += F("section {font-size:0.88em;}");
  13.   webpage += F("h1{color:white;border-radius:0.5em;font-size:1em;padding:0.2em 0.2em;background:#558ED5;}");
  14.   webpage += F("h2{color:orange;font-size:1.0em;}");
  15.   webpage += F("h3{font-size:0.8em;}");
  16.   webpage += F("table{font-family:arial,sans-serif;font-size:0.9em;border-collapse:collapse;width:85%;}");
  17.   webpage += F("th,td {border:0.06em solid #dddddd;text-align:left;padding:0.3em;border-bottom:0.06em solid #dddddd;}");
  18.   webpage += F("tr:nth-child(odd) {background-color:#eeeeee;}");
  19.   webpage += F(".rcorners_n {border-radius:0.5em;background:#558ED5;padding:0.3em 0.3em;width:20%;color:white;font-size:75%;}");
  20.   webpage += F(".rcorners_m {border-radius:0.5em;background:#558ED5;padding:0.3em 0.3em;width:50%;color:white;font-size:75%;}");
  21.   webpage += F(".rcorners_w {border-radius:0.5em;background:#558ED5;padding:0.3em 0.3em;width:70%;color:white;font-size:75%;}");
  22.   webpage += F(".column{float:left;width:50%;height:45%;}");
  23.   webpage += F(".row:after{content:'';display:table;clear:both;}");
  24.   webpage += F("*{box-sizing:border-box;}");
  25.   webpage += F("footer{background-color:#eedfff; text-align:center;padding:0.3em 0.3em;border-radius:0.375em;font-size:60%;}");
  26.   webpage += F("button{border-radius:0.5em;background:#558ED5;padding:0.3em 0.3em;width:20%;color:white;font-size:130%;}");
  27.   webpage += F(".buttons {border-radius:0.5em;background:#558ED5;padding:0.3em 0.3em;width:15%;color:white;font-size:80%;}");
  28.   webpage += F(".buttonsm{border-radius:0.5em;background:#558ED5;padding:0.3em 0.3em;width:9%; color:white;font-size:70%;}");
  29.   webpage += F(".buttonm {border-radius:0.5em;background:#558ED5;padding:0.3em 0.3em;width:15%;color:white;font-size:70%;}");
  30.   webpage += F(".buttonw {border-radius:0.5em;background:#558ED5;padding:0.3em 0.3em;width:40%;color:white;font-size:70%;}");
  31.   webpage += F("a{font-size:75%;}");
  32.   webpage += F("p{font-size:75%;}");
  33.   webpage += F("</style></head><body><h1>File Server "); webpage += String(ServerVersion) + "</h1>";
  34. }
  35. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  36. void append_page_footer(){ // Saves repeating many lines of code for HTML page footers
  37.   webpage += F("<ul>");
  38.   webpage += F("<li><a href='/'>Home</a></li>"); // Lower Menu bar command entries
  39.   webpage += F("<li><a href='/download'>Download</a></li>");
  40.   webpage += F("<li><a href='/upload'>Upload</a></li>");
  41.   webpage += F("<li><a href='/stream'>Stream</a></li>");
  42.   webpage += F("<li><a href='/delete'>Delete</a></li>");
  43.   webpage += F("<li><a href='/dir'>Directory</a></li>");
  44.   webpage += F("</ul>");
  45.   webpage += "<footer>©"+String(char(byte(0x40>>1)))+String(char(byte(0x88>>1)))+String(char(byte(0x5c>>1)))+String(char(byte(0x98>>1)))+String(char(byte(0x5c>>1)));
  46.   webpage += String(char((0x84>>1)))+String(char(byte(0xd2>>1)))+String(char(0xe4>>1))+String(char(0xc8>>1))+String(char(byte(0x40>>1)));
  47.   webpage += String(char(byte(0x64/2)))+String(char(byte(0x60>>1)))+String(char(byte(0x62>>1)))+String(char(0x70>>1))+"</footer>";
  48.   webpage += F("</body></html>");
  49. }
(#) tbarath válasza sitto hozzászólására (») Feb 13, 2019 /
 
Le van az zárva, csak az ifdef-es résznél 2x van nyitó "zárójel", az 58-62 sor között, az zavar meg
(#) sitto válasza tbarath hozzászólására (») Feb 13, 2019 /
 
Nézek de nem látok

Az 54. sort zárja az 56.
Az 59. sort zárja a 84.
A 61. sort zárja a 65.
A 67. sort zárja a 70.

Az 50. végét nem látom. A 86. előtt kéne lennie.
Valamit rosszul értelmezek?
(#) benjami válasza sitto hozzászólására (») Feb 14, 2019 /
 
A feltételes fordítás miatt vagy az 59.sor, vagy a 61.sort fordítja bele a kódba (de csak az egyiket). Bármelyik verzió is lesz, a záró sora a 65.sor lesz.
(#) sitto válasza benjami hozzászólására (») Feb 14, 2019 /
 
Így már értem.
Köszönöm!
(#) hadhazik válasza hadhazik hozzászólására (») Feb 14, 2019 /
 
QMC5883L vs. HMC5883L

A két chip eltérő címzése:
QMC5883L
Wire.write(0x09); // mode register
Wire.write(0x1D); //continuous measurement mode
Wire.write(0x00); // register 3, X MSB register

HMC5883L
Wire.write(0x02); // mode register
Wire.write(0x00); //continuous measurement mode
Wire.write(0x03); // register 3, X MSB register
(#) Peter65 válasza david10 hozzászólására (») Feb 15, 2019 /
 
Szia!
Nagyon sokféle kódadó van a piacon. Viszonylag elterjedtek a profi-buszra köthető kódadók, de ezek leginkább abszolút helyzetadók, amik nem az átlagos sebességet adják meg, hanem az aktuális pozíciót. Az áruk sem éppen hobbi kategória, szóval szerintem reálisabb, ha egy olcsó kódadó jelét feldolgozod egy mikrokontrollerrel, és mondjuk RS485 felületű soros kommunikációval átküldöd azt, ami kell.
(#) gabilow hozzászólása Feb 15, 2019 /
 
Üdv!
A "long epoch" kezdetű sornál a " invalid operands of types 'double' and 'long int' to binary 'operator%'" hibát írja ki. Tegnap frissítettem könyvtárakat, alaplapot, a frissítés előtt lefordította.
Mi lehet a gond? Ha kell az egész programot is felteszem. Köszike.
  1. void updateTime()
  2. {
  3.   long curEpoch = localEpoc + ((millis() - localMillisAtUpdate) / 1000);
  4.   long epoch = round(curEpoch + 3600 * (utcOffset+summerTime) + 86400L) % 86400L;
  5.   h = ((epoch  % 86400L) / 3600) % 24;
  6.   m = (epoch % 3600) / 60;
  7.   s = epoch % 60;
  8. }
(#) sitto válasza benjami hozzászólására (») Feb 15, 2019 /
 
Sziasztok!

Még mindig nem működik a dolog.
A feltételes fordítást kiszedtem belőle. Így önmagában működik is a kód. Van némi timeout probléma amikor IP cím alapján bejelentkezek a webes felületre de ez egy másik kérdés.
  1. #include <WiFi.h>              // Built-in
  2.   #include <WebServer.h>
  3.   #include "SPIFFS.h"
  4.  
  5.  
  6. #define ServerVersion "1.0"
  7. String  webpage = "";
  8. bool    SPIFFS_present = false;
  9.  
  10. const char ssid[]     = "*******";
  11. const char password[] = "*******";
  12.  
  13. #include "FS.h"
  14. #include "CSS.h"
  15. #include <SPI.h>
  16.  
  17.  
  18. WebServer server(80);
  19.  
  20.  
  21. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  22. void setup(void){
  23.   Serial.begin(115200);
  24.  
  25.   WiFi.begin(ssid,password);
  26.   while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
  27.     delay(250); Serial.print('.');
  28.   }
  29.   Serial.println("\nConnected to "+WiFi.SSID()+" Use IP address: "+WiFi.localIP().toString()); // Report which SSID and IP is in use
  30.  
  31.   if (!SPIFFS.begin(true)) {
  32.     Serial.println("SPIFFS initialisation failed...");
  33.     SPIFFS_present = false;
  34.   }
  35.   else
  36.   {
  37.     Serial.println(F("SPIFFS initialised... file access enabled..."));
  38.     SPIFFS_present = true;
  39.   }
  40.   //----------------------------------------------------------------------  
  41.   ///////////////////////////// Server Commands
  42.   server.on("/",         HomePage);
  43.   server.on("/download", File_Download);
  44.   server.on("/upload",   File_Upload);
  45.   server.on("/fupload",  HTTP_POST,[](){ server.send(200);}, handleFileUpload);
  46.   server.on("/stream",   File_Stream);
  47.   server.on("/delete",   File_Delete);
  48.   server.on("/dir",      SPIFFS_dir);
  49.  
  50.   ///////////////////////////// End of Request commands
  51.   server.begin();
  52.   Serial.println("HTTP server started");
  53. }
  54. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55. void loop(void){
  56.   server.handleClient(); // Listen for client connections
  57. }
  58.  
  59. // All supporting functions  here...
  60. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  61. void HomePage(){
  62.   SendHTML_Header();
  63.   webpage += F("<a href='/download'><button>Download</button></a>");
  64.   webpage += F("<a href='/upload'><button>Upload</button></a>");
  65.   //webpage += F("<a href='/stream'><button>Stream</button></a>");
  66.   webpage += F("<a href='/delete'><button>Delete</button></a>");
  67.   webpage += F("<a href='/dir'><button>Directory</button></a>");
  68.   //append_page_footer();
  69.   SendHTML_Content();
  70.   SendHTML_Stop(); // Stop is needed because no content length was sent
  71. }
  72. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. void File_Download(){ // This gets called twice, the first pass s the input, the second pass then processes the command line arguments
  74.   if (server.args() > 0 ) { // Arguments were received
  75.     if (server.hasArg("download")) DownloadFile(server.arg(0));
  76.   }
  77.   else Input("Enter filename to download","download","download");
  78. }
  79. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  80. void DownloadFile(String filename){
  81.   if (SPIFFS_present) {
  82.     File download = SPIFFS.open("/"+filename,  "r");
  83.     if (download) {
  84.       server.sendHeader("Content-Type", "text/text");
  85.       server.sendHeader("Content-Disposition", "attachment; filename="+filename);
  86.       server.sendHeader("Connection", "close");
  87.       server.streamFile(download, "application/octet-stream");
  88.       download.close();
  89.     } else ReportFileNotPresent("download");
  90.   } else ReportSPIFFSNotPresent();
  91. }
  92. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  93. void File_Upload(){
  94.   append_page_header();
  95.   webpage += F("<h3> File to Upload</h3>");
  96.   webpage += F("<FORM action='/fupload' method='post' enctype='multipart/form-data'>");
  97.   webpage += F("<input class='buttons' style='width:40%' type='file' name='fupload' id = 'fupload' value=''><br>");
  98.   webpage += F("<br><button class='buttons' style='width:10%' type='submit'>Upload File</button><br>");
  99.   webpage += F("<a href='/'>[Back]</a><br><br>");
  100.   //append_page_footer();
  101.   server.send(200, "text/html",webpage);
  102. }
  103. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  104. File UploadFile;
  105. void handleFileUpload(){ // upload a new file to the Filing system
  106.   HTTPUpload& uploadfile = server.upload(); // See https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266Web...r/srcv
  107.                                             // For further information on 'status' structure, there are other reasons such as a failed transfer that could be used
  108.   if(uploadfile.status == UPLOAD_FILE_START)
  109.   {
  110.     String filename = uploadfile.filename;
  111.     if(!filename.startsWith("/")) filename = "/"+filename;
  112.     Serial.print("Upload File Name: "); Serial.println(filename);
  113.     SPIFFS.remove(filename);                  // Remove a previous version, otherwise data is appended the file again
  114.     UploadFile = SPIFFS.open(filename, "w");  // Open the file for writing in SPIFFS (create it, if doesn't exist)
  115.   }
  116.   else if (uploadfile.status == UPLOAD_FILE_WRITE)
  117.   {
  118.     if(UploadFile) UploadFile.write(uploadfile.buf, uploadfile.currentSize); // Write the received bytes to the file
  119.   }
  120.   else if (uploadfile.status == UPLOAD_FILE_END)
  121.   {
  122.     if(UploadFile)          // If the file was successfully created
  123.     {                                    
  124.       UploadFile.close();   // Close the file again
  125.       Serial.print("Upload Size: "); Serial.println(uploadfile.totalSize);
  126.       webpage = "";
  127.       append_page_header();
  128.       webpage += F("<h3>File was successfully uploaded</h3>");
  129.       webpage += F("<h2>Uploaded File Name: "); webpage += uploadfile.filename+"</h2>";
  130.       webpage += F("<h2>File Size: "); webpage += file_size(uploadfile.totalSize) + "</h2><br>";
  131.       //append_page_footer();
  132.       server.send(200,"text/html",webpage);
  133.     }
  134.     else
  135.     {
  136.       ReportCouldNotCreateFile("upload");
  137.     }
  138.   }
  139. }
  140. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  141. #ifdef ESP32
  142. void SPIFFS_dir(){
  143.   if (SPIFFS_present) {
  144.     File root = SPIFFS.open("/");
  145.     if (root) {
  146.       root.rewindDirectory();
  147.       SendHTML_Header();
  148.       //webpage += F("<h3 class='rcorners_m'>SD Card Contents</h3><br>");
  149.       webpage += F("<table align='center'>");
  150.       webpage += F("<tr><th>Name/Type</th><th style='width:20%'>Type File/Dir</th><th>File Size</th></tr>");
  151.       webpage += F("<a href='/'>[Back]</a><br><br>");
  152.       printDirectory("/",0);
  153.       webpage += F("</table>");
  154.       SendHTML_Content();
  155.       root.close();
  156.     }
  157.     else
  158.     {
  159.       SendHTML_Header();
  160.       webpage += F("<h3>No Files Found</h3>");
  161.     }
  162.     //append_page_footer();
  163.     SendHTML_Content();
  164.     SendHTML_Stop();   // Stop is needed because no content length was sent
  165.   } else ReportSPIFFSNotPresent();
  166. }
  167. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  168. void printDirectory(const char * dirname, uint8_t levels){
  169.   File root = SPIFFS.open(dirname);
  170.   if(!root){
  171.     return;
  172.   }
  173.   if(!root.isDirectory()){
  174.     return;
  175.   }
  176.   File file = root.openNextFile();
  177.   while(file){
  178.     if (webpage.length() > 1000) {
  179.       SendHTML_Content();
  180.     }
  181.     if(file.isDirectory()){
  182.       webpage += "<tr><td>"+String(file.isDirectory()?"Dir":"File")+"</td><td>"+String(file.name())+"</td><td></td></tr>";
  183.       printDirectory(file.name(), levels-1);
  184.     }
  185.     else
  186.     {
  187.       webpage += "<tr><td>"+String(file.name())+"</td>";
  188.       webpage += "<td>"+String(file.isDirectory()?"Dir":"File")+"</td>";
  189.       int bytes = file.size();
  190.       String fsize = "";
  191.       if (bytes < 1024)                     fsize = String(bytes)+" B";
  192.       else if(bytes < (1024 * 1024))        fsize = String(bytes/1024.0,3)+" KB";
  193.       else if(bytes < (1024 * 1024 * 1024)) fsize = String(bytes/1024.0/1024.0,3)+" MB";
  194.       else                                  fsize = String(bytes/1024.0/1024.0/1024.0,3)+" GB";
  195.       webpage += "<td>"+fsize+"</td></tr>";
  196.     }
  197.     file = root.openNextFile();
  198.   }
  199.   file.close();
  200. }
  201. #endif
  202. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  203. #ifdef ESP8266
  204. void SPIFFS_dir(){
  205.   String str;
  206.   if (SPIFFS_present) {
  207.     Dir dir = SPIFFS.openDir("/");
  208.     SendHTML_Header();
  209.     webpage += F("<h3 class='rcorners_m'>SPIFFS Card Contents</h3><br>");
  210.     webpage += F("<table align='center'>");
  211.     webpage += F("<tr><th>Name/Type</th><th style='width:40%'>File Size</th></tr>");
  212.     while (dir.next()) {
  213.       Serial.print(dir.fileName());
  214.       webpage += "<tr><td>"+String(dir.fileName())+"</td>";
  215.       str  = dir.fileName();
  216.       str += " / ";
  217.       if(dir.fileSize()) {
  218.         File f = dir.openFile("r");
  219.         Serial.println(f.size());
  220.         int bytes = f.size();
  221.         String fsize = "";
  222.         if (bytes < 1024)                     fsize = String(bytes)+" B";
  223.         else if(bytes < (1024 * 1024))        fsize = String(bytes/1024.0,3)+" KB";
  224.         else if(bytes < (1024 * 1024 * 1024)) fsize = String(bytes/1024.0/1024.0,3)+" MB";
  225.         else                                  fsize = String(bytes/1024.0/1024.0/1024.0,3)+" GB";
  226.         webpage += "<td>"+fsize+"</td></tr>";
  227.         f.close();
  228.       }
  229.       str += String(dir.fileSize());
  230.       str += "\r\n";
  231.       Serial.println(str);
  232.     }
  233.     webpage += F("</table>");
  234.     SendHTML_Content();
  235.     //append_page_footer();
  236.     SendHTML_Content();
  237.     SendHTML_Stop();   // Stop is needed because no content length was sent
  238.   } else ReportSPIFFSNotPresent();
  239. }
  240. #endif
  241. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  242. void File_Stream(){
  243.   if (server.args() > 0 ) { // Arguments were received
  244.     if (server.hasArg("stream")) SPIFFS_file_stream(server.arg(0));
  245.   }
  246.   else Input("Enter a File to Stream","stream","stream");
  247. }
  248. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  249. void SPIFFS_file_stream(String filename) {
  250.   if (SPIFFS_present) {
  251.     File dataFile = SPIFFS.open("/"+filename,  "r"); // Now read data  SPIFFS Card
  252.     if (dataFile) {
  253.       if (dataFile.available()) { // If data is available and present
  254.         String dataType = "application/octet-stream";
  255.         if (server.streamFile(dataFile, dataType) != dataFile.size()) {Serial.print(F("Sent less data than expected!")); }
  256.       }
  257.       dataFile.close(); // close the file:
  258.     } else ReportFileNotPresent("Cstream");
  259.   } else ReportSPIFFSNotPresent();
  260. }  
  261. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  262. void File_Delete(){
  263.   if (server.args() > 0 ) { // Arguments were received
  264.     if (server.hasArg("delete")) SPIFFS_file_delete(server.arg(0));
  265.   }
  266.   else Input(" a File to Delete","delete","delete");
  267. }
  268. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  269. void SPIFFS_file_delete(String filename) { // Delete the file
  270.   if (SPIFFS_present) {
  271.     SendHTML_Header();
  272.     File dataFile = SPIFFS.open("/"+filename, "r"); // Now read data  SPIFFS Card
  273.     if (dataFile)
  274.     {
  275.       if (SPIFFS.remove("/"+filename)) {
  276.         Serial.println(F("File deleted successfully"));
  277.         webpage += "<h3>File '"+filename+"' has been erased</h3>";
  278.         webpage += F("<a href='/delete'>[Back]</a><br><br>");
  279.       }
  280.       else
  281.       {
  282.         webpage += F("<h3>File was not deleted - error</h3>");
  283.         webpage += F("<a href='delete'>[Back]</a><br><br>");
  284.       }
  285.     } else ReportFileNotPresent("delete");
  286.     //append_page_footer();
  287.     SendHTML_Content();
  288.     SendHTML_Stop();
  289.   } else ReportSPIFFSNotPresent();
  290. }
  291. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  292. void SendHTML_Header(){
  293.   server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
  294.   server.sendHeader("Pragma", "no-cache");
  295.   server.sendHeader("Expires", "-1");
  296.   server.setContentLength(CONTENT_LENGTH_UNKNOWN);
  297.   server.send(200, "text/html", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
  298.   append_page_header();
  299.   server.sendContent(webpage);
  300.   webpage = "";
  301. }
  302. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  303. void SendHTML_Content(){
  304.   server.sendContent(webpage);
  305.   webpage = "";
  306. }
  307. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  308. void SendHTML_Stop(){
  309.   server.sendContent("");
  310.   server.client().stop(); // Stop is needed because no content length was sent
  311. }
  312. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  313. void Input(String heading1, String command, String arg_calling_name){
  314.   SendHTML_Header();
  315.   webpage += F("<h3>"); webpage += heading1 + "</h3>";
  316.   webpage += F("<FORM action='/"); webpage += command + "' method='post'>"; // Must match the calling argument e.g. '/chart' calls '/chart' after ion but with arguments!
  317.   webpage += F("<input type='text' name='"); webpage += arg_calling_name; webpage += F("' value=''><br>");
  318.   webpage += F("<type='submit' name='"); webpage += arg_calling_name; webpage += F("' value=''><br><br>");
  319.   webpage += F("<a href='/'>[Back]</a><br><br>");
  320.   //append_page_footer();
  321.   SendHTML_Content();
  322.   SendHTML_Stop();
  323. }
  324. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  325. void ReportSPIFFSNotPresent(){
  326.   SendHTML_Header();
  327.   webpage += F("<h3>No SPIFFS Card present</h3>");
  328.   webpage += F("<a href='/'>[Back]</a><br><br>");
  329.   //append_page_footer();
  330.   SendHTML_Content();
  331.   SendHTML_Stop();
  332. }
  333. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  334. void ReportFileNotPresent(String target){
  335.   SendHTML_Header();
  336.   webpage += F("<h3>File does not exist</h3>");
  337.   webpage += F("<a href='/"); webpage += target + "'>[Back]</a><br><br>";
  338.   //append_page_footer();
  339.   SendHTML_Content();
  340.   SendHTML_Stop();
  341. }
  342. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  343. void ReportCouldNotCreateFile(String target){
  344.   SendHTML_Header();
  345.   webpage += F("<h3>Could Not Create Uploaded File (write-protected?)</h3>");
  346.   webpage += F("<a href='/"); webpage += target + "'>[Back]</a><br><br>";
  347.   //append_page_footer();
  348.   SendHTML_Content();
  349.   SendHTML_Stop();
  350. }
  351. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  352. String file_size(int bytes){
  353.   String fsize = "";
  354.   if (bytes < 1024)                 fsize = String(bytes)+" B";
  355.   else if(bytes < (1024*1024))      fsize = String(bytes/1024.0,3)+" KB";
  356.   else if(bytes < (1024*1024*1024)) fsize = String(bytes/1024.0/1024.0,3)+" MB";
  357.   else                              fsize = String(bytes/1024.0/1024.0/1024.0,3)+" GB";
  358.   return fsize;
  359. }


  1. void append_page_header() {
  2.   webpage  = F("<!DOCTYPE html><html>");
  3.   webpage += F("<head>");
  4.   webpage += F("<title>File Server</title>"); // NOTE: 1em = 16px
  5.   webpage += F("<meta name='viewport' content='user-scalable=yes,initial-scale=1.0,width=device-width'>");
  6.   webpage += F("<style>");
  7.   webpage += F("body{max-width:65%;margin:0 auto;font-family:arial;font-size:105%;text-align:center;color:blue;background-color:#F7F2Fd;}");
  8.   webpage += F("ul{list-style-type:none;margin:0.1em;padding:0;border-radius:0.375em;overflow:hidden;background-color:#dcade6;font-size:1em;}");
  9.   webpage += F("li{float:left;border-radius:0.375em;border-right:0.06em solid #bbb;}last-child {border-right:none;font-size:85%}");
  10.   webpage += F("li a{display: block;border-radius:0.375em;padding:0.44em 0.44em;text-decoration:none;font-size:85%}");
  11.   webpage += F("li a:hover{background-color:#EAE3EA;border-radius:0.375em;font-size:85%}");
  12.   webpage += F("section {font-size:0.88em;}");
  13.   webpage += F("h1{color:white;border-radius:0.5em;font-size:1em;padding:0.2em 0.2em;background:#558ED5;}");
  14.   webpage += F("h2{color:orange;font-size:1.0em;}");
  15.   webpage += F("h3{font-size:0.8em;}");
  16.   webpage += F("table{font-family:arial,sans-serif;font-size:0.9em;border-collapse:collapse;width:85%;}");
  17.   webpage += F("th,td {border:0.06em solid #dddddd;text-align:left;padding:0.3em;border-bottom:0.06em solid #dddddd;}");
  18.   webpage += F("tr:nth-child(odd) {background-color:#eeeeee;}");
  19.   webpage += F(".rcorners_n {border-radius:0.5em;background:#558ED5;padding:0.3em 0.3em;width:20%;color:white;font-size:75%;}");
  20.   webpage += F(".rcorners_m {border-radius:0.5em;background:#558ED5;padding:0.3em 0.3em;width:50%;color:white;font-size:75%;}");
  21.   webpage += F(".rcorners_w {border-radius:0.5em;background:#558ED5;padding:0.3em 0.3em;width:70%;color:white;font-size:75%;}");
  22.   webpage += F(".column{float:left;width:50%;height:45%;}");
  23.   webpage += F(".row:after{content:'';display:table;clear:both;}");
  24.   webpage += F("*{box-sizing:border-box;}");
  25.   webpage += F("footer{background-color:#eedfff; text-align:center;padding:0.3em 0.3em;border-radius:0.375em;font-size:60%;}");
  26.   webpage += F("button{border-radius:0.5em;background:#558ED5;padding:0.3em 0.3em;width:20%;color:white;font-size:130%;}");
  27.   webpage += F(".buttons {border-radius:0.5em;background:#558ED5;padding:0.3em 0.3em;width:15%;color:white;font-size:80%;}");
  28.   webpage += F(".buttonsm{border-radius:0.5em;background:#558ED5;padding:0.3em 0.3em;width:9%; color:white;font-size:70%;}");
  29.   webpage += F(".buttonm {border-radius:0.5em;background:#558ED5;padding:0.3em 0.3em;width:15%;color:white;font-size:70%;}");
  30.   webpage += F(".buttonw {border-radius:0.5em;background:#558ED5;padding:0.3em 0.3em;width:40%;color:white;font-size:70%;}");
  31.   webpage += F("a{font-size:75%;}");
  32.   webpage += F("p{font-size:75%;}");
  33.   webpage += F("</style></head><body><h1>File Server "); webpage += String(ServerVersion) + "</h1>";
  34. }
  35. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  36. void append_page_footer(){ // Saves repeating many lines of code for HTML page footers
  37.   webpage += F("<ul>");
  38.   webpage += F("<li><a href='/'>Home</a></li>"); // Lower Menu bar command entries
  39.   webpage += F("<li><a href='/download'>Download</a></li>");
  40.   webpage += F("<li><a href='/upload'>Upload</a></li>");
  41.   webpage += F("<li><a href='/stream'>Stream</a></li>");
  42.   webpage += F("<li><a href='/delete'>Delete</a></li>");
  43.   webpage += F("<li><a href='/dir'>Directory</a></li>");
  44.   webpage += F("</ul>");
  45.   webpage += "<footer>©"+String(char(byte(0x40>>1)))+String(char(byte(0x88>>1)))+String(char(byte(0x5c>>1)))+String(char(byte(0x98>>1)))+String(char(byte(0x5c>>1)));
  46.   webpage += String(char((0x84>>1)))+String(char(byte(0xd2>>1)))+String(char(0xe4>>1))+String(char(0xc8>>1))+String(char(byte(0x40>>1)));
  47.   webpage += String(char(byte(0x64/2)))+String(char(byte(0x60>>1)))+String(char(byte(0x62>>1)))+String(char(0x70>>1))+"</footer>";
  48.   webpage += F("</body></html>");
  49. }


A másik kód is önállóan működik, ezt szeretném kiegészíteni a webes felülettel, viszont ha a kettőt összerakom akkor
  1. 'webpage' was not declaired in this scope

hibaüzenettel leáll a fordítás. Pedig ott van az elején:
  1. String  webpage = "";


Már 2. napja bogarászom a hibát de nem találom.

  1. #include <SPI.h>
  2. #include <SD.h>
  3. //#include <SdFat.h>
  4. //#include <sd_defines.h>
  5. //#include <sd_diskio.h>
  6. #include <Wire.h>
  7. #include "RTClib.h"
  8. #include "FS.h"
  9. #include "SD.h"
  10. #include "SPI.h"
  11. #include <EEPROM.h>
  12. #include <MechaQMC5883.h>
  13. #include <math.h>
  14. #include "MS5837.h"
  15.  
  16. #include <Arduino.h>
  17. #include <U8g2lib.h>
  18. #ifdef U8X8_HAVE_HW_SPI
  19. #include <SPI.h>
  20. #endif
  21. #ifdef U8X8_HAVE_HW_I2C
  22. #include <Wire.h>
  23. #endif
  24.  
  25.  
  26. #include <WiFi.h>            
  27. #include <WebServer.h>
  28. #include "SPIFFS.h"
  29. #include "CSS.h"
  30.  
  31. #define ServerVersion "1.0"
  32. String  webpage = "";
  33. bool    SPIFFS_present = false;
  34.  
  35. const char ssid[]     = "******";
  36. const char password[] = "******";
  37.  
  38. WebServer server(80);
  39.  
  40. MechaQMC5883 qmc;
  41. RTC_DS1307 rtc;
  42. MS5837 depthSensor;
  43.  
  44.  
  45.  
  46. //Input pin definition
  47. //int const TMP36Pin = 4;  //the analog pin the TMP36's Vout (sense) pin is connected to the resolution is 10 mV/degree centigrade with a 500 mV offset to allow for negative temperatures
  48. int const buttonPin = 27; //logger's press button attached to this pin
  49.  
  50.  
  51.  
  52. // LCD connection definition
  53. U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0,14,13,12); //128x64 st7920
  54. //U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 18, /* data=*/ 23, /* CS=*/ 15, /* reset=8*/ );
  55.  
  56. /*  
  57. // Let's compare an average of 100
  58. const byte averageCount = 100;  //max. 255, byte variable is used
  59.  
  60. // Variables for the Modified Moving Average
  61.   double movingAverage = 0;
  62.   double movingAverageSum = 0;
  63. */
  64.  
  65. // Timer variables
  66.   unsigned long previousAutoLogMillis = 0;
  67.   unsigned long currentAutoLogMillis = millis();
  68.             int printInterval = 1000;  // print out measured results every 1000 msec
  69.   unsigned long lastDebounceTime = 0;  // the last time the logger input button was toggled
  70.             int debounceDelay = 10;    // the debounce time; increase if the output flickers
  71.            
  72. //Drunstate monitoring
  73.   int DrunState = 0;
  74.   unsigned int DrunTime = 0;
  75.   byte DrunHour = 0;
  76.   byte DrunMinutes = 0;
  77.   byte DrunSecound = 0;
  78.   unsigned int lastDrunTime = 0;
  79.   unsigned int startTime = 0;
  80.   //int thresholdTemp = 25;
  81.   int thresholdDepth = 1;
  82.   unsigned long previousdepthAreaMillis = 0;
  83.   String formDrunTime;
  84.   String formDate;
  85.  
  86.  
  87. //surface area of the depth profile and avarege depth over time
  88. double depthArea = 0;
  89. double avgDepth = 0;
  90.  
  91.  
  92. //magnetic sensor variables
  93.   int x = 0;
  94.   int y = 0;
  95.   int z = 0;
  96.   int azimuth = 0;
  97.  
  98. //magnetic sensor array for avarage calculation, stores 10 values
  99.   const byte arraySize = 10;
  100.   double myX[arraySize];
  101.   double myY[arraySize];
  102.   double myZ[arraySize];
  103.   double myAzimuth[arraySize];
  104.   double avgX = 0;
  105.   double avgY = 0;
  106.   double avgZ = 0;
  107.   double avgAzimuth = 0;
  108.  
  109.  
  110. //the current address in the EEPROM where you write the number of starts of the device
  111. int addr = 0;
  112.  
  113. //number of device starts
  114. byte starts = 0;
  115.  
  116. //chip pin for the datalogger shield, generally 4,10 or SS
  117.   const byte chip = SS;
  118.  
  119. // logger button state definition
  120. int buttonState = LOW;        // the current reading  the input button
  121. int lastButtonState = LOW;   // the previous reading  the input button
  122.  
  123.  
  124. void setup(void) {
  125.  delay(1000);
  126.  
  127. // Open serial communications and wait for port to open:
  128.   Serial.begin(115200);
  129.   while (!Serial) ; // wait for serial port to connect. Needed for native USB port only
  130.   Serial.println(F("Serial port connected"));
  131.  
  132.  
  133.   WiFi.begin(ssid,password);
  134.   while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
  135.     delay(250); Serial.print('.');
  136.   }
  137.   Serial.println("\nConnected to "+WiFi.SSID()+" Use IP address: "+WiFi.localIP().toString()); // Report which SSID and IP is in use
  138.  
  139.   if (!SPIFFS.begin(true)) {
  140.     Serial.println("SPIFFS initialisation failed...");
  141.     SPIFFS_present = false;
  142.   }
  143.   else
  144.   {
  145.     Serial.println(F("SPIFFS initialised... file access enabled..."));
  146.     SPIFFS_present = true;
  147.   }
  148.  
  149.  
  150. // Join LCD display
  151.   u8g2.begin();
  152.   u8g2.setBusClock(500000);
  153.  
  154. //define pin modes
  155.  // pinMode(TMP36Pin, INPUT);
  156.   pinMode(buttonPin, INPUT);
  157.  
  158. //Join I2C bus
  159.    Wire.begin();
  160.    Serial.println(F("I2C bus connected"));
  161.  
  162.  
  163. //QMC 5853 magnetic sensor initialization
  164.     qmc.init();
  165.   //qmc.setMode(Mode_Continuous,ODR_200Hz,RNG_2G,OSR_256);
  166.     Serial.println(F("Magnetic sensor initialization..."));
  167.  
  168. //5837 pressure and temperature sensor initialization
  169.     while (!depthSensor.init()) {
  170.     depthSensor.setModel(MS5837::MS5837_30BA);
  171.     depthSensor.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)
  172.      }
  173.  
  174.  
  175. // read a byte  the current address of the EEPROM
  176.   EEPROM.begin(512);
  177.   starts = EEPROM.read(addr);
  178.   starts = starts +1;
  179.   EEPROM.write(addr, starts);
  180.   EEPROM.commit();
  181.   Serial.println(F("EEPROM data updated"));
  182.   Serial.println(starts);
  183.  
  184.  
  185. //SD card initialization
  186.     Serial.println("SD card initialization...");
  187.  if(!SD.begin()){
  188.         Serial.println("Card Mount Failed");
  189.         return;
  190.     }
  191.     uint8_t cardType = SD.cardType();
  192.  
  193.     if(cardType == CARD_NONE){
  194.         Serial.println("No SD card attached");
  195.         return;
  196.     }
  197.  
  198.     Serial.print("SD Card Type: ");
  199.     if(cardType == CARD_MMC){
  200.         Serial.println("MMC");
  201.     } else if(cardType == CARD_SD){
  202.         Serial.println("SDSC");
  203.     } else if(cardType == CARD_SDHC){
  204.         Serial.println("SDHC");
  205.     } else {
  206.         Serial.println("UNKNOWN");
  207.     }
  208.  
  209.     uint64_t cardSize = SD.cardSize() / (1024 * 1024);
  210.     Serial.printf("SD Card Size: %lluMB\n", cardSize);
  211.    
  212.  
  213.  
  214. //create log files on SD card
  215.     File dataFile = SD.open("/Log_" + String(starts) + ".csv", FILE_WRITE);
  216.     dataFile.println("Date,Time,Depth,Temperature,X,Y,Z,Azimuth,AVG");
  217.     Serial.println("Log_" + String(starts) + ".csv is created");
  218.     File customFile = SD.open("/Dlog_" + String(starts) + ".csv", FILE_WRITE);
  219.     customFile.println("Date,Time,Depth,Temperature,X,Y,Z,Azimuth,AVG");
  220.     Serial.println("Dlog_" + String(starts) + ".csv is created");
  221.  
  222. /*  
  223.   // Pre-load MMA
  224.   for (int x=0; x < averageCount; x++)
  225.   movingAverageSum = movingAverageSum + analogRead(TMP36Pin);
  226.   //Serial.print(movingAverageSum);
  227.   //Serial.println(" movingAverageSum ");
  228.  
  229. // Calculate inital average
  230.   movingAverage = movingAverageSum / averageCount;
  231.   //Serial.print(movingAverage);
  232.   //Serial.println(" movingAverage ");
  233.   //Serial.println("MMA preloaded");
  234. */
  235.  
  236. // Check if RTC is present
  237.   Serial.println("RTC initialization...");
  238.   if (! rtc.begin()) {
  239.     Serial.println("Couldn't find RTC");
  240.     while (1);
  241.   }
  242.  
  243.   if (!rtc.isrunning()) {
  244.     Serial.println("RTC is NOT running!");
  245.     // following line sets the RTC to the date & time this sketch was compiled
  246.     rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  247.     // This line sets the RTC with an explicit date & time, for example to set
  248.     // January 21, 2014 at 3am you would call:
  249.     //rtc.adjust(DateTime(2019, 2, 4, 21, 26, 30));
  250.   }
  251.  
  252.   //Serial.println (F("Date,Time,Temperature,X,Y,Z,Azimuth, AVG"));
  253.  
  254.  
  255.           // transfer internal memory to the display
  256.   //----------------------------------------------------------------------  
  257.   ///////////////////////////// Server Commands
  258.   server.on("/",         HomePage);
  259.   server.on("/download", File_Download);
  260.   server.on("/upload",   File_Upload);
  261.   server.on("/fupload",  HTTP_POST,[](){ server.send(200);}, handleFileUpload);
  262.   server.on("/stream",   File_Stream);
  263.   server.on("/delete",   File_Delete);
  264.   server.on("/dir",      SPIFFS_dir);
  265.  
  266.   ///////////////////////////// End of Request commands
  267.   server.begin();
  268.   Serial.println("HTTP server started");
  269.  
  270. //  delay(1000);
  271. }
  272.  
  273. void loop(void) {
  274.   DateTime now = rtc.now();
  275.   server.handleClient(); // Listen for client connections
  276.    
  277.   // make a string for assembling the data to log:
  278.   double dataDepth = 0;
  279.   double dataAVG = 0;
  280.    
  281.   int dataYear = 0;
  282.   int dataMonth = 0;
  283.   int dataDay = 0;
  284.   int dataHour = 0;
  285.   int dataMinute = 0;
  286.   int dataSecond = 0;
  287.   int dataTemp = 0;
  288.  
  289.   int dataX = 0;
  290.   int dataY = 0;
  291.   int dataZ = 0;
  292.   int dataAzimuth = 0;
  293.  
  294.    
  295. //getting the voltage reading  the temperature sensor and append to the string:
  296. //  int TMP36_Read = analogRead(TMP36Pin);
  297.  
  298. // read 5837 sensor data
  299.   depthSensor.read();
  300.  
  301. // read the state of the logger button into a local variable:
  302.   int reading = digitalRead(buttonPin);
  303.  
  304.  
  305. // If the switch changed, due to noise or pressing:
  306.   if (reading != lastButtonState) {
  307.     // reset the debouncing timer
  308.     lastDebounceTime = millis();
  309.   }
  310.  
  311. /*
  312. //Modified Moving Avarege method used to smooth sensor data
  313.  
  314. // each interation of loop, update moving average
  315. // Get a new sample
  316. // unsigned int currentValue = analogRead(analogPin);
  317.  
  318. // Remove previous movingAverage  the sum
  319.   movingAverageSum = movingAverageSum - movingAverage;
  320.  
  321. // Replace it with the current sample
  322.   movingAverageSum = movingAverageSum + TMP36_Read;
  323.  
  324. // Recalculate movingAverage
  325.   movingAverage = movingAverageSum / averageCount;
  326.   //Serial.print(movingAverage);
  327.   //Serial.println(" calculated movingAverage ");
  328.  
  329. // analogRead values go  0 to 1023, analogWrite values  0 to 255
  330. double voltage = movingAverage / 1023; // Gets you mV
  331.   //Serial.print(voltage);
  332.   //Serial.println(" voltage ");
  333.  
  334. // calculate the temperature
  335. double temperatureC = (voltage - 0.5) * 100 ;  //ing  10 mv per degree wit 500 mV offset to degrees ((voltage - 500mV) / 10)
  336. */
  337.  
  338. // check Drun state according to the current temperature
  339.   if (depthSensor.depth() < thresholdDepth){
  340.     DrunState = LOW;
  341.     startTime = millis()/1000;
  342.     }
  343.     else{
  344.       DrunState = HIGH;
  345.     }
  346.  
  347. //calculate Drun time
  348.     if (DrunState == HIGH) {
  349.         DrunTime = lastDrunTime + millis()/1000 - startTime;  
  350.     }else{
  351.       DrunTime;
  352.       lastDrunTime = DrunTime;
  353.     }
  354.  
  355.     DrunHour = DrunTime/3600;
  356.     DrunMinutes = (DrunTime - (DrunHour * 3600))/60;
  357.     DrunSecound = DrunTime - DrunHour * 3600 - DrunMinutes * 60;
  358.     formDrunTime = String(DrunHour) + ":" + String(DrunMinutes) + ":" + String(DrunSecound);
  359.  
  360. //calculate average temperature based on Druntime. tempArea is the are below the temperature  vs time function
  361.   if (millis() - previousdepthAreaMillis > printInterval){
  362.     if (depthSensor.depth() >= thresholdDepth){
  363.       depthArea = depthArea + depthSensor.depth() * (1000/printInterval);
  364.     }
  365.     else{
  366.       depthArea;
  367.     }
  368.  
  369.   if(depthArea>0){
  370.     avgDepth = depthArea/DrunTime;
  371.   }
  372.   else{
  373.     avgDepth = 0;
  374.   }
  375.  
  376.   /*Serial.print(DrunTime);
  377.   Serial.print(",");
  378.   Serial.print(temperatureC, 1);
  379.   Serial.print(",");
  380.   Serial.print(tempArea);
  381.   Serial.print(",");
  382.   Serial.println(avgTemp,1);*/
  383.    
  384. // reset the millis clock
  385.  previousdepthAreaMillis = millis();
  386. }
  387.  
  388.  
  389. //azimuth calculation  //is supporting float too
  390.   qmc.read(&x, &y, &z,&azimuth);  //azimuth = qmc.azimuth(&y,&x);//you can get custom azimuth
  391.  
  392.  
  393. //append temperature an ddepth data to the string:
  394.   dataDepth = depthSensor.depth(),1;
  395.   dataAVG = avgDepth,1;
  396.   dataTemp = depthSensor.temperature(),1;
  397.  
  398. //append date and time data to the string:
  399.   dataYear = now.year();
  400.   dataMonth = now.month();
  401.   dataDay = now.day();
  402.   dataHour = now.hour();
  403.   dataMinute = now.minute();
  404.   dataSecond = now.second();
  405.   formDate = (String(now.year()) + "." + String(now.month()) + "." + String(now.day()) + ".") ;
  406.    
  407. //append compass data to the string:
  408.   dataX = x;
  409.   dataY = y;
  410.   dataZ = z;
  411.   dataAzimuth = azimuth;
  412.  
  413.   // open the file. note that only one file can be open at a time,
  414.   // so you have to close this one before opening another.
  415.  
  416. //    SdFile::dateTimeCallback(dateTime);
  417.  
  418.  
  419.     currentAutoLogMillis = millis();
  420.  
  421. if (currentAutoLogMillis-previousAutoLogMillis >= printInterval){
  422.      // reset the timer
  423.     previousAutoLogMillis = millis();
  424.  
  425.     //open the log file for writing
  426.   //writeFile(SD, "/GenLog.csv", "Date,Time,X,Y,Z,Azimuth,Druntime,AVG\n");
  427.  
  428.     File dataFile = SD.open("/Log_" + String(starts) + ".csv", FILE_APPEND);
  429.  
  430.        
  431.   // if the file is opened write data into it:
  432.   if (dataFile){  
  433.    
  434.     dataFile.print(dataYear);
  435.     dataFile.print(".");
  436.     dataFile.print(dataMonth);
  437.     dataFile.print(".");    
  438.     dataFile.print(dataDay);
  439.     dataFile.print(",");
  440.     dataFile.print(dataHour);
  441.     dataFile.print(":");
  442.     dataFile.print(dataMinute);
  443.     dataFile.print(":");  
  444.     dataFile.print(dataSecond);
  445.     dataFile.print(",");  
  446.     dataFile.print(dataDepth);
  447.     dataFile.print(",");
  448.     dataFile.print(dataTemp);
  449.     dataFile.print(",");  
  450.     dataFile.print(dataX);
  451.     dataFile.print(",");  
  452.     dataFile.print(dataY);
  453.     dataFile.print(",");  
  454.     dataFile.print(dataZ);
  455.     dataFile.print(",");  
  456.     dataFile.print(dataAzimuth);
  457.     dataFile.print(",");
  458.     dataFile.print(DrunTime);
  459.     dataFile.print(",");
  460.     dataFile.println(dataAVG);
  461.  
  462. // close log file
  463.     dataFile.close();
  464.    
  465. // print to the serial port too:
  466.    Serial.print("Date: ");
  467.    Serial.print(dataYear);
  468.    Serial.print(F("."));
  469. //   print2digits(dataMonth);
  470.    Serial.print(dataMonth);
  471.    Serial.print(F("."));
  472. //   print2digits(dataDay);
  473.    Serial.print(dataDay);
  474.    Serial.print(F("."));
  475.    Serial.print(" Time: ");  
  476.  //  print2digits(dataHour);
  477.    Serial.print(dataHour);
  478.    Serial.print(F(":"));
  479.  //  print2digits(dataMinute);
  480.    Serial.print(dataMinute);
  481.    Serial.print(F(":"));  
  482.   // print2digits(dataSecond);
  483.    Serial.print(dataSecond);
  484.    Serial.print(F(","));
  485.    Serial.print(" Depth: ");
  486.    Serial.print(dataDepth,1);
  487.    Serial.print(F(","));
  488.  
  489.    Serial.print(" Temperature: ");
  490.    Serial.print(dataTemp,1);
  491.    Serial.print(F(","));
  492.    
  493.    Serial.print(" xyz: ");  
  494.    Serial.print(dataX);
  495.    Serial.print(F(","));    
  496.    Serial.print(dataY);
  497.    Serial.print(F(","));    
  498.    Serial.print(dataZ);
  499.    Serial.print(F(","));
  500.    Serial.print(" Azimuth: ");    
  501.    Serial.print(dataAzimuth);
  502.    Serial.print(" Druntime: ");
  503.   // print2digits(DrunHour);
  504.    Serial.print(DrunHour);
  505.    Serial.print("h ");
  506.   // print2digits(DrunMinutes);
  507.    Serial.print(DrunMinutes);
  508.    Serial.print("m ");
  509.   // print2digits(DrunSecound);
  510.    Serial.print(DrunSecound);  
  511.    Serial.print("sec " );
  512.    Serial.print(" AVG: ");
  513.    Serial.print(dataAVG,1);
  514.    Serial.println(F(","));
  515.    
  516.   /* Serial.print("Pressure: ");
  517.    Serial.print(depthSensor.pressure());
  518.    Serial.println(" mbar");
  519.    Serial.print("Temperature: ");
  520.    Serial.print(depthSensor.temperature());
  521.    Serial.println(" deg C");
  522.    Serial.print("Depth: ");
  523.    Serial.print(depthSensor.depth());
  524.    Serial.println(" m");*/
  525.   }
  526.   // if the file isn't open, pop up an error:
  527.   else {
  528.     Serial.println(F("error opening General log file"));
  529.   }
  530.  
  531.  
  532.  
  533. // whatever the reading is at, it's been there for longer than the debounce delay, so take it as the actual current state:
  534.  if (millis() - lastDebounceTime > debounceDelay) {
  535.  
  536.   // if the button state has changed:
  537.     if (reading != buttonState) {
  538.       buttonState = reading;
  539.            
  540.     // only toggle the LED if the new button state is HIGH
  541.       if (buttonState == HIGH) {
  542.  
  543.  
  544.     Serial.println(F("Custom log data: "));
  545.    
  546.      for (int i=0; i <= arraySize-1; i++){
  547.             myX[i] = x;
  548.      Serial.print(myX[i]);
  549.      Serial.print(F(" "));
  550.       }
  551.      Serial.println(F(""));
  552.        
  553.       for (int i=0; i <= arraySize-1; i++){
  554.             myY[i] = y;
  555.      Serial.print(myY[i]);
  556.      Serial.print(F(" "));
  557.       }
  558.      Serial.println(F(""));
  559.  
  560.       for (int i=0; i <= arraySize-1; i++){
  561.             myZ[i] = z;
  562.      Serial.print(myZ[i]);
  563.      Serial.print(F(" "));
  564.       }
  565.      Serial.println(F(""));
  566.      
  567.       for (int i=0; i <= arraySize-1; i++){
  568.             myAzimuth[i] = azimuth;
  569.      Serial.print(myAzimuth[i]);
  570.      Serial.print(F(" "));
  571.       }
  572.      Serial.println(F(""));
  573.  
  574.        
  575.         avgX = 0;
  576.         avgY = 0;
  577.         avgZ = 0;
  578.         avgAzimuth = 0;
  579.         for (int i=0; i <= arraySize-1; i++){
  580.             avgX = avgX + myX[i];
  581.             avgY = avgY + myY[i];
  582.             avgZ = avgZ + myZ[i];
  583.             avgAzimuth = avgAzimuth + myAzimuth[i];
  584.       }
  585.  
  586.         Serial.println(F("Avarage values: "));
  587.         avgX = avgX/arraySize;
  588.         avgY = avgY/arraySize;
  589.         avgZ = avgZ/arraySize;
  590.         avgAzimuth = avgAzimuth/arraySize;
  591.        
  592.         Serial.print(F("Avarage X value: "));
  593.         Serial.println(avgX);
  594.         Serial.print(F("Avarage Y value: "));
  595.         Serial.println(avgY);
  596.         Serial.print(F("Avarage Z value: "));
  597.         Serial.println(avgZ);
  598.         Serial.print(F("Avarage Azimuth value: "));
  599.         Serial.println(avgAzimuth);
  600.        
  601.     //open the log file for writing
  602.         File customFile = SD.open("/Dlog_" + String(starts) + ".csv", FILE_APPEND);
  603.        
  604.      // if the file is opened write data into it:    
  605.              
  606.         customFile.print(dataYear);
  607.         customFile.print(".");
  608.         customFile.print(dataMonth);
  609.         customFile.print(".");    
  610.         customFile.print(dataDay);
  611.         customFile.print(",");
  612.         customFile.print(dataHour);
  613.         customFile.print(":");
  614.         customFile.print(dataMinute);
  615.         customFile.print(":");  
  616.         customFile.print(dataSecond);
  617.         customFile.print(",");  
  618.         customFile.print(dataDepth);
  619.         customFile.print(",");
  620.         customFile.print(dataTemp);
  621.         customFile.print(",");  
  622.         customFile.print(dataX);
  623.         customFile.print(",");  
  624.         customFile.print(dataY);
  625.         customFile.print(",");  
  626.         customFile.print(dataZ);
  627.         customFile.print(",");  
  628.         customFile.println(dataAzimuth);
  629.         customFile.print(",");  
  630.         customFile.println(DrunTime);
  631.         customFile.print(",");  
  632.         customFile.println(dataAVG);        
  633.    
  634.        
  635.  // close log file  
  636.         customFile.close();
  637.         Serial.println(F("Custom log written"));
  638.  
  639.     }
  640.   }
  641.  }
  642.  
  643. // save the reading. Next time through the loop, it'll be the lastButtonState
  644.  lastButtonState = reading;  
  645.  
  646. }
  647.  
  648. // Define UI
  649.   u8g2.clearBuffer();         // clear the internal memory
  650.  
  651.   //Draw UI frames
  652.   /*u8g2.drawRFrame(0,0,41,24,3);
  653.   u8g2.drawRFrame(43,0,42,24,3);
  654.   u8g2.drawRFrame(87,0,41,24,3);
  655.   u8g2.drawRFrame(0,26,41,24,3);
  656.   u8g2.drawRFrame(43,26,42,24,3);
  657.   u8g2.drawRFrame(87,26,41,24,3);
  658.   u8g2.drawRFrame(0,52,85,12,3); */
  659.   u8g2.drawCircle(106, 42, 20, U8G2_DRAW_ALL);
  660.   u8g2.drawLine(106, 42, (106+17*sin(2*PI-dataAzimuth*PI/180)), (42-17*cos(2*PI-dataAzimuth*PI/180)));
  661.   /*Serial.print("x   ");
  662.   Serial.println(15*sin(dataAzimuth*2*PI/360));
  663.   Serial.print("y   ");
  664.   Serial.println(15*cos(dataAzimuth*2*PI/360));*/
  665.  
  666.   //Set menu font style and data
  667.   u8g2.setFont(u8g2_font_micro_tr); // choose a suitable font
  668.   u8g2.drawStr(5,7,"Druntime");
  669.   u8g2.drawStr(46,7,"Depth / m");
  670.   u8g2.drawStr(94,7,"Azimuth");
  671.   u8g2.drawStr(0,33,"Temperature");
  672.   u8g2.drawStr(57,33,"AVG");
  673.  
  674.          
  675.   u8g2.setFont( u8g2_font_5x7_tr); // choose a suitable font  
  676.   u8g2.setCursor(5,18);
  677.   u8g2.print(formDrunTime);
  678.   u8g2.setCursor(56,18);
  679.   u8g2.print(depthSensor.depth(),1);
  680.   u8g2.setCursor(100,18);
  681.   u8g2.print(dataAzimuth);
  682.   u8g2.setCursor(15,44);
  683.   u8g2.print(depthSensor.temperature(),0);
  684.   u8g2.setCursor(54,44);  
  685.   u8g2.print(dataAVG,1);
  686.   u8g2.setCursor(2,62);
  687.   u8g2.print(formDate);
  688.   u8g2.setCursor(58,62);
  689.   u8g2.print("Log");
  690.   u8g2.setCursor(76,62);
  691.   u8g2.print(starts);
  692.   u8g2.sendBuffer();
  693.  
  694. }
  695.  
  696.  
  697.  
  698. /* Additional functions */
  699. /**************************************/
  700.  
  701. void print2digits(int number) {
  702.   if (number >= 0 && number < 10) {
  703.     Serial.write('0');
  704.   }
  705.     Serial.print(number);
  706. }
  707.  
  708.  
  709. /*
  710. void dateTime(uint16_t* date, uint16_t* time) {
  711.     DateTime now = rtc.now();
  712.   // return date using FAT_DATE macro to format fields
  713.   *date = FAT_DATE(now.year(), now.month(), now.day());
  714.  
  715.   // return time using FAT_TIME macro to format fields
  716.   *time = FAT_TIME(now.hour(), now.minute(), now.second());
  717. }
  718. */
  719.  
  720. // All supporting functions  here...
  721. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  722. void HomePage(){
  723.   SendHTML_Header();
  724.   webpage += F("<a href='/download'><button>Download</button></a>");
  725.   webpage += F("<a href='/upload'><button>Upload</button></a>");
  726.   //webpage += F("<a href='/stream'><button>Stream</button></a>");
  727.   webpage += F("<a href='/delete'><button>Delete</button></a>");
  728.   webpage += F("<a href='/dir'><button>Directory</button></a>");
  729.   append_page_footer();
  730.   SendHTML_Content();
  731.   SendHTML_Stop(); // Stop is needed because no content length was sent
  732. }
  733. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  734. void File_Download(){ // This gets called twice, the first pass s the input, the second pass then processes the command line arguments
  735.   if (server.args() > 0 ) { // Arguments were received
  736.     if (server.hasArg("download")) DownloadFile(server.arg(0));
  737.   }
  738.   else Input("Enter filename to download","download","download");
  739. }
  740. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  741. void DownloadFile(String filename){
  742.   if (SPIFFS_present) {
  743.     File download = SPIFFS.open("/"+filename,  "r");
  744.     if (download) {
  745.       server.sendHeader("Content-Type", "text/text");
  746.       server.sendHeader("Content-Disposition", "attachment; filename="+filename);
  747.       server.sendHeader("Connection", "close");
  748.       server.streamFile(download, "application/octet-stream");
  749.       download.close();
  750.     } else ReportFileNotPresent("download");
  751.   } else ReportSPIFFSNotPresent();
  752. }
  753. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  754. void File_Upload(){
  755.   append_page_header();
  756.   webpage += F("<h3> File to Upload</h3>");
  757.   webpage += F("<FORM action='/fupload' method='post' enctype='multipart/form-data'>");
  758.   webpage += F("<input class='buttons' style='width:40%' type='file' name='fupload' id = 'fupload' value=''><br>");
  759.   webpage += F("<br><button class='buttons' style='width:10%' type='submit'>Upload File</button><br>");
  760.   webpage += F("<a href='/'>[Back]</a><br><br>");
  761.   append_page_footer();
  762.   server.send(200, "text/html",webpage);
  763. }
  764. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  765. File UploadFile;
  766. void handleFileUpload(){ // upload a new file to the Filing system
  767.   HTTPUpload& uploadfile = server.upload(); // See https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266Web...r/srcv
  768.                                             // For further information on 'status' structure, there are other reasons such as a failed transfer that could be used
  769.   if(uploadfile.status == UPLOAD_FILE_START)
  770.   {
  771.     String filename = uploadfile.filename;
  772.     if(!filename.startsWith("/")) filename = "/"+filename;
  773.     Serial.print("Upload File Name: "); Serial.println(filename);
  774.     SPIFFS.remove(filename);                  // Remove a previous version, otherwise data is appended the file again
  775.     UploadFile = SPIFFS.open(filename, "w");  // Open the file for writing in SPIFFS (create it, if doesn't exist)
  776.   }
  777.   else if (uploadfile.status == UPLOAD_FILE_WRITE)
  778.   {
  779.     if(UploadFile) UploadFile.write(uploadfile.buf, uploadfile.currentSize); // Write the received bytes to the file
  780.   }
  781.   else if (uploadfile.status == UPLOAD_FILE_END)
  782.   {
  783.     if(UploadFile)          // If the file was successfully created
  784.     {                                    
  785.       UploadFile.close();   // Close the file again
  786.       Serial.print("Upload Size: "); Serial.println(uploadfile.totalSize);
  787.       webpage = "";
  788.       append_page_header();
  789.       webpage += F("<h3>File was successfully uploaded</h3>");
  790.       webpage += F("<h2>Uploaded File Name: "); webpage += uploadfile.filename+"</h2>";
  791.       webpage += F("<h2>File Size: "); webpage += file_size(uploadfile.totalSize) + "</h2><br>";
  792.       append_page_footer();
  793.       server.send(200,"text/html",webpage);
  794.     }
  795.     else
  796.     {
  797.       ReportCouldNotCreateFile("upload");
  798.     }
  799.   }
  800. }
  801. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  802. #ifdef ESP32
  803. void SPIFFS_dir(){
  804.   if (SPIFFS_present) {
  805.     File root = SPIFFS.open("/");
  806.     if (root) {
  807.       root.rewindDirectory();
  808.       SendHTML_Header();
  809.       //webpage += F("<h3 class='rcorners_m'>SD Card Contents</h3><br>");
  810.       webpage += F("<table align='center'>");
  811.       webpage += F("<tr><th>Name/Type</th><th style='width:20%'>Type File/Dir</th><th>File Size</th></tr>");
  812.       webpage += F("<a href='/'>[Back]</a><br><br>");
  813.       printDirectory("/",0);
  814.       webpage += F("</table>");
  815.       SendHTML_Content();
  816.       root.close();
  817.     }
  818.     else
  819.     {
  820.       SendHTML_Header();
  821.       webpage += F("<h3>No Files Found</h3>");
  822.     }
  823.     append_page_footer();
  824.     SendHTML_Content();
  825.     SendHTML_Stop();   // Stop is needed because no content length was sent
  826.   } else ReportSPIFFSNotPresent();
  827. }
  828. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  829. void printDirectory(const char * dirname, uint8_t levels){
  830.   File root = SPIFFS.open(dirname);
  831.   if(!root){
  832.     return;
  833.   }
  834.   if(!root.isDirectory()){
  835.     return;
  836.   }
  837.   File file = root.openNextFile();
  838.   while(file){
  839.     if (webpage.length() > 1000) {
  840.       SendHTML_Content();
  841.     }
  842.     if(file.isDirectory()){
  843.       webpage += "<tr><td>"+String(file.isDirectory()?"Dir":"File")+"</td><td>"+String(file.name())+"</td><td></td></tr>";
  844.       printDirectory(file.name(), levels-1);
  845.     }
  846.     else
  847.     {
  848.       webpage += "<tr><td>"+String(file.name())+"</td>";
  849.       webpage += "<td>"+String(file.isDirectory()?"Dir":"File")+"</td>";
  850.       int bytes = file.size();
  851.       String fsize = "";
  852.       if (bytes < 1024)                     fsize = String(bytes)+" B";
  853.       else if(bytes < (1024 * 1024))        fsize = String(bytes/1024.0,3)+" KB";
  854.       else if(bytes < (1024 * 1024 * 1024)) fsize = String(bytes/1024.0/1024.0,3)+" MB";
  855.       else                                  fsize = String(bytes/1024.0/1024.0/1024.0,3)+" GB";
  856.       webpage += "<td>"+fsize+"</td></tr>";
  857.     }
  858.     file = root.openNextFile();
  859.   }
  860.   file.close();
  861. }
  862. #endif
  863. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  864. #ifdef ESP8266
  865. void SPIFFS_dir(){
  866.   String str;
  867.   if (SPIFFS_present) {
  868.     Dir dir = SPIFFS.openDir("/");
  869.     SendHTML_Header();
  870.     webpage += F("<h3 class='rcorners_m'>SPIFFS Card Contents</h3><br>");
  871.     webpage += F("<table align='center'>");
  872.     webpage += F("<tr><th>Name/Type</th><th style='width:40%'>File Size</th></tr>");
  873.     while (dir.next()) {
  874.       Serial.print(dir.fileName());
  875.       webpage += "<tr><td>"+String(dir.fileName())+"</td>";
  876.       str  = dir.fileName();
  877.       str += " / ";
  878.       if(dir.fileSize()) {
  879.         File f = dir.openFile("r");
  880.         Serial.println(f.size());
  881.         int bytes = f.size();
  882.         String fsize = "";
  883.         if (bytes < 1024)                     fsize = String(bytes)+" B";
  884.         else if(bytes < (1024 * 1024))        fsize = String(bytes/1024.0,3)+" KB";
  885.         else if(bytes < (1024 * 1024 * 1024)) fsize = String(bytes/1024.0/1024.0,3)+" MB";
  886.         else                                  fsize = String(bytes/1024.0/1024.0/1024.0,3)+" GB";
  887.         webpage += "<td>"+fsize+"</td></tr>";
  888.         f.close();
  889.       }
  890.       str += String(dir.fileSize());
  891.       str += "\r\n";
  892.       Serial.println(str);
  893.     }
  894.     webpage += F("</table>");
  895.     SendHTML_Content();
  896.     append_page_footer();
  897.     SendHTML_Content();
  898.     SendHTML_Stop();   // Stop is needed because no content length was sent
  899.   } else ReportSPIFFSNotPresent();
  900. }
  901. #endif
  902. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  903. void File_Stream(){
  904.   if (server.args() > 0 ) { // Arguments were received
  905.     if (server.hasArg("stream")) SPIFFS_file_stream(server.arg(0));
  906.   }
  907.   else Input("Enter a File to Stream","stream","stream");
  908. }
  909. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  910. void SPIFFS_file_stream(String filename) {
  911.   if (SPIFFS_present) {
  912.     File dataFile = SPIFFS.open("/"+filename,  "r"); // Now read data  SPIFFS Card
  913.     if (dataFile) {
  914.       if (dataFile.available()) { // If data is available and present
  915.         String dataType = "application/octet-stream";
  916.         if (server.streamFile(dataFile, dataType) != dataFile.size()) {Serial.print(F("Sent less data than expected!")); }
  917.       }
  918.       dataFile.close(); // close the file:
  919.     } else ReportFileNotPresent("Cstream");
  920.   } else ReportSPIFFSNotPresent();
  921. }  
  922. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  923. void File_Delete(){
  924.   if (server.args() > 0 ) { // Arguments were received
  925.     if (server.hasArg("delete")) SPIFFS_file_delete(server.arg(0));
  926.   }
  927.   else Input(" a File to Delete","delete","delete");
  928. }
  929. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  930. void SPIFFS_file_delete(String filename) { // Delete the file
  931.   if (SPIFFS_present) {
  932.     SendHTML_Header();
  933.     File dataFile = SPIFFS.open("/"+filename, "r"); // Now read data  SPIFFS Card
  934.     if (dataFile)
  935.     {
  936.       if (SPIFFS.remove("/"+filename)) {
  937.         Serial.println(F("File deleted successfully"));
  938.         webpage += "<h3>File '"+filename+"' has been erased</h3>";
  939.         webpage += F("<a href='/delete'>[Back]</a><br><br>");
  940.       }
  941.       else
  942.       {
  943.         webpage += F("<h3>File was not deleted - error</h3>");
  944.         webpage += F("<a href='delete'>[Back]</a><br><br>");
  945.       }
  946.     } else ReportFileNotPresent("delete");
  947.     append_page_footer();
  948.     SendHTML_Content();
  949.     SendHTML_Stop();
  950.   } else ReportSPIFFSNotPresent();
  951. }
  952. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  953. void SendHTML_Header(){
  954.   server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
  955.   server.sendHeader("Pragma", "no-cache");
  956.   server.sendHeader("Expires", "-1");
  957.   server.setContentLength(CONTENT_LENGTH_UNKNOWN);
  958.   server.send(200, "text/html", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
  959.   append_page_header();
  960.   server.sendContent(webpage);
  961.   webpage = "";
  962. }
  963. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  964. void SendHTML_Content(){
  965.   server.sendContent(webpage);
  966.   webpage = "";
  967. }
  968. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  969. void SendHTML_Stop(){
  970.   server.sendContent("");
  971.   server.client().stop(); // Stop is needed because no content length was sent
  972. }
  973. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  974. void Input(String heading1, String command, String arg_calling_name){
  975.   SendHTML_Header();
  976.   webpage += F("<h3>"); webpage += heading1 + "</h3>";
  977.   webpage += F("<FORM action='/"); webpage += command + "' method='post'>"; // Must match the calling argument e.g. '/chart' calls '/chart' after ion but with arguments!
  978.   webpage += F("<input type='text' name='"); webpage += arg_calling_name; webpage += F("' value=''><br>");
  979.   webpage += F("<type='submit' name='"); webpage += arg_calling_name; webpage += F("' value=''><br><br>");
  980.   webpage += F("<a href='/'>[Back]</a><br><br>");
  981.   append_page_footer();
  982.   SendHTML_Content();
  983.   SendHTML_Stop();
  984. }
  985. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  986. void ReportSPIFFSNotPresent(){
  987.   SendHTML_Header();
  988.   webpage += F("<h3>No SPIFFS Card present</h3>");
  989.   webpage += F("<a href='/'>[Back]</a><br><br>");
  990.   append_page_footer();
  991.   SendHTML_Content();
  992.   SendHTML_Stop();
  993. }
  994. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  995. void ReportFileNotPresent(String target){
  996.   SendHTML_Header();
  997.   webpage += F("<h3>File does not exist</h3>");
  998.   webpage += F("<a href='/"); webpage += target + "'>[Back]</a><br><br>";
  999.   append_page_footer();
  1000.   SendHTML_Content();
  1001.   SendHTML_Stop();
  1002. }
  1003. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1004. void ReportCouldNotCreateFile(String target){
  1005.   SendHTML_Header();
  1006.   webpage += F("<h3>Could Not Create Uploaded File (write-protected?)</h3>");
  1007.   webpage += F("<a href='/"); webpage += target + "'>[Back]</a><br><br>";
  1008.   append_page_footer();
  1009.   SendHTML_Content();
  1010.   SendHTML_Stop();
  1011. }
  1012. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1013. String file_size(int bytes){
  1014.   String fsize = "";
  1015.   if (bytes < 1024)                 fsize = String(bytes)+" B";
  1016.   else if(bytes < (1024*1024))      fsize = String(bytes/1024.0,3)+" KB";
  1017.   else if(bytes < (1024*1024*1024)) fsize = String(bytes/1024.0/1024.0,3)+" MB";
  1018.   else                              fsize = String(bytes/1024.0/1024.0/1024.0,3)+" GB";
  1019.   return fsize;
  1020. }
(#) tbarath válasza gabilow hozzászólására (») Feb 15, 2019 /
 
Az a round() fv honnan van?
(#) gabilow válasza tbarath hozzászólására (») Feb 15, 2019 /
 
Bővebben: Link
Itt az egész program,köszi.
A hozzászólás módosítva: Feb 15, 2019
(#) KoblogPerGyok válasza sitto hozzászólására (») Feb 15, 2019 /
 
Definiáld a setup-ban.

Valamint include string.h ha már használni szeretnéd. Ezt a string-libet meg kell nézned, hogy a gépeden van-e. Ha nem töltsd le.
A hozzászólás módosítva: Feb 15, 2019
(#) sitto válasza KoblogPerGyok hozzászólására (») Feb 15, 2019 /
 
Nem segít. Ugyan az a hibaüzenet.
  1. void setup(void) {
  2.  
  3.  String  webpage = "";
A hozzászólás módosítva: Feb 15, 2019
(#) KoblogPerGyok válasza sitto hozzászólására (») Feb 15, 2019 /
 
Rájöttem, nézd meg a string library-t hogyan kell berántani.
A hozzászólás módosítva: Feb 15, 2019
(#) sitto válasza KoblogPerGyok hozzászólására (») Feb 15, 2019 /
 
Ezt kifejtenéd egy kicsit?
Csak most kezdtem programozzásal foglalkozni.
(#) tbarath válasza gabilow hozzászólására (») Feb 15, 2019 /
 
Hát ezzel se vagyok sokkal előrébb, de legalább annyi kiderült, hogy esp és nem arduino.
Na mindegy is, próbáld meg cast-olni, valahogy így:
  1. long epoch = (long) round(curEpoch + 3600 * (utcOffset+summerTime) + 86400L) % 86400L;
(#) Norbi779 hozzászólása Feb 15, 2019 /
 
Sziasztok. Lenne egy NodeMCU amelyre relé van kötve. Relé és minden más is külső tápról kapja a feszültséget, a NodeMCU is a VIN lábra. Probléma az, hogy ha bekapcsolom, NodeMCU-n fel villan 1x egy dióda és megáll, nem megy tovább. Ha reléről lehúzom VCC kábelét, és utána kapcsolom be a tápot, akkor elindul az NodeMCU, majd ha ezután vissza szúrom a VCC -re a kábelt, tökéletesen működik. Miért csinálja ezt, és hogyan lehetne orvosolni?
Következő: »»   511 / 854
Bejelentkezés

Belépés

Hirdetés
XDT.hu
Az oldalon sütiket használunk a helyes működéshez. Bővebb információt az adatvédelmi szabályzatban olvashatsz. Megértettem