0

$USD

$USD
TUTORIALS OBLOQIoT

UART OBLOQ IoT Module Tutorial 8: Sending HTTP GET request

DFRobot Oct 18 2018 2168

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.

 

The commands

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.

|2|1|yourNetworkName,yourNetworkPassword|

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.

UART OBLOQ Connection to WiFi success

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.

JSON Placeholder test posts route.png

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

|3|1|destinationURL|

You can check below at figure 3 how the command looks like after we substitute the destination URL.

OBLOQ HTTP GET command format

Figure 3 – Sending the HTTP GET request command.

Upon sending the command, the UART OBLOQ should answer in the following format:

|3|HTTPResponseCode|RequestResponseBody|

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.

UART OBLOQ HTTP GET Response.png

Figure 4 – Output of the HTTP GET command.

UART OBLOQ module Tutorials: