Note that there are some explanatory texts on larger screens.

plurals
  1. POArduino: turn on and off ethernet server availability
    primarykey
    data
    text
    <p>I need to setup an ethernet (web) server that have to be turned on and off depending on some conditions on the Arduino UNO.</p> <p>I read the docs of the <code>Server</code> class in the <a href="http://www.arduino.cc/en/Reference/Ethernet" rel="nofollow"><code>Ethernet</code> library</a> and it seems there is no chance to stop the server once you started, i.e. there is no <code>EthernetServer.begin()</code> counterpart.</p> <p>I thought then to setup the server in the <code>setup</code> section and serve incoming connections depending on when the given condition:</p> <pre><code>EthernetServer server = EthernetServer(80); void setup() { Ethernet.begin(mac, ip); server.begin(); } void loop() { if (condition) { EthernetClient client = server.available(); if (client == true) { // serve the client... } } else { // do something else } } </code></pre> <p>This indeed works, but the client is not properly rejected: it is just leaved pending. In the browser one can see the web page loading idefinitely, and if the condition turns to <code>true</code> the client will eventually be served for the request issued when the condition was <code>false</code>.</p> <p>I see no methods for rejecting the request (there is no counterpart of <code>EthernetServer.available()</code>). The only thing that comes to my mind is to perform a</p> <pre><code>server.available().stop(); </code></pre> <p>in the beginning of the else block. This prevent to serve requests issued while the condition was <code>false</code>, but doesn't prevent the connection between the client and the server to take place (it's like opening a connection and shut it down immediately).</p> <p>How could I avoid to establish connections at all while the condition is <code>false</code>?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload