Gemalto is now part of the Thales Group, find out more.

You are here

ZOC-Script - Internet Services: Example HTTP POST & GET BGS2/EHS6

Showcase, January 26, 2016 - 2:01pm, 5666 views

This article is intended to provide an example of showing the modules Internet Services HTTP functionality.

HTTP GET is used for downloading data (in this case: content of a sample text file).
HTTP POST is used to upload data (in this case: uploading another line of text to the sample text file - via PHP script running on a server).

The scripts provided were built for BGS2, slight changes need to be applied to make it work on EHS6 (see: Troubleshooting). Further, when changes are applied, script also works on EHS5.

Trouble-Shooting

  • EHS6 uses the service parameter "cmd" (AT^SISS=<id>,<servParm>) to select HTTP POST/GET Method instead of "hcMethod" in BGS2 → however, EHS6 download/GET also works with hcMethod (Module responds with "OK")
  • EHS6 needs to set an EOD Flag before it sends out the actual POST request to the server! The EOD Flag signals that the user has typed in all input data via AT^SISW command
  • (The full script provided here is only completely tested for BGS2, to make it work on EHS6 the above mentioned changes need to be applied!!)
  • For HTTP POST, defining the correct header -> correct CONTENT LENGTH is critical!!
  • Commands & timings need to fit/need to be in the right order especially when opening the Service → SISO -> SISR, SISW
  • Make sure that the Character Set is set to GSM standard (AT+CSCS="GSM") if getting errors while setting up the Socket Profile and Connection Profile
  • On the server-side make sure to use the function: "file_get_contents(php://input)" to get the complete content/body of the HTTP POST request
  • Make sure that the server has the correct user rights set (e.g. upload.php is allowed to write data on your text file)

 Module: AT-Commands

  • Note: It's important that a few commands need to be set in the correct order!

Server-side: PHP-Script

  • For HTTP POST: The server you are contacting needs a PHP script running that parses all incoming data and writes them to the text file
  • An example upload.php file is included in the provided zip-file

Module-side: Internet-Services (HTTP POST/GET)

 Download: HTTP GET

  1. Make sure that SIM is active & Module is attached to network
  2. (Switch on URCs with: AT^SCFG="Tcp/WithURCs","on" )
  3. Set up Internet Connection Profile & APN with: AT^SICS=1,<settings>
  4. Set up Internet Services Profile with: AT^SISS=1,<settings> → Here its important to select the HTTP service and the GET Method, to select the just configured connection profile (3.) and to set up the URL
  5. Open Internet Service with: AT^SISO=1 → Opens up service with profile 1!
  6. Read data with: AT^SISR=1,<bytesToRead> → Command responses with: ^SISR: <srvProfileId>,<cnfReadLength> if cnfReadLength is -2 all data have been read!
  7. Close Internet Service with: AT^SISC=1

 Download Example BGS2 SICS and SISS Setup

/* Switch on URCs */
AT^SCFG="Tcp/WithURCs","on"


/* SICS: */
/* Select GPRS as Connectin Type */
AT^SICS=1,"conType","GPRS0"

/* Switch on ASCII Format */
AT^SICS=1,"alphabet","1"

/* Select APN & user/pswd */
AT^SICS=1,"apn","internet.t-mobile"
AT^SICS=1,"user",""
AT^SICS=1,"passwd",""'


/* SISS:*/
/* Select Sockettype: HTTP*/
AT^SISS=1,"srvType","http"

/* Select Connection Profile 1 */
AT^SISS=1,"conId","1"

/* Switch on ASCII Format*/
AT^SISS=1,"alphabet","1"

/* Select HTTP GET Method !!! COMMAND FOR BGS2 !!!! */
AT^SISS=1,hcMethod,0

/* Select URL */
AT^SISS=1,"address","http://ae.c-wm.net/~httpsuser/dateien/Gemaltofile.txt"

/* SISO:*/
AT^SISO=1

/* SISR:*/
/* Example: Read 500 bytes on Socket with ID: 1 */
AT^SISR=1,500

/* SISC: */
/* Close Socket Connection */
AT^SISC=1

Upload: HTTP POST

  • Note: to differentiate easier from Download & Upload, I have simply used another profile/service ID (2) for the upload setup.
  1. Make sure that SIM is active & Module is attached to network
  2. (Switch on URCs with: AT^SCFG="Tcp/WithURCs","on" )
  3. Set up Internet Connection Profile & APN with: AT^SICS=2,<settings>
  4. Set up Internet Services Profile with: AT^SISS=2,<settings> → Here its important to select the HTTP service and the POST Method, to select the just configured connection profile (3.) and to set up the URL
  5. In contrast to HTTP GET, we will now have to define the correct payload length to be uploaded for the HTTP Header! It is very important that this needs to be calculated before sending out the data → AT^SISS=2,hcContLen,<LENGTH(payload)> e.g. 5 bytes for "Hello" 
    → EHS6 needs AT^SISS=2,"cmd","1" instead of hcMethod as service parameter!!
  6. Open Internet Service with: AT^SISO=2 → Opens up service with profile 2!
  7. Open up window to write data: AT^SISW=2,<LENGTH(payload)> → Wait for correct response (see ATC Spec)
  8. Write data via Terminal on Serial Connection e.g. "Hello" → (BGS2) wait for HTTP OK Response
  9. → EHS6: Finish input by setting EOD Flag: AT^SISW=2,0,1 → wait for HTTP POST Response: 200
  10. Close Internet Service with: AT^SISC=2

 Upload Example BGS2 SICS and SISS Setup

/* Switch on URCs */
AT^SCFG="Tcp/WithURCs","on"


/* SICS: */
/* Select GPRS as Connectin Type */
AT^SICS=2,"conType","GPRS0"

/* Switch on ASCII Format */
AT^SICS=2,"alphabet","1"

/* Select APN & user/pswd */
AT^SICS=2,"apn","internet.t-mobile"
AT^SICS=2,"user",""
AT^SICS=2,"passwd",""'


/* SISS:*/
/* Select Sockettype: HTTP*/
AT^SISS=2,"srvType","http"

/* Select Connection Profile 1 */
AT^SISS=2,"conId","2"

/* Switch on ASCII Format*/
AT^SISS=2,"alphabet","1"

/* Select HTTP POST Method !!! COMMAND FOR BGS2 !!!! */
AT^SISS=2,hcMethod,1

/* Select URL */
AT^SISS=2,"address","http://ae.c-wm.net/~httpsuser/dateien/upload.php"


/* Define the Content (only for Rexx Script) & its Length for the HTTP Header */
payload='Hello'
AT^SISS=2,hcContLen,LENGTH(payload)

/* SISO:*/
AT^SISO=2

/* SISW:*/
/* Example: Upload 5 bytes on Socket with ID: 2 */
AT^SISW=2,5

/* SISC: */
/* Close Socket Connection */
AT^SISC=2

Requisites:

-BGS2 module with a SIM Card introduced in the SIM Card Holder. For EHSx you need to modify the scripts

-Adecuate the scripts with your PIN , APN, user, password and servers. Inside the scripts you can find the lines to modify

--------------------------

CALL ZocSend "AT+cpin="PIN"^M" /* introduce your PIN here */

CALL atcmd 'AT^^SICS=2,"apn","internet.t-mobile"' /* introduce your APN Here */
CALL atcmd 'AT^^SICS=2,"user","user"' /* introduce your user Here */
CALL atcmd 'AT^^SICS=2,"passwd","password"' /* introduce your password Here */

CALL atcmd 'AT^^SISS=1,"address","http://xxx/yyy/zzz/file.txt"' /* introduce the server, path and file here */

CALL ZocSend "AT+cpin="PIN"^M" /* introduce your PIN here */

CALL atcmd 'AT^^SICS=2,"apn","internet.t-mobile"' /* introduce your APN Here */
CALL atcmd 'AT^^SICS=2,"user","user"' /* introduce your user Here */
CALL atcmd 'AT^^SICS=2,"passwd","password"' /* introduce your password Here */

CALL atcmd 'AT^^SISS=2,"address","http://xxx.yyy.zzz/upload.php"' /* Introduce your server and the right path here */

--------------------------------------

Regards,
Kotinkar & Alopez

nc_emendo's picture
nc_emendo

Do you have examples, where using the on-board JVM?

Kotinkar

Contributors

Profile Picture
Kotinkar
Profile Picture
Alopez