I am trying to create a project in my free time just for a bit of fun - it consists of two MKR1000 (one acting as a web server connected to one laptop, and the other acting as a web client connected to a different laptop - so I can view the Serial Monitor).

One MKR1000 has a potentiometer attached to it (therefore I can change the value of it), and sends the potentiometer value to the serial monitor every 4 seconds.

THE AIM: Once the web server sets up the wifi network, and the web client connects to that wifi network, I want to send the potentiometer value across to the web client every time it gets updated. However I am clueless on how to achieve this.

This is my web server void loop code (the rest is similar to the https://www.arduino.cc/en/Tutorial/Wifi101WiFiWebServer):

void loop() {
  WiFiClient client = server.available();
  // listen for incoming clients
  if (client) {
    // if you get a client,
    Serial.println("new client");
    // print a message out the serial port
    String currentLine = "";
    // make a String to hold incoming data from the client
    while (client.connected()) {
      // loop while the client's connected
      if (client.available()) {
        // if there's bytes to read from the client,
        char c = client.read();
        // read a byte, then
        // print it out the serial monitor
        if (c == '\n') {
          if (currentLine.length() == 0) {
            client.println("HTTP/1.1 200 OK");
            // the content of the HTTP response follows the header:
            client.print("Click <a href=\"/showValue\">here</a> showValue of the potentiometer <br>");
            // The HTTP response ends with another blank line:
            // break out of the while loop:
          } else {
            // if you got a newline, then clear currentLine:
            currentLine = "";
        } else if (c != '\r') {
          currentLine += c;
          // add it to the end of the currentLine
        if (currentLine.endsWith("GET /showValue")) {

And this is my web client code I use this https://www.arduino.cc/en/Tutorial/Wifi101WiFiWebClient - I am not sure how I should modify this in order to receive the potentiometer value across from the web server MKR1000. Any tips or hints would be hugely appreciated!

I am sorry if this is a simple question, however I am just starting with the Arduino idea, and I'm new to coding!



At the bottom of the page for the client code link you provided, there's a link to a Chat Server example. If you study the code I think you'll see how to send and receive the potentiometer reading. Hint: Look in the code where it echoes what it receives.

mkr1000 WiFi Chat Server

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.