<aside> <img src="/icons/computer-chip_gray.svg" alt="/icons/computer-chip_gray.svg" width="40px" />

Networked Microcontroller: simpleWebServer (LED control)

Using MCU as server

I tested an Arduino UNO R4 with this example code and documentation.

For the below code, the port 80 on MCU is listening to HTTP request, and it will turn the LED on/off when receiving GET / H or GET /L.

        WiFiServer server(80); //this determine the port open for listening
        
        //{...} Codes in between excluded
        
        // Check to see if the client request was "GET /H" or "GET /L":
        if (currentLine.endsWith("GET /H HTTP/1.1")) {
          digitalWrite(LED_BUILTIN, HIGH);               // GET /H turns the LED on
        }
        if (currentLine.endsWith("GET /L HTTP/1.1")) {
          digitalWrite(LED_BUILTIN, LOW);                // GET /L turns the LED off
        }

Below is the bash to send the corresponding HTTP request to get the MCU’s LED on and off.

 % curl <http://10.23.11.250:80/H>
 % curl <http://10.23.11.250:80/L>

For experimenting, I also changed the code into the below version:

        WiFiServer server(100); //this determine the port open for listening
        
        //{...} Codes in between excluded
        
        // Check to see if the client request was "POST /Cat" or "GET /Cute":
        if (currentLine.endsWith("POST /Cat HTTP/1.1")) {
          digitalWrite(LED_BUILTIN, HIGH);               // POST /Cat turns the LED on
        }
        if (currentLine.endsWith("GET /Cute HTTP/1.1")) {
          digitalWrite(LED_BUILTIN, LOW);                // GET /Cute turns the LED off
        }

Now that the MCU is listening on port 100, it will turn the LED on/off when receiving POST / Cat or GET /Cute. So I twig the bash into below:

% curl -X POST -d "anything will do" <http://10.23.11.250:100/Cat>
% curl <http://10.23.11.250:100/Cute> 

</aside>

<aside> <img src="/icons/computer-chip_gray.svg" alt="/icons/computer-chip_gray.svg" width="40px" />

Networked Microcontroller: BasicAuthGet

Using MCU as client (basically using curl in MCU)

I tested an Arduino UNO R4 with this example code and documentation.

I encountered some issues in the beginning, later on realizing the issue is a combination of the port number, and the path, meaning the path I put in content.get()