HTTP Request to Web Server

Beginner This section will lead you step by step how to send GET / POST / PUT requests from Pico LTE device to web server over HTTP with cellular connection.

The Pico LTE provides all the components you will need for establishing an HTTP connection to a web server. You don't need any additional hardware equipments for this example. In the tutorial, we choose webhook.site as the web server to test our requests.

Before starting this Pico LTE tutorial, the Pico LTE SDK installation and configuration steps must be completed. Below are the system requirements for this tutorial. If you haven't followed the SDK installation steps, please refer to the page below before proceeding with the tutorial. The details of these steps will not be covered in this tutorial.

System Requirements

Hardware Requirements Software Requirements
• Sixfab Pico LTE
• Micro USB cable
• Thonny IDE

If you have completed all the requirements, you are ready to send a request to the Web Server via HTTP. Let's get started!

Preparing Coding Environment

  1. Download the Pico LTE SDK repository to your local machine. If you have already downloaded it, skip this step.
  2. Open script "examples → http → get.py or post.py or put.py" from the repository via Thonny IDE.
  3. If you haven't, create a config.json file in the root directory of Pico LTE device.

Pico LTE GET Request to a Web Server using HTTP

Preparing the Webhook.site

Firstly, open the https://webhook.site link in your browser on the host machine. A unique URL will be displayed for you. Refer to the figure below to locate your unique address easily. Keep in mind that all requests sent to your unique address will be visible on the sidebar.



Since our example also reads the response of the request, we may need to create a special one to understand if Pico LTE gets it correctly. Please click Edit button on the right side of the menu, and there has to be new pop-up panel about editing the response.

Status Code: The status code is a number determined by the standards, and it expresses the successful reception of a message with the number 200.

Content Type: The content type is utilized to specify the desired message format. It can be set to "text/plain" for returning plain text or "application/json" for returning a JSON file.

Response Body: The response body refers to the desired response to be returned.

In our example, we aimed to return a success message and include the request time to the server. Once you have prepared your custom response, click the save button.

{
    "response": "Hello",
    "timeOfReq": $request.timestamp$
}

Test the Code Example

Copy the following code block into the config.json file and enter your HTTP Server information.

{
  "https":{
        "server": "YOUR_HTTP_SERVER",
        "username": "YOUR_HTTP_USERNAME",
        "password": "YOUR_HTTP_PASSWORD"
   },
}

Since Webhook.site does not need use any user name and password settings, we will only provide the host address. 'Username' and 'Password' values can be deleted. For example:

{
  "https":{
        "server": "https://webhook.site/000-****-****-****-*********",
        "username": "",
        "password": ""
   },
}

Add picoLTE.http.set_auth() line below picoLTE.network.get_pdp_ready() if you are using basic HTTP authentication with a username and password specified in the config.json file.

Run the "get.py" script that you opened in Thonny IDE. When you run the script, you should see a log similar to the log below, and you should see the new GET request in your Webhook.site dashboard.



>>> %Run -c $EDITOR_CONTENT INFO: Sending a GET request. INFO: {'response': ['OK'], 'status': 0} INFO: {'response': ['+QHTTPGET: 0,200', '{', ' response": "Hello", "timeOfReq": 1686009056', '}', 'OK', '+QHTTPREAD: 0'], 'status': 0} INFO: Get request succeeded.


Troubleshooting

I'm getting +CME ERROR: 703 error when reading the response.

Please increase the sleeping time before asking the Pico LTE to read response. It should be solved.

Pico LTE POST Request to a Web Server using HTTP

Preparing the Webhook.site

Firstly, open the https://webhook.site link in your browser on the host machine. A unique URL will be displayed for you. Refer to the figure below to locate your unique address easily. Keep in mind that all requests sent to your unique address will be visible on the sidebar.



Since our example also reads the response of the request, we may need to create a special one to understand if Pico LTE gets it correctly. Please click Edit button on the right side of the menu, and there has to be new pop-up panel about editing the response.

Status Code: The status code is a number determined by the standards, and it expresses the successful reception of a message with the number 200.

Content Type: The content type is utilized to specify the desired message format. It can be set to "text/plain" for returning plain text or "application/json" for returning a JSON file.

Response Body: The response body refers to the desired response to be returned.

In our example, we aimed to return a success message and include the request time to the server. Once you have prepared your custom response, click the save button.

{
    "response": "Hello",
    "timeOfReq": $request.timestamp$
}

Test the Code Example

Copy the following code block into the config.json file and enter your HTTP Server information.

{
  "https":{
        "server": "YOUR_HTTP_SERVER",
        "username": "YOUR_HTTP_USERNAME",
        "password": "YOUR_HTTP_PASSWORD"
   },
}

Since Webhook.site does not need use any user name and password settings, we will only provide the host address. 'Username' and 'Password' values can be deleted. For example:

{
  "https":{
        "server": "https://webhook.site/000-****-****-****-*********",
        "username": "",
        "password": ""
   },
}

Add picoLTE.http.set_auth() line below picoLTE.network.get_pdp_ready() if you are using basic HTTP authentication with a username and password specified in the config.json file.

Run the "post.py" script that you opened in Thonny IDE. When you run the script, you should see a log similar to the log below, and you should see the new POST request in your Webhook.site dashboard.



>>> %Run -c $EDITOR_CONTENT INFO: Sending a POST request. INFO: {'response': ['OK', '+QHTTPPOST: 0,200'], 'status': 0} INFO: Post request succeeded. INFO: {'response': ['{', '"response": "Hello",', '"timeOfReq": 1687272527', '}', 'OK', '+QHTTPREAD: 0'], 'status': 0}


Troubleshooting

I'm getting +CME ERROR: 703 error when reading the response.

Please increase the sleeping time before asking the Pico LTE to read response. It should be solved.

I'm getting +CME ERROR: 712 error while sending a POST request.

This error described as wrong or empty URL setting for the host. Please check your config.json file and put the proper URL which includes "https://" and its query.

Pico LTE PUT Request to a Web Server using HTTP

Preparing the Webhook.site

Firstly, open the https://webhook.site link in your browser on the host machine. A unique URL will be displayed for you. Refer to the figure below to locate your unique address easily. Keep in mind that all requests sent to your unique address will be visible on the sidebar.



Since our example also reads the response of the request, we may need to create a special one to understand if Pico LTE gets it correctly. Please click Edit button on the right side of the menu, and there has to be new pop-up panel about editing the response.

Status Code: The status code is a number determined by the standards, and it expresses the successful reception of a message with the number 200.

Content Type: The content type is utilized to specify the desired message format. It can be set to "text/plain" for returning plain text or "application/json" for returning a JSON file.

Response Body: The response body refers to the desired response to be returned.

In our example, we aimed to return a success message and include the request time to the server. Once you have prepared your custom response, click the save button.

{
    "response": "Hello",
    "timeOfReq": $request.timestamp$
}

Test the Code Example

Copy the following code block into the config.json file and enter your HTTP Server information.

{
  "https":{
        "server": "YOUR_HTTP_SERVER",
        "username": "YOUR_HTTP_USERNAME",
        "password": "YOUR_HTTP_PASSWORD"
   },
}

Since Webhook.site does not need use any user name and password settings, we will only provide the host address. 'Username' and 'Password' values can be deleted. For example:

{
  "https":{
        "server": "https://webhook.site/000-****-****-****-*********",
        "username": "",
        "password": ""
   },
}

Add picoLTE.http.set_auth() line below picoLTE.network.get_pdp_ready() if you are using basic HTTP authentication with a username and password specified in the config.json file.

Run the "put.py" script that you opened in Thonny IDE. When you run the script, you should see a log similar to the log below, and you should see the new PUT request in your Webhook.site dashboard.



>>> %Run -c $EDITOR_CONTENT INFO: Sending a PUT request. INFO: {'response': ['OK', '+QHTTPPUT: 0,200'], 'status': 0} INFO: Put request succeeded. INFO: {'response': ['{', '"response": "Hello",', '"timeOfReq": 1687278386', '}', 'OK', '+QHTTPREAD: 0'], 'status': 0}

Troubleshooting

I'm getting +CME ERROR: 703 error when reading the response.

Please increase the sleeping time before asking the Pico LTE to read response. It should be solved.

I'm getting +CME ERROR: 712 error while sending a PUT request.

This error described as wrong or empty URL setting for the host. Please check your config.json file and put the proper URL which includes "https://" and its query.