<div dir="ltr">Díky,<div><br></div><div>delay jsem dal pryč. Už to funguje. "Multitasking" na arduinu jsem dělal pomocí millis, tady to funguje taky, viz kód níže, ale jak se to dělá elegantněji na ESP32? Pochopil jsem, že když použiji Arduino framework, tak by mělo jít psát přímo s využitím freertos? Omlouvám se za lama dotazy, ale to tam nemusím už nic includovat a rovnou můžu používat něco jako? </div><div><br></div><div>void vATaskFunction( void *pvParameters )</div>    {<br>        for( ;; )<br>        {<br>            -- Task application code here. --<br>        }<br><br>        /* Tasks must not attempt to return from their implementing<br>        function or otherwise exit.  In newer FreeRTOS port<br>        attempting to do so will result in an configASSERT() being<br>        called if it is defined.  If it is necessary for a task to<br>        exit then have the task call vTaskDelete( NULL ) to ensure<br>        its exit is clean. */<br>        vTaskDelete( NULL );<br>    }<div><br></div><div>Potřebuji něco kolem 10 ti tasku, nic náročného, každý se provede do max 1s. Nebo to mám udělat jen pomocí millis? Je potřeba, aby tam na pozadí běžel dash a OTA, takto mi to funguje:<div><br></div><div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Consolas,"Courier New",monospace;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(197,134,192)">#include</span><span style="color:rgb(86,156,214)"> </span><span style="color:rgb(206,145,120)"><Arduino.h></span></div><br><div><span style="color:rgb(106,153,85)">  /* ESP32 Dependencies */</span></div><div><span style="color:rgb(86,156,214)">  </span><span style="color:rgb(197,134,192)">#include</span><span style="color:rgb(86,156,214)"> </span><span style="color:rgb(206,145,120)"><WiFi.h></span></div><div><span style="color:rgb(86,156,214)">  </span><span style="color:rgb(197,134,192)">#include</span><span style="color:rgb(86,156,214)"> </span><span style="color:rgb(206,145,120)"><AsyncTCP.h></span></div><div><span style="color:rgb(86,156,214)">  </span><span style="color:rgb(197,134,192)">#include</span><span style="color:rgb(86,156,214)"> </span><span style="color:rgb(206,145,120)"><ESPAsyncWebServer.h></span></div><br><div><span style="color:rgb(197,134,192)">#include</span><span style="color:rgb(86,156,214)"> </span><span style="color:rgb(206,145,120)"><ESPDash.h></span></div><br><br><div><span style="color:rgb(197,134,192)">#include</span><span style="color:rgb(86,156,214)"> </span><span style="color:rgb(206,145,120)"><WiFiUdp.h></span></div><div><span style="color:rgb(197,134,192)">#include</span><span style="color:rgb(86,156,214)"> </span><span style="color:rgb(206,145,120)"><ArduinoOTA.h></span></div><br><div><span style="color:rgb(197,134,192)">#include</span><span style="color:rgb(86,156,214)"> </span><span style="color:rgb(206,145,120)">"uptime.h"</span></div><div><span style="color:rgb(197,134,192)">#include</span><span style="color:rgb(86,156,214)"> </span><span style="color:rgb(206,145,120)">"uptime_formatter.h"</span></div><br><br><div><span style="color:rgb(106,153,85)">/* Your WiFi Credentials */</span></div><div><span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">char</span>* <span style="color:rgb(156,220,254)">ssid</span> = <span style="color:rgb(206,145,120)">"puhy_iot"</span>;<span style="color:rgb(106,153,85)"> // SSID</span></div><div><span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">char</span>* <span style="color:rgb(156,220,254)">password</span> = <span style="color:rgb(206,145,120)">"iot44puhy"</span>;<span style="color:rgb(106,153,85)"> // Password</span></div><br><br><div><span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">char</span>* <span style="color:rgb(156,220,254)">OTAhostname</span> = <span style="color:rgb(206,145,120)">"ESP-puhy"</span>;</div><br><div><span style="color:rgb(106,153,85)">/* Start Webserver */</span></div><div><span style="color:rgb(78,201,176)">AsyncWebServer</span> <span style="color:rgb(156,220,254)">server</span>(<span style="color:rgb(181,206,168)">80</span>);</div><br><div><span style="color:rgb(106,153,85)">/* Attach ESP-DASH to AsyncWebServer */</span></div><div><span style="color:rgb(78,201,176)">ESPDash</span> <span style="color:rgb(156,220,254)">dashboard</span>(&<span style="color:rgb(156,220,254)">server</span>); </div><br><br><div><span style="color:rgb(106,153,85)">/* </span></div><div><span style="color:rgb(106,153,85)">  Button Card</span></div><div><span style="color:rgb(106,153,85)">  Format - (Dashboard Instance, Card Type, Card Name)</span></div><div><span style="color:rgb(106,153,85)">*/</span></div><div><span style="color:rgb(78,201,176)">Card</span> <span style="color:rgb(156,220,254)">button</span>(&<span style="color:rgb(156,220,254)">dashboard</span>, <span style="color:rgb(78,201,176)">BUTTON_CARD</span>, <span style="color:rgb(206,145,120)">"Zalévej"</span>);</div><div><span style="color:rgb(78,201,176)">Card</span> <span style="color:rgb(156,220,254)">button1</span>(&<span style="color:rgb(156,220,254)">dashboard</span>, <span style="color:rgb(78,201,176)">BUTTON_CARD</span>, <span style="color:rgb(206,145,120)">"Čisti"</span>);</div><div><span style="color:rgb(78,201,176)">Card</span> <span style="color:rgb(156,220,254)">button2</span>(&<span style="color:rgb(156,220,254)">dashboard</span>, <span style="color:rgb(78,201,176)">BUTTON_CARD</span>, <span style="color:rgb(206,145,120)">"Zatop"</span>);</div><br><br><div><span style="color:rgb(78,201,176)">Card</span> <span style="color:rgb(156,220,254)">uptimeCard</span>(&<span style="color:rgb(156,220,254)">dashboard</span>, <span style="color:rgb(78,201,176)">STATUS_CARD</span>, <span style="color:rgb(206,145,120)">"Uptime"</span>, <span style="color:rgb(206,145,120)">"success"</span>);</div><br><br><br><br><div><span style="color:rgb(106,153,85)">/* </span></div><div><span style="color:rgb(106,153,85)">  Slider Card</span></div><div><span style="color:rgb(106,153,85)">  Format - (Dashboard Instance, Card Type, Card Name, Card Symbol(optional), int min, int max)</span></div><div><span style="color:rgb(106,153,85)">*/</span></div><div><span style="color:rgb(78,201,176)">Card</span> <span style="color:rgb(156,220,254)">slider</span>(&<span style="color:rgb(156,220,254)">dashboard</span>, <span style="color:rgb(78,201,176)">SLIDER_CARD</span>, <span style="color:rgb(206,145,120)">"Test Slider"</span>, <span style="color:rgb(206,145,120)">""</span>, <span style="color:rgb(181,206,168)">0</span>, <span style="color:rgb(181,206,168)">255</span>);</div><br><div><span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">int</span> <span style="color:rgb(156,220,254)">ledHeartBeatPin</span> = <span style="color:rgb(181,206,168)">2</span>;</div><div><span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">int</span> <span style="color:rgb(156,220,254)">ledPin</span> = <span style="color:rgb(181,206,168)">5</span>;</div><br><div><span style="color:rgb(106,153,85)">// setting PWM properties</span></div><div><span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">int</span> <span style="color:rgb(156,220,254)">ledPinPWM</span> = <span style="color:rgb(181,206,168)">13</span>;<span style="color:rgb(106,153,85)">  /* GPIO13 */</span></div><div><span style="color:rgb(106,153,85)">//int dutyCycle;</span></div><div><span style="color:rgb(106,153,85)">/* Setting PWM Properties */</span></div><div><span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">int</span> <span style="color:rgb(156,220,254)">PWMFreq</span> = <span style="color:rgb(181,206,168)">5000</span>;<span style="color:rgb(106,153,85)"> /* 5 KHz */</span></div><div><span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">int</span> <span style="color:rgb(156,220,254)">PWMChannel</span> = <span style="color:rgb(181,206,168)">0</span>;</div><div><span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">int</span> <span style="color:rgb(156,220,254)">PWMResolution</span> = <span style="color:rgb(181,206,168)">8</span>;</div><div><span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">int</span> <span style="color:rgb(156,220,254)">MAX_DUTY_CYCLE</span> = (<span style="color:rgb(86,156,214)">int</span>)(<span style="color:rgb(220,220,170)">pow</span>(<span style="color:rgb(181,206,168)">2</span>, <span style="color:rgb(156,220,254)">PWMResolution</span>) - <span style="color:rgb(181,206,168)">1</span>);</div><br><br><div><span style="color:rgb(106,153,85)">// Variables will change:</span></div><div><span style="color:rgb(86,156,214)">int</span> <span style="color:rgb(156,220,254)">ledState</span> = <span style="color:rgb(86,156,214)">LOW</span>;<span style="color:rgb(106,153,85)">             // ledState used to set the LED</span></div><br><div><span style="color:rgb(106,153,85)">// Generally, you should use "unsigned long" for variables that hold time</span></div><div><span style="color:rgb(106,153,85)">// The value will quickly become too large for an int to store</span></div><div><span style="color:rgb(86,156,214)">unsigned</span> <span style="color:rgb(86,156,214)">long</span> <span style="color:rgb(156,220,254)">previousMillis</span> = <span style="color:rgb(181,206,168)">0</span>;<span style="color:rgb(106,153,85)">        // will store last time LED was updated</span></div><br><div><span style="color:rgb(106,153,85)">// constants won't change:</span></div><div><span style="color:rgb(86,156,214)">long</span> <span style="color:rgb(156,220,254)">heartBeatInterval</span> = <span style="color:rgb(181,206,168)">1000</span>;<span style="color:rgb(106,153,85)">           // interval at which to blink (milliseconds)</span></div><br><br><div><span style="color:rgb(86,156,214)">void</span> <span style="color:rgb(220,220,170)">setup</span>() {</div><br><div><span style="color:rgb(220,220,170)">pinMode</span> (<span style="color:rgb(156,220,254)">ledPin</span>, <span style="color:rgb(86,156,214)">OUTPUT</span>);</div><div><span style="color:rgb(220,220,170)">pinMode</span> (<span style="color:rgb(156,220,254)">ledHeartBeatPin</span>, <span style="color:rgb(86,156,214)">OUTPUT</span>);</div><div><span style="color:rgb(220,220,170)">pinMode</span> (<span style="color:rgb(156,220,254)">ledPinPWM</span>, <span style="color:rgb(86,156,214)">OUTPUT</span>);</div><br><div>  <span style="color:rgb(220,220,170)">ledcSetup</span>(<span style="color:rgb(156,220,254)">PWMChannel</span>, <span style="color:rgb(156,220,254)">PWMFreq</span>, <span style="color:rgb(156,220,254)">PWMResolution</span>);</div><div><span style="color:rgb(106,153,85)">  /* Attach the LED PWM Channel to the GPIO Pin */</span></div><div>  <span style="color:rgb(220,220,170)">ledcAttachPin</span>(<span style="color:rgb(156,220,254)">ledPinPWM</span>, <span style="color:rgb(156,220,254)">PWMChannel</span>);</div><br><br><div>  <span style="color:rgb(156,220,254)">Serial</span>.<span style="color:rgb(220,220,170)">begin</span>(<span style="color:rgb(181,206,168)">115200</span>);</div><br><div><span style="color:rgb(106,153,85)">  /* Connect WiFi */</span></div><div>  <span style="color:rgb(156,220,254)">WiFi</span>.<span style="color:rgb(220,220,170)">mode</span>(<span style="color:rgb(86,156,214)">WIFI_STA</span>);</div><div>  <span style="color:rgb(156,220,254)">WiFi</span>.<span style="color:rgb(220,220,170)">begin</span>(<span style="color:rgb(156,220,254)">ssid</span>, <span style="color:rgb(156,220,254)">password</span>);</div><div>  <span style="color:rgb(197,134,192)">if</span> (<span style="color:rgb(156,220,254)">WiFi</span>.<span style="color:rgb(220,220,170)">waitForConnectResult</span>() != <span style="color:rgb(79,193,255)">WL_CONNECTED</span>) {</div><div>      <span style="color:rgb(156,220,254)">Serial</span>.<span style="color:rgb(220,220,170)">printf</span>(<span style="color:rgb(206,145,120)">"WiFi Failed!</span><span style="color:rgb(215,186,125)">\n</span><span style="color:rgb(206,145,120)">"</span>);</div><div>      <span style="color:rgb(197,134,192)">return</span>;</div><div>  }</div><div>  <span style="color:rgb(156,220,254)">Serial</span>.<span style="color:rgb(220,220,170)">print</span>(<span style="color:rgb(206,145,120)">"IP Address: "</span>);</div><div>  <span style="color:rgb(156,220,254)">Serial</span>.<span style="color:rgb(220,220,170)">println</span>(<span style="color:rgb(156,220,254)">WiFi</span>.<span style="color:rgb(220,220,170)">localIP</span>());</div><br><div><span style="color:rgb(106,153,85)">  /* Attach Button Callback */</span></div><div>  <span style="color:rgb(156,220,254)">button</span>.<span style="color:rgb(220,220,170)">attachCallback</span>([&](<span style="color:rgb(86,156,214)">bool</span> <span style="color:rgb(156,220,254)">value</span>){</div><div><span style="color:rgb(106,153,85)">    /* Print our new button value received from dashboard */</span></div><div>    <span style="color:rgb(156,220,254)">Serial</span>.<span style="color:rgb(220,220,170)">println</span>(<span style="color:rgb(206,145,120)">"Button Triggered: "</span><span style="color:rgb(220,220,170)">+</span><span style="color:rgb(78,201,176)">String</span>((<span style="color:rgb(156,220,254)">value</span>)?<span style="color:rgb(206,145,120)">"true"</span>:<span style="color:rgb(206,145,120)">"false"</span>));</div><div><span style="color:rgb(106,153,85)">    /* Make sure we update our button's value and send update to dashboard */</span></div><div>    <span style="color:rgb(156,220,254)">button</span>.<span style="color:rgb(220,220,170)">update</span>(<span style="color:rgb(156,220,254)">value</span>);</div><div>    <span style="color:rgb(220,220,170)">digitalWrite</span> (<span style="color:rgb(156,220,254)">ledPin</span>, <span style="color:rgb(156,220,254)">value</span>);</div><div>    <span style="color:rgb(156,220,254)">dashboard</span>.<span style="color:rgb(220,220,170)">sendUpdates</span>();</div><div>  });</div><br><div><span style="color:rgb(106,153,85)">  /* Attach Slider Callback */</span></div><div>  <span style="color:rgb(156,220,254)">slider</span>.<span style="color:rgb(220,220,170)">attachCallback</span>([&](<span style="color:rgb(86,156,214)">int</span> <span style="color:rgb(156,220,254)">value</span>){</div><div><span style="color:rgb(106,153,85)">    /* Print our new slider value received from dashboard */</span></div><div>    <span style="color:rgb(156,220,254)">Serial</span>.<span style="color:rgb(220,220,170)">println</span>(<span style="color:rgb(206,145,120)">"Slider Triggered: "</span><span style="color:rgb(220,220,170)">+</span><span style="color:rgb(78,201,176)">String</span>(<span style="color:rgb(156,220,254)">value</span>));</div><div><span style="color:rgb(106,153,85)">    /* Make sure we update our slider's value and send update to dashboard */</span></div><div>    <span style="color:rgb(156,220,254)">slider</span>.<span style="color:rgb(220,220,170)">update</span>(<span style="color:rgb(156,220,254)">value</span>);</div><div>    <span style="color:rgb(220,220,170)">ledcWrite</span>(<span style="color:rgb(156,220,254)">PWMChannel</span>, <span style="color:rgb(156,220,254)">value</span>);</div><div>    <span style="color:rgb(156,220,254)">dashboard</span>.<span style="color:rgb(220,220,170)">sendUpdates</span>();</div><div>  });</div><br><div><span style="color:rgb(106,153,85)">  /* Start AsyncWebServer */</span></div><div>  <span style="color:rgb(156,220,254)">server</span>.<span style="color:rgb(220,220,170)">begin</span>();</div><br><br><div><span style="color:rgb(156,220,254)">ArduinoOTA</span>.<span style="color:rgb(220,220,170)">setHostname</span>(<span style="color:rgb(156,220,254)">OTAhostname</span>);</div><div>  <span style="color:rgb(156,220,254)">ArduinoOTA</span>.<span style="color:rgb(220,220,170)">onStart</span>([]()</div><div>  {</div><div>    <span style="color:rgb(156,220,254)">Serial</span>.<span style="color:rgb(220,220,170)">println</span>(<span style="color:rgb(206,145,120)">"Start"</span>);</div><div>  });</div><div>  <span style="color:rgb(156,220,254)">ArduinoOTA</span>.<span style="color:rgb(220,220,170)">onEnd</span>([]()</div><div>  {</div><div>    <span style="color:rgb(156,220,254)">Serial</span>.<span style="color:rgb(220,220,170)">println</span>(<span style="color:rgb(206,145,120)">"</span><span style="color:rgb(215,186,125)">\n</span><span style="color:rgb(206,145,120)">End"</span>);</div><div>  });</div><div>  <span style="color:rgb(156,220,254)">ArduinoOTA</span>.<span style="color:rgb(220,220,170)">onProgress</span>([](<span style="color:rgb(86,156,214)">unsigned</span> <span style="color:rgb(86,156,214)">int</span> <span style="color:rgb(156,220,254)">progress</span>, <span style="color:rgb(86,156,214)">unsigned</span> <span style="color:rgb(86,156,214)">int</span> <span style="color:rgb(156,220,254)">total</span>)</div><div>  {</div><div>    <span style="color:rgb(156,220,254)">Serial</span>.<span style="color:rgb(220,220,170)">printf</span>(<span style="color:rgb(206,145,120)">"Progress: %u%%</span><span style="color:rgb(215,186,125)">\r</span><span style="color:rgb(206,145,120)">"</span>, (<span style="color:rgb(156,220,254)">progress</span> / (<span style="color:rgb(156,220,254)">total</span> / <span style="color:rgb(181,206,168)">100</span>)));</div><div>  });</div><div>  <span style="color:rgb(156,220,254)">ArduinoOTA</span>.<span style="color:rgb(220,220,170)">onError</span>([](<span style="color:rgb(78,201,176)">ota_error_t</span> <span style="color:rgb(156,220,254)">error</span>)</div><div>  {</div><div>    <span style="color:rgb(156,220,254)">Serial</span>.<span style="color:rgb(220,220,170)">printf</span>(<span style="color:rgb(206,145,120)">"Error[%u]: "</span>, <span style="color:rgb(156,220,254)">error</span>);</div><div>    <span style="color:rgb(197,134,192)">if</span> (<span style="color:rgb(156,220,254)">error</span> == <span style="color:rgb(79,193,255)">OTA_AUTH_ERROR</span>) <span style="color:rgb(156,220,254)">Serial</span>.<span style="color:rgb(220,220,170)">println</span>(<span style="color:rgb(206,145,120)">"Auth Failed"</span>);</div><div>    <span style="color:rgb(197,134,192)">else</span> <span style="color:rgb(197,134,192)">if</span> (<span style="color:rgb(156,220,254)">error</span> == <span style="color:rgb(79,193,255)">OTA_BEGIN_ERROR</span>) <span style="color:rgb(156,220,254)">Serial</span>.<span style="color:rgb(220,220,170)">println</span>(<span style="color:rgb(206,145,120)">"Begin Failed"</span>);</div><div>    <span style="color:rgb(197,134,192)">else</span> <span style="color:rgb(197,134,192)">if</span> (<span style="color:rgb(156,220,254)">error</span> == <span style="color:rgb(79,193,255)">OTA_CONNECT_ERROR</span>) <span style="color:rgb(156,220,254)">Serial</span>.<span style="color:rgb(220,220,170)">println</span>(<span style="color:rgb(206,145,120)">"Connect Failed"</span>);</div><div>    <span style="color:rgb(197,134,192)">else</span> <span style="color:rgb(197,134,192)">if</span> (<span style="color:rgb(156,220,254)">error</span> == <span style="color:rgb(79,193,255)">OTA_RECEIVE_ERROR</span>) <span style="color:rgb(156,220,254)">Serial</span>.<span style="color:rgb(220,220,170)">println</span>(<span style="color:rgb(206,145,120)">"Receive Failed"</span>);</div><div>    <span style="color:rgb(197,134,192)">else</span> <span style="color:rgb(197,134,192)">if</span> (<span style="color:rgb(156,220,254)">error</span> == <span style="color:rgb(79,193,255)">OTA_END_ERROR</span>) <span style="color:rgb(156,220,254)">Serial</span>.<span style="color:rgb(220,220,170)">println</span>(<span style="color:rgb(206,145,120)">"End Failed"</span>);</div><div>  });</div><div>  <span style="color:rgb(156,220,254)">ArduinoOTA</span>.<span style="color:rgb(220,220,170)">begin</span>();</div><br><br><div>}</div></div></div><div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Consolas,"Courier New",monospace;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(86,156,214)">void</span> <span style="color:rgb(220,220,170)">loop</span>() {</div><div><span style="color:rgb(106,153,85)">  /* Nothing so far */</span></div><div> <span style="color:rgb(156,220,254)">ArduinoOTA</span>.<span style="color:rgb(220,220,170)">handle</span>();</div><br><div><span style="color:rgb(106,153,85)">  // here is where you'd put code that needs to be running all the time.</span></div><br><div><span style="color:rgb(106,153,85)">  // check to see if it's time to blink the LED; that is, if the difference</span></div><div><span style="color:rgb(106,153,85)">  // between the current time and last time you blinked the LED is bigger than</span></div><div><span style="color:rgb(106,153,85)">  // the interval at which you want to blink the LED.</span></div><div>  <span style="color:rgb(86,156,214)">unsigned</span> <span style="color:rgb(86,156,214)">long</span> <span style="color:rgb(156,220,254)">currentMillis</span> = <span style="color:rgb(220,220,170)">millis</span>();</div><br><div>  <span style="color:rgb(197,134,192)">if</span> (<span style="color:rgb(156,220,254)">currentMillis</span> - <span style="color:rgb(156,220,254)">previousMillis</span> >= <span style="color:rgb(156,220,254)">heartBeatInterval</span>) {</div><div><span style="color:rgb(106,153,85)">    // save the last time you blinked the LED</span></div><div>    <span style="color:rgb(156,220,254)">previousMillis</span> = <span style="color:rgb(156,220,254)">currentMillis</span>;</div><br><div><span style="color:rgb(106,153,85)">    // if the LED is off turn it on and vice-versa:</span></div><div>    <span style="color:rgb(197,134,192)">if</span> (<span style="color:rgb(156,220,254)">ledState</span> == <span style="color:rgb(86,156,214)">LOW</span>) {</div><div>      <span style="color:rgb(156,220,254)">ledState</span> = <span style="color:rgb(86,156,214)">HIGH</span>;</div><div>      <span style="color:rgb(156,220,254)">heartBeatInterval</span> = <span style="color:rgb(181,206,168)">2500</span>;</div><div>    } <span style="color:rgb(197,134,192)">else</span> {</div><div>      <span style="color:rgb(156,220,254)">heartBeatInterval</span> = <span style="color:rgb(181,206,168)">20</span>;</div><div>      <span style="color:rgb(156,220,254)">ledState</span> = <span style="color:rgb(86,156,214)">LOW</span>;</div><div>    }</div><br><div><span style="color:rgb(106,153,85)">    // set the LED with the ledState of the variable:</span></div><div>    <span style="color:rgb(220,220,170)">digitalWrite</span>(<span style="color:rgb(156,220,254)">ledHeartBeatPin</span>, <span style="color:rgb(156,220,254)">ledState</span>);</div><br><div><span style="color:rgb(156,220,254)">Serial</span>.<span style="color:rgb(220,220,170)">println</span>(<span style="color:rgb(78,201,176)">uptime_formatter</span>::<span style="color:rgb(220,220,170)">getUptime</span>());</div><br><div><span style="color:rgb(156,220,254)">uptimeCard</span>.<span style="color:rgb(220,220,170)">update</span>(<span style="color:rgb(78,201,176)">uptime_formatter</span>::<span style="color:rgb(220,220,170)">getUptime</span>());</div><br><br><div>  }</div></div></div><div><br></div><div><br></div><div><div><div dir="ltr" data-smartmail="gmail_signature"><div dir="ltr"><div dir="ltr"><div>Díky za podporu.</div><div><br></div><div>HP</div><div><br></div><div></div></div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">pá 28. 5. 2021 v 6:10 odesílatel Pavel Brychta <<a href="mailto:pavel.brychta@duhasys.eu" target="_blank">pavel.brychta@duhasys.eu</a>> napsal:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  
    
  
  <div>
    <p>DD,</p>
    <p>ano, handler se dává do loop(), ale doporučuju odstranit ten
      nešťastný delay() i když to zrovna nemusí být zdroj problému.
      Potíž je v tom, že nepíšete jak se projevuje to, že to nefunguje -
      pokud upoad proběhne, ale podezřele rychle a firmware se ve
      skutečnosti nenahraje, tak je to tím, že jste nevymazal paměť
      flash (pio run -t erase) a to ESP má uloženou jinou partition
      tabulku. Vždycky, když nahrávám do nového modulu, tak udělám výmaz
      flash a teprve pak nahraju první firmware. Já prakticky výhradně
      používám Wrover 16MB moduly s trošku upravenou vnitřní konfigurací
      a všechny tyto úpravy dělám v přípravku mimo zařízení před
      osazením (reklamní linka <a href="https://s.click.aliexpress.com/e/_9j8PIP" target="_blank">https://s.click.aliexpress.com/e/_9j8PIP</a>
      ).</p>
    <p>P.B.<br>
    </p>
    <div>Dne 27. 05. 21 v 23:22 Jan Půhoný
      napsal(a):<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">
        <div>
          <div dir="ltr">
            <div dir="ltr">
              <div>Dobrý večer,</div>
              <div><br>
              </div>
              <div>ten ESPDash je super. Ještě jednou díky za tip.
                Ohledně těch WDT asi tam dám i ten externí, bude potřeba
                ale časovat někde kolem 1minuty, aby to nezabíralo v
                případě update firmware.</div>
              <div><br>
              </div>
              <div>Trochu se s trápím s tím, jak zkombinovat svůj kód s
                OTA update. Funguje mi jen jedno nebo druhé, ale
                dohromady ne.</div>
              <div><br>
              </div>
              <div>Když to napíšu takto z(viz níže), tak OTA je vidět
                (např. v Arduino IDE) ale nejde nic nahrát. Testoval
                jsem jak Arduino IDE, tak platformio.</div>
              <div><br>
              </div>
              <div><img src="cid:179b1d3c397cb971f161" alt="image.png" width="277" height="43"><br>
              </div>
              <div><br>
              </div>
              <div>Když tam dám jen příklad OTA tak upload normálně
                funguje, když tam dám jen ESPDash, normálně to funguje.
                Ale dohromady ne. </div>
              <div><br>
              </div>
              <div>Píše se ten OTA handler opravdu do loop?</div>
              <div><br>
                #include <Arduino.h><br>
                #if defined(ESP8266)<br>
                  /* ESP8266 Dependencies */<br>
                  #include <ESP8266WiFi.h><br>
                  #include <ESPAsyncTCP.h><br>
                  #include <ESPAsyncWebServer.h><br>
                #elif defined(ESP32)<br>
                  /* ESP32 Dependencies */<br>
                  #include <WiFi.h><br>
                  #include <AsyncTCP.h><br>
                  #include <ESPAsyncWebServer.h><br>
                #endif<br>
                #include <ESPDash.h><br>
                <br>
                <br>
                #include <WiFiUdp.h><br>
                <b>#include <ArduinoOTA.h></b><br>
                <br>
                /* Your WiFi Credentials */<br>
                const char* ssid = "******"; // SSID<br>
                const char* password = "******"; // Password<br>
                <br>
                const char* OTAhostname = "ESP-puhy";<br>
                <br>
                /* Start Webserver */<br>
                AsyncWebServer server(80);<br>
                <br>
                /* Attach ESP-DASH to AsyncWebServer */<br>
                ESPDash dashboard(&server); <br>
                <br>
                /* <br>
                  Button Card<br>
                  Format - (Dashboard Instance, Card Type, Card Name)<br>
                */<br>
                Card button(&dashboard, BUTTON_CARD, "Test Button");<br>
                <br>
                /* <br>
                  Slider Card<br>
                  Format - (Dashboard Instance, Card Type, Card Name,
                Card Symbol(optional), int min, int max)<br>
                */<br>
                Card slider(&dashboard, SLIDER_CARD, "Test Slider",
                "", 0, 255);<br>
                <br>
                <br>
                void setup() {<br>
                  Serial.begin(115200);<br>
                <br>
                  /* Connect WiFi */<br>
                  WiFi.mode(WIFI_STA);<br>
                  WiFi.begin(ssid, password);<br>
                  if (WiFi.waitForConnectResult() != WL_CONNECTED) {<br>
                      Serial.printf("WiFi Failed!\n");<br>
                      return;<br>
                  }<br>
                  Serial.print("IP Address: ");<br>
                  Serial.println(WiFi.localIP());<br>
                <br>
                  /* Attach Button Callback */<br>
                  button.attachCallback([&](bool value){<br>
                    /* Print our new button value received from
                dashboard */<br>
                    Serial.println("Button Triggered:
                "+String((value)?"true":"false"));<br>
                    /* Make sure we update our button's value and send
                update to dashboard */<br>
                    button.update(value);<br>
                    dashboard.sendUpdates();<br>
                  });<br>
                <br>
                  /* Attach Slider Callback */<br>
                  slider.attachCallback([&](int value){<br>
                    /* Print our new slider value received from
                dashboard */<br>
                    Serial.println("Slider Triggered: "+String(value));<br>
                    /* Make sure we update our slider's value and send
                update to dashboard */<br>
                    slider.update(value);<br>
                    dashboard.sendUpdates();<br>
                  });<br>
                <br>
                  /* Start AsyncWebServer */<br>
                  server.begin();<br>
                <br>
                ArduinoOTA.setHostname(OTAhostname);<br>
                  ArduinoOTA.onStart([]()<br>
                  {<br>
                    Serial.println("Start");<br>
                  });<br>
                  ArduinoOTA.onEnd([]()<br>
                  {<br>
                    Serial.println("\nEnd");<br>
                  });<br>
                  ArduinoOTA.onProgress([](unsigned int progress,
                unsigned int total)<br>
                  {<br>
                    Serial.printf("Progress: %u%%\r", (progress / (total
                / 100)));<br>
                  });<br>
                  ArduinoOTA.onError([](ota_error_t error)<br>
                  {<br>
                    Serial.printf("Error[%u]: ", error);<br>
                    if (error == OTA_AUTH_ERROR) Serial.println("Auth
                Failed");<br>
                    else if (error == OTA_BEGIN_ERROR)
                Serial.println("Begin Failed");<br>
                    else if (error == OTA_CONNECT_ERROR)
                Serial.println("Connect Failed");<br>
                    else if (error == OTA_RECEIVE_ERROR)
                Serial.println("Receive Failed");<br>
                    else if (error == OTA_END_ERROR) Serial.println("End
                Failed");<br>
                  });<br>
                  ArduinoOTA.begin();<br>
                }<br>
                <br>
                void loop() {<br>
                  /* Nothing so far */<br>
                <b> ArduinoOTA.handle();</b><br>
                <br>
                 delay(5000);<br>
                <br>
                }<br>
              </div>
              <div><br>
              </div>
              <div>Díky,</div>
              <div><br>
              </div>
              <div>HP</div>
              <div><br>
              </div>
            </div>
          </div>
        </div>
        <br>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">st 26. 5. 2021 v 13:45
          odesílatel Pavel Brychta <<a href="mailto:pavel.brychta@duhasys.eu" target="_blank">pavel.brychta@duhasys.eu</a>>
          napsal:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          <div>
            <p>Co se týče WDT, tak fakt nevím - mě zatím vždycky stačil
              vnitřní v ESP32 (má i brownout detector, který už jsem
              také viděl zabrat). Zařízení mi běží 24/7. Expandér můžu
              doporučit místo toho PCF raději MCP23008 (nebo 16, pokud
              je 8 GPIO málo) - minimálně z toho důvodu, že má
              asynchronní reset, takže po resetu jsou GPIO v
              definovaných stavech.</p>
            <p>P.B.<br>
            </p>
            <div>Dne 26. 05. 21 v 13:30 Jan Půhoný napsal(a):<br>
            </div>
            <blockquote type="cite">
              <div dir="ltr">Díky za reakce. Jde mi o to mít to co
                nejvíce low level. Opravdu do toho nechci tahat RasPi.
                Musí to jet i když nepůjde wifi a s tou Atmegou to drží
                roky až se divím. 
                <div><br>
                </div>
                <div>Maximálně do budoucna můžu přidat nějakou
                  vizualizaci na něčem jako RasPi, ale to spíš už přímo
                  posílat requesty na www a ukládat do MySQL. Potřebuji
                  aby ta logika byla spolehlivá. Ano, mám na tom rybičky
                  a čerpadlo topení ( a taky zalévání na zahradě a
                  vodoměr a zvonky a fakt hodně blbostí :-)
                  <div><br>
                  </div>
                  <div>Atmega s watchdogem to zatím pár let dala bez
                    ztráty kytičky, uptime tam přetékal bez toho aby se
                    to nějak resetovalo nebo tak něco.</div>
                  <div><br>
                  </div>
                  <div>Mám to vše jakoby centralizované u hlavního
                    rozvaděče, takže nepotřebuji bezdrátové nody po
                    domě, jde mi o to nahradit tu AtMegu něčím
                    výkonnějším.</div>
                  <div><br>
                  </div>
                  <div>Budu tam potřebovat hodně I/O, je dobrý nápad k
                    tomu ESP32 dávat pár PCF8574 jako I/O expander nebo
                    je něco robusnějšího?</div>
                  <div><br>
                  </div>
                  <div>A další věc, je potřeba k ESP32 dávat externí
                    WDT?</div>
                  <div><br>
                  </div>
                  <div>
                    <div>
                      <div>
                        <div dir="ltr">
                          <div dir="ltr">
                            <div>
                              <div dir="ltr">
                                <div>HP</div>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                      <br>
                    </div>
                  </div>
                </div>
              </div>
              <br>
              <div class="gmail_quote">
                <div dir="ltr" class="gmail_attr">st 26. 5. 2021 v 11:47
                  odesílatel Pavel Brychta <<a href="mailto:pavel.brychta@duhasys.eu" target="_blank">pavel.brychta@duhasys.eu</a>>
                  napsal:<br>
                </div>
                <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Tak zrovna to je
                  exemplární případ, jak to určitě nedělat. Zde <br>
                  <a href="https://github.com/Alextros00/ESP32-MQTT-Relay-Control/blob/main/main/app_main.c" rel="noreferrer" target="_blank">https://github.com/Alextros00/ESP32-MQTT-Relay-Control/blob/main/main/app_main.c</a>
                  <br>
                  není jediná zmínka, nebo náznak řešení nějakého
                  failsafe mechanizmu. <br>
                  Celé to je na úrovni primitivního Arduino example,
                  který se s detaily <br>
                  jako je třeba jméno topcu vůbec nezalamuje. MQTT
                  failsafe samo o sobě <br>
                  nevyřeší ani omylem.<br>
                  <br>
                  P.B.<br>
                  <br>
                  Dne 26. 05. 21 v 11:28 T. Meinlschmidt napsal(a):<br>
                  > proto pisu mqtt. esp32 tu podporu mqtt ma pomerne
                  slusnou. viz treba <br>
                  > takovy easy priklad<br>
                  ><br>
                  > <a href="https://github.com/Alextros00/Home-Automation-NodeRED-ESP-Telegram" rel="noreferrer" target="_blank">https://github.com/Alextros00/Home-Automation-NodeRED-ESP-Telegram</a><br>
                  ><br>
                  > tm<br>
                  ><br>
                  > Dne 2021-05-26 10:54, Pavel Brychta napsal:<br>
                  >> ... až na to, že když pak lehne to Pi, nebo
                  WiFi, tak zůstane třeba<br>
                  >> čerpadlo běžet stále, nebo uvaříte rybičky.
                  Přiznám se, že takovouto<br>
                  >> cestou bych nikdy nešel, protože to znamená
                  mít failsafe procesy v ESP<br>
                  >> a řídící logiku jinde, což pro účely
                  automatizace považuji za hodně<br>
                  >> nešťastné řešení. Když už, tak autonomní
                  pocesy na zařízení a API pro<br>
                  >> parametrizaci do toho rPi...<br>
                  >><br>
                  >> P.B.<br>
                  >><br>
                  >> Dne 26. 05. 21 v 10:49 T. Meinlschmidt
                  napsal(a):<br>
                  >>> dobre dopoledne.<br>
                  >>><br>
                  >>> ja se priznam, ze bych vubec nesel touhle
                  cestou, ale mel ESP ciste <br>
                  >>> na hw veci a sber nejakych dat,<br>
                  >>> a celou tu logiku nechal v node-red +
                  mqtt (treba na rpi). Casem na <br>
                  >>> to muzete navazat mobil, UI si udelate
                  podle sebe pomerne jednoduse, <br>
                  >>> navic to umi spoustu veci z jinych
                  zdroju.<br>
                  >>><br>
                  >>> tm<br>
                  >>><br>
                  >>> Dne 2021-05-26 10:32, Jan Půhoný napsal:<br>
                  >>>> Dobré dopoledne,<br>
                  >>>><br>
                  >>>> Ještě bych potřeboval poradit co
                  použít za systém na ESP32.<br>
                  >>>> Jedná se mi o to, že do ESP32
                  přepisuji z Atmegy 2560 něco jako<br>
                  >>>> řízení topení a různých zdrojů tepla
                  a různých hejblátek<br>
                  >>>> doma. Do teď to běží na ATMEGA 2560 a
                  mám tam jednoduchý<br>
                  >>>> "multitasking" pomocí millis. Jedná
                  se v podstatě jen o čtení<br>
                  >>>> teplotních čidel, webserver a pak
                  různé výstupy v podobě SSR<br>
                  >>>> relé + vstupy a logika mezi tím. Nic
                  složitého. Na druhou stranu<br>
                  >>>> za ty roky to celkem naboptnalo co se
                  kódu týče a ten webserver na<br>
                  >>>> té AT2560 je takový dost líný. Navíc
                  tam potřebuji číst http<br>
                  >>>> requesty data z komerční meteostanice
                  a na to už to moc není.<br>
                  >>>><br>
                  >>>> Neexistuje nějaký opensource projekt
                  na ESP32, kde by byly<br>
                  >>>> vyřešeny základní věci jako webserver
                  + nějaká grafika a<br>
                  >>>> hejblátka abych to nemusel psát úplně
                  od začátku. Líbilo by se<br>
                  >>>> mi už https a základní struktura a
                  dopsal bych si do toho jen tu<br>
                  >>>> vlastní logiku a ovládání vstupů a
                  výstupů.<br>
                  >>>><br>
                  >>>> Je dobrý nápad na to ESP dávat
                  FreeRTOS, nebo to už je překonané<br>
                  >>>> a používáte něco lepšího? Případně
                  víte o nějakém open<br>
                  >>>> source projektu pro domácí
                  automatizaci pro ESP32?<br>
                  >>>><br>
                  >>>> Ano, googlil jsem, ale serp je
                  zaplaven videi geeků kteří připojí<br>
                  >>>> k pár relátkům esp a myslí si co
                  nevymysleli a trochu se v tom<br>
                  >>>> ztrácím. Já bych potřeboval něco
                  trochu robusnějšího.<br>
                  >>>><br>
                  >>>> Díky za nápady.<br>
                  >>>><br>
                  >>>> HP<br>
                  >>>>
                  _______________________________________________<br>
                  >>>> HW-list mailing list  -  sponsored by
                  <a href="http://www.HW.cz" rel="noreferrer" target="_blank">www.HW.cz</a><br>
                  >>>> <a href="mailto:Hw-list@list.hw.cz" target="_blank">Hw-list@list.hw.cz</a><br>
                  >>>> <a href="http://list.hw.cz/mailman/listinfo/hw-list" rel="noreferrer" target="_blank">http://list.hw.cz/mailman/listinfo/hw-list</a><br>
                  >>>
                  _______________________________________________<br>
                  >>> HW-list mailing list  -  sponsored by <a href="http://www.HW.cz" rel="noreferrer" target="_blank">www.HW.cz</a><br>
                  >>> <a href="mailto:Hw-list@list.hw.cz" target="_blank">Hw-list@list.hw.cz</a><br>
                  >>> <a href="http://list.hw.cz/mailman/listinfo/hw-list" rel="noreferrer" target="_blank">http://list.hw.cz/mailman/listinfo/hw-list</a><br>
                  >>
                  _______________________________________________<br>
                  >> HW-list mailing list  -  sponsored by <a href="http://www.HW.cz" rel="noreferrer" target="_blank">www.HW.cz</a><br>
                  >> <a href="mailto:Hw-list@list.hw.cz" target="_blank">Hw-list@list.hw.cz</a><br>
                  >> <a href="http://list.hw.cz/mailman/listinfo/hw-list" rel="noreferrer" target="_blank">http://list.hw.cz/mailman/listinfo/hw-list</a><br>
                  > _______________________________________________<br>
                  > HW-list mailing list  -  sponsored by <a href="http://www.HW.cz" rel="noreferrer" target="_blank">www.HW.cz</a><br>
                  > <a href="mailto:Hw-list@list.hw.cz" target="_blank">Hw-list@list.hw.cz</a><br>
                  > <a href="http://list.hw.cz/mailman/listinfo/hw-list" rel="noreferrer" target="_blank">http://list.hw.cz/mailman/listinfo/hw-list</a><br>
                  _______________________________________________<br>
                  HW-list mailing list  -  sponsored by <a href="http://www.HW.cz" rel="noreferrer" target="_blank">www.HW.cz</a><br>
                  <a href="mailto:Hw-list@list.hw.cz" target="_blank">Hw-list@list.hw.cz</a><br>
                  <a href="http://list.hw.cz/mailman/listinfo/hw-list" rel="noreferrer" target="_blank">http://list.hw.cz/mailman/listinfo/hw-list</a><br>
                </blockquote>
              </div>
              <br>
              <fieldset></fieldset>
              <pre>_______________________________________________
HW-list mailing list  -  sponsored by <a href="http://www.HW.cz" target="_blank">www.HW.cz</a>
<a href="mailto:Hw-list@list.hw.cz" target="_blank">Hw-list@list.hw.cz</a>
<a href="http://list.hw.cz/mailman/listinfo/hw-list" target="_blank">http://list.hw.cz/mailman/listinfo/hw-list</a>
</pre>
            </blockquote>
          </div>
          _______________________________________________<br>
          HW-list mailing list  -  sponsored by <a href="http://www.HW.cz" rel="noreferrer" target="_blank">www.HW.cz</a><br>
          <a href="mailto:Hw-list@list.hw.cz" target="_blank">Hw-list@list.hw.cz</a><br>
          <a href="http://list.hw.cz/mailman/listinfo/hw-list" rel="noreferrer" target="_blank">http://list.hw.cz/mailman/listinfo/hw-list</a><br>
        </blockquote>
      </div>
      <br>
      <fieldset></fieldset>
      <pre>_______________________________________________
HW-list mailing list  -  sponsored by <a href="http://www.HW.cz" target="_blank">www.HW.cz</a>
<a href="mailto:Hw-list@list.hw.cz" target="_blank">Hw-list@list.hw.cz</a>
<a href="http://list.hw.cz/mailman/listinfo/hw-list" target="_blank">http://list.hw.cz/mailman/listinfo/hw-list</a>
</pre>
    </blockquote>
  </div>

_______________________________________________<br>
HW-list mailing list  -  sponsored by <a href="http://www.HW.cz" rel="noreferrer" target="_blank">www.HW.cz</a><br>
<a href="mailto:Hw-list@list.hw.cz" target="_blank">Hw-list@list.hw.cz</a><br>
<a href="http://list.hw.cz/mailman/listinfo/hw-list" rel="noreferrer" target="_blank">http://list.hw.cz/mailman/listinfo/hw-list</a><br>
</blockquote></div></div></div>