54
Waspmote GPRS/GPS Networking Guide

Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

Waspmote GPRS/GPS Networking Guide

Page 2: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

-2- v4.2

Index

Document version: v4.2 - 06/2015© Libelium Comunicaciones Distribuidas S.L.

INDEX

1. General Considerations ....................................................................................................................... 51.1. Hardware SIM908 (discontinued) ...........................................................................................................................................51.2. Hardware SIM928A ......................................................................................................................................................................71.3. Waspmote Libraries .....................................................................................................................................................................9

1.3.1. Waspmote GPRS+GPS Files......................................................................................................................................91.3.2. Constructor .....................................................................................................................................................................91.3.3. Working Modes .............................................................................................................................................................91.3.4. Library fuses ...................................................................................................................................................................91.3.5. Debug modes ..............................................................................................................................................................101.3.6. Special errors ..............................................................................................................................................................10

2. Initialization ....................................................................................................................................... 112.1. Initializing the GPRS+GPSmodule ......................................................................................................................................112.2. Setting the GPRS+GPS Power Mode ..................................................................................................................................112.3. Closing the GPRS+GPS module ...........................................................................................................................................112.4. Switching GPRS+GPS off ........................................................................................................................................................112.5. Setting time and date .............................................................................................................................................................122.6. Checking the GSM connection ............................................................................................................................................122.7. Setting operator parameters ................................................................................................................................................12

3. SIM related functions ........................................................................................................................ 133.1. Setting the PIN ...........................................................................................................................................................................133.2. Changing PIN number.............................................................................................................................................................133.3. Getting IMSI ................................................................................................................................................................................133.4. Getting IMEI ................................................................................................................................................................................13

4. Call functions ..................................................................................................................................... 144.1. Setting Information returned when receiving a call ....................................................................................................144.2. Making Calls ................................................................................................................................................................................144.3. Making Missed Calls .................................................................................................................................................................144.4. Hanging up calls ........................................................................................................................................................................15

5. SMS related functions ....................................................................................................................... 165.1. Setting Information returned when receiving an SMS ................................................................................................165.2. Setting Mode for SMS ..............................................................................................................................................................165.3. Sending SMS ...............................................................................................................................................................................165.4. Deleting SMS ..............................................................................................................................................................................175.5. Getting the number of total SMSs stored in the SIM ...................................................................................................17

Page 3: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

-3- v4.2

Index

6. HTTP and FTP protocols .................................................................................................................... 186.1. Configuring HTTP/FTP profile ..............................................................................................................................................186.2. Creating your own FTP server ..............................................................................................................................................186.3. Uploading a file ..........................................................................................................................................................................206.4. Downloading a file ...................................................................................................................................................................226.5. HTTP protocol ............................................................................................................................................................................23

6.5.1. GET method .................................................................................................................................................................236.5.2. POST method ...............................................................................................................................................................246.5.3. Server response ..........................................................................................................................................................24

6.6. HTTP queries with GET and POST methods ....................................................................................................................256.7. Sending a frame to Meshlium ..............................................................................................................................................26

7. TCP and UDP connections ................................................................................................................. 287.1. Configuring TCP/UDP profile ................................................................................................................................................287.2. Setting DNS servers ..................................................................................................................................................................287.3. Set local port ...............................................................................................................................................................................297.4. Saving configuration profile .................................................................................................................................................297.5. Creating a TCP/UDP client or a TCP server .......................................................................................................................297.6. Sending data...............................................................................................................................................................................307.7. Closing connections ................................................................................................................................................................307.8. Enabling/disabling close connection quickly .................................................................................................................307.9. Getting IP direction from an URL ........................................................................................................................................317.10. Enabling/disabling to adds an IP head ...........................................................................................................................317.11. Setting autosending timer ..................................................................................................................................................317.12. Enabling/disabling to show remote IP address and port when received data ................................................317.13. Enabling/disabling to show transfer protocol in IP head ........................................................................................327.14. Enabling/disabling to discard input AT data in TCP data send ..............................................................................327.15. Enabling/disabling to get data manually ......................................................................................................................327.16. Getting data manually ..........................................................................................................................................................32

8. General functions .............................................................................................................................. 338.1. Managing incoming data .......................................................................................................................................................338.2. Sending any AT command .....................................................................................................................................................338.3. Setting volume and mode for monitor speaker ............................................................................................................338.4. Setting CLI presentation in incoming calls ......................................................................................................................348.5. Setting CLI presentation in outcoming calls ...................................................................................................................348.6. Gets the phone activity status ..............................................................................................................................................348.7. Setting loudspeaker level ......................................................................................................................................................348.8. Setting call alert mode and level .........................................................................................................................................358.9. Mute ...............................................................................................................................................................................................358.10. Getting current operator .....................................................................................................................................................358.11. Getting available operators ................................................................................................................................................368.12. Setting preferred operator ..................................................................................................................................................368.13. Getting cell information .......................................................................................................................................................368.14. Getting module information .............................................................................................................................................37

Page 4: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

-4- v4.2

9. GPS related functions for SIM908 .................................................................................................... 389.1. Defined variables ......................................................................................................................................................................389.2. Starting the GPS engine .........................................................................................................................................................389.3. Stopping the GPS engine .......................................................................................................................................................399.4. Checking GPS status ................................................................................................................................................................399.5. Waiting for signal connection ...............................................................................................................................................399.6. Reading NMEA strings .............................................................................................................................................................409.7. Converting to degrees ............................................................................................................................................................419.8. Setting RTC time and date from the GPS..........................................................................................................................41

10. GPS related functions for SIM928A ................................................................................................ 4210.1. Defined variables ....................................................................................................................................................................4210.2. Starting the GPS engine .......................................................................................................................................................4210.3. Stopping the GPS engine ....................................................................................................................................................4310.4. Checking GPS status ..............................................................................................................................................................4310.5. Waiting for signal connection ............................................................................................................................................4310.6. Reading GPS data ...................................................................................................................................................................4410.7. Setting RTC time and date from the GPS .......................................................................................................................44

11. Working with Hibernate mode ....................................................................................................... 45

12. Geolocation tracker application example ..................................................................................... 46

13. Code examples and extended information ................................................................................... 49

14. API changelog .................................................................................................................................. 51

15. Documentation changelog ............................................................................................................. 52

Appendix 1: CME error codes ............................................................................................................... 53

Appendix 2: CMS error codes ............................................................................................................... 54

Index

Page 5: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

General Considerations

-5- v4.2

1. General ConsiderationsIn June of 2015, the GPRS+GPS module with chipset SIM908 is discontinued. The chosen chipset to replace it is the SIM928A. So the new version of GPRS+GPS uses the SIM928A. Those 2 chipsets are very similar: there are not any differences regarding GPRS features or handling. There are only small differences in GPS performance and handling. This Guide is valid for both modules.

1.1. Hardware SIM908 (discontinued)

Figure: GPRS+GPS module

Model: SIM908 (SIMCom)

Quadband: 850MHz/900MHz/1800MHz/1900MHz

TX Power: 2W (Class 4) 850MHz/900MHz, 1W (Class 1) 1800MHz/1900MHz

Sensitivity: -109dBm

Antenna connector: UFL

External Antenna: 0dBi

Consumption in power down mode: 30µA

GPS features:

Time-To-First-Fix 30s (typ.)

Sensitivity:

• Tracking: -160 dBm

• Acquisition: -143 dBm

Accuracy horizontal position : <2.5m CEP

Power consumption (GSM engine in idle mode)

• Acquisition : 77mA

• Tracking : 76mA

Page 6: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

General Considerations

-6- v4.2

Actions:

• Making/Receiving calls.

• Making ‘x’ tone missed calls.

• Sending/Receiving SMS.

• Single connection and multiple connections TCP/IP and UDP/IP clients.

• TCP/IP server.

• HTTP service.

• FTP service (downloading and uploading files). • GPS receiver • OTA. Refer to the Over the Air Programming Guide for more information:

http://www.libelium.com/development/waspmote/documentation/over-the-air-programming-guide-otap/

Figure: GPRS+GPS module in Waspmote

Page 7: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

General Considerations

-7- v4.2

1.2. Hardware SIM928A

Figure: GPRS+GPS module

Model: SIM928A (SIMCom)

Quadband: 850 MHz / 900MHz / 1800 MHz / 1900 MHz

TX Power: 2 W (Class 4) 850 MHz / 900 MHz, 1 W (Class 1) 1800 MHz / 1900 MHz

Sensitivity: -109 dBm

Antenna connector: UFL

External Antenna: 0 dBi

Consumption in sleep mode: 1 mA to 1.5 mA

Consumption in power down mode: 0 μA

GPS features:

Time-To-First-Fix 30 s (typ.)

Sensitivity:

• Tracking: -160 dBm

• Acquisition: -147 dBm

Accuracy horizontal position : <2.5 m CEP

Power consumption (GSM engine in idle mode)

• Acquisition : 72 mA

• Tracking : 67 mA

Page 8: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

General Considerations

-8- v4.2

Actions: • Making/Receiving calls. • Making ‘x’ tone missed calls. • Sending/Receiving SMS. • Single connection and multiple connections TCP/IP and UDP/IP clients. • TCP/IP server. • HTTP service. • FTP service (downloading and uploading files). • GPS receiver. • OTA. Refer to the Over the Air Programming Guide for more information:

http://www.libelium.com/development/waspmote/documentation/over-the-air-programming-guide-otap/

Figure: GPRS+GPS module in Waspmote

Note: There are 2 different GPRS modules, the GPRS+GPS module and the GPRS module (also know GPRS Pro module). The GPRS module offers GPRS connectivity. The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS features: the software library is the same.

This is the guide for the GPRS+GPS module. If you are not interested in adding GPS features to your GPRS module, you may consider the GPRS module.

Page 9: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

General Considerations

-9- v4.2

1.3. Waspmote Libraries1.3.1. Waspmote GPRS+GPS FilesAs commented before, there are two GPRS+GPS modules based in two modules from SIMCom. Both modules use the same core library files: WaspGPRS_Pro_core.h and WaspGPRS_Pro_core.cpp. To manage the proper functions of each module, two differents libraries have been developed.

SIM908 module (old GPRS+GPS version) needs WaspGPRS_SIM908.h and WaspGPRS_SIM908.cpp files and the next line must be introduced at the beginning of the code:

#include <WaspGPRS_SIM908.h>

SIM928A module (new GPRS+GPS version) uses WaspGPRS_SIM928A.h and WaspGPRS_SIM928A.cpp and the next line must be introduced at the beginning of the code:

#include <WaspGPRS_SIM928A.h>

1.3.2. ConstructorIn order to start using Waspmote GPRS+GPS library, an object from class ‘WaspGPRS_SIM908’ or class ‘WaspGPRS_SIM928A’ must be created. This object, called ‘GPRS_SIM908’ or ‘GPRS_SIM928A’, is created inside Waspmote GPRS+GPS library and it is public to all libraries. The object ‘GPRS_SIM928A’ is used throughout the guide to show how the Waspmote GPRS+GPS library works.

When creating this constructor, some variables are defined with a value by default, that can be modified later. These variables are:

• baudRate : specifies the baudrate used to communicate with the module (57600 by default). • _socket : specifies the socket used to communicate with the module (UART1 by default). • _pwrMode : specifies the power mode (ON by default).

1.3.3. Working ModesSome constants have been defined to set the different working modes for GPRS+GPS module.

• 0: GPRS_PRO_ON. Module is powered on. Starts in full functionality mode. • 1: GPRS_PRO_FULL. Module is set in full functionality (power consumption around 10-40mA). • 2: GPRS_PRO_RF_OFF. Module deactivates RF circuits (power consumption around 10-40mA). • 3: GPRS_PRO_MIN. Module is set on minimum functionality (power consumption around 10-40mA). • 4: GPRS_PRO_SLEEP. Module enters in sleep mode when there is no data on serial port. From time to time, it communicates

with carrier to maintain the connection (power consumption 1-2mA ). • 5: GPRS_PRO_POWER_OFF. Module is powered off. The power transistors are switched off.

Minimum functionality mode and RF disabled functionality mode cannot be switched to each other. When the module communicates with carrier, current peaks between 1-1’4A are produced.

1.3.4. Library fusesThe library for this module is divided in 4 sections and a section with functions and constants that always are active. Each section is activated/deactivated by a fuse. This fuses are located in WaspGPRS_Pro _core.h. By default this fuses have a ‘1’ allowing to use the functions. The WaspGPRS_Pro _core.h have this fuses:

• GSM_FUSE: Call and SMS related functions and constants • HTTP_FUSE: HTTP related functions and constants • FTP_FUSE: FTP related functions and constants • IP_FUSE: TCP and UDP related functions and constants • OTA_FUSE: Over The Air Programming related functions and constants

For deactivate a section change the ‘1’ in the related fuse by ‘0’.

Note: If you use a function with the related fused with a value of ‘0’, the compiler will give you an error. Please, be carefully using the fuses when compiling.

Page 10: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

General Considerations

-10- v4.2

1.3.5. Debug modes

The library has two debug modes implemented that allows to the experimented user show the data transmitted and received between the Waspmote and the GPRS+GPS module. The value of the GRPS_debug_mode constant selects the debug mode:

• ‘0’ Disables all debug messages • ‘1’ Shows only the commands sent to the GPRS+GPSmodule and some extra messages • ‘2’ Shows commands sent to the GPRS+GPS module, the data answered by the module and some extra messages

The constant GPRS_debug_mode is located in WaspGPRS_Pro_core.h file.

1.3.6. Special errors

Some functions can give an extra error code (CME or CMS error codes).

This code is stored on GPRS_SIM928A.CME_CMS_code . To know the description of the code see the appendix.

Page 11: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

Initialization

-11- v4.2

2. Initialization

2.1. Initializing the GPRS+GPSmoduleThe GPRS+GPS module is connected to a multiplexer, since it is connected to the same microcontroller socket. To start using the GPRS+GPS module, this multiplexer must be switched on and choose the correct combination for the GPRS+GPS to be selected.

To open the socket and set the multiplexer to the correct combination, a function has been developed. This function powers on (GPRS_SIM928A.setMode(GPRS_PRO_ON)) the module too.

Example of use:

{ GPRS_SIM928A.ON(); // Opens socket and sets multiplexer }

2.2. Setting the GPRS+GPS Power ModeSets the current internal Power Mode on the GPRS+GPS. GPRS+GPS module has five different power modes: GPRS_PRO_ON, GPRS_PRO_FULL, GPRS_PRO_RF_OFF, GPRS_PRO_MIN, GPRS_PRO_SLEEP, GPRS_PRO_POWER_OFF. The function will set up the pwrMode variable to one of the five values, but also sends the serial command to the GPRS+GPS module. It returns ‘1’ on success, ‘0’ and ‘-2’ if error and ‘-3’ when the module starts successfully with low battery.

Example of use:

{ uint8_t powerMode = 0; GPRS_SIM928A.setMode(GPRS_PRO_ON); // Powers GPRS+GPS on powerMode = GPRS_SIM928A.getMode(); // Get GPRS+GPS power mode }

Related variables

GPRS_SIM928A.pwrMode stores GPRS+GPS power mode

2.3. Closing the GPRS+GPS moduleIt closes the socket to which the GPRS+GPS module is connected. It means disconnecting the internal socket drivers inside the ATMEGA1281 processor.

Example of use:

{ GPRS_SIM928A.close(); // Closes socket }

2.4. Switching GPRS+GPS offIt closes the socket to which the GPRS+GPS module is connected to and turns it off.

Example of use:

{ GPRS_SIM928A.OFF(); // Closes socket and turns it off }

Page 12: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

Initialization

-12- v4.2

2.5. Setting time and dateThis function updates the time and the date of the GPRS+GPS module from the RTC.

It returns ‘1’ on success, ‘0’ or ‘-2’ if error

Example of use:

{ GPRS_SIM928A.setTime(); // Updates time and date }

2.6. Checking the GSM connectionIt checks if the module is connected to the network for a time desired by the input parameter.

If the GPRS+GPS module does not connect within these attempts, function exits with ‘0’.

It returns ‘1’ when connected and ‘0’ if not.

Example of use:

{ GPRS_SIM928A.check(180); // Waits 180 seconds for connection }

According to Libelium experience, 180 seconds is the recommended timeout for connecting the GPRS network. The timeout may vary depending on the network range and quality of service. If the user detects this timeout does not allow his GPRS to connect, he can experiment with higher values. 180 seconds would be the maximum advised timeout: if the GSM/GPRS module cannot connect in 2 minutes, it is better to stop trying and check again in the next loop.

2.7. Setting operator parametersWhen the GPRS module uses some services like IP connections (TCP/UDP), HTTP services or FTP transfers, it’s mandatory to configure operator parameters like APN, login and password.

There are two ways to configure these settings. The first one is to use the definitions into the file WaspGPRS_Pro_core.h.

#define AT_GPRS_APN “APN”#define AT_GPRS_LOGIN “login”#define AT_GPRS_PASSW “password”

The second one is to use the function set_APN().Example of use:

{ // If only APN is necessary GPRS_SIM928A.set_APN(“provider_apn”); // If APN, login and password are necessary GPRS_SIM928A.set_APN(“provider_apn”,“login”,“password”);}

Page 13: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

SIM related functions

-13- v4.2

3. SIM related functionsSome functions have been developed to configure some settings related with GSM, specifically with managing calls and SMS.

3.1. Setting the PINIt sets the PIN to the SIM and it returns ‘1’ on success, ‘0’ if error and ‘-2’ if CME error code available.

Example of use

{ GPRS_SIM928A.setPIN(“1234”); //SetsPIN=1234totheSIM}

3.2. Changing PIN numberIt changes PIN number of SIM card.

It returns ‘1’ on success, ‘0’ if error and ‘-2’ if CME error code available.

Example of use

{ GPRS_SIM928A.changePIN(“1234”,“4321”);//Changes“1234”to“4321”PINnumber}

3.3. Getting IMSIIt gets the IMSI from the SIM card and it stores the IMSI into buffer_GPRS variable.

It returns ‘1’ if connected, ‘0’ if not.

Example of use

{ GPRS_SIM928A.getIMSI();}

Getting IMSI example for SIM928A:

http://www.libelium.com/development/waspmote/examples/gprsgps-22-getting-imsi-from-sim-and-imei

The example for SIM908 can be found in Waspmote’s IDE.

3.4. Getting IMEIIt gets the IMEI from the SIM card and it stores the IMEI into buffer_GPRS variable.

It returns ‘1’ if connected, ‘0’ if not.

Example of use

{ GPRS_SIM928A.getIMEI();}

Getting IMEI example for SIM928A:

http://www.libelium.com/development/waspmote/examples/gprsgps-22-getting-imsi-from-sim-and-imei

The example for SIM908 can be found in Waspmote’s IDE.

Page 14: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

Call functions

-14- v4.2

4. Call functions

4.1. Setting Information returned when receiving a callThis function configures the information returned by the module when a call is received. It is useful to generate interruptions or to store data from the incoming call .

It returns ‘1’ on success, ‘0’ if error and ‘-1’ if no memory and ‘-2’ if error with CME error code available.

Example of use

{ GPRS_SIM908.setInfoIncomingCall(); // Sets information returned by the module when incoming call }

4.2. Making CallsIt makes a call to the given telephone number.

It returns ‘1’ on success, ‘0’ if error.

Note: the number can be using the country code or only the phone number.

Example of use

{ GPRS_SIM928A.makeCall(“*********”);//Makesacalltothedesirednumber}

Making call example for SIM928A:

http://www.libelium.com/development/waspmote/examples/gprsgps-07-making-call

The example for SIM908 can be found in Waspmote’s IDE.

4.3. Making Missed CallsIt makes a specified duration missed call to the given telephone number.

It returns ‘1’ on success, ‘0’ if error.

Note 1: the calling time includes the time to send the request to the carrier, so the receiving call time is a bit shorter than the input parameter.

Note 2: the number can be using the country code or only the phone number.

Example of use

{ GPRS_SIM928A.makeLostCall(“*********”,10);//Makesalostcallof10secondstothedesirednumber }

Making lost call example for SIM928A:

http://www.libelium.com/development/waspmote/examples/gprsgps-06-making-lost-call

The example for SIM908 can be found in Waspmote’s IDE.

Page 15: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

Call functions

-15- v4.2

4.4. Hanging up callsIt hangs up all the active calls. It returns ‘1’ on success and ‘0’ if error.

Example of use

{ GPRS_SIM928A.hangUp();//Hangsalltheactivecallsup}

Page 16: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

SMS related functions

-16- v4.2

5. SMS related functions

5.1. Setting Information returned when receiving an SMSThis function configures the information returned by the module when an SMS is received. It is useful to generate interruptions or to store data from the incoming SMS.

It returns ‘1’ on success and ‘0’ if error.

Example of use

{ GPRS_SIM928A.setInfoIncomingSMS(); // Sets information returned by the module when incoming SMS}

5.2. Setting Mode for SMSIt sets the text mode for the SMS and it returns ‘1’ on success and ‘0’ if error.

It returns ‘1’ on success and ‘0’ if error.

Example of use

{ GPRS_SIM928A.setTextModeSMS(); // Sets text mode for SMS }

5.3. Sending SMSIt sends a SMS to the specified number.

It returns ‘1’ on success, ‘0’ if error, ‘-2’ if error sending the SMS and ‘-3’ if error sending the SMS with CMS error code available.

Note: the maximum length is 90 Bytes (90 characters).

Example of use

{ GPRS_SIM928A.sendSMS(“HelloWorld!”,“6********”);//SendsthistextinanSMStothedesirednumber}

Sending SMS example for SIM928A:

http://www.libelium.com/development/waspmote/examples/gprsgps-08-sending-sms

The example for SIM908 can be found in Waspmote’s IDE.

Page 17: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

SMS related functions

-17- v4.2

5.4. Deleting SMSIt deletes a SMS in memory selected by sms_index.

It returns ‘1’ on success, ‘0’ if error and ‘-2’ if error with CMS error code available.

Example of use:

{ GPRS_SIM928A.deleteSMS(“2”);//DeletestheSMSatindex2}

5.5. Getting the number of total SMSs stored in the SIMIt gets the number of total SMSs stored in the SIM

It returns the number of SMSs, or ‘-2’ if error

Example of use:

{ total_SMS = GPRS_SIM928A.getTotalSMS(); // Gets the number of SMS}

Page 18: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

HTTP and FTP protocols

-18- v4.2

6. HTTP and FTP protocols

6.1. Configuring HTTP/FTP profileIt configures GPRS connection with login, password and some other parameters for use with HTTP and FTP funtions.

The configuration parameters from ‘WaspGPRS_core.h’ are AT_GPRS_APN, AT_GPRS_LOGIN and AT_GPRS_PASSW. Also, function GPRS_SIM928A.set_APN() can be used.

It returns:

• ‘1’ on success• ‘0’ if error• ‘-2’ if error setting the type of internet connection, • ‘-3’ if error setting the APN• ‘-4’ if error setting the user name• ‘-5’ if error setting the password• ‘-6’ if error saving the configuration

Example of use:

{ GPRS_SIM928A.configureGPRS_HTTP_FTP(1);//Configuresprofile1foruseit}

6.2. Creating your own FTP serverFirst, you should get a server. This server will receive your frames and store them. There is no need to purchase a physical server since there are companies that offer remote servers.

Note: The server used by Libelium to realize the upload and download tests is a Pure-FTPD server (www.pureftpd.org) and it is hosted into a OVH server (www.ovh.com). The Pure-FTPD server has the settings by default:

• TLS encryption support: Optional • TLS cipher suite: High-Medium + TLSv1 • Allow anonymous logins: No • Allow anonymous uploads: No • Maximum load for anonymous downloads: 4 • Maximum idle time (minutes): 15 • Maximum connections: 50 • Maximum connections per IP address: 8 • Allow logins with root password: Yes • Broken clients compatibility: No

From Libelium, we recommend the use of this server hosting provider to obtain good results to upload and download files, but we can’t guarantee the perfect performance of the FTP server.

Also, Libelium has tested with Guebs hosting (www.guebs.com) with good results.

Page 19: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

HTTP and FTP protocols

-19- v4.2

Follow the next steps to create your own FTP server using the terminal:

1 - Install the pure-ftpd server: sudo apt-get install pure-ftpd

2 - Stop the server: sudo /etc/init.d/pure-ftpd stop

3 - Before creating the user, it is necessary create a directory to stored the received data: sudo mkdir /home/ftp and inclide a false shell. To check if the shell exist: sudo more /etc/shells

4 - If it isn’t the line /bin/false, edit the file, for example with vim, and include it: sudovim/etc/shells

5 - After creating a new folder to store data, you have to create a group and a user with false shell, because this type of user don’t need a valid shell (more secure), therefore select /bin/false shell for user and /dev/null as directory: sudo groupadd ftpgroup

sudouseradd-gftpgroup-d/dev/null-s/bin/falseuser1

6 - Modify folder permissions: sudo chown -R user1 /home/ftp sudo chmod -R 755 /home/ftp

7 - Add the new user to the pure-ftpd database: sudo pure-pw useradd username -u ftpuser -g ftpgroup -d /home/ftp

Set the user password when it request.

8 - Update the pure-ftpd database: sudo pure-pw mkdb

9 - When the users are include in the ftp, start the server: sudo /etc/init.d/pure-ftpd start

Remember to open the ports in your router. After this, you will be able to receive FTP transmissions on your server. We advise to use FileZilla to visualize and manage your FTP server.

Page 20: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

HTTP and FTP protocols

-20- v4.2

6.3. Uploading a fileIt uploads a file to a FTP server.

It returns:

• ‘1’ on success

• ‘0’ if error opening connection with the GPRS provider

• ‘-1’ if no GPRS connection

• ‘-2’ if error opening the connection

• ‘-3’ if error getting the IP address

• ‘-4’ if error setting the FTP/HTTP ID (no answer from module)

• ‘-5’ if error setting the FTP mode (no answer from module)

• ‘-6’ if error setting the FTP type (no answer from module)

• ‘-7’ if error setting the FTP server(no answer from module)

• ‘-8’ if error setting the FTP port (no answer from module)

• ‘-9’ if error setting the user name

• ‘-10’ if error setting the password

• ‘-11’ if error starting the SD

• ‘-12’ if error taking the file size in the SD

• ‘-13’ if error setting the file name in the FTP server (no answer from module)

• ‘-14’ if error setting the path of the file in the FTP server (no answer from module)

• ‘-15’ if error opening the FTP session (no answer from module)

• ‘-16’ if error when request to send data

• ‘-17’ error sending data to the FTP

• ‘-18’ if error waiting for send more data

• ‘-19’ if error when setting Upload File (with CME error code available)

• ‘-20’ if error closing the FTP session (no answer from module)

• ‘-21’ setting the file name in the FTP to get the file size

• ‘-22’ setting the path in the FTP to get the file size

• ‘-23’ if error getting the file size (no answer from module)

• ‘-24’ if error opening SD file

• ‘-25’ if error when setting pointer to the beginning of the file

• ‘-40’ if error from FTP when the module sends data with error code available

• ‘-41’ if error setting the FTP/HTTP ID with CME error code available

• ‘-42’ if error setting the FTP mode (with CME error code available)

• ‘-43’ if error setting the FTP type (with CME error code available)

• ‘-44’ if error setting the FTP server (with CME error code available)

• ‘-45’ if error setting the FTP port (with CME error code available)

• ‘-46’ if error setting the user name (with CME error code available)

• ‘-47’ if error setting the password (with CME error code available)

• ‘-48’ if error setting the file name in the FTP server (with CME error code available)

Page 21: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

HTTP and FTP protocols

-21- v4.2

• ‘-49’ if error setting the path of the file in the FTP server (with CME error code available)

• ‘-50’ if error opening the FTP session (with CME error code available)

• ‘-51’ if error closing the FTP session (with CME error code available)

• ‘-53’ setting the file name in the FTP to get the file size (with CME error code available)

• ‘-54’ setting the path in the FTP to get the file size (with CME error code available)

• ‘-55’ if error getting the file size (with CME error code available)

• ‘-56’ if FTP is busy error getting the size of the file from the FTP

• ‘-57’ if FTP is busy sending data

• ‘-58’ if timeout

Example of use

{ //Uploadsfile.txtfilewithHTTP/FTPprofile1 GPRS_SIM928A.uploadFile(“/SD_folder/file.txt” ,“/FTP_folder/test_file.txt” ,“username” ,“password” ,“FTP_server” ,“FTP_port” , 1); }

Uploading files example for SIM928A:

http://www.libelium.com/development/waspmote/examples/gprsgps-20-uploading-files-to-a-ftp-server

The example for SIM908 can be found in Waspmote’s IDE.

Page 22: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

HTTP and FTP protocols

-22- v4.2

6.4. Downloading a fileIt downloads a file from an FTP server.

It returns:‘1’ on success‘0’ if error opening connection with the GPRS provider‘-1’ error downloading the file‘-2’ if error getting the IP address‘-3’ if error setting the FTP/HTTP ID‘-4’ if error setting the FTP mode‘-5’ if error setting the FTP type‘-6’ if error setting the FTP server‘-7’ if error setting the FTP port‘-8’ if error setting the user name‘-9’ if error setting the password‘-12’ if error setting the file name in the FTP server, ‘-13’ if error setting the path of the file in the FTP server‘-14’ if error opening the FTP session‘-15’ if error starting the SD‘-16’ if error creating the file‘-17’ error requesting data to the FTP‘-18’ if error saving data into the SD‘-19’ if error requesting more data to the FTP‘-21’ setting the file name in the FTP to get the file size‘-22’ setting the path in the FTP to get the file size‘-23’ if error getting the file size‘-41’ if error setting the FTP/HTTP ID with CME error code available‘-42’ if error setting the FTP mode with CME error code available,‘-43’ if error setting the FTP type with CME error code available‘-44’ if error setting the FTP server with CME error code available‘-45’ if error setting the FTP port with CME error code available‘-46’ if error setting the user name with CME error code available,‘-47’ if error setting the password with CME error code available‘-48’ if error setting the file name in the FTP server with CME error code available‘-49’ if error setting the path of the file in the FTP server with CME error code available‘-50’ if error opening the FTP session with CME error code available‘-51’ if error requesting data to the FTP with CME error code available‘-52’ if error requesting more data to the FTP with CME error code available‘-53’ setting the file name in the FTP to get the file size with CME error code available‘-54’ setting the path in the FTP to get the file size with CME error code available‘-55’ if error getting the file size with CME error code available‘-56’ if FTP is busy error getting the size of the file from the FTP‘-57’ if FTP is busy sending data‘-58’ if timeout

Page 23: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

HTTP and FTP protocols

-23- v4.2

Example of use:

{ //Uploadstest_file.txtfilewithHTTP/FTPprofile2 GPRS_SIM928A.downloadFile(“/FTP_folder/test_file.txt” ,“/SD_folder/file.txt” ,”username” ,“password” ,“FTP_server” ,“FTP_port” , 2); }

• Downloading files example for SIM928A:http://www.libelium.com/development/waspmote/examples/gprsgps-21-downloading-files-from-a-ftp-server

The example for SIM908 can be found in Waspmote’s IDE.

6.5. HTTP protocolHTTP is a great protocol because it is a standard, simple and light way to send information to web servers.

Libelium has created a little web service in order to allow GPRS, WiFi or 3G modules users to test the HTTP mode. This web service is a little code, written in PHP, which is continuously listening to the HTTP port (port number 80) of our test server “pruebas.libelium.com”. This is a kind of RESTful service. GPRS, WiFi or 3G modules can send HTTP instances to our web service. HTTP instances should have the following structures so that our web service can understand.

6.5.1. GET method

In GET method the data are sent to the server append to the main URL with the ‘?’ character. The base sentence to perform GET method is shown below:

pruebas.libelium.com/getpost_frame_parser.php?<variable1=value1>&<variable2=value2>&<...>&view=html

Where:

• getpost_frame_parser.php? : It is the main URL, where the web service is running. • <variable1=value1> : It is a couple with the variable name and value which we want the web service to parse. • view=html: It is an optional argument. It shows a “pretty” response (HTML formated)

All arguments must be separated by “&”. The variable name and value must be separated by “=”.

Some examples:

pruebas.libelium.com/getpost_frame_parser.php?var1=3.1415pruebas.libelium.com/getpost_frame_parser.php?var1=3.1415&view=htmlpruebas.libelium.com/getpost_frame_parser.php?var1=3.1415&var2=123456&var3=hello&view=html

Page 24: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

HTTP and FTP protocols

-24- v4.2

6.5.2. POST methodUnlike GET method, with POST method the data are sent to the server into an extra data field. The URL only includes the site name and the PHP direction:

pruebas.libelium.com/getpost_frame_parser.php

The body is very similar to the used in GET method:

<variable1=value1>&<variable2=value2>&<...>&view=htmlWhere:

• <variable1=value1> : It is a couple with the variable name and value which we want the web service to parse. All arguments must be separated by “&”. The variable name and value must be separated by “=”.

• Some examples of data field:

var1=3.1415 var1=3.1415&var2=123456 var1=3.1415&var2=123456&var3=hello

6.5.3. Server responseIf the web service receives one instance with the appropriate format, some actions will happen:

• the web service grabs the string and parses it. So the PHP code creates couples with the variables name and value. • the web service responses to the sender device (to the sender IP) with an HTML-formatted reply.

Figure: Operating with the web service from a PC browser

Figure: Operating with the web service from a Waspmote GPRS

Page 25: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

HTTP and FTP protocols

-25- v4.2

Remember this PHP code is really simple and is offered with the only purpose of testing, without any warranty. The source code is available here:

downloads.libelium.com/waspmote-html-get-post-php-parser-tester.zip

The user may find it interesting to copy this code and make it run on his own server (physical or virtual). If the user wants to go further, he can complete the code. For example, once the couples are parsed, the user can modify the PHP to save data into a txt file, or insert couples into a database, or include a timestamp...

6.6. HTTP queries with GET and POST methodsThe function readURL() can be used to send data, using the GET method, to a server and receive a response. The syntax of the function depends of the data to send.

If the data to be sent is a plain string, the syntax is shown below:

GPRS_SIM928A.readURL(url,HTTP_FTP_profile);

Where:

• url: the URL to get the information from • HTTP_FTP_profile: profile used with the function configureGPRS_HTTP_FTP()

Example of GET query:

{//GETmethodwithoutframeusingHTTP/FTPprofile1GPRS_SIM928A.readURL(“http://pruebas.libelium.com/getpost_frame_parser.php?var1=2&var2=2.1516”,1);}

The function readURL() can be used to send data, using POST method, to a server and receive a response. The sintaxis of the function depends of the data to send.

If the data to be sent is a plain string, the sintaxis is shown below:

GPRS_SIM928A.readURL(url,POST_data,HTTP_FTP_profile);

Where:

• url: the URL to get the information from • POST_data: data to send wit the POST request • HTTP_FTP_profile: profile used with the function configureGPRS_HTTP_FTP()

Example of POST query:

{//POSTmethodwithoutframeusingHTTP/FTPprofile1GPRS_SIM928A.readURL(“http://pruebas.libelium.com/getpost_frame_parser.php” ,“var1=2&var2=2.1516” , 1); }

Page 26: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

HTTP and FTP protocols

-26- v4.2

The funcion returns:

‘0’ if error ‘1’ on success ‘2’ if buffer_GPRS is full. The answer from the server is limited by the length of buffer_GPRS. To increase the length of the answer, increase the BUFFER_SIZE constant.‘-1’ if no GPRS connection‘-2’ if error opening the connection,‘-3’ if error getting the IP address,‘-4’ if error initializing the HTTP service‘-5’ if error setting CID the HTTP service‘-6’ if error setting the URL the HTTP service‘-7’ if error starting HTTP session‘-8’ if error getting data from URL‘-9’ if error closing the HTTP service‘-10’ if error initializing the HTTP service with CME error code available‘-11’ if error setting CID the HTTP service with CME error code available‘-12’ if error setting the URL the HTTP service with CME error code available‘-13’ if error starting HTTP session with CME error code available‘-14’ if error getting data from url with CME error code available‘-15’ if error closing the HTTP service with CME error code available‘-20’ if error getting data from URL with CME error code available

Reading an URL using GET and POST methods examples for SIM928A:

http://www.libelium.com/development/waspmote/examples/gprsgps-19a-reading-url-with-get http://www.libelium.com/development/waspmote/examples/gprsgps-19c-reading-url-with-post

The examples for SIM908 can be found in Waspmote’s IDE.

6.7. Sending a frame to MeshliumSince June 2014, it is possible to send HTTP queries from Waspmote to Meshlium. All data sent using the Waspmote Frame to Meshlium is stored in the Meshlium’s database using the Frame Parser. Thus, it is possible to access to this data or synchronize it to external systems.

For this purpose, we need to use the Waspmote Frame which permits to create sensor formatted frames in an easy way. Then the frame is used as seen below.

The function readURL() can be used to send data, using both GET and POST methods to Meshlium and receive a response.

GPRS_SIM928A.readURL(url,frame.buffer,frame.length,HTTP_FTP_profile,HTTP_method);

Where:

• url: the URL to get the information from • frame.buffer: buffer from frame class. The frame must composed before to use the readURL() function • frame.length: the length of frame.buffer • HTTP_FTP_profile: profile used with the function configureGPRS_HTTP_FTP() • HTTP_method: must be GET in order to use the GET method or POST in order to use the POST method

Page 27: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

HTTP and FTP protocols

-27- v4.2

Example of GET query with frame:

{//GETmethodwithframeusingHTTP/FTPprofile1GPRS_SIM928A.readURL(“http://pruebas.libelium.com/getpost_frame_parser.php?” , frame.buffer , frame.length , 1 , GET);}

Example of POST query with frame:

{//POSTmethodwithframeusingHTTP/FTPprofile1GPRS_SIM928A.readURL(“http://pruebas.libelium.com/getpost_frame_parser.php” , frame.buffer , frame.length , 1 , POST); }

It returns:

• ‘0’ if error • ‘1’ on success • ‘2’ if buffer_GPRS is full. The answer from the server is limited by the length of buffer_GPRS. To increase the length of the

answer, increase the BUFFER_SIZE constant. • ‘-1’ if no GPRS connection • ‘-2’ if error opening the connection, • ‘-3’ if error getting the IP address, • ‘-4’ if error initializing the HTTP service • ‘-5’ if error setting CID the HTTP service • ‘-6’ if error setting the URL the HTTP service • ‘-7’ if error starting HTTP session • ‘-8’ if error getting data from URL • ‘-9’ if error closing the HTTP service • ‘-10’ if error initializing the HTTP service with CME error code available • ‘-11’ if error setting CID the HTTP service with CME error code available • ‘-12’ if error setting the URL the HTTP service with CME error code available • ‘-13’ if error starting HTTP session with CME error code available • ‘-14’ if error getting data from URL with CME error code available • ‘-15’ if error closing the HTTP service with CME error code available • ‘-16’ if error configuring the HTTP content parameter • ‘-17’ if error configuring the HTTP content parameter with CME error code available • ‘-18’ if error sending the POST data • ‘-19’ if error sending the POST data with CME error code available • ‘-20’ if error getting data from URL with CME error code available

HTTP query using GET and POST methods with Waspmote Frame examples for SIM928A:

http://www.libelium.com/development/waspmote/examples/gprsgps-19b-reading-url-with-get-and-frame http://www.libelium.com/development/waspmote/examples/gprsgps-19d-reading-url-with-post-and-frame

The examples for SIM908 can be found in Waspmote’s IDE.

Page 28: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

TCP and UDP connections

-28- v4.2

7. TCP and UDP connections

7.1. Configuring TCP/UDP profileIt configures GPRS connection with login, password and some other parameters for use with TCP/UDP connections with parameters from ‘WaspGPRS_Pro_core.h’ file. The configuration parameters from ‘WaspGPRS_Pro_core.h are AT_GPRS_APN, AT_GPRS_LOGIN and AT_GPRS_PASSW. Also, function GPRS_SIM928A.set_APN() can be used

There are two modes of connection for TCP/UDP application: Single connection and multi-connection. When in single connection mode, GPRS+GPS module can work at both transparent mode and non-transparent mode. When in multi-connection mode, GPRS+GPS module only can work at non-transparent mode.

It returns:

• ‘1’ on success• ‘0’ if error• ‘-2’ if error dettaching the GPRS connection• ‘-3’ if error attaching the GPRS connection• ‘-4’ if error setting the application mode,• ‘-5’ if error setting the connection mode• ‘-6’ if error establishing the connection with the GPRS provider• ‘-15’ if error dettaching the GPRS connection with CME error code available• ‘-16’ if error attaching the GPRS connection with CME error code available

Example of use:

{ GPRS_SIM928A.configureGPRS_TCP_UDP(MULTI_CONNECTION);//Configurestheprofileformultipleconnections GPRS_SIM928A.configureGPRS_TCP_UDP(SINGLE_CONNECTION,NON_TRANSPARENT);//Configurestheprofilefor single connection and non transparent mode }

7.2. Setting DNS serversIt sets the directions of DNS servers from ‘GPRS_Pro_core.h’ file or by the user into the code.

It returns ‘1’ on success, ‘0’ if error and ’-2’ if CME error code available.

Example of use:

{ GPRS_SIM928A.setDNS();//SetsDNSserversfromGPRS_Pro_core.h GPRS_SIM928A.setDNS(“***.***.***.***”);//SetsDNSserver GPRS_SIM928A.setDNS(“***.***.***.***”,”***.***.***.***”);//SetsDNSservers}

Page 29: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

TCP and UDP connections

-29- v4.2

7.3. Set local portIt sets the internal port for TCP or UDP connection. This function will be effective only in single connection mode and when module is set as a Client.

It returns ‘1’ on success, ‘0’ if error.

Example of use:

{ GPRS_SIM928A.setLocalPort(“UDP”,32000); //SetlocalportforanUDPconnection}

7.4. Saving configuration profileIt saves the configuration profile into the internal NVRAM of the GPRS+GPS module.

It returns ‘1’ on success, ‘0’ if error.

Example of use:

{ GPRS_SIM928A.saveGPRS_TCP_UDPconfiguration();}

7.5. Creating a TCP/UDP client or a TCP serverIn single connection mode, GPRS+GPS can be configured as either TCP/UDP client or TCP server. When in multi-connection mode, GPRS+GPS can work as an absolute TCP/UDP client, which can establish 8 connections in total. It also can be configured as one TCP server, which allows 7 TCP/UDP clients to connect in; and the TCP server also can act as a client, establishing 7 connections to one remote server.

It returns ‘1’ on success, ‘0’ if error setting the connection, ‘-2’ if error setting the connection with CME error code available and ‘-3’ if time out waiting the connection.

Example of use:

{ GPRS_SIM928A.createSocket(TCP_SERVER,“512”);//CreatesaTCPserverGPRS_SIM928A.createSocket(UDP_CLIENT,3,“82.200.15.92”,“12002”);//CreatesanUDPclientinconnectionnumber3 GPRS_SIM928A.createSocket(TCP_CLIENT,“82.200.15.92”,“12002”);//CreatesanTCPclientin single connection mode }

Page 30: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

TCP and UDP connections

-30- v4.2

7.6. Sending dataThis function sends ‘data’ to the specified ‘n_connection’ .

It returns’1’ on success, ‘0’ if error waiting the response of the module, ‘-2’ if error with CME error code available, ‘-3’ if no feedback detected and ‘-4’ if the send fails.

Example of use:

{ GPRS_SIM928A.sendData(“Testmessageinsingleconnection!”);//Sendingdatainsingleconnection mode GPRS_SIM928A.sendData(“Testmessageinsingleconnection!”,1);//Sendingdatainmulti-connection by connection number 1 }

For send binary data or raw data the function needs an uint8_t pointer to the data and the length of the data.

It returns ‘1’ on success, ‘0’ if error waiting the response of the module, ‘-2’ if error with CME error code available, ‘-3’ if no feedback detected and ‘-4’ if the send fails.

Example of use:

{ GPRS_SIM928A.sendData(frame.buffer,frame.length);//Sendaframeinsingleconnectionmode GPRS_SIM928A.sendData(frame.buffer,frame.length,1);//Sendaframeinmulticonnectionby connection number 1 }

7.7. Closing connectionsIt closes TCP/UDP connection.

It returns ‘1’ on success, ‘0’ if error.

Example of use

{ GPRS_SIM928A.closeSocket(); // Closes connection in single connection mode GPRS_SIM928A.closeSocket(5); // Closes connection 5 in multi connection mode GPRS_SIM928A.closeSocket(8);//ClosesTCPserver}

7.8. Enabling/disabling close connection quicklyIt enables/disables to close the connection quickly.

It returns ‘1’ on success, ‘0’ if error.

Example of use:

{ GPRS_SIM928A.QuickcloseSocket(DISABLE);}

Page 31: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

TCP and UDP connections

-31- v4.2

7.9. Getting IP direction from an URLIt gets the IP direction from a URL using DNS servers. Stores the IP direction in ‘buffer_GPRS’.

It returns ‘1’ on success, ‘0’ if error.

Example of use:

{ GPRS_SIM928A.getIPfromDNS(“www.libelium.com”);//GetsIPdirectionfromLibelium’swebsite }

7.10. Enabling/disabling to adds an IP headIt enables/disables to add an IP head at the beginning of a package received.

It returns ‘1’ on success, ‘0’ if error.

Example of use:

{ GPRS_SIM928A.IPHeader(ENABLE);}

7.11. Setting autosending timerIt sets a timer when module is sending data. Time is in seconds from 0 to 100.

It returns ‘1’ on success, ‘0’ if error.

Example of use:

{ GPRS_SIM928A.SetAutoSendingTimer(DISABLE); GPRS_SIM928A.SetAutoSendingTimer(ENABLE,5); //Setstimerat5seconds}

7.12. Enabling/disabling to show remote IP address and port when received dataIt enables or disables to show remote IP address and port when received data.

It returns ‘1’ on success, ‘0’ if error.

Example of use:

{ GPRS_SIM928A.ShowRemoteIP(DISABLE);}

Page 32: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

TCP and UDP connections

-32- v4.2

7.13. Enabling/disabling to show transfer protocol in IP headIt enables or disables to show transfer protocol in IP head when received data.

It returns ‘1’ on success, ‘0’ if error.

Example of use:

{ GPRS_SIM928A.ShowProtocolHeader(ENABLE);}

7.14. Enabling/disabling to discard input AT data in TCP data sendIt enables or disables to discard input AT data in TCP data send.

It returns ‘1’ on success, ‘0’ if error.

Example of use:

{ GPRS_SIM928A.DiscardInputATData(ENABLE);}

7.15. Enabling/disabling to get data manuallyIt enables or disables to get data manually from a TCP/UDP connection.

It returns ‘1’ on success, ‘0’ if error.

Example of use:

{ GPRS_SIM928A.SetDataManually(ENABLE);//Enabletogetdatamanuallyinsingleconnection GPRS_SIM928A.SetDataManually(DISABLE,6);//Disabletogetdatamanuallyinconnection6in multi-connection mode}

7.16. Getting data manuallyIt gets data manually from a TCP or UDP connection.

It returns ‘1’ on success, ‘0’ if error.

Example of use:

{ GPRS_SIM928A.GetDataManually(25);//Gets25charactersfromsingleconnection GPRS_SIM928A.GetDataManually(20,2);//Gets20characterfromconnection2inmulti-connectionmode}

Page 33: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

General functions

-33- v4.2

8. General functions

8.1. Managing incoming dataIt waits for incoming calls, SMSs or TCP/UDP data up to 20 seconds. When a call or SMS is received, this function stores in the tlfIN variable the telephone number which sent the SMS or made the call, in the buffer_GPRS variable the text of the SMS received and in sms_index the last SMS received index.

It executes the function readCall() if a call is received, readSMS() if a SMS is received and readIPData().

Returns ‘1’ for call, ‘2’ for SMS, ‘3’ for IP data and ‘0’ for error or not data.

Note 1: the phone number has a maximum length of 15 characters, including country code.

Note 2: the SMS text has a maximum size of 100 characters.

Note 3: the TCP/UDP data string has a maximum size of 150 characters.

Example of use:

{ GPRS_SIM928A.manageIncomingData();//Managesincomingdata}

Related variables:

• GPRS_SIM928A.tlfIN it stores the telephone number of the incoming SMS • GPRS_SIM928A.sms it stores the text of the received SMS • GPRS_SIM928A.buffer_GPRS it stores the data of TCP/UDP connections or the number of the incoming call

8.2. Sending any AT commandIt sends any AT command to the GPRS+GPS module and it stores in buffer_GPRS variable the answer returned by the GPRS+GPS module. This variable ends with the character ‘\0’.

It returns ‘1’ on success and ‘0’ if error.

Example of use :

{ GPRS_SIM928A.sendCommand(“+CCLK?”);//ItsendstheATcommand‘CCLK’}

8.3. Setting volume and mode for monitor speakerThese functions configure volume (0 to 9) and mode (0 to 9) of the monitor speaker.

They return ‘1’ on success, ‘0’ if error .

Example of use:

{ GPRS_SIM928A.setMonitorVolume(7); GPRS_SIM928A.setMonitorMode(1); }

Page 34: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

General functions

-34- v4.2

8.4. Setting CLI presentation in incoming callsThis function enables or disables the presentation of the incoming call.

It returns ‘1’ on success, ‘0’ if error.

Example of use:

{ GPRS_SIM928A.setCLIPresentation(ENABLE);}

8.5. Setting CLI presentation in outcoming calls/*This function restricts or enables the presentation of the CLI to the called party when originating a call. Allowed modes DEFAULT_CLIR, INVOKE_CLIR or SUPPRESS_CLIR.

It returns ‘1’ on success, ‘0’ if error.

Example of use:

{ GPRS_SIM928A.setCLIRestriction(SUPPRESS_CLIR); // Restricts the CLI for called party }

8.6. Gets the phone activity statusThis function gets the phone activity status and it returns ‘0’ for error, ‘1’= Ready, ‘2’= Unknown, ‘3’= Ringing and ‘4’= Call in progress.

Example of use:

{ status=GPRS_SIM928A.getPhoneActStatus(); }

8.7. Setting loudspeaker levelThis function sets loudspeaker volume level between 0-100.

It returns ‘1’ on success, ‘0’ if error and ‘-2’ if error with CME error code available..

Example of use:

{ GPRS_SIM928A.setLoudspeakerLevel(55);}

Page 35: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

General functions

-35- v4.2

8.8. Setting call alert mode and levelThis function configures mode, level and melody (0 to 19) of calls alert. Allowed modes are NORMAL_MODE or SILENT_MODE.

Allowed levels are LEVEL_OFF, LEVEL_LOW, LEVEL_MEDIUM, LEVEL_HIGH and LEVEL_CRESCENDO.

It returns:• ‘1’ on success• ‘0’ if error setting the sound mode• ‘-2’ if error setting the sound mode with CME error code available,• ‘-3’ if error setting the sound type• ‘-4’ if error setting the sound type with CME error code available,• ‘-5’ if error setting the ring level• ‘-6’ if error setting the ring level with CME error code available

Example of use:

{ GPRS_SIM928A.setCallAlert(SILENT_MODE);//Allsoundsfrommoduleareprevented GPRS_SIM928A.setCallAlert(NORMAL_MODE,2,LEVEL_CRESCENDO);}

8.9. MuteThis function enables or disables mute during a call.

It returns ‘1’ on success, ‘0’ if error and ‘-2’ if error with CME error code available.

Example of use:

{ GPRS_SIM928A.setMute(ENABLE);}

8.10. Getting current operatorIt gets the currently selected operator from network and stores it in ‘operator_name’.

It returns ‘1’ on success and ‘0’ if error and ‘-2’ if CME error code available.

Example of use:

{ GPRS_SIM928A.getcurrentOperator(); }

Page 36: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

General functions

-36- v4.2

8.11. Getting available operatorsThis function gets the currently available operators from network and stores it in ‘operators_list’.

It returns ‘1’ on success, ‘0’ if error and ‘-2’ if CME error code available.

Example of use:

{ GPRS_SIM928A.getAvailableOperators();}

Related variables

operators_list struct that stores the format and the name of the operators.

8.12. Setting preferred operatorThis function sets the preferred operator in the operators list into GPRS+GPS module.

It returns ‘1’ on success, ‘0’ if error and ‘-2’ if CME error code available.

Example of use:

{ GPRS_SIM928A.setPreferredOperator(1,0,“operator”);//Sets“operator”inshortformatinthe second index }

8.13. Getting cell informationThis function gets the information from the cell where the module is connected and stores it in ‘RSSI’ and ‘cellID’ variables.

It returns ‘1’ on success, ‘0’ if error and ‘-2’ if CME error code available.

Example of use:

{ GPRS_SIM928A.getCellInfo();}

The RSSI value is measured in -dBm.

Getting RSSI and cell ID example for SIM928A:

http://www.libelium.com/development/waspmote/examples/gprsgps-10-getting-rssi-and-cellid

The example for SIM908 can be found in Waspmote’s IDE.

Page 37: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

General functions

-37- v4.2

8.14. Getting module information The function whoamI() get the model of the module and saves it in buffer_GPRS. The function firmware_version()get the firmware of the module and saves it in buffer_GPRS.

These functions return ‘1’ on success, ‘0’ if error.

Example of use:

{USB.print(F(“WhoamI:“)); GPRS_SIM928A.whoamI();USB.println(GPRS_SIM928A.buffer_GPRS);USB.print(F(“Firmwareversion:“));GPRS_SIM928A.firmware_version();USB.println(GPRS_SIM928A.buffer_GPRS);}

Page 38: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

GPS related functions for SIM908

-38- v4.2

9. GPS related functions for SIM908

9.1. Defined variablesGPRS_SIM908.longitude stores longitude in ddmm.mmmmmm

GPRS_SIM908.EW_indicator stores ‘E’ for east or ‘W’ for west

GPRS_SIM908.latitude stores latitude in dddmm.mmmmmm

GPRS_SIM908.NS_indicator stores ‘N’ for north or ‘S’ for south

GPRS_SIM908.altitude stores altitude calculated with MSL_altitude and geoid separation

GPRS_SIM908.UTC_time stores UTC time in hhmmss

GPRS_SIM908.date stores date in ddmmyy

GPRS_SIM908.TTFF stores the time to first fix in seconds

GPRS_SIM908.num_sat stores the number of the satellites used in the solution

GPRS_SIM908.speedOG stores the speed over the ground

GPRS_SIM908.courseOG stores the course over the ground

GPRS_SIM908.sat_info stores data from up to 12 satellites in use into a table. Dimension of the table are 4 x 12. Data stored are: satellite ID, Elevation, azimuth and SNR (C/N0)

GPRS_SIM908.MSL_altitude stores Mean Sea Level altitude

GPRS_SIM908.geoid_separation stores the geoid to ellipsoid separation

GPRS_SIM908.HDOP stores the Horizontal Dilution Of Precision

GPRS_SIM908.PDOP stores the Position Dilution Of Precision

GPRS_SIM908.VDOP stores the Vertical Dilution Of Precision

GPRS_SIM908.mode stores the working mode of the GPS engine. ‘A’ for Autonomous mode, ‘D’ for differential GPS mode, ‘E’ for DR, ‘N’ if output data is not valid and ‘R’ if coarse position

GPRS_SIM908.manual_auto stores the mode of 2D/3D operation. ‘M’ for manual and ‘A’ for automatic change

GPRS_SIM908.FIX_2D_3D stores the status of the GPS fix. ‘1’ if not fixed, ‘2’ if 2D fix and ‘3’ if 3D fix

9.2. Starting the GPS engineTo start the GPS engine, the function GPRS_SIM908.GPS_ON() must be used.

The GPS module needs to recognize satellites before start working. Connecting to satellites is a process that may take some time, typically less than 35 seconds with good signal quality. So, the function GPRS_SIM908.waitForGPSSignal() should be used after to wait the GPS fix.

It returns ‘1’ on success, ‘0’ if error.

Example of use:

{ GPRS_SIM908.GPS_ON();}

Page 39: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

GPS related functions for SIM908

-39- v4.2

9.3. Stopping the GPS engineIt stops only the GPS engine. The GPRS+GPS module still active.

It returns ‘1’ on success, ‘0’ if error.

Example of use:

{ GPRS_SIM908.GPS_OFF();}

9.4. Checking GPS statusThe function GPRS_SIM908.check() has been developed to know the status of the GPS connection

It returns:

• ‘1’ if the status is unknow • ‘2’ if the satellites are not fixed • ‘3’ if the satellites are fixed in 2D operation • ‘4’ if the satellites are fixed in 3D operation • ‘0’ if error

Example of use:

{ int status; status = GPRS_SIM908.check(); USB.print(F(“GPSstatus:“); USB.println(status,DEC);}

9.5. Waiting for signal connectionOnce the GPS engine is set on, it is necessary to wait for signal connection. The function in charge of this duty is GPRS_SIM908.waitForGPSSignal(). This function waits to connect to satellites for a specific time. The default time to wait for signal connection is 120 seconds. But another time can be specified. If the GPS engine connects to satellites, the function returns successfully. If the GPS does not connect to satellites for the specified time, then returns error.

It returns ‘1’ if the GPS has connected within the period of time and ‘0’ if not.

Example of use:

{//definetimeout#defineGPS_TIMEOUT200 // wait to connect for a maximum time of 200 seconds bool status = GPRS_SIM908.waitForGPSSignal(GPS_TIMEOUT); if(status == true) { // connected } else { // not connected }}

Page 40: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

GPS related functions for SIM908

-40- v4.2

9.6. Reading NMEA stringsWhen the GPS engine fixes the satellites signal, NMEA strings can be requested in order to extract GPS data. Each NMEA string must be requested using the function GPRS_SIM908.getGPSData(). This function needs two input parameters. The first one is the NMEA string to request: Basic, GGA, GLL, GSA, GSV, RMC, VTG or ZDA. The second parameter indicates if the NMEA string must be parsed or not (‘0’ not parsed, ‘1’ parsed). When the NMEA string is parsed, the related variables are updated. To know the relation between the NMEA strings and the variables see the table below:

API variablesNMEA strings

Basic GGA GLL GSA GSV RMC VTG ZDA

latitude X X X X

NS_indicator X X X X

longitude X X X X

EW_indicator X X X X

altitude X

date X X X

UTC_time X X X X X

TTFF X

num_sat X X X

speedOG X X X

courseOG X X X

MSL_altitude X

geoid_separation X

HDOP X X

PDOP X

VDOP X

sat_info X X

mode X X X

manual_auto X

FIX_2D_3D X

Figure: Table with NMEA strings and variables

Example of use:

{ // Reads GGA string without parseGPRS_SIM908.getGPSData(GGA,0);USB.println(GPRS_SIM908.buffer_GPRS);}

Showing GPS information example for SIM908 can be found in Wasmpte’s IDE.

Page 41: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

GPS related functions for SIM908

-41- v4.2

9.7. Converting to degreesThere is a useful function to convert the longitude or the latitude given by the GPS module to degrees. This function is called GPRS_SIM908.convert2Degrees and returns the longitude or latitude represented as a float. Range: 180 to -180.

Example of use

{ floatlongitude; floatlatitude;longitude=GPRS_SIM908.convert2Degrees(GPRS_SIM908.longitude, GPRS_SIM908.EW_indicator); latitude=GPRS_SIM908.convert2Degrees(GPRS_SIM908.latitude, GPRS_SIM908.NS_indicator); }

9.8. Setting RTC time and date from the GPSIt sets time and date to the RTC, getting the data from the GPS engine. Inside this function, time and date are obtained from the GPS engine.

It returns ‘1’ if time and date have been updated and ‘0’ if not.

Example of use

{ //Sets time and date to the RTC from the GPS engine GPRS_SIM908.setTimeFromGPS(); }

Page 42: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

GPS related functions for SIM928A

-42- v4.2

10. GPS related functions for SIM928A

10.1. Defined variablesGPRS_SIM928A.longitude stores longitude in ±ddd.dddddd

GPRS_SIM928A.latitude stores latitude in ±dd.dddddd

GPRS_SIM928A.altitude stores MSL altitude

GPRS_SIM928A.UTC_time stores UTC time in hhmmss

GPRS_SIM928A.date stores date in ddmmyy

GPRS_SIM928A.sats_in_view stores the number of the satellites in view

GPRS_SIM928A.num_sat stores the number of the satellites used in the solution

GPRS_SIM928A.speedOG stores the speed over the ground

GPRS_SIM928A.courseOG stores the course over the ground

GPRS_SIM928A.HDOP stores the Horizontal Dilution Of Precision

GPRS_SIM928A.PDOP stores the Position Dilution Of Precision

GPRS_SIM928A.VDOP stores the Vertical Dilution Of Precision

GPRS_SIM928A.GPS_status ‘0’ for GPS disabled and ‘1’ for GPS enabled

GPRS_SIM928A.fix_status ‘0’ if position is not fixed and ‘1’ if position is fixed

GPRS_SIM928A.SNR stores the signal / noise ratio

GPRS_SIM928A.mode stores the working mode of the GPS engine. ‘A’ for Autonomous mode, ‘D’ for differential GPS mode, ‘E’ for DR, ‘N’ if output data is not valid and ‘R’ if coarse position

10.2. Starting the GPS engineTo start the GPS engine, the function GPRS_SIM928A.GPS_ON() must be used.

The GPS module needs to recognize satellites before start working. Connecting to satellites is a process that may take some time, typically less than 35 seconds with good signal quality. So, the function GPRS_SIM928A.waitForGPSSignal() should be used after to wait the GPS fix.

It returns ‘1’ on success, ‘0’ if error.

Example of use:

{ GPRS_SIM928A.GPS_ON();}

Page 43: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

GPS related functions for SIM928A

-43- v4.2

10.3. Stopping the GPS engineIt stops only the GPS engine. The GPRS+GPS module still active.

It returns ‘1’ on success, ‘0’ if error.

Example of use:

{ GPRS_SIM928A.GPS_OFF();}

10.4. Checking GPS statusThe function GPRS_SIM928A.checkGPS() has been developed to know the status of the GPS connection

It returns:

• ‘1’ if satellites are fixed • ‘2’ if satellites are not fixed • ‘0’ if timeout

Example of use:

{ int status; status = GPRS_SIM928A.checkGPS(); USB.print(F(“GPSstatus:“); USB.println(status,DEC);}

10.5. Waiting for signal connectionOnce the GPS engine is set on, it is necessary to wait for signal connection. The function in charge of this duty is GPRS_SIM928A.waitForGPSSignal(). This function waits to connect to satellites for a specific time. The default time to wait for signal connection is 120 seconds. But another time can be specified. If the GPS engine connects to satellites, the function returns successfully. If the GPS does not connect to satellites for the specified time, then returns error.

It returns ‘1’ if the GPS has connected within the period of time and ‘0’ if not.

Example of use:

{//definetimeout#defineGPS_TIMEOUT200 // wait to connect for a maximum time of 200 seconds bool status = GPRS_SIM928A.waitForGPSSignal(GPS_TIMEOUT); if(status == true) { // connected } else { // not connected }}

Page 44: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

GPS related functions for SIM928A

-44- v4.2

10.6. Reading GPS dataOnce the position is fixed, the function getGPSData() reads the data which the module has parsed from NMEA strings. The function only needs one parameter to select if the must be returned as a string stored in buffer_GPRS (the parameter will be ‘0’) or must be stored in the library variables (the parameter will be ‘1’).

It returns ‘1’ if success, ‘-1’ if timeout reading the data and ‘-2’ if error.

Example of use:

{ // Read GPS data and store it in buffer_GPRSGPRS_SIM928A.getGPSData(0);USB.println(GPRS_SIM928A.buffer_GPRS);}

Showing GPS information example for SIM928A:

http://www.libelium.com/development/waspmote/examples/gprsgps-24-getting-gps-info

10.7. Setting RTC time and date from the GPSIt sets time and date to the RTC, getting the data from the GPS engine. Inside this function, time and date are obtained from the GPS engine.

It returns ‘1’ if time and date have been updated and ‘0’ if not.

Example of use

{ //Sets time and date to the RTC from the GPS engine GPRS_SIM928A.setTimeFromGPS(); }

Page 45: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

Working with Hibernate mode

-45- v4.2

11. Working with Hibernate modeWhen using the GPRS+GPS module with Hibernate mode, a little trick is necessary. Hibernate mode is woken up by the RTC’s interrupt pin which is connected to the socket1’s RX pin. So, it is necessary to add the following lines to get the GPRS+GPS module working after calling the funcion PWR.ifHibernate():

{ // Checks if we come from a normal reset or an hibernate reset PWR.ifHibernate(); delay(3000); RTC.ON(); RTC.clearAlarmFlag(); RTC.OFF(); // now, GPRS_Pro can start}

Lost call with hibernate example for SIM928A:

http://www.libelium.com/development/waspmote/examples/gprs-23-lost-call-with-hibernate

The example for SIM908 can be found in Waspmote’s IDE.

Page 46: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

Geolocation tracker application example

-46- v4.2

12. Geolocation tracker application exampleThe GPRS+GPS module allows the developer to send the GPS location and sensor data to the cloud, via GPRS. This chapter shows how to track a Waspmote with GPRS+GPS module and see in the web with Google Maps API. The example for Waspmote and the PHP script for the server are shown as help or inspiration for the developer.

Before starting to use Waspmote, you must install the PHP script (shown at the end of the chapter). To use the PHP script you need an Apache server with PHP active. You can run the script in a PC installing Apache with PHP. You can do this easily with the installer from these websites (or the package manager for Linux):

• For Windows use WAMP: http://www.wampserver.com/ • For Linux use LAMP: Use your package manager in Linux • For Mac use MAMP: http://www.mamp.info/

In these websites, you have manuals to help you to install the server and activate PHP. Extract the PHP script on your computer. You must change the Google Maps API v3 key in the PHP script:

“http://maps.googleapis.com/maps/api/js?key=your_key&sensor=false”

To show the map with the marker you need to access to the next URL:

The IP address or server domain must be the same used in the example code of Waspmote (in case you are running the demo on your computer, replace “your_IP_or_domain” by “localhost”)

Once the PHP script has been installed and Waspmote has the example code (GPRS+GPS 26: demo GPS tracker) uploaded, Waspmote can be switched on. Remember, you must configure your APN, login and password. If you don’t do this, the GPRS+GPS module cannot connect to the GPRS network. Also, you must set the URL with the IP address of your computer (external IP, not the LAN IP address) or your server’s domain.

When the GPS fixes the GPS satellites, the GPRS+GPS module will connect to the network and send the GPS data through the Internet to the PHP script in your computer. When a frame is received, a marker will be shown in the map.

Figure: Geolocation tracker demo - Map Figure: Geolocation tracker demo - Satellite

Page 47: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

Geolocation tracker application example

-47- v4.2

<?php if(!empty($_GET[‘latitude’])&&!empty($_GET[‘longitude’])&&!empty($_GET[‘time’])&&!empty($_GET[‘satellites’])&&!empty($_GET[‘speedOTG’])&&!empty($_GET[‘course’])){functiongetParameter($par,$default=null){if(isset($_GET[$par])&&strlen($_GET[$par]))return$_GET[$par];elseif(isset($_POST[$par])&&strlen($_POST[$par]))return$_POST[$par];elsereturn$default; }$file=‘gps.txt’;$lat=getParameter(“latitude”);$lon=getParameter(“longitude”);$time=getParameter(“time”);$sat=getParameter(“satellites”);$speed=getParameter(“speedOTG”);$course=getParameter(“course”);$person=$lat.”,”.$lon.”,”.$time.”,”.$sat.”,”.$speed.”,”.$course.”\n”; echo“DATA:\nLatitude:“.$lat.”\nLongitude:“.$lon.”\nTime:“.$time.”\nSatellites:“.$sat.”\nSpeedOTG:“.$speed.”\nCourse:“.$course;if(!file_put_contents($file,$person,FILE_APPEND|LOCK_EX))echo“\n\tErrorsavingData\n”;elseecho“\n\tDataSave\n”; } else {?><!DOCTYPEhtml><html> <head><!--LoadJquery--><scriptlanguage=”JavaScript”type=”text/javascript”src=”jquery-1.10.1.min.js”></script><!--LoadGoogleMapsApi--><!--IMPORTANT:changetheAPIv3key--><scriptsrc=”http://maps.googleapis.com/maps/api/js?key=your_key&sensor=false”></script><!--InitializeMapandmarkers--><scripttype=”text/javascript”>varmyCenter=newgoogle.maps.LatLng(41.669578,-0.907495);varmarker;varmap;varmapProp;functioninitialize() { mapProp = { center:myCenter, zoom:15,mapTypeId:google.maps.MapTypeId.ROADMAP };setInterval(‘mark()’,5000); } function mark() { map=newgoogle.maps.Map(document.getElementById(“googleMap”),mapProp);varfile=“gps.txt”;$.get(file,function(txt){varlines=txt.split(“\n”);for(vari=0;i<lines.length;i++){console.log(lines[i]);

Page 48: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

Geolocation tracker application example

-48- v4.2

varwords=lines[i].split(“,”);if((words[0]!=””)&&(words[1]!=””)) { marker=new google.maps.Marker({position:newgoogle.maps.LatLng(words[0],words[1]), }); marker.setMap(map);map.setCenter(newgoogle.maps.LatLng(words[0],words[1]));document.getElementById(‘sat’).innerHTML=words[3];document.getElementById(‘speed’).innerHTML=words[4];document.getElementById(‘course’).innerHTML=words[5]; } }marker.setAnimation(google.maps.Animation.BOUNCE); }); }google.maps.event.addDomListener(window,‘load’,initialize); </script></head><body> <?phpecho‘<!--DrawinformationtableandGoogleMapsdiv--><div> <center><br /><b>SIM908GPSpositionDEMO</b><br/><br/><divid=”superior”style=”width:800px;border:1pxsolid”><tablestyle=”width:100%”> <tr> <td>Time</td> <td>Satellites</td> <td>Speed OTG</td> <td>Course</td> </tr> <tr><tdid=”time”>’.date(“YMd-H:m”).’</td><tdid=”sat”></td><tdid=”speed”></td><tdid=”course”></td> </tr> </table></div> <br /><br /><divid=”googleMap”style=”width:800px;height:700px;”></div> </center></div>’; ?></body></html><?php } ?>

Geolocation tracker example for SIM928A:

http://www.libelium.com/development/waspmote/examples/gprsgps-26-demo-gsp-tracker

The example for SIM908 can be found in Waspmote’s IDE.

Page 49: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

-49- v4.2

13. Code examples and extended information

In the Waspmote Development section you can find complete examples:

http://www.libelium.com/development/waspmote/examples

Example:

#include “WaspGPRS_SIM928A.h”

int answer;

void setup(){}

void loop(){ // setup for Serial port over USB: USB.ON(); USB.println(F(“USB port started...”)); // activates the GPRS+GPS module: answer = GPRS_SIM928A.ON(); if ((answer == 1) || (answer == -3)) { USB.println(F(“GPRS+GPS module ready...”)); // sets pin code: USB.println(F(“Setting PIN code...”)); // **** must be substituted by the SIM code if (GPRS_SIM928A.setPIN(“****”) == 1) { USB.println(F(“PIN code accepted”)); } else { USB.println(F(“PIN code incorrect”)); }

// waits for connection to the network: answer = GPRS_SIM928A.check(180); if (answer == 1) { USB.println(F(“GPRS+GPS module connected to the network...”)); // configures GPRS Connection for HTTP or FTP applications: answer = GPRS_SIM928A.configureGPRS_HTTP_FTP(1); if (answer == 1) { USB.println(F(“Uploading the file 1...”));

// uploads file from SD card to the FTP server: answer = GPRS_SIM928A.uploadFile(“/dirSD1/dirSD2/fileSD1.txt”, “/ftp1/ftp2/fileFTP1.txt”, “username”, “password”, “IP_server”, “port”, 1); if (answer == 1) { USB.println(F(“Upload done”)); }

Page 50: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

-50- v4.2

else if(answer < -40) { USB.print(F(“Upload failed. Error code: “)); USB.println(answer, DEC); USB.print(F(“CME error code: “)); USB.println(GPRS_SIM928A.CME_CMS_code, DEC); } else { USB.print(F(“Upload failed1. Error code: “)); USB.println(answer, DEC); }

USB.println(F(“Uploading the file 2”));

// uploads file from SD card to the FTP server: answer = GPRS_SIM928A.uploadFile(“/fileSD2.txt”, “/fileFTP2.txt”, “username”, “password”, “IP_server”, “port”, 1); if (answer == 1) { USB.println(F(“Upload done”)); } else if (answer < -40) { USB.print(F(“Upload failed. Error code: “)); USB.println(answer, DEC); USB.print(F(“CME error code: “)); USB.println(GPRS_SIM928A.CME_CMS_code, DEC); } else { USB.print(F(“Upload failed. Error code: “)); USB.println(answer, DEC); } } else { USB.println(F(“Configuration failed. Error code:”)); USB.println(answer, DEC); } } else { USB.println(F(“GPRS+GPS module cannot connect to the network”)); } } else { USB.println(F(“GPRS+GPS module not ready”)); }

GPRS_SIM928A.OFF(); // powers off the GPRS+GPS module

USB.println(F(“Sleeping...”));

// activates the RTC: RTC.ON(); // sleeps one hour PWR.deepSleep(“00:01:00:00”, RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);

// deactivates the RTC: RTC.OFF();}

Page 51: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

-51- v4.2

14. API changelogKeep track of the software changes on this link:

www.libelium.com/development/waspmote/documentation/changelog/#GPRS-GPS

Page 52: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

-52- v4.2

15. Documentation changelog

From v4.1 to v4.2

• Added references to the new GPRS+GPS version, with the chipset SIM928A

From v4.0 to v4.1:

• Created new chapter “API changelog”

Page 53: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

Appendix 1: CME error codes

-53- v4.2

Appendix 1: CME error codes

CME error code Description

0 phone failure

1 no connection to phone

2 phone-adapter link reserved

3 operation not allowed

4 operation not supported

5 PH-SIM PIN required

6 PH-FSIM PIN required

7 PH-FSIM PUK required

10 SIM not inserted

11 SIM PIN required

12 SIM PUK required

13 SIM failure

14 SIM busy

15 SIM wrong

16 incorrect password

17 SIM PIN2 required

18 SIM PUK2 required

20 memory full

21 invalid index

22 not found

23 memory failure

24 text string too long

25 invalid characters in text string

26 dial string too long

27 invalid characters in dial string

30 no network service

31 network timeout

32 network not allowed - emergency call only

40 network personalization PIN required

41 network personalization PUK required

42 network subset personalization PIN required

43 network subset personalization PUK required

44 service provider personalization PIN required

45 service provider personalization PUK required

46 corporate personalization PIN required

47 corporate personalization PUK required

99 resource limitation

CME error code Description

100 unknown

103 Illegal MS

106 Illegal ME

107 GPRS services not allowed

111 PLMN not allowed

112 Location area not allowed

113 Roaming not allowed in this location area

132 service option not supported

133 requested service option not subscribed

134 service option temporarily out of order

148 unspecified GPRS error

149 PDP authentication failure

150 invalid mobile class

151 Operation barred – Fixed dialing numbers only

Page 54: Waspmote GPRS/GPS - Libelium€¦ · The GPRS+GPS module offers exactly the same GPRS features, and adds GPS features too. Both modules are controlled in the same way for the GPRS

Appendix 2: CMS error codes

-54- v4.2

Appendix 2: CMS error codes

CMS error code Description

300 ME failure

301 SMS reserved

302 operation not allowed

303 operation not supported

304 invalid PDU mode

305 invalid text mode

310 SIM not inserted

311 SIM pin necessary

312 PH SIM pin necessary

313 SIM failure

314 SIM busy

315 SIM wrong

316 SIM PUK required

317 SIM PIN2 required

318 SIM PUK2 required

320 memory failure

321 invalid memory index

322 memory full

323 invalid input parameter

324 invalid input format

330 SMSC address unknown

331 no network

332 network timeout

340 no CNMA ACK

500 Unknown

512 SIM not ready

513 unread records on SIM

514 CB error unknown

515 PS busy

517 SIM BL not ready

528 Invalid (non-hex) chars inPDU

529 Incorrect PDU length

530 Invalid MTI

531 Invalid (non-hex) chars in address

532 Invalid address (no digits read)

533 Incorrect PDU length (UDL)

534 Incorrect SCA length

536 Invalid First Octet (should be 2 or 34)

537 Invalid Command Type

538 SRR bit not set

539 SRR bit set

CMS error code Description

540 Invalid User Data Header IE

753 missing required CMD parameter

754 invalid SIM command

755 invalid File Id

756 missing required P1/2/3 parameter

757 invalid P1/2/3 parameter

758 missing required command data

759 invalid characters in command data

765 Invalid input value

766 Unsupported mode

767 Operation failed

768 Mux already running

769 Unable to get control

770 SIM network reject

765 Invalid input value

766 Unsupported mode

767 Operation failed

768 Mux already running

769 Unable to get control

770 SIM network reject

771 Call setup in progress

772 SIM powered down

773 SIM file not present