Nano 33 IOT Error after sending repeating packages using WiFiWebServer library

Hey,

I am using the Nano-33-IOT. I am currently trying to send live data to a website hosted by the arduino. I am using the WiFiNINA_Generic and WiFiWebServer library.
I am plotting the data with a SVG using ajax to update the data.

However after around 30-60 seconds it stops plotting and the arduino is stuck after calling this function, the Serial.print is not called.

void WiFiWebServer::send(int code, const char* content_type, const String& content) 
{
  Serial.print("WiFiWebServer send has been called");
  String header;
  
  // Can we asume the following?
  //if(code == 200 && content.length() == 0 && _contentLength == CONTENT_LENGTH_NOT_SET)
  //  _contentLength = CONTENT_LENGTH_UNKNOWN;

  WS_LOGDEBUG1(F("send1: len = "), content.length());
  WS_LOGDEBUG1(F("content = "), content);

  _prepareHeader(header, code, content_type, content.length());
  _currentClient.write((const uint8_t *)header.c_str(), header.length());
  if (content.length())
  {
    WS_LOGDEBUG1(F("send1: write header = "), header);
    //sendContent(content);
    sendContent(content, content.length());
  }
}

I thought it may be connected to this problem since half of the time the arduino sends about a dozen incomplete packages before getting stuck. However it seems to be fixed with the firmware update so i am not sure.

Remove packet parsing from availDataTcp() function to avoid packets corruption by giulcioffi · Pull Request #49 · arduino/nina-fw · GitHub

I have tried to slow down the data being sent to one data package per second but the error still occurred. If someone has a similar problem or knows the answer feel free to respond.

Thanks for reading.

Corrupted Package:

Link to library:
https://github.com/khoih-prog/WiFiWebServer

Welcome to the forum.

Can you post a complete sketch that shows the issue, so I can run it on my board?

Hey,

Thanks for the welcome :grinning:.

Yeah of course. Sorry i didn't clean up an leftover code and i didn't care about readability too much. I just analog read a pin with nothing attached to it, since i just care about the data being sent succesfully.

I will also send a picture where you need to go on the website to start it.







#include "defines.h"
#include "arduino_secrets.h"


#define TIMER_INTERRUPT_DEBUG         0
#define _TIMERINTERRUPT_LOGLEVEL_     0

#include "SAMDTimerInterrupt.h"


SAMDTimer ITimer(TIMER_TC3);

// WLAN DATEN
  char ssid[] = SECRET_SSID;        
  char pass[] = SECRET_PASS;    
  int keyIndex = 0;      // nur für WEP            
  int status= WL_IDLE_STATUS;




// Variablen zum erzeugen zufaeliiger Werte  
  int messungaktiv=0;
  int svg_zaehler = 0;
  int svg_interrupt_zaehler = 0;
  unsigned long i=0; 
  unsigned long k=0;
  unsigned long w=0;
  unsigned long h=0;
  unsigned long d=0;
  unsigned int x = 0;
  unsigned long n=0;
  unsigned long m=0;
  unsigned long  data[110];
  unsigned long  zeit[110];
  unsigned long messung[110];
  
// Interrrupt Varaiblen  
  volatile  int  data_i[1200];
  volatile  int  zeit_i[1200];
  volatile  int  analog_overhead=0;
  volatile  int  ajax_refresh_length=0;
  volatile long o=0; //davor = o=1;
  volatile long u=0;
  volatile int z=0;
  volatile long z_k=0;
  volatile long y=1;
  volatile long a=0;
  volatile long zaehler=0;
  volatile long dimension=0;
  char XML_Buffer[50];
  char XML_Content[1500];//2200 // 1500 ^=SVG Number 45
  volatile int website_zaehler = 0;
  volatile int messung_zaehler = 0;
  volatile int messung_zaehler_init = 0;

  


// Ajax Varaiblen
  int Position = 0;
  int Auffrischungslaenge = 0;
  volatile int Index = 1;
  volatile int SVG_durchgaenge = 0;
  int xml_zaehler=0;
  int zeit_xml;
  int data_xml;
  int start_button=1;
 
  long size_zeit = 0;
  unsigned long size_data = 0;
  
  char SendeBuffer[00];//800
  char sender_graph[2250];//2800 //2250 ^=SVG Number 45

  const char ekg_img[] PROGMEM = {"Ides"};

   //200
  const char Javascript_3[] PROGMEM = {"setInterval(function()\n    {\n      getGraph();\n    }, 200);\n   function getGraph()\n    \n\t{\n   if(document.getElementById(\"checkbox\").checked==1) {  var GraphvalHttpRequest = new XMLHttpRequest();\n      GraphvalHttpRequest.onreadystatechange = function()\n      {\n        if(this.readyState == 4 && this.status == 200)\n {     \n  var GraphvalRequest=this.responseXML;\n  var i;\n  var zeile = GraphvalRequest.getElementsByTagName(\"Z\");\n  var index = GraphvalRequest.getElementsByTagName(\"I\")[0].childNodes[0].nodeValue;\n  var Position = GraphvalRequest.getElementsByTagName(\"P\")[0].childNodes[0].nodeValue;\n  var svg = document.getElementById(\"svg_frame\"); \n  var current_svg_id= \"svg_graph_\" + index;\n  var current_svg = svg.contentDocument.getElementById(current_svg_id).contentDocument; \n  for (i = 0; i<zeile.length-2; i++){ var linie_graph = +Position + +i;\n var momentane_linie=current_svg.getElementById(linie_graph);\n var linie_element = current_svg.createElementNS('http://www.w3.org/2000/svg', 'line'); linie_element.setAttribute(\"id\" ,linie_graph);\n linie_element.setAttribute(\"x1\" ,zeile[i].getElementsByTagName(\"z\")[0].childNodes[0].nodeValue);linie_element.setAttribute(\"y1\",zeile[i].getElementsByTagName(\"d\")[0].childNodes[0].nodeValue);\n linie_element.setAttribute(\"x2\",zeile[i+1].getElementsByTagName(\"z\")[0].childNodes[0].nodeValue);linie_element.setAttribute(\"y2\",zeile[i+1].getElementsByTagName(\"d\")[0].childNodes[0].nodeValue);  \n var parent = current_svg.getElementsByTagName(\"g\")[0]; parent.replaceChild(linie_element,momentane_linie); console.log(current_svg);\n }}};\n GraphvalHttpRequest.open(\"GET\", \"XML_Content.xml\", true);\n  GraphvalHttpRequest.send();\n }} "};

  //const char index_html[] PROGMEM = {"<!DOCTYPE html><html><head></head><body><h1>Test</h1><p>\"100 mal nachladen wenn es klappt->large html/package porblem\"</p></body></html>"};
  const char index_html[] PROGMEM = {"<!DOCTYPE html>\n<html>\n\n<head>\n    <title>EKG</title>\n    <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n</head>\n\n<body>\n    <header>\n        \n        <h1>Kabelloses EKG</h1>\n    </header>\n\n<section>\n    <nav>\n\t\t<div class=\"Auswahlmenue\">\n\t<span class=\"Auswahloben\"><a class=\"active\" href=\"index.html\">Homepage</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Aktuelle_Messung.html\">Daten aktuelle Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Alte_Messung.html\">Auswahl alter Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"App.html\">Alles zur App</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Sonstiges.html\">Sonstiges</a></span>\t\t\n\t</div> \n    </nav>\n</section>   \n\t\t\n<section>\n\n\t<p> Tabelle 1:</p>\n\t<table class=\"Messung\" border=\"10\" cellpadding=\"5\" cellspacing=\"0\"> \n        <tr>\n            <th>Season</th>\n            <th>Month</th>\n            <th>Rent</th>\n            <th colspan=\"2\">Utilities</th>\n            <th>Groceries</th>\n            <th>Eating Out</th>\n            <th>Entertainment</th>\n        </tr>\n        <tr>\n            <td rowspan=\"3\">Fall</td>\n            <td>June</td>\n            <td>€1300</td>\n            <td>€100</td>\n            <td>€50</td>\n            <td>350€</td>\n            <td>100€</td>\n            <td>€50</td>\n\n        </tr>\n\n        <tr>\n            <td>July</td>\n            <td>€1300</td>\n            <td>€100</td>\n            <td>€50</td>\n            <td>350€</td>\n            <td>100€</td>\n            <td>€50</td>\n\n        </tr>\n\n        <tr>\n            <td>August</td>\n            <td>€1300</td>\n            <td>€100</td>\n            <td>€50</td>\n            <td>350€</td>\n            <td>100€</td>\n            <td>€50</td>\n\n        </tr>\n    </table>\n    </section>\n\n</body>\n\n</html>"};    
  const char Alte_Messung_html[] PROGMEM = {"<!DOCTYPE html>\n<html>\n\n<head>\n    <title>EKG</title>\n    <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n</head>\n\n<body>\n    <header>\n        \n        <h1>Kabelloses EKG</h1>\n    </header>\n\n    <nav>\n\n<section>\n    <nav>\n\t\t<div class=\"Auswahlmenue\">\n\t<span class=\"Auswahloben\"><a  href=\"index.html\">Homepage</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Aktuelle_Messung.html\">Daten aktuelle Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a class=\"active\" href=\"Alte_Messung.html\">Auswahl alter Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"App.html\">Alles zur App</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Sonstiges.html\">Sonstiges</a></span>\t\t\n\t</div> \n    </nav>\n</section>  \n<section>\n<div id=\"body\" </div> <img src=\"img_ekg_theme.jpg\" alt=\"EKG_Project_Theme\" <p>EKG App</p> </body></html>"};
  const char Aktuelle_Messung_html[] PROGMEM = {"<!DOCTYPE html>\n<html>\n\n<head>\n    <title>EKG</title>\n    <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n</head>\n\n<body>\n\n    <header>\n        \n        <h1>Kabelloses EKG</h1>\n    </header>\n\n<section>\n    <nav>\n\t\t<div class=\"Auswahlmenue\">\n\t<span class=\"Auswahloben\"><a href=\"index.html\">Homepage</a></span>\t\n\t<span class=\"Auswahloben\"><a class=\"active\" href=\"Aktuelle_Messung.html\">Daten aktuelle Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Alte_Messung.html\">Auswahl alter Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"App.html\">Alles zur App</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Sonstiges.html\">Sonstiges</a></span>\t\t\n\t</div>\n    </nav>\n</section>   \n\n<div class=\"content\">\n      \n<section>\n\t  <p><iframe src=\"Test_svg_data.html\" frameborder=\"0\" height=\"400\"\n\t\t\t\t\n      width=\"100%\"></iframe></p>\n\t\t\n</section>\n\t\n<section>\t \n\t <p><iframe src=\"Daten.html\" frameborder=\"0\" height=\"200\"\n\t\t\t\t\n      width=\"70%\"></iframe></p>\n\t\t\n\n\n</section>\n</div> \n</body>\n\n</html>"};  
  const char App_html[] PROGMEM = {"<!DOCTYPE html>\n<html>\n\n<head>\n    <title>EKG</title>\n    <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n</head>\n\n<body>\n    <header>\n        \n        <h1>Kabelloses EKG</h1>\n    </header>\n\n<section>\n    <nav>\n\t\t<div class=\"Auswahlmenue\">\n\t<span class=\"Auswahloben\"><a  href=\"index.html\">Homepage</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Aktuelle_Messung.html\">Daten aktuelle Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Alte_Messung.html\">Auswahl alter Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a class=\"active\" href=\"App.html\">Alles zur App</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Sonstiges.html\">Sonstiges</a></span>\t\t\n\t</div> \n    </nav>\n</section>  \n   \n<section>\n"};
 
  const char Sonstiges_html[] PROGMEM = {"<!DOCTYPE html>\n<html>\n\n<head>\n    <title>EKG</title>\n    <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n</head>\n\n<body>\n    <header>\n        \n        <h1>Kabelloses EKG</h1>\n    </header>\n\n<section>\n    <nav>\n\t\t<div class=\"Auswahlmenue\">\n\t<span class=\"Auswahloben\"><a  href=\"index.html\">Homepage</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Aktuelle_Messung.html\">Daten aktuelle Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Alte_Messung.html\">Auswahl alter Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a class=\"active\" href=\"App.html\">Alles zur App</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Sonstiges.html\">Sonstiges</a></span>\t\t\n\t</div> \n    </nav>\n</section> <div class=\"content\"> <input type=\"checkbox\" id=\"checkbox\"> \n <section>\n\t  <p><iframe src=\"Test_svg_data.html\" id=\"svg_frame\" frameborder=\"0\" height=\"400\"\n\t\t\t\t\n      width=\"100%\"></iframe></p>\n\n</section>\n  \n<section>\n <script src=\"ajax_script.js\" > </script></div> </body> </html>"};

  const char style_css[] PROGMEM = {"\nbody {\n\tfont-family: Helvetica, Arial, sans-serif;\n\t\n\tbackground-color: indianred;\n\t\n\tcolor: #320b50;\n\t\n\tfont-size: 30px;\n\tline-height: 42px;\n\tmargin: 40px 0;\n}\n\nbody::before {\n\tposition: fixed;\n\tcontent: \"\";\n\theight: 400px;\n\twidth: 400px;\n\ttop: 20px;\n\tright: 30px;\n\topacity: 0.2;\n}\n\nh1,h2,h3,h4,h5,h6 {\n\tfont-family: 'Verdana', cursive;\n}\n\nh1 {\n\twidth: 60%;\n\tmax-width: 960px;\n\tmargin: 0 auto 60px;\n\ttransform: rotate(-0deg);\n\tcolor: white;\n\ttext-align: left;\n\tfont-size: 5rem;\n\tline-height: 5rem;\n\ttext-shadow:  0 1px 0 hsl(52,7%,20%),\n                  0 2px 0 hsl(52,7%,18%),\n                  0 3px 0 hsl(52,7%,16%),\n                  0 4px 0 hsl(52,7%,14%),\n                  0 5px 0 hsl(52,7%,12%),\n                  0 6px 0 hsl(52,7%,10%),\n                  0 7px 0 hsl(52,7%,8%),\n                  0 8px 0 hsl(52,7%,6%),\n                  0 0 5px rgba(0,0,0,.05),\n                  0 1px 3px rgba(0,0,0,.2),\n                  0 3px 5px rgba(0,0,0,.2),\n                  0 5px 10px rgba(0,0,0,.2),\n                  0 10px 10px rgba(0,0,0,.2),\n                  0 20px 20px rgba(0,0,0,.3);\n}\n\t\nh2\t{\n\tcolor: white;\n}\n \t\nsection {\n  position: relative;\n  border-top: solid 1px #aaa;\n  border-bottom: solid 1px #444;\n  padding:25px 0;\n}\n\n  section:first-child::before {\n    position: absolute;\n    content: \"\";\n    width: 100%;\n    height: 1px;\n    border-top: solid 1px #444;\n    top: -2px;\n    left: 0;\n  }\n\n  section:last-child::after {\n    position: absolute;\n    content: \"\";\n    width: 100%;\n    border-top: solid 1px #bbb;\n    bottom: -2px;\n    left: 0;\n  }\n\n.Messung {\n\tdisplay: inline-block;\n\tlist-style: none;\n\tmargin: 0 2% 0 0;\n\tpadding: 0;\n\t\n}\n\n.content {\n\tposition: relative;\n\tbackground: #e7eef1;\n\twidth: 80%;\n\tmax-width: 1080px;\n\tmargin: 60px auto;\n\tpadding: 40px 40px 60px;\n\tbox-sizing: border-box;\n\tborder-radius: 2px;\n\tbox-shadow: 0 12px 0 -6px #AD5C5C;\t\n}\n.content::before {\n\tposition: absolute;\n\tdisplay: block;\n\tcontent: \"\";\n\tborder: solid 6px transparent;\n\tborder-right: solid 6px #AD5C5C;\n\tborder-top-width: 0px;\n    background: none;\n    bottom: -6px;\n\tleft: -6px;\n}\n\n  .content::after {\n    position: absolute;\n    display: block;\n    content: \"\";\n    border: solid 6px transparent;\n    border-top: solid 6px #AD5C5C;\n    border-bottom-width: 0px;\n    background: none;\n    right: 0;\n    bottom: -6px;\n  }\n\n\na {\n\ttext-decoration: none;\n}\n\n.Auswahlmenue{\n\tbackground-color: #d13d4d;\n\theight: 30%\n}\n\n.Auswahloben input { \n  opacity: 0;\n  width: 0;\n  height: 0;\n}\n\n.Auswahloben {\n\tposition: relative;\n\tdisplay: inline-block;\n\tmargin-left: -6px;\n\tz-index: 2;\n\tcolor: white;\n\tvertical-align: top;\n\tcontent: \"Homepage\";\n\tfont-size: 20px;\n\tline-height: 35px;\n\ttext-align: top;\n\tbackground-color: #d13d4d;\n\ttext-shadow: 0 1px 0 #3359a5;\n\twidth: 18%;\n\theight: 200px;\n\tborder: solid 1px #351111;\n\tborder-top: solid 1px transparent;\n\tborder-bottom: solid 1px transparent;\n\ttext-decoration: none;\n\n}\n\n.Auswahloben:first-child {\n\tmargin-left: 0px;\n}\n\n.Auswahloben:hover {\n\tbackground-color: #8e236b;\n}\n\n.Auswahloben:target {\n\tcolor: red;\n}\n\ninput:checked {\n\tbackground-color: blue;\n}\n\n\n\n.table{\n\tdisplay: inline-block;\n\tlist-style: none;\n\tmargin: 0 2% 0 0;\n\tpadding: 0;\n}\n\n\n"};
  const char Test_svg_data_html[] PROGMEM = {" \n<html>\n<head>\n\n    \n    \n\n</head>\n<style>\n #row {\n\tposition: relative;\n\tdisplay: border-box;\n}\n\n.column {\n\tposition: absolute;\n    float: left;\n\twidth: 25%;\n}\n\n#row img{\n\tposition: relative;\n}\t\n</style>\n<body>\n\t<div id=\"row\">\n  <div class=\"column\">\n    <object  data=\"linie1.svg\" id=\"svg_graph_1\" type=\"image/svg+xml\"></object>\n  </div>\n  <div class=\"column\">\n    <object  data=\"linie2.svg\" id=\"svg_graph_2\" type=\"image/svg+xml\"></object>\n  </div>\n  <div class=\"column\">\n    <object  data=\"linie3.svg\" id=\"svg_graph_3\" type=\"image/svg+xml\"></object>\n</div>\n<div class=\"column\">\n    <object  data=\"linie4.svg\" id=\"svg_graph_4\" type=\"image/svg+xml\"></object>\n</div>\n\t\t<div class=\"column\">\n    <object  data=\"linie5.svg\" id=\"svg_graph_5\" type=\"image/svg+xml\"></object>\n</div>\n</div>\n</body>\n</html>\n"};  const char Test_ajax_data_html[] PROGMEM = {"\n<!DOCTYPE html>\n<html>\n\n<head>\n\n</head>\n\t<body>\n<wrapper><text id=\"linie_0\"> </text>\n<text id=\"linie_1\"> </text>\n<text id=\"linie_2\"> </text>\n<text id=\"linie_3\"> </text>\n<text id=\"linie_4\"> </text>\n<text id=\"linie_5\"> </text>\n<text id=\"linie_6\"> </text>\n<text id=\"linie_7\"> </text>\n<text id=\"linie_8\"> </text>\n<text id=\"linie_9\"> </text> \n<text id=\"linie_10\"> Hallo</text>\n<text id=\"linie_11\"> </text>\n<text id=\"linie_12\"> </text>\n<text id=\"linie_13\"> </text>\n<text id=\"linie_14\"> </text>\n<text id=\"linie_15\"> </text>\n<text id=\"linie_16\"> </text>\n<text id=\"linie_17\"> </text>\n<text id=\"linie_18\"> </text>\n<text id=\"linie_19\"> </text>\n<text id=\"linie_20\"> </text>\n<text id=\"linie_21\"> </text>\n<text id=\"linie_22\"> </text>\n<text id=\"linie_23\"> </text>\n<text id=\"linie_24\"> </text>\n<text id=\"linie_25\"> </text>\n<text id=\"linie_26\"> </text>\n<text id=\"linie_27\"> </text>\n<text id=\"linie_28\"> </text>\n<text id=\"linie_29\"> </text>\n<text id=\"linie_30\"> </text>\n<text id=\"linie_31\"> </text>\n<text id=\"linie_32\"> </text>\n<text id=\"linie_33\"> </text>\n<text id=\"linie_34\"> </text>\n<text id=\"linie_35\"> </text>\n<text id=\"linie_36\"> </text>\n<text id=\"linie_37\"> </text>\n<text id=\"linie_38\"> </text>\n<text id=\"linie_39\"> </text>\n<text id=\"linie_40\"> </text>\n<text id=\"linie_41\"> </text>\n<text id=\"linie_42\"> </text>\n<text id=\"linie_43\"> </text>\n<text id=\"linie_44\"> </text>\n<text id=\"linie_45\"> </text>\n<text id=\"linie_46\"> </text>\n<text id=\"linie_47\"> </text>\n<text id=\"linie_48\"> </text>\n<text id=\"linie_49\"> </text>\n<text id=\"linie_50\"> </text>\n </wrapper></body> \n </html> /n"};   
#define HW_TIMER_INTERVAL_MS          5L //5
//35
#define SVG_length 45  
#define SVG_number  5
#define analog_buffer 4


WiFiWebServer server(80);


void AD_Wandlung_Simulation(void)
{
    //Serial.print("Interrupts aufgerufen");
    if(z>=SVG_length*analog_buffer*SVG_number+2&&analog_overhead<=SVG_durchgaenge*SVG_length){
        data_i[analog_overhead]=analogRead(A0);
        zeit_i[analog_overhead]= analog_overhead;
        analog_overhead++;
        website_zaehler++;
    }       
    if(o==1) {
      messung_zaehler_init=1;
      data_i[z] = analogRead(A0);
      zeit_i[z] = z;
      /*if (z==10) {
        Serial.println("Simulation_Test");
        Serial.println(data_i[0]);
        Serial.println(data_i[1]);
        Serial.println(data_i[2]);
        Serial.println(data_i[3]);
        Serial.println(data_i[4]);
        Serial.println(data_i[5]);
        Serial.println(data_i[6]);
        Serial.println(data_i[7]);
        Serial.println(data_i[8]);
        Serial.println(data_i[9]);
        }*/
     website_zaehler++;
     z++;
        if (z>=SVG_length*analog_buffer*SVG_number+2) {
            o=0; 
        }
     }   
    if(messung_zaehler_init==1)
         messung_zaehler++;  
    if(z>=SVG_length*analog_buffer*SVG_number+2&&o==2){
      // z=analog_overhead;
      //analog_overhead=0;
       //o=1;
      z=analog_overhead; 
      analog_overhead=0;
      
      o=1;
        /*Serial.println("Zumindest wurde der reset von z_Array aufgerufen");*/
    }
    
}


void zahlenraushauen(){
     n= millis();
     char data_buffer[70];
     char loeschen[] = "";
     long  t=0;
     n= millis();
     for (i=0; i < 10; i++) {
            for (k=0; k<10; k++) {    
                  w= i + random(3,6);
                  d= -0.5*k + random(3,6);
                  h = w + d + random(3,6);
                  delay(1);
                  m= millis();
                  t= m-n;
                  data[i*10+k] = h;
                  zeit[i*10+k] = t;
                  messung[i*10+k] = i*10+k;               
            }     
    }
}


void handleTabelle () {
  char loeschen[] = "";
  char auswaehlbuffer[3];
  unsigned long ze;
  unsigned long da;
  unsigned long me;
   /*Tabellenvaraiblen*/
  char t_header[] PROGMEM = "<table class=\"Aktuelle_Messung\"> <tr> <th>Messung</th> <th>Zeit seit Messbeginn</th> <th>Ergebniss</th> </tr>";
  char t_ende[] PROGMEM =  "</table>";
  char t_zstart[] PROGMEM = "<tr> ";
  char t_sstart[] PROGMEM = "<td>";
  char t_sende[] PROGMEM = "</td>";
  char t_zende[] PROGMEM = "</tr>";
  strcpy(auswaehlbuffer,loeschen);
  Serial.println("Aufgerufen");
  strcat(SendeBuffer,t_header);
  for (int f=0; f<10; f += 1) {
    strcat(SendeBuffer, t_zstart );
    strcat(SendeBuffer, t_sstart );
    me = messung[f];
    sprintf(auswaehlbuffer,"%lu",me);
    strcat(SendeBuffer, auswaehlbuffer );
    strcpy(auswaehlbuffer,loeschen);
    strcat(SendeBuffer, t_sende );
    
    strcat(SendeBuffer, t_sstart );
    ze = zeit[f];
    sprintf(auswaehlbuffer,"%lu",ze);
    strcat(SendeBuffer, auswaehlbuffer );
    strcpy(auswaehlbuffer,loeschen);
    strcat(SendeBuffer, t_sende );
    
    strcat(SendeBuffer, t_sstart );
    da = data[f];
    sprintf(auswaehlbuffer,"%lu",da);
    strcat(SendeBuffer, auswaehlbuffer );
    strcpy(auswaehlbuffer,loeschen);
    strcat(SendeBuffer, t_sende );
    strcat(SendeBuffer, t_zende );
    }
  Serial.println("1.Station");
  strcat(SendeBuffer, t_ende ); 
  Serial.println("2.Station");
}

void handleGraph1() {
   svg_zaehler=0;
   handleGraph();
}

void handleGraph2() {
   svg_zaehler=1;
   handleGraph();
}

void handleGraph3() {
   svg_zaehler=2;
   handleGraph();
}

void handleGraph4() {
   svg_zaehler=3;
   handleGraph();
}

void handleGraph5() {
   svg_zaehler=4;
   handleGraph();
}

void handleGraph() {

   Serial.println("Graph Aufgerufen");
   messung_zaehler_init = 0;
   website_zaehler = 0;
   messung_zaehler = 0;
   //*char svg_start[] PROGMEM = "<svg width=\"1800\" height=\"200\">\n  <rect width=\"1800\" height=\"200\" style=\"fill:rgb(244,244,244);stroke-width:3;stroke:rgb(0,0,0)\" /> <g stroke=\"blue\">";*//
   char svg_start[200];
   String graph;
   unsigned long datenlaenge = i*10+k;
   int unteres_Limit =svg_zaehler*SVG_length;
   int oberes_Limit = svg_zaehler*SVG_length+SVG_length;
   
   unsigned long weite =  1200;
   sprintf(svg_start,"<svg xmlns=\"http://www.w3.org/2000/svg\" id=\"svg_%d\" version=\"1.1\" width=\"%lu\" height=\"1300\">   <g stroke=\"blue\" stroke-width=\"1\" >\n",svg_zaehler,weite);
   char g_ende[] PROGMEM = "</g>"; 
   char svg_ende[] PROGMEM = "</svg>"; 
   int x1;
   int x2;
   int y1;
   int y2;
   int x1_0=0;
   int x2_0=0;
   int y1_0=0;
   int y2_0=0;
   char buffer_graph[100];
   
   char loeschen[] = "";
   strcpy(buffer_graph,loeschen);
   strcpy(sender_graph,loeschen);
   strcat(sender_graph,svg_start);
   y1= data_i[unteres_Limit-1];
   x1= zeit_i[unteres_Limit-1];
   if(svg_zaehler==0) {
        y1=data_i[0];
        x1=zeit_i[0];
   }
   Serial.println("Programmstart");
   for (int f=unteres_Limit; f<=oberes_Limit; f += 1) {
      y2= data_i[f];
      x2= zeit_i[f];
      sprintf(buffer_graph,"<line id=\"%d\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", f-unteres_Limit, x1_0, y1_0, x2_0, y2_0);
      y1= y2;
      x1= x2;
      strcat(sender_graph,buffer_graph);
   }
   Serial.println("Buffer ausgefüllt");
   strcat(sender_graph,g_ende);
   strcat(sender_graph,svg_ende);
   Serial.println("Sender fertig ausgefüllt ausgefüllt");
   //Serial.println(sender_graph);
   server.send(200,"image/svg+xml",sender_graph);
   if(svg_interrupt_zaehler==3) {
       o=2; }
   svg_zaehler++;
   Serial.println("Sender fertig geschickt");
   strcpy(sender_graph,loeschen);
  }


void handleXMLcontent(){
  if(start_button==1){
    o=1;
    start_button=0;
    }
  char loeschen[] = "";
  strcpy(XML_Content,loeschen);
  strcpy(XML_Buffer,loeschen);
  Position=(Position+Auffrischungslaenge);
  if(Position>=SVG_length) {
    Position=0;
    Index++;  
    }
  if (Index>=SVG_number+1) {
    Index=1;
    }
  Auffrischungslaenge = z-Position-SVG_length*SVG_durchgaenge-1;
  if (Auffrischungslaenge<0) {
    Auffrischungslaenge = 0;
    }
  if((Position+Auffrischungslaenge)>=SVG_length){
    Auffrischungslaenge= SVG_length-Position;
    }
  const char XML_0[] PROGMEM="<?xml version=\"1.0\" encoding=\"UTF-8\"?><w><I>";
  strcat(XML_Content,XML_0);
  sprintf(XML_Buffer,"%d",Index);
  strcat(XML_Content,XML_Buffer);
  const char XML_1[] PROGMEM="</I><P>";
  strcat(XML_Content,XML_1);
  sprintf(XML_Buffer,"%d",Position);
  strcat(XML_Content,XML_Buffer);
  const char XML_2[] PROGMEM="</P><A>";
  strcat(XML_Content,XML_2);
  sprintf(XML_Buffer,"%d",Auffrischungslaenge);
  strcat(XML_Content,XML_Buffer);
  const char XML_3[] PROGMEM="</A><S>";
  strcat(XML_Content,XML_3);
  sprintf(XML_Buffer,"%d",SVG_length);
  strcat(XML_Content,XML_Buffer);
  const char XML_4[] PROGMEM="</S>";
  strcat(XML_Content,XML_4);
    Serial.println("z Werten");
    Serial.println(z);
  Serial.println("analog_overhead Werten");
  Serial.println(analog_overhead);
  Serial.println("Website mit fespeicherten Werten");
  Serial.println(website_zaehler);
  Serial.println("Interrupt Ticker Zähler");
  Serial.println(messung_zaehler);
  for(xml_zaehler=SVG_durchgaenge*SVG_length+Position;xml_zaehler<=SVG_durchgaenge*SVG_length+Auffrischungslaenge+1+Position;xml_zaehler++) {
    data_xml=data_i[xml_zaehler];
    zeit_xml=zeit_i[xml_zaehler];
    sprintf(XML_Buffer,"<Z><d>%lu</d><z>%lu</z></Z>\n",data_xml,zeit_xml);
    strcat(XML_Content,XML_Buffer);
  }
  const char XML_5[] PROGMEM="</w>";
  strcat(XML_Content,XML_5);
  server.send(200,"text/xml",XML_Content);
  Serial.println("S");
  if (Position+Auffrischungslaenge>=SVG_length) {
     SVG_durchgaenge++;
     Serial.println("Svg.durchgaenge:");
     Serial.println(SVG_durchgaenge);
     if (SVG_durchgaenge>=SVG_number*analog_buffer) {
         SVG_durchgaenge=0;
         o=2; 
         }
    }
  
  }

void handleXMLcontent_website(){
  server.send(200,"text/html",Test_ajax_data_html); 
}

void handleRoot() {
  Serial.println("Index_html");
  server.send_P(200,"text/html",index_html); 
}

void handleCss() {
  Serial.println("Style_Css");
  server.send_P ( 200, "text/css", style_css);
}

void handleAktuell() {
  Serial.println("Aktuell_html");
  server.send_P(200,"text/html",Aktuelle_Messung_html);
}

void handleAlte() {
  server.send_P(200,"text/html",Alte_Messung_html);
}

void handleApp() {
    Serial.println("App_html");
  server.send_P(200,"text/html",App_html);
}

void handleSonstiges() {
   Serial.println("Sonstiges_html");
  server.send_P(200,"text/html",Sonstiges_html);
}

void handleEKG_image() {
  Serial.println("handleEKG_image Aufgerufen");
  server.send_P(200,"image/jpg",ekg_img,sizeof(ekg_img));
  Serial.println("EKG_image Gesendet");
}

void handleTest_svg_data() {
  server.send_P(200,"text/html",Test_svg_data_html);
}

void handleAjaxDaten() {
  server.send_P(200,"text/html",Test_ajax_data_html);
  Serial.println("handleAjaxDaten Aufgerufen");
}

void handleAjaxScript() {
  server.send_P(200,"text/javascript",Javascript_3);
  Serial.println("handleAjaxScript Aufgerufen");
}

void handleDaten() {
  char loeschen[] = "";
  /*HTML Aktuelle Daten --> Aktuelle Daten*/
  char Anfang PROGMEM[] ="<!DOCTYPE html>\n\n<html>\n<head>\n</head>\n<body>\n<h2>Aktuelle Daten</h2>\n";
  char Ende PROGMEM[] = "</body>\n</html>";   
   strcpy(SendeBuffer,loeschen);
   strcat(SendeBuffer,Anfang);
   handleTabelle();
   Serial.println("3.Station");
   strcat(SendeBuffer,Ende);
   Serial.println("4.Station");
   Serial.print(SendeBuffer);
   Serial.println("5.Station");
   server.send(200,"text/html",SendeBuffer);
   Serial.println("6.Station");
}

void handleNotFound(){
  String message = "File Not Found\n\n";
  server.send(404, "text/plain", message);
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("You are connected:");
  Serial.println("");
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  
  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");

}

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    Serial.println(ssid);
    printWifiStatus();
    delay(1000);
  }
    zahlenraushauen();
    
    server.on("/", handleRoot);
    server.on("/style.css", handleCss); 
    server.on("/index.html", handleRoot);
    server.on("/Aktuelle_Messung.html", handleAktuell);
    server.on("/Alte_Messung.html", handleAlte);
    server.on("/App.html", handleApp);
    server.on("/Sonstiges.html", handleSonstiges);
    server.on("/Daten.html", handleDaten);
    server.on("/Test_svg_data.html", handleTest_svg_data);
    server.on("/linie1.svg", handleGraph1);
    server.on("/linie2.svg", handleGraph2);
    server.on("/linie3.svg", handleGraph3);
    server.on("/linie4.svg", handleGraph4);
    server.on("/linie5.svg", handleGraph5);
    server.on("/XML_Content.xml", handleXMLcontent);
    server.on("/Test_ajax_data.html", handleAjaxDaten);
    server.on("/ajax_script.js", handleAjaxScript);
    server.on("/Html.html", handleXMLcontent_website);
    server.on("/img_ekg_theme.jpg", handleEKG_image);
    
    server.onNotFound(handleNotFound);

    server.begin();
    Serial.println("HTTP server started");
    ITimer.attachInterruptInterval(HW_TIMER_INTERVAL_MS * 1000, AD_Wandlung_Simulation);
}

void loop() {
    
    server.handleClient();

}

You have to go to Sonstiges.html and click the button.

Thanks for answering btw.

I got your code to compile and run. I needed to include some header files you missed.

May I first make a few small suggestions that will not solve your issue but could still be useful.

  • your code create quite couple of warnings. Make sure you enable warnings in the IDE and try to remove as many as possible.
    File -> Preferences -> Compiler Warnings: ALL

  • As you noticed yourself your code could use some better formatting for readability. Try:
    Tools -> Auto Format

You can change the formatting to suit your style. Google "formatter.conf" site:arduino.cc

  • Avoid using multiple languages in your code. C/C++ and English are enough. :slight_smile:

  • stick to one naming convention for variables, functions ... most Arduino user use camelCase for functions and variables and CAPITALS_WITH_UNDERSCORE for constants

  • some of your variable names seem a bit short

Regarding the issue, you may need a debugger to analyze this completely. Here is what I found:

  • I can confirm slowing down the requests does not solve the issue.
  • Some requests seem to take quite a lot of time. I just looked at the browser tools for Network.
  • your loop function is called very often and usually uses little time, during requests the loop time increases a bit but overall, this looks OK
  • when the sketch breaks, the loop function is still running in most cases
  • the libraries you are using seems cleanly written (does not mean there are no bug, but it is a good sign)
  • you seem to have little available RAM 55% used, that is usually not a too bad, but you are working a lot on buffers and data copying, maybe you are running out of heap, the behavior looks a bit like this could be the case (With a debugger you could fill the RAM with a fixed patter and then read it again when the sketch breaks).
  • The issue could also come from the WiFi module. Have you tried to get debug prints from that?
  • I had a quick look at the network traffic with WireShark and there was no obvious issue. There were a few unusual packets (marked by the tool) with retries but I would expect that for WiFi.

I have an Arduino Nano RP2040 with a lot more RAM. If you could remove the SAMD specific code we could try and see what happens on that board. The WiFi module is the same.

I have tried debugging the library itself with visual micro but i couldn't get it to run.

Visual Micro - Problem with Library Debugging

I don't know how to get debug form the WiFi module itself. I have also tried making sendebuffer[] and xml_buffer[] smaller and reduced their combined sizeabout 2500, and i have been using new and delete. I didn't seem to help. I will try to implement your tips and staying with two languages :grin: . I think the only code which is SAMD specific is the IT.attachInterruptInterval()? I have tried using theTimerInterrupt_Generic Library and the code worked. The i commented out the SAMD specific commands and replaced them with the ones that should work with the RP2040. I hope it works :crossed_fingers: .

Forgot the code


#include "defines.h"
#include "arduino_secrets.h"


//#define TIMER_INTERRUPT_DEBUG         0
//#define _TIMERINTERRUPT_LOGLEVEL_     0

//#include "SAMDTimerInterrupt.h"


// These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h"
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
#define TIMER_INTERRUPT_DEBUG         1   //  0      with rp2040 examples
#define _TIMERINTERRUPT_LOGLEVEL_     4   //  0
//Examples   RP2040  SAMD



#include "TimerInterrupt_Generic.h"




RPI_PICO_Timer ITimer0(0);
//SAMDTimer ITimer0(TIMER_TC3);

#define TIMER_INTERVAL_MS    5L

//SAMDTimer ITimer(TIMER_TC3);

// WLAN DATEN
char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;
int keyIndex = 0;      // nur für WEP
int status = WL_IDLE_STATUS;




// Variablen zum erzeugen zufaeliiger Werte
int messungaktiv = 0;
int svg_zaehler = 0;
int svg_interrupt_zaehler = 0;
unsigned long i = 0;
unsigned long k = 0;
unsigned long w = 0;
unsigned long h = 0;
unsigned long d = 0;
unsigned int x = 0;
unsigned long n = 0;
unsigned long m = 0;
unsigned long  data[110];
unsigned long  zeit[110];
unsigned long messung[110];

// Interrrupt Varaiblen
volatile  int  data_i[1200];
volatile  int  zeit_i[1200];
volatile  int  analog_overhead = 0;
volatile  int  ajax_refresh_length = 0;
volatile long o = 0; //davor = o=1;
volatile long u = 0;
volatile int z = 0;
volatile long z_k = 0;
volatile long y = 1;
volatile long a = 0;
volatile long zaehler = 0;
volatile long dimension = 0;
char XML_Buffer[50];
//char XML_Content[1500];//2200 // 1500 ^=SVG Number 45
volatile int website_zaehler = 0;
volatile int messung_zaehler = 0;
volatile int messung_zaehler_init = 0;




// Ajax Varaiblen
int Position = 0;
int Auffrischungslaenge = 0;
volatile int Index = 1;
volatile int SVG_durchgaenge = 0;
int xml_zaehler = 0;
int zeit_xml;
int data_xml;
int start_button = 1;

long size_zeit = 0;
unsigned long size_data = 0;

char SendeBuffer[00];//800
//char sender_graph[2250];//2800 //2250 ^=SVG Number 45

const char ekg_img[] PROGMEM = {"Ides"};

//200
const char Javascript_3[] PROGMEM = {"setInterval(function()\n    {\n      getGraph();\n    }, 200);\n   function getGraph()\n    \n\t{\n   if(document.getElementById(\"checkbox\").checked==1) {  var GraphvalHttpRequest = new XMLHttpRequest();\n      GraphvalHttpRequest.onreadystatechange = function()\n      {\n        if(this.readyState == 4 && this.status == 200)\n {     \n  var GraphvalRequest=this.responseXML;\n  var i;\n  var zeile = GraphvalRequest.getElementsByTagName(\"Z\");\n  var index = GraphvalRequest.getElementsByTagName(\"I\")[0].childNodes[0].nodeValue;\n  var Position = GraphvalRequest.getElementsByTagName(\"P\")[0].childNodes[0].nodeValue;\n  var svg = document.getElementById(\"svg_frame\"); \n  var current_svg_id= \"svg_graph_\" + index;\n  var current_svg = svg.contentDocument.getElementById(current_svg_id).contentDocument; \n  for (i = 0; i<zeile.length-2; i++){ var linie_graph = +Position + +i;\n var momentane_linie=current_svg.getElementById(linie_graph);\n var linie_element = current_svg.createElementNS('http://www.w3.org/2000/svg', 'line'); linie_element.setAttribute(\"id\" ,linie_graph);\n linie_element.setAttribute(\"x1\" ,zeile[i].getElementsByTagName(\"z\")[0].childNodes[0].nodeValue);linie_element.setAttribute(\"y1\",zeile[i].getElementsByTagName(\"d\")[0].childNodes[0].nodeValue);\n linie_element.setAttribute(\"x2\",zeile[i+1].getElementsByTagName(\"z\")[0].childNodes[0].nodeValue);linie_element.setAttribute(\"y2\",zeile[i+1].getElementsByTagName(\"d\")[0].childNodes[0].nodeValue);  \n var parent = current_svg.getElementsByTagName(\"g\")[0]; parent.replaceChild(linie_element,momentane_linie); console.log(current_svg);\n }}};\n GraphvalHttpRequest.open(\"GET\", \"XML_Content.xml\", true);\n  GraphvalHttpRequest.send();\n }} "};

//const char index_html[] PROGMEM = {"<!DOCTYPE html><html><head></head><body><h1>Test</h1><p>\"100 mal nachladen wenn es klappt->large html/package porblem\"</p></body></html>"};
const char index_html[] PROGMEM = {"<!DOCTYPE html>\n<html>\n\n<head>\n    <title>EKG</title>\n    <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n</head>\n\n<body>\n    <header>\n        \n        <h1>Kabelloses EKG</h1>\n    </header>\n\n<section>\n    <nav>\n\t\t<div class=\"Auswahlmenue\">\n\t<span class=\"Auswahloben\"><a class=\"active\" href=\"index.html\">Homepage</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Aktuelle_Messung.html\">Daten aktuelle Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Alte_Messung.html\">Auswahl alter Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"App.html\">Alles zur App</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Sonstiges.html\">Sonstiges</a></span>\t\t\n\t</div> \n    </nav>\n</section>   \n\t\t\n<section>\n\n\t<p> Tabelle 1:</p>\n\t<table class=\"Messung\" border=\"10\" cellpadding=\"5\" cellspacing=\"0\"> \n        <tr>\n            <th>Season</th>\n            <th>Month</th>\n            <th>Rent</th>\n            <th colspan=\"2\">Utilities</th>\n            <th>Groceries</th>\n            <th>Eating Out</th>\n            <th>Entertainment</th>\n        </tr>\n        <tr>\n            <td rowspan=\"3\">Fall</td>\n            <td>June</td>\n            <td>€1300</td>\n            <td>€100</td>\n            <td>€50</td>\n            <td>350€</td>\n            <td>100€</td>\n            <td>€50</td>\n\n        </tr>\n\n        <tr>\n            <td>July</td>\n            <td>€1300</td>\n            <td>€100</td>\n            <td>€50</td>\n            <td>350€</td>\n            <td>100€</td>\n            <td>€50</td>\n\n        </tr>\n\n        <tr>\n            <td>August</td>\n            <td>€1300</td>\n            <td>€100</td>\n            <td>€50</td>\n            <td>350€</td>\n            <td>100€</td>\n            <td>€50</td>\n\n        </tr>\n    </table>\n    </section>\n\n</body>\n\n</html>"};
const char Alte_Messung_html[] PROGMEM = {"<!DOCTYPE html>\n<html>\n\n<head>\n    <title>EKG</title>\n    <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n</head>\n\n<body>\n    <header>\n        \n        <h1>Kabelloses EKG</h1>\n    </header>\n\n    <nav>\n\n<section>\n    <nav>\n\t\t<div class=\"Auswahlmenue\">\n\t<span class=\"Auswahloben\"><a  href=\"index.html\">Homepage</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Aktuelle_Messung.html\">Daten aktuelle Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a class=\"active\" href=\"Alte_Messung.html\">Auswahl alter Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"App.html\">Alles zur App</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Sonstiges.html\">Sonstiges</a></span>\t\t\n\t</div> \n    </nav>\n</section>  \n<section>\n<div id=\"body\" </div> <img src=\"img_ekg_theme.jpg\" alt=\"EKG_Project_Theme\" <p>EKG App</p> </body></html>"};
const char Aktuelle_Messung_html[] PROGMEM = {"<!DOCTYPE html>\n<html>\n\n<head>\n    <title>EKG</title>\n    <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n</head>\n\n<body>\n\n    <header>\n        \n        <h1>Kabelloses EKG</h1>\n    </header>\n\n<section>\n    <nav>\n\t\t<div class=\"Auswahlmenue\">\n\t<span class=\"Auswahloben\"><a href=\"index.html\">Homepage</a></span>\t\n\t<span class=\"Auswahloben\"><a class=\"active\" href=\"Aktuelle_Messung.html\">Daten aktuelle Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Alte_Messung.html\">Auswahl alter Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"App.html\">Alles zur App</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Sonstiges.html\">Sonstiges</a></span>\t\t\n\t</div>\n    </nav>\n</section>   \n\n<div class=\"content\">\n      \n<section>\n\t  <p><iframe src=\"Test_svg_data.html\" frameborder=\"0\" height=\"400\"\n\t\t\t\t\n      width=\"100%\"></iframe></p>\n\t\t\n</section>\n\t\n<section>\t \n\t <p><iframe src=\"Daten.html\" frameborder=\"0\" height=\"200\"\n\t\t\t\t\n      width=\"70%\"></iframe></p>\n\t\t\n\n\n</section>\n</div> \n</body>\n\n</html>"};
const char App_html[] PROGMEM = {"<!DOCTYPE html>\n<html>\n\n<head>\n    <title>EKG</title>\n    <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n</head>\n\n<body>\n    <header>\n        \n        <h1>Kabelloses EKG</h1>\n    </header>\n\n<section>\n    <nav>\n\t\t<div class=\"Auswahlmenue\">\n\t<span class=\"Auswahloben\"><a  href=\"index.html\">Homepage</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Aktuelle_Messung.html\">Daten aktuelle Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Alte_Messung.html\">Auswahl alter Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a class=\"active\" href=\"App.html\">Alles zur App</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Sonstiges.html\">Sonstiges</a></span>\t\t\n\t</div> \n    </nav>\n</section>  \n   \n<section>\n"};

const char Sonstiges_html[] PROGMEM = {"<!DOCTYPE html>\n<html>\n\n<head>\n    <title>EKG</title>\n    <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n</head>\n\n<body>\n    <header>\n        \n        <h1>Kabelloses EKG</h1>\n    </header>\n\n<section>\n    <nav>\n\t\t<div class=\"Auswahlmenue\">\n\t<span class=\"Auswahloben\"><a  href=\"index.html\">Homepage</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Aktuelle_Messung.html\">Daten aktuelle Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Alte_Messung.html\">Auswahl alter Messung</a></span>\t\n\t<span class=\"Auswahloben\"><a class=\"active\" href=\"App.html\">Alles zur App</a></span>\t\n\t<span class=\"Auswahloben\"><a href=\"Sonstiges.html\">Sonstiges</a></span>\t\t\n\t</div> \n    </nav>\n</section> <div class=\"content\"> <input type=\"checkbox\" id=\"checkbox\"> \n <section>\n\t  <p><iframe src=\"Test_svg_data.html\" id=\"svg_frame\" frameborder=\"0\" height=\"400\"\n\t\t\t\t\n      width=\"100%\"></iframe></p>\n\n</section>\n  \n<section>\n <script src=\"ajax_script.js\" > </script></div> </body> </html>"};

const char style_css[] PROGMEM = {"\nbody {\n\tfont-family: Helvetica, Arial, sans-serif;\n\t\n\tbackground-color: indianred;\n\t\n\tcolor: #320b50;\n\t\n\tfont-size: 30px;\n\tline-height: 42px;\n\tmargin: 40px 0;\n}\n\nbody::before {\n\tposition: fixed;\n\tcontent: \"\";\n\theight: 400px;\n\twidth: 400px;\n\ttop: 20px;\n\tright: 30px;\n\topacity: 0.2;\n}\n\nh1,h2,h3,h4,h5,h6 {\n\tfont-family: 'Verdana', cursive;\n}\n\nh1 {\n\twidth: 60%;\n\tmax-width: 960px;\n\tmargin: 0 auto 60px;\n\ttransform: rotate(-0deg);\n\tcolor: white;\n\ttext-align: left;\n\tfont-size: 5rem;\n\tline-height: 5rem;\n\ttext-shadow:  0 1px 0 hsl(52,7%,20%),\n                  0 2px 0 hsl(52,7%,18%),\n                  0 3px 0 hsl(52,7%,16%),\n                  0 4px 0 hsl(52,7%,14%),\n                  0 5px 0 hsl(52,7%,12%),\n                  0 6px 0 hsl(52,7%,10%),\n                  0 7px 0 hsl(52,7%,8%),\n                  0 8px 0 hsl(52,7%,6%),\n                  0 0 5px rgba(0,0,0,.05),\n                  0 1px 3px rgba(0,0,0,.2),\n                  0 3px 5px rgba(0,0,0,.2),\n                  0 5px 10px rgba(0,0,0,.2),\n                  0 10px 10px rgba(0,0,0,.2),\n                  0 20px 20px rgba(0,0,0,.3);\n}\n\t\nh2\t{\n\tcolor: white;\n}\n \t\nsection {\n  position: relative;\n  border-top: solid 1px #aaa;\n  border-bottom: solid 1px #444;\n  padding:25px 0;\n}\n\n  section:first-child::before {\n    position: absolute;\n    content: \"\";\n    width: 100%;\n    height: 1px;\n    border-top: solid 1px #444;\n    top: -2px;\n    left: 0;\n  }\n\n  section:last-child::after {\n    position: absolute;\n    content: \"\";\n    width: 100%;\n    border-top: solid 1px #bbb;\n    bottom: -2px;\n    left: 0;\n  }\n\n.Messung {\n\tdisplay: inline-block;\n\tlist-style: none;\n\tmargin: 0 2% 0 0;\n\tpadding: 0;\n\t\n}\n\n.content {\n\tposition: relative;\n\tbackground: #e7eef1;\n\twidth: 80%;\n\tmax-width: 1080px;\n\tmargin: 60px auto;\n\tpadding: 40px 40px 60px;\n\tbox-sizing: border-box;\n\tborder-radius: 2px;\n\tbox-shadow: 0 12px 0 -6px #AD5C5C;\t\n}\n.content::before {\n\tposition: absolute;\n\tdisplay: block;\n\tcontent: \"\";\n\tborder: solid 6px transparent;\n\tborder-right: solid 6px #AD5C5C;\n\tborder-top-width: 0px;\n    background: none;\n    bottom: -6px;\n\tleft: -6px;\n}\n\n  .content::after {\n    position: absolute;\n    display: block;\n    content: \"\";\n    border: solid 6px transparent;\n    border-top: solid 6px #AD5C5C;\n    border-bottom-width: 0px;\n    background: none;\n    right: 0;\n    bottom: -6px;\n  }\n\n\na {\n\ttext-decoration: none;\n}\n\n.Auswahlmenue{\n\tbackground-color: #d13d4d;\n\theight: 30%\n}\n\n.Auswahloben input { \n  opacity: 0;\n  width: 0;\n  height: 0;\n}\n\n.Auswahloben {\n\tposition: relative;\n\tdisplay: inline-block;\n\tmargin-left: -6px;\n\tz-index: 2;\n\tcolor: white;\n\tvertical-align: top;\n\tcontent: \"Homepage\";\n\tfont-size: 20px;\n\tline-height: 35px;\n\ttext-align: top;\n\tbackground-color: #d13d4d;\n\ttext-shadow: 0 1px 0 #3359a5;\n\twidth: 18%;\n\theight: 200px;\n\tborder: solid 1px #351111;\n\tborder-top: solid 1px transparent;\n\tborder-bottom: solid 1px transparent;\n\ttext-decoration: none;\n\n}\n\n.Auswahloben:first-child {\n\tmargin-left: 0px;\n}\n\n.Auswahloben:hover {\n\tbackground-color: #8e236b;\n}\n\n.Auswahloben:target {\n\tcolor: red;\n}\n\ninput:checked {\n\tbackground-color: blue;\n}\n\n\n\n.table{\n\tdisplay: inline-block;\n\tlist-style: none;\n\tmargin: 0 2% 0 0;\n\tpadding: 0;\n}\n\n\n"};
const char Test_svg_data_html[] PROGMEM = {" \n<html>\n<head>\n\n    \n    \n\n</head>\n<style>\n #row {\n\tposition: relative;\n\tdisplay: border-box;\n}\n\n.column {\n\tposition: absolute;\n    float: left;\n\twidth: 25%;\n}\n\n#row img{\n\tposition: relative;\n}\t\n</style>\n<body>\n\t<div id=\"row\">\n  <div class=\"column\">\n    <object  data=\"linie1.svg\" id=\"svg_graph_1\" type=\"image/svg+xml\"></object>\n  </div>\n  <div class=\"column\">\n    <object  data=\"linie2.svg\" id=\"svg_graph_2\" type=\"image/svg+xml\"></object>\n  </div>\n  <div class=\"column\">\n    <object  data=\"linie3.svg\" id=\"svg_graph_3\" type=\"image/svg+xml\"></object>\n</div>\n<div class=\"column\">\n    <object  data=\"linie4.svg\" id=\"svg_graph_4\" type=\"image/svg+xml\"></object>\n</div>\n\t\t<div class=\"column\">\n    <object  data=\"linie5.svg\" id=\"svg_graph_5\" type=\"image/svg+xml\"></object>\n</div>\n</div>\n</body>\n</html>\n"};  const char Test_ajax_data_html[] PROGMEM = {"\n<!DOCTYPE html>\n<html>\n\n<head>\n\n</head>\n\t<body>\n<wrapper><text id=\"linie_0\"> </text>\n<text id=\"linie_1\"> </text>\n<text id=\"linie_2\"> </text>\n<text id=\"linie_3\"> </text>\n<text id=\"linie_4\"> </text>\n<text id=\"linie_5\"> </text>\n<text id=\"linie_6\"> </text>\n<text id=\"linie_7\"> </text>\n<text id=\"linie_8\"> </text>\n<text id=\"linie_9\"> </text> \n<text id=\"linie_10\"> Hallo</text>\n<text id=\"linie_11\"> </text>\n<text id=\"linie_12\"> </text>\n<text id=\"linie_13\"> </text>\n<text id=\"linie_14\"> </text>\n<text id=\"linie_15\"> </text>\n<text id=\"linie_16\"> </text>\n<text id=\"linie_17\"> </text>\n<text id=\"linie_18\"> </text>\n<text id=\"linie_19\"> </text>\n<text id=\"linie_20\"> </text>\n<text id=\"linie_21\"> </text>\n<text id=\"linie_22\"> </text>\n<text id=\"linie_23\"> </text>\n<text id=\"linie_24\"> </text>\n<text id=\"linie_25\"> </text>\n<text id=\"linie_26\"> </text>\n<text id=\"linie_27\"> </text>\n<text id=\"linie_28\"> </text>\n<text id=\"linie_29\"> </text>\n<text id=\"linie_30\"> </text>\n<text id=\"linie_31\"> </text>\n<text id=\"linie_32\"> </text>\n<text id=\"linie_33\"> </text>\n<text id=\"linie_34\"> </text>\n<text id=\"linie_35\"> </text>\n<text id=\"linie_36\"> </text>\n<text id=\"linie_37\"> </text>\n<text id=\"linie_38\"> </text>\n<text id=\"linie_39\"> </text>\n<text id=\"linie_40\"> </text>\n<text id=\"linie_41\"> </text>\n<text id=\"linie_42\"> </text>\n<text id=\"linie_43\"> </text>\n<text id=\"linie_44\"> </text>\n<text id=\"linie_45\"> </text>\n<text id=\"linie_46\"> </text>\n<text id=\"linie_47\"> </text>\n<text id=\"linie_48\"> </text>\n<text id=\"linie_49\"> </text>\n<text id=\"linie_50\"> </text>\n </wrapper></body> \n </html> /n"};
//#define HW_TIMER_INTERVAL_MS          5L //5
//35
#define SVG_length 5
#define SVG_number  5
#define analog_buffer 4


WiFiWebServer server(80);


void AD_Wandlung_Simulation(void)
{
  //Serial.print("Interrupts aufgerufen");
  if (z >= SVG_length * analog_buffer * SVG_number + 2 && analog_overhead <= SVG_durchgaenge * SVG_length) {
    data_i[analog_overhead] = analogRead(A0);
    zeit_i[analog_overhead] = analog_overhead;
    analog_overhead++;
    website_zaehler++;
  }
  if (o == 1) {
    messung_zaehler_init = 1;
    data_i[z] = analogRead(A0);
    zeit_i[z] = z;
    /*if (z==10) {
      Serial.println("Simulation_Test");
      Serial.println(data_i[0]);
      Serial.println(data_i[1]);
      Serial.println(data_i[2]);
      Serial.println(data_i[3]);
      Serial.println(data_i[4]);
      Serial.println(data_i[5]);
      Serial.println(data_i[6]);
      Serial.println(data_i[7]);
      Serial.println(data_i[8]);
      Serial.println(data_i[9]);
      }*/
    website_zaehler++;
    z++;
    if (z >= SVG_length * analog_buffer * SVG_number + 2) {
      o = 0;
    }
  }
  if (messung_zaehler_init == 1)
    messung_zaehler++;
  if (z >= SVG_length * analog_buffer * SVG_number + 2 && o == 2) {
    // z=analog_overhead;
    //analog_overhead=0;
    //o=1;
    z = analog_overhead;
    analog_overhead = 0;

    o = 1;
    /*Serial.println("Zumindest wurde der reset von z_Array aufgerufen");*/
  }

}


void zahlenraushauen() {
  n = millis();
  char data_buffer[70];
  char loeschen[] = "";
  long  t = 0;
  n = millis();
  for (i = 0; i < 10; i++) {
    for (k = 0; k < 10; k++) {
      w = i + random(3, 6);
      d = -0.5 * k + random(3, 6);
      h = w + d + random(3, 6);
      delay(1);
      m = millis();
      t = m - n;
      data[i * 10 + k] = h;
      zeit[i * 10 + k] = t;
      messung[i * 10 + k] = i * 10 + k;
    }
  }
}


void handleTabelle () {
  char loeschen[] = "";
  char auswaehlbuffer[3];
  unsigned long ze;
  unsigned long da;
  unsigned long me;
  /*Tabellenvaraiblen*/
  char t_header[] PROGMEM = "<table class=\"Aktuelle_Messung\"> <tr> <th>Messung</th> <th>Zeit seit Messbeginn</th> <th>Ergebniss</th> </tr>";
  char t_ende[] PROGMEM =  "</table>";
  char t_zstart[] PROGMEM = "<tr> ";
  char t_sstart[] PROGMEM = "<td>";
  char t_sende[] PROGMEM = "</td>";
  char t_zende[] PROGMEM = "</tr>";
  strcpy(auswaehlbuffer, loeschen);
  Serial.println("Aufgerufen");
  strcat(SendeBuffer, t_header);
  for (int f = 0; f < 10; f += 1) {
    strcat(SendeBuffer, t_zstart );
    strcat(SendeBuffer, t_sstart );
    me = messung[f];
    sprintf(auswaehlbuffer, "%lu", me);
    strcat(SendeBuffer, auswaehlbuffer );
    strcpy(auswaehlbuffer, loeschen);
    strcat(SendeBuffer, t_sende );

    strcat(SendeBuffer, t_sstart );
    ze = zeit[f];
    sprintf(auswaehlbuffer, "%lu", ze);
    strcat(SendeBuffer, auswaehlbuffer );
    strcpy(auswaehlbuffer, loeschen);
    strcat(SendeBuffer, t_sende );

    strcat(SendeBuffer, t_sstart );
    da = data[f];
    sprintf(auswaehlbuffer, "%lu", da);
    strcat(SendeBuffer, auswaehlbuffer );
    strcpy(auswaehlbuffer, loeschen);
    strcat(SendeBuffer, t_sende );
    strcat(SendeBuffer, t_zende );
  }
  Serial.println("1.Station");
  strcat(SendeBuffer, t_ende );
  Serial.println("2.Station");
}

void handleGraph1() {
  svg_zaehler = 0;
  handleGraph();
}

void handleGraph2() {
  svg_zaehler = 1;
  handleGraph();
}

void handleGraph3() {
  svg_zaehler = 2;
  handleGraph();
}

void handleGraph4() {
  svg_zaehler = 3;
  handleGraph();
}

void handleGraph5() {
  svg_zaehler = 4;
  handleGraph();
}

void handleGraph() {

  Serial.println("Graph Aufgerufen");
  messung_zaehler_init = 0;
  website_zaehler = 0;
  messung_zaehler = 0;
  //*char svg_start[] PROGMEM = "<svg width=\"1800\" height=\"200\">\n  <rect width=\"1800\" height=\"200\" style=\"fill:rgb(244,244,244);stroke-width:3;stroke:rgb(0,0,0)\" /> <g stroke=\"blue\">";*//
  char * sender_graph = new char[450]; //2250 //851 ^ 15
  char svg_start[200];
  String graph;
  unsigned long datenlaenge = i * 10 + k;
  int unteres_Limit = svg_zaehler * SVG_length;
  int oberes_Limit = svg_zaehler * SVG_length + SVG_length;

  unsigned long weite =  1200;
  sprintf(svg_start, "<svg xmlns=\"http://www.w3.org/2000/svg\" id=\"svg_%d\" version=\"1.1\" width=\"%lu\" height=\"1300\">   <g stroke=\"blue\" stroke-width=\"1\" >\n", svg_zaehler, weite);
  char g_ende[] PROGMEM = "</g>";
  char svg_ende[] PROGMEM = "</svg>";
  int x1;
  int x2;
  int y1;
  int y2;
  int x1_0 = 0;
  int x2_0 = 0;
  int y1_0 = 0;
  int y2_0 = 0;
  char buffer_graph[100];

  char loeschen[] = "";
  strcpy(buffer_graph, loeschen);
  strcpy(sender_graph, loeschen);
  strcat(sender_graph, svg_start);
  y1 = data_i[unteres_Limit - 1];
  x1 = zeit_i[unteres_Limit - 1];
  if (svg_zaehler == 0) {
    y1 = data_i[0];
    x1 = zeit_i[0];
  }
  Serial.println("Programmstart");
  for (int f = unteres_Limit; f <= oberes_Limit; f += 1) {
    y2 = data_i[f];
    x2 = zeit_i[f];
    sprintf(buffer_graph, "<line id=\"%d\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", f - unteres_Limit, x1_0, y1_0, x2_0, y2_0);
    y1 = y2;
    x1 = x2;
    strcat(sender_graph, buffer_graph);
  }
  Serial.println("Buffer ausgefüllt");
  strcat(sender_graph, g_ende);
  strcat(sender_graph, svg_ende);
  Serial.println("Sender fertig ausgefüllt ausgefüllt");
  //Serial.println(sender_graph);
  server.send(200, "image/svg+xml", sender_graph);
  if (svg_interrupt_zaehler == 3) {
    o = 2;
  }
  svg_zaehler++;
  Serial.println("Sender fertig geschickt");
  strcpy(sender_graph, loeschen);
  delete sender_graph;
}


void handleXMLcontent() {
  char * XML_Content = new char[400]; // 1500^45 //691^15
  if (start_button == 1) {
    o = 1;
    start_button = 0;
  }
  char loeschen[] = "";
  strcpy(XML_Content, loeschen);
  strcpy(XML_Buffer, loeschen);
  Position = (Position + Auffrischungslaenge);
  if (Position >= SVG_length) {
    Position = 0;
    Index++;
  }
  if (Index >= SVG_number + 1) {
    Index = 1;
  }
  Auffrischungslaenge = z - Position - SVG_length * SVG_durchgaenge - 1;
  if (Auffrischungslaenge < 0) {
    Auffrischungslaenge = 0;
  }
  if ((Position + Auffrischungslaenge) >= SVG_length) {
    Auffrischungslaenge = SVG_length - Position;
  }
  const char XML_0[] PROGMEM = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><w><I>";
  strcat(XML_Content, XML_0);
  sprintf(XML_Buffer, "%d", Index);
  strcat(XML_Content, XML_Buffer);
  const char XML_1[] PROGMEM = "</I><P>";
  strcat(XML_Content, XML_1);
  sprintf(XML_Buffer, "%d", Position);
  strcat(XML_Content, XML_Buffer);
  const char XML_2[] PROGMEM = "</P><A>";
  strcat(XML_Content, XML_2);
  sprintf(XML_Buffer, "%d", Auffrischungslaenge);
  strcat(XML_Content, XML_Buffer);
  const char XML_3[] PROGMEM = "</A><S>";
  strcat(XML_Content, XML_3);
  sprintf(XML_Buffer, "%d", SVG_length);
  strcat(XML_Content, XML_Buffer);
  const char XML_4[] PROGMEM = "</S>";
  strcat(XML_Content, XML_4);
  Serial.println("z Werten");
  Serial.println(z);
  Serial.println("analog_overhead Werten");
  Serial.println(analog_overhead);
  Serial.println("Website mit fespeicherten Werten");
  Serial.println(website_zaehler);
  Serial.println("Interrupt Ticker Zähler");
  Serial.println(messung_zaehler);
  for (xml_zaehler = SVG_durchgaenge * SVG_length + Position; xml_zaehler <= SVG_durchgaenge * SVG_length + Auffrischungslaenge + 1 + Position; xml_zaehler++) {
    data_xml = data_i[xml_zaehler];
    zeit_xml = zeit_i[xml_zaehler];
    sprintf(XML_Buffer, "<Z><d>%lu</d><z>%lu</z></Z>\n", data_xml, zeit_xml);
    strcat(XML_Content, XML_Buffer);
  }
  const char XML_5[] PROGMEM = "</w>";
  strcat(XML_Content, XML_5);
  server.send(200, "text/xml", XML_Content);
  Serial.println("S");
  if (Position + Auffrischungslaenge >= SVG_length) {
    SVG_durchgaenge++;
    Serial.println("Svg.durchgaenge:");
    Serial.println(SVG_durchgaenge);
    if (SVG_durchgaenge >= SVG_number * analog_buffer) {
      SVG_durchgaenge = 0;
      o = 2;
    }
  }
  delete XML_Content;
}

void handleXMLcontent_website() {
  server.send(200, "text/html", Test_ajax_data_html);
}

void handleRoot() {
  Serial.println("Index_html");
  server.send_P(200, "text/html", index_html);
}

void handleCss() {
  Serial.println("Style_Css");
  server.send_P ( 200, "text/css", style_css);
}

void handleAktuell() {
  Serial.println("Aktuell_html");
  server.send_P(200, "text/html", Aktuelle_Messung_html);
}

void handleAlte() {
  server.send_P(200, "text/html", Alte_Messung_html);
}

void handleApp() {
  Serial.println("App_html");
  server.send_P(200, "text/html", App_html);
}

void handleSonstiges() {
  Serial.println("Sonstiges_html");
  server.send_P(200, "text/html", Sonstiges_html);
}

void handleEKG_image() {
  Serial.println("handleEKG_image Aufgerufen");
  server.send_P(200, "image/jpg", ekg_img, sizeof(ekg_img));
  Serial.println("EKG_image Gesendet");
}

void handleTest_svg_data() {
  server.send_P(200, "text/html", Test_svg_data_html);
}

void handleAjaxDaten() {
  server.send_P(200, "text/html", Test_ajax_data_html);
  Serial.println("handleAjaxDaten Aufgerufen");
}

void handleAjaxScript() {
  server.send_P(200, "text/javascript", Javascript_3);
  Serial.println("handleAjaxScript Aufgerufen");
}

void handleDaten() {
  char loeschen[] = "";
  /*HTML Aktuelle Daten --> Aktuelle Daten*/
  char Anfang PROGMEM[] = "<!DOCTYPE html>\n\n<html>\n<head>\n</head>\n<body>\n<h2>Aktuelle Daten</h2>\n";
  char Ende PROGMEM[] = "</body>\n</html>";
  strcpy(SendeBuffer, loeschen);
  strcat(SendeBuffer, Anfang);
  handleTabelle();
  Serial.println("3.Station");
  strcat(SendeBuffer, Ende);
  Serial.println("4.Station");
  Serial.print(SendeBuffer);
  Serial.println("5.Station");
  server.send(200, "text/html", SendeBuffer);
  Serial.println("6.Station");
}

void handleNotFound() {
  String message = "File Not Found\n\n";
  server.send(404, "text/plain", message);
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("You are connected:");
  Serial.println("");
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");

}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    Serial.println(ssid);
    printWifiStatus();
    delay(1000);
  }
  zahlenraushauen();

  server.on("/", handleRoot);
  server.on("/style.css", handleCss);
  server.on("/index.html", handleRoot);
  server.on("/Aktuelle_Messung.html", handleAktuell);
  server.on("/Alte_Messung.html", handleAlte);
  server.on("/App.html", handleApp);
  server.on("/Sonstiges.html", handleSonstiges);
  server.on("/Daten.html", handleDaten);
  server.on("/Test_svg_data.html", handleTest_svg_data);
  server.on("/linie1.svg", handleGraph1);
  server.on("/linie2.svg", handleGraph2);
  server.on("/linie3.svg", handleGraph3);
  server.on("/linie4.svg", handleGraph4);
  server.on("/linie5.svg", handleGraph5);
  server.on("/XML_Content.xml", handleXMLcontent);
  server.on("/Test_ajax_data.html", handleAjaxDaten);
  server.on("/ajax_script.js", handleAjaxScript);
  server.on("/Html.html", handleXMLcontent_website);
  server.on("/img_ekg_theme.jpg", handleEKG_image);

  server.onNotFound(handleNotFound);

  server.begin();
  Serial.println("HTTP server started");
  ITimer0.attachInterruptInterval(5L * 1000, AD_Wandlung_Simulation);
}

void loop() {

  server.handleClient();

}

I got the example to run on the Arduino Nano RP2040 Connect. But it performed worse. It also made me investigate the code a bit more and found an additional issue.

The RP2040 uses mbedOS which is a bit more sensitive to using interrupts wrong. As a rule, you should try to keep interrupt service routines as short as possible and avoid using external interfaces, in your case analogRead and Serial.print any bulky library as well as malloc or new.

I also have a bad feeling about using new for objects 400 bytes in size. With the small amount of RAM you have, the probability increases that a region with this amount of RAM is not available.

I would recommend you move some code into loop.

Regarding the const char I recommend you remove all unnecessary characters. I have seen that some JavaScript libraries ship two versions, one for reading with normal formatting and one minimum version with all characters removed that are not needed for fast web loading.

Regarding the general issue, I would recommend you do some testing with a smaller sketch/html page. When I look at the browser network data there are sometimes long delays for some files and some files fail.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.