title: How to send data from my website to my Arduino netshield
body: <p>I want to for example turn LEDs on or off via website interface, but my main problem is that whenever I search for solutions every one is doing it via making the NetShield itself as the server and host the website from it, but I want to host the website on my own pc and when I click a button that action will send some data to the Arduino and I will read the data and turn on the LED.</p>
  
  <p>I've tried with jQuery which is sending an HTTP POST request, but via close inspection the shield gives HTTP response 405 which after I read it seems that NetShield is not allowing modifying requests, so I've tried with HTTP GET but when I click the button nothing really goes to Arduino.</p>
  
  <p>Btw everything about the network is correct and every port/firewall rule is open that it needs</p>
  
  <p>Here is the HTML of the website:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;AgroSystem&lt;/title&gt;
          &lt;link rel="icon" href="/res/IconRaster.png" type="image/png"&gt;
          &lt;meta name="keywords" content="HTML, CSS, XML, XHTML, JavaScript, Agro, System, Agriculture, Zemedelie, Mashina, Auto, Network, Arduino, Better, Fast, Automatic, Farm, Farming"&gt;
          &lt;meta name="author" content="Danislav Chengeliev"&gt;
          &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
          &lt;script src="lib/jquery/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"&gt;&lt;/script&gt;
          &lt;script src="src/script.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div&gt;
              &lt;strong&gt;&lt;h1&gt;Лампи&lt;/h1&gt;&lt;/strong&gt;
              &lt;ul&gt;
                  &lt;a href="" id="button-lamps-start"&gt;&lt;li&gt;Старт&lt;/li&gt;&lt;/a&gt;
                  &lt;a href="" id="button-lamps-stop"&gt;&lt;li&gt;Стоп&lt;/li&gt;&lt;/a&gt;
              &lt;/ul&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And here is my script:</p>
  
  <pre><code>jQuery(document).ready(function() { 
      $("#button-lamps-start").click(function() {
          console.log("test");
          $.get("http://192.168.5.100:80/", "test");
      });
      $("#button-lamps-stop").click(() =&gt; {
          alert(10); //for testing purposes
      });
  });
  </code></pre>
  
  <p>And here is the Arduino source:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>// TODO: Measure real values from moist sensor in real soil
  
  #include &lt;Wire.h&gt;
  #include &lt;Ethernet.h&gt;
  #include &lt;Adafruit_Sensor.h&gt;
  #include &lt;Adafruit_TSL2561_U.h&gt;
  #include &lt;Adafruit_GFX.h&gt;
  #include &lt;Adafruit_SSD1306.h&gt;
  
  byte mac[] = {
    0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
  };
  
  // Constructing objects
  Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 1);
  Adafruit_SSD1306 Display(128, 32, &amp;Wire, -1);
  IPAddress localip(192,168,5,100);
  IPAddress remoteip(192, 168, 5, 111);
  EthernetClient client;
  
  sensors_event_t event;
  
  #define LightSensorLED 22
  
  #define FanInStartBtn 23
  #define FanInStopBtn 25
  
  #define FanOutStartBtn 27
  #define FanOutStopBtn 29
  
  #define FanInLED 28
  #define FanOutLED 36
  
  #define moistSensor A8
  
  #define waterLevel A9
  #define chemicalLevelSpray A10
  #define chemicalLevel A11
  
  #define rainSensor A12
  
  void setup() {
    //temp for debugging
    Serial.begin(9600);
  
    // Pinouts
    pinMode(LightSensorLED, OUTPUT);
    pinMode(FanInLED, OUTPUT);
    pinMode(FanOutLED, OUTPUT);
  
    // Pinins
    pinMode(FanInStartBtn, INPUT);
    pinMode(FanInStopBtn, INPUT);
    pinMode(FanOutStartBtn, INPUT);
    pinMode(FanOutStopBtn, INPUT);
    pinMode(moistSensor, INPUT);
    pinMode(waterLevel, INPUT);
  
    // Init ethernet
    Ethernet.begin(mac, remoteip);
    Serial.println("beg");
    Ethernet.setLocalIP(localip);
    Serial.println("set ip");
    Serial.println(Ethernet.localIP());
    if (!client.connect(remoteip, 80)) {
      Serial.println("noo");
      do {
        Serial.println("try again");
        client.connect({192,168,5,111}, 80);
      } while (!client.connected());
    }
  Serial.println("con");
    // Init displays
    Display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  
    // Init sensors
    tsl.begin();
    tsl.enableAutoRange(true);
    tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);
  }
  #define w(x) client.println(x);
  void loop() {
    lightSensor(LightSensorLED, 10);
    FanControls(FanInStartBtn, FanInStopBtn, FanInLED);
    FanControls(FanOutStartBtn, FanOutStopBtn, FanOutLED);
    delay(250);
    if (client.available()) {
      for (int i = 0; i &lt; client.available(); i++) {
        Serial.println(client.read());    // THIS SHOULD DUMP ALL THE BYETS FROM THE NETSHIELD TO SERIAL MONITOR
      }
    }
    //Serial.print((817 - analogRead(moistSensor)) / 4); Serial.println("%"); //not finished
    //Serial.println(analogRead(waterLevel) / 6); //not finished
    //Serial.print(analogRead(chemicalLevelSpray) / 6); Serial.println("%"); //not finished
    //Serial.print(analogRead(chemicalLevel) / 6); Serial.println("%"); //not finished
    //Serial.print(analogRead(rainSensor)); //not finished / not for reading but for turning lamp
  }
  
  void FanControls(unsigned const char FanStartPort, unsigned const char FanStopPort, unsigned const char FanLEDPort) {
    if (!digitalRead(FanStartPort)) {
      digitalWrite(FanLEDPort, 0);
    } else if (!digitalRead(FanStopPort)) {
      digitalWrite(FanLEDPort, 1);
    }
  }
  
  void lightSensor(unsigned const char portNumber, unsigned const int value) {
    // Retrieves the data from the sensor
    tsl.getEvent(&amp;event);
  
    // Check if its night and turn on the lamps
    if (event.light &lt;= value) {
      digitalWrite(portNumber, 0);
    } else if (event.light &gt; value) {
      digitalWrite(portNumber, 1);
    }
  }
  </code></pre>