I am trying to create a project in my free time just for a bit of fun. It consists of two MKR1000s (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 w WifFi 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
Serial.write(c);
// print it out the serial monitor
if (c == '\n') {
if (currentLine.length() == 0) {
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
// 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:
client.println();
// break out of the while loop:
break;
} 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")) {
Serial.println(sensorValue);
delay(2000);
}
}
}
client.stop();
}
}
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!