Send HTTP requests from Pico LTE

Send GET, POST and PUT requests from the Pico LTE to a web server over the cellular connection, with Webhook.site as the test server.

These examples send GET, POST and PUT requests from the Pico LTE to a web server over the cellular connection, and read the response. Webhook.site is the test server: it shows every request it receives. No extra hardware is needed.

Before you begin

Required

Hardware

  • Sixfab Pico LTE or Pico LTE 2Registered and active in Sixfab Connect, connected to the computer with the micro USB cable.

Software

Prepare Webhook.site

  1. Open Webhook.site.

    Open webhook.site in a browser. It shows your unique URL; the requests sent to it appear in the side bar.

  2. Set response.

    The examples also read the server’s response. Click Edit and set:

    • Status code: 200, success.
    • Content type: text/plain for plain text, application/json for JSON.
    • Response body: the response to return; this one returns a message and the time of the request:
    {
        "response": "Hello",
        "timeOfReq": $request.timestamp$
    }

    Click Save.

Set server

In config.json, set the server; Webhook.site needs no username or password, so leave them empty:

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

For a server with basic HTTP authentication, set username and password, and add picoLTE.http.set_auth() after picoLTE.network.get_pdp_ready() in the script.

Run examples

Open the script from the examples/http folder of the SDK repository in Thonny and click Run. The request appears on Webhook.site, and the log shows the response.

The folder also has get_with_custom_header.py and post_with_custom_header.py, which send custom request headers.

Troubleshooting

  • +CME ERROR: 703 when reading the response: wait longer before reading it.
  • +CME ERROR: 712 on a POST or PUT request: the server URL is wrong or empty. Set the full URL, with https:// and the query, in config.json.