In this tutorial, we will check how to send a HTTP GET request from the UART OBLOQ.
As a destination for our request, we will use a fake online REST API that is very useful for testing without the need to write code to setup a web server.
We will be using a serial to USB converter and the Arduino serial monitor to be able to send commands to the UART OBLOQ from a computer. Please check here the electronic diagram for the connections needed.
Before being able to send HTTP GET requests, we will need to connect the device to a WiFi network. Please check a detailed guide on how to do it here.
As mentioned, the first thing we need to do is connecting the UART OBLOQ to a WiFi network. This can be achieved with the following command, where you should change yourNetworkName by the name of your network, and yourNetworkPassword by the password of your network.
The reception of the command will be signaled by OBLOQ by returning a |2|1|. Followed by that, the device will periodically print |2|2| during the connection procedure, which may take a while.
Once the connection procedure is finished with success, OBLOQ will return the IP assigned to the device on the network, as shown in figure 1.
Figure 1 – Connecting OBLOQ to a WiFi network.
Now, we will send the request to this endpoint of the testing API. As shown in figure 2, we can check the expected result by accessing it using a web browser. Note that it returns a JSON structure with some testing content, simulating a forum post.
Figure 2 – Result of HTTP request to JSON placeholder testing API.
Now, to make the request from OBLOQ, we simply need to send the command below, changing destinationURL by the endpoint of the testing API
You can check below at figure 3 how the command looks like after we substitute the destination URL.
Figure 3 – Sending the HTTP GET request command.
Upon sending the command, the UART OBLOQ should answer in the following format:
Note that, in our case, we expect the response code to be 200 (success) and the response body to match what we have obtained in figure 2. As shown in figure 4, this is what we obtain after sending the command.
Figure 4 – Output of the HTTP GET command.
UART OBLOQ module Tutorials: