Thales' cellular IoT products business is now part of Telit Cinterion, find out more.

You are here

Telit Cinterion IoT Developer Community

Concept Board: Internet Services - HTTP

Tutorial, April 15, 2014 - 5:03pm, 13322 views

This is part of tutorial series for Internet Services usage on Gemalto Concept Board:

General overview

EHS6 offers built-in HTTP implementation to be used over AT command interface. The module can work as HTTP client performing GET, POST or HEAD requests. HTTPS is also supported. Network special events are indicated with ^SIS URC. The configuration steps are similar to the scenario from basics tutorial:

  1. Configuring Internet Connection
  2. Configuring Internet Service
  3. Opening Internet Service
  4. Reading from/writing to internet service
  5. Closing Internet Service

In this tutorial step 1 will be omitted as configuration of Internet Connection has been described in basics tutorial.

Configuration of Internet Service

For tutorial purpose an Internet Service will be created under service profile id equal 1. Let's assume that Internet Connection has already been configured under connection profile id equal 0.

First set service type using following command:

AT^SISS=1,"srvType","HTTP"

Then assign the service to previously created connection profile:

AT^SISS=1,"conId",0

After this enter the address of accessed server (also port number may be specified). GET parameters are passed within the address:

AT^SISS=1,"address","http://example.com:80/index.html?par1=val1&par2=val2"

Further configuration depends on which HTTP method is used.

Configuration of HTTP GET request

If GET method is used only cmd parameter is mandatory:

AT^SISS=1,"cmd","get"

No further configuration is needed.

Configuration of HTTP HEAD request

If HEAD method is used also only cmd parameter is mandatory:

AT^SISS=1,"cmd","head"

No further configuration is needed.

Configuration of HTTP POST request

To configure POST method cmd and hcContLen parameters must be passed. Let's assume that we need to send following key-value pairs to the server:

key1 = val1

key2 = val2

Which converted to HTTP form compliant format will look like:

key1=val1&key2=val2

First the method ***** to be specified:

AT^SISS=1,"cmd","post"

There are two ways forpassing data to the module when using POST method. If data length is equal 254 or less, hcContent parameter may be used. Fill hcContent parameter with data and set hcContLen to 0 as this triggers the module to send data stored in hcContent field. Use following commands:

AT^SISS=1,"hcContLen","0"

AT^SISS=1,"hcContent","key1=val1&key2=val2"

Alternatively for larger amount of data, a mechanism involving AT^SISW command may be used, where the module waits for data to be put over AT interface after opening the service. Setting hcContLen to non-zero value triggers the module to operate in this mode:

AT^SISS=1,"hcContLen","1"

After above commands complete the service is ready to be open. 

Performing request and reading the response

Opening the service

If configuration is complete the service may be open with:

AT^SISO=1

When GET, HEAD or POST with hcContLen equal 0 is used, the connection is established and HTTP request is sent. The response is automatically fetched and stored in buffer. If you're using above methods, you can pass to "Reading the data" section.

Supplying data for POST request

If POST method is used and hcContLen is set to non-zero value, the module will display ^SISW: 0,1 indicating that it's ready to accept the content. To send the data from tutorial you need to calculate length and pass it invoking following command:

AT^SISW=1,19,1

1st parameter is the id, 2nd is data length and 3rd (optional), is end of data flag. After invoking this command the module will enter data mode. Please note that no echo is present when being in data mode.

Remember also that up to 1500 bytes may be passed during single AT^SISW call, but you can execute this command multiple *****. This is especially handy when large amount of data is sent. The module sends end of message marker when after EOD is set to 1. After this the server should generate the response and send it back. Like in other cases the response is automatically fetched and stored in buffer.

Reading the data

If TCP URCs are enabled ^SISR: 1,1 will be displayed to indicate new content in incoming data buffer. It may be read with the command:

AT^SISR=1,1500

Above command may be called multiple ***** till end of data is reached, which is indicated by ^SISR: 1,2 URC.  As no more data will come, the service may be closed with:

AT^SISC=1

Examples

Please take a look at following example AT command logs from HTTP Internet Services usage:

HTTP GET example

AT^SICS=0,"conType","gprs0"

OK

AT^SICS=0,"apn","internet"

OK

AT^SISS=1,"srvType","HTTP"

OK

AT^SISS=1,"conId",0

OK

AT^SISS=1,"address","http://example.com/"

OK

AT^SISS=1,"cmd","get"

OK

AT^SISO=1

OK

^SIS: 1,0,2200,"Http example.com:80"

^SISR: 1,1

AT^SISR=1,1500

^SISR: 1,1270

<!doctype html>

<html>

(...)

OK

^SISR: 1,2

at^sisc=1

OK

HTTP HEAD example

AT^SICS=0,"conType","gprs0"

OK

AT^SICS=0,"apn","internet"

OK

AT^SISS=1,"srvType","HTTP"

OK

AT^SISS=1,"conId",0

OK

AT^SISS=1,"address","http://example.com:80/index.html?par1=val1&par2=val2"

OK

AT^SISS=1,"cmd","head"

OK

AT^SISO=1

OK

^SIS: 1,0,2200,"Http example.com:80"

^SISR: 1,1

AT^SISR=1,1500

^SISR: 1,288

Accept-Ranges: bytes

(...)

OK

^SISR: 1,2

at^sisc=1

OK

HTTP POST example

AT^SICS=0,"conType","gprs0"

OK

AT^SICS=0,"apn","internet"

OK

AT^SISS=0,"srvType","HTTP"

OK

AT^SISS=0,"conId",0

OK

AT^SISS=0,"address","http://example.com/"

OK

AT^SISS=0,"cmd","post"

OK

AT^SISS=0,"hcContLen","0"

OK

AT^SISS=0,"hcContent","key1=val1&key2=val2"

OK

AT^SISO=0

OK

^SIS: 0,0,2200,"Http example.com:80"

^SISW: 0,2

^SISR: 0,1

AT^SISR=0,1500

^SISR: 0,1270

<!doctype html>

<html>

(...)

OK

^SISR: 0,2

AT^SISC=0

OK

Summary

As you can see, you can manage to perform HTTP request will only few AT commands. Remember that for other Gemalto products the usage may vary. Feel free to check refer to product documentation for details.

Author

Jędrzej Gemalto Moderator's picture
Jędrzej Gemalto Moderator