Libelium SIM5215, Waspmote 4G, LE910 Networking Manual

Waspmote 4G
Networking Guide
-2-
v7.3
Document version: v7.3 - 10/2018 © Libelium Comunicaciones Distribuidas S.L.
INDEX
1. Introduction ..........................................................................................................................4
2. 3G (SIM5215) vs 4G (LE910) ................................................................................................... 5
3. Hardware ...............................................................................................................................6
3.1. Specications ..................................................................................................................................... 6
3.2. Versions .............................................................................................................................................. 6
3.3. How to connect the module ............................................................................................................ 7
3.4. Antennas ............................................................................................................................................ 9
3.5. Power consumption........................................................................................................................ 10
3.6. Time consumption .......................................................................................................................... 10
4. Software ............................................................................................................................... 11
4.1. Waspmote library ............................................................................................................................ 11
4.1.1. Waspmote 4G library ..........................................................................................................11
4.1.2. Class constructor .................................................................................................................11
4.1.3. API constants .......................................................................................................................11
4.1.4. API variables .........................................................................................................................12
4.1.5. API functions ........................................................................................................................13
4.1.6. Error codes ...........................................................................................................................13
4.2. Switching on .................................................................................................................................... 16
4.3. Switching o .................................................................................................................................... 16
4.4. SIM card............................................................................................................................................ 16
4.4.1. Entering PIN .........................................................................................................................16
4.4.2. Getting IMEI, IMSI and ICCID ..............................................................................................17
4.5. Checking network connection status ........................................................................................... 18
4.6. Setting operator parameters ......................................................................................................... 19
4.7. SMS ................................................................................................................................................... 19
4.7.1. Setting SMS conguration ..................................................................................................19
4.7.2. Sending SMSs .......................................................................................................................20
4.7.3. Reading SMSs .......................................................................................................................20
4.7.4. Deleting SMSs ......................................................................................................................21
4.8. HTTP client ....................................................................................................................................... 22
4.8.1. HTTP connections ................................................................................................................22
4.8.2. HTTP request methods .......................................................................................................23
4.8.3. Sending Waspmote frames to Meshlium via HTTP .........................................................25
4.8.4. Sending Waspmote frames to Meshlium via HTTPS .......................................................27
4.9. FTP client .......................................................................................................................................... 28
-3-
v7.3
4.9.1. Opening an FTP session .....................................................................................................28
4.9.2. FTP upload............................................................................................................................29
4.9.3. FTP download ......................................................................................................................30
4.9.4. FTP delete le .......................................................................................................................31
4.9.5. FTP working directory .........................................................................................................31
4.9.6. Closing an FTP session ........................................................................................................31
4.10. TCP/UDP connections................................................................................................................... 32
4.10.1. Socket identiers ...............................................................................................................32
4.10.2. Socket information structure ...........................................................................................32
4.10.3. Socket status structure .....................................................................................................33
4.10.4. Creating a TCP/UDP client socket ....................................................................................34
4.10.5. Creating a TCP/UDP server socket ..................................................................................35
4.10.6. Sending data ......................................................................................................................36
4.10.7. Receiving data ...................................................................................................................37
4.10.8. Closing a socket .................................................................................................................38
4.10.9. SSL sockets .........................................................................................................................38
4.11. GPS ................................................................................................................................................. 41
4.11.1. Standalone or Autonomous GPS (S-GPS) .......................................................................42
4.11.2. Assisted GPS (A-GPS).........................................................................................................42
4.11.3. Get GPS position ...............................................................................................................42
4.11.4. Indoor tracking using 4G and A-GPS mode (geolocation) ............................................44
4.12. e-mail management functions .................................................................................................... 47
4.12.1. Reseting e-mail parameters .............................................................................................47
4.12.2. Setting the SMTP server ...................................................................................................47
4.12.3. Conguring SMTP parameters ........................................................................................47
4.12.4. Setting the sender parameters: address, username and password ..........................48
4.12.5. Saving e-mail parameters ................................................................................................48
4.12.6. Sending an e-mail ..............................................................................................................48
5. Certications ....................................................................................................................... 50
6. Code examples and extended information .....................................................................51
7. API changelog ...................................................................................................................... 52
8. Documentation changelog ................................................................................................53
-4-
v7.3
Introduction
1. Introduction
This guide explains the features and use of the new 4G module. This module was specically integrated for our
new product lines Waspmote v15, Plug & Sense! v15 and Meshlium v4.0, released on October 2016. The 4G module is not compatible Waspmote v12, Plug & Sense! v12 or Meshlium 3.x.
If you are using previous versions of our products, please use the corresponding guides, available on our Development website.
You can get more information about the generation change on the document “New generation of Libelium product lines”. The 4G module has been integrated into the devices Waspmote OEM, Plug & Sense! and Meshlium.
The new 4G module enables the connectivity to high speed LTE, HSPA+, WCDMA cellular networks in order to make possible the creation of the next level of worldwide compatible projects inside the new “Internet of Things” era.
The new communication module is specially oriented to work with Internet servers, implementing internally several application layer protocols, which make easier to send the information to the cloud. We can make HTTP navigation, downloading and uploading content to a web server. We can also set secure connections using SSL
certicates and setting TCP/IP private sockets. In the same way, the FTP protocol is also available which is really useful when your application requires handling les.
The module includes a GPS/GLONASS receiver, able to perform geolocation services using NMEA sentences,
oering information such as latitude, longitude, altitude and speed; that makes it perfect to perform tracking
applications.
The new 4G module oers the maximum performance of the 4G network as it uses 2 dierent antennas (normal
+ diversity) for reception (MIMO DL 2x2), choosing the best received signal at any time and getting a maximum download speed of 100 Mbps.
We chose the LE910 chipset family from Telit as it comprises the most complete 4G/LTE set of variants released
up to date. It counts with many dierent models, each one specically designed for one market but all of them
with the same footprint:
LE910-EUG (Europe / Brazil): CE, GCF, ANATEL
LE910-NAG (US / Canada): FCC, IC, PTCRB, AT&T approved
LE910-AU V2 (Australia): RCM, Telstra approved
Important note: The current stock of the LE910 4G radio that the manufacturer ‘Telit’ is distributing comprises the v2 version which does not have GPS. The models are:
LE910-EU V2 for Europe or Brazil
LE910-NA V2 for US or Canada
These v2 radios are similar to the v1 ones, but support more bands and do not have a GPS receiver.
Important:
All documents and any examples they contain are provided as-is and are subject to change without notice. Except to the extent prohibited by law, Libelium makes no express or implied representation or warranty of
any kind with regard to the documents, and specically disclaims the implied warranties and conditions of merchantability and tness for a particular purpose.
The information on Libelium’s websites has been included in good faith for general informational purposes
only. It should not be relied upon for any specic purpose and no representation or warranty is given as to its
accuracy or completeness.
-5-
v7.3
3G (SIM5215) vs 4G (LE910)
2. 3G (SIM5215) vs 4G (LE910)
The new 4G module (specic for the new lines Waspmote v15, Plug & Sense! v15 and Meshlium 4.0) introduces
some changes with respect to the 3G module (available for the old lines Waspmote v12, Plug & Sense! v12, Meshlium 3.5 and the new Waspmote v15):
The new 4G counts with many dierent models, one specically designed for each market:
- LE910-EU (Europe / Brazil): CE, GCF, ANATEL
- LE910-NAG (US / Canada): FCC, IC, PTCRB, AT&T approved
- LE910-AU V2 (Australia): RCM, Telstra approved
The GPS module also makes it possible to perform geo-location services using NMEA sentences, oering information such as latitude, longitude, altitude and speed, what makes it perfect for tracking applications.
The new 4G module oers the maximum performance of the 4G network as it uses 2 dierent antennas (normal + diversity) for reception (MIMO DL 2x2), choosing the best received signal at any time and getting a maximum download speed of 100 Mbps.
Features comparison:
Features [v12] 3G module (SIM5215) [v15] 4G module (LE910)
Chipset manufacturer SIMCom Telit
Cellular protocols 3G / GPRS / GSM 4G / 3G / GPRS / GSM
Certications CE, GCF, FCC, IC, PTCRB
CE, GCF, ANATEL, FCC, IC, PTCRB, AT&T
Compliant, KCC, RCM, NTT DoCoMo, KDDi
GPS No Yes
Camera option Yes No
SD card Yes No
USB connectivity Yes Yes
Download max speed 384 kbps 100 Mbps
Upload max speed 384 kbps 50 Mbps
Antenna diversity No Yes
Cellular carriers (mobile
network operator)
Any
Any + Specially tested with AT&T, SK Telecom,
Telstra, NTT DoCoMo or KDDi
FTP Yes Yes
FTPS (Secure) Yes No
HTTP Yes Yes
HTTPS (Secure) Yes No
TCP/UDP sockets Yes Yes
SSL sockets No Yes
Mails Yes Yes
4G compatibility:
Item Compatible Notes
Waspmote 12 Yes New Waspmote API needed (v025 or newer)
Waspmote 15 Yes New Waspmote API needed (v025 or newer)
Old 3G codes No
The new 4G module provides new improved
examples and libraries
-6-
v7.3
Hardware
3. Hardware
3.1. Specications
The 4G module is based on the LE910 chipset, manufactured by Telit. The module is managed by UART and it must be connected to socket 1 (direct connection, without Expansion Board). The main features of the module are listed below:
Output power:
- Class 4 (2 W, 33 dBm) @ GSM 850 / 900
- Class 1 (1 W, 30 dBm) @ GSM 1800 / 1900
- Class E2 (0.5 W, 27 dBm) @ EDGE 850 / 900
- Class E2 (0.4 W, 26 dBm) @ EDGE 1800 /1900
- Class 3 (0.25 W, 24 dBm) @ UMTS
- Class 3 (0.2 W, 23 dBm) @ LTE
Data transmission:
- LTE: » Uplink up to 50 Mbps » Downlink up to 100 Mbps
- HSPA+: » Uplink up to 5.76 Mbps » Downlink up to 42.0 Mbps
- UMTS: » Uplink/Downlink up to 384 kbps
Protocols:
- TCP/UDP
- HTTP
- FTP
GPS receiver (in certain versions)
3.2. Versions
Telit has dierent versions of the LE910 chipset. Each one of them was especially designed to comply with the RF and cellular regulations in dierent countries or regions of the world. Libelium has integrated the following
versions:
Features LE910 EUG LE910 NAG LE910 AU V2
Region Europe and Brazil
USA and Canada
(Americas)
Australia
Supported 4G bands
B20 (800), B3 (1800), B7
(2600)
B17 (700), B5 (850), B4
(1700), B2 (1900)
B3 (1800), B7 (2600), B28
(700)
3G fall-back Yes Yes No
Supported 3G bands
B5 (850), B8 (900), B1
(2100)
B5 (850), B2 (1900) None
2G fall-back Yes Yes No
Supported 2G bands GSM 900, DCS 1800 GSM 850, PCS 1900 None
GPS/GLONASS Yes Yes No
Certications CE (R&TTE), GCF FCC, IC, PTCRB, AT&T RCM, Telstra
Figure : 4G module
-7-
v7.3
Hardware
Important note: The current stock of the LE910 4G radio that the manufacturer ‘Telit’ is distributing comprises the v2 version which does not have GPS. The models are:
LE910-EU V2 for Europe or Brazil
LE910-NA V2 for US or Canada
These v2 radios are similar to the v1 ones, but support more bands and do not have a GPS receiver.
Features LE910 EU V2 LE910 NA V2
Region Europe USA and Canada (Americas)
Supported 4G bands
B20 (800), B8 (900), B3 (1800), B1
(2100), B7 (2600)
B12 (700), B13 (700), B5 (850), B4
(1700), B2 (1900)
3G fall-back Yes Yes
Supported 3G bands B8 (900), B1 (2100) B5 (850), B2 (1900)
2G fall-back Yes No
Supported 2G bands 900 / 1800 None
GPS/GLONASS No No
3.3. How to connect the module
This module must be connected to the SOCKET1 on the Waspmote board. Like any other cellular radio, the connection is native so the radio does not need the Expansion Radio Board.
Figure : Module connected to Waspmote in SOCKET1
-8-
v7.3
Hardware
The SIM card used in the 4G module OEM version is a “standard SIM”, also known as “mini SIM”. The next picture shows how the SIM card must be plugged in the 4G module.
Figure : SIM card installation in OEM version
On the other hand, Plug and Sense! models with 4G radio provide a special connector in order to plug both micro USB wire and nano SIM card for the 4G module.
Figure : SIM card installation in Plug and Sense! version
Figure : Push-push mechanism in the External SIM/USB socket
-9-
v7.3
Hardware
3.4. Antennas
The 4G module comes with 2 cellular antennas for improving the signal reception: normal (main) antenna and diversity antenna. Besides, a 3rd antenna is also included for the GPS receiver (when it is available in the 4G module).
All these 3 antennas are the same model and can be used in any of the 4G sockets. The operating bands of the dipole antenna go from 698 to 960 MHz and from 1710 to 2690 MHz. The maximum gain of the antenna is observed at 2.6 GHz: 3.4 dBi.
To get the maximum performance, it is recommended to place the antennas like that:
The main cellular antenna should be in vertical position, pointing to the sky, in order to radiate better to the cellular base stations around.
The diversity cellular antenna should be in horizontal position (orthogonal, 90º, to the main antenna). Besides, the plane where the antenna is should be also orthogonal to the main antenna’s plain. Finally, it is advised to place this 2nd cellular antenna as fas as possible from the main antenna. These 3 measures will maximize the gain due to reception diversity.
The GPS antenna should be in horizontal position, because the GPS satellite signal will come from above.
Figure : 4G module antennas
-10-
v7.3
Hardware
3.5. Power consumption
The 4G module is directly powered by the battery. The next table shows the Waspmote’s peak current consumption
in dierent states of the 4G module.
State
Mean power
consumption
On 100 mA
Transmitting data 400 mA
Receiving data 400 mA
Non-rechargeable batteries are not advised for the 4G module, because the high peaks of current consumption could make the voltage of these batteries to go below 3.3 V so Waspmote would reset. The rechargeable battery
will not suer this eect as long as its level is above 20%.
3.6. Time consumption
The following table describes the mean elapsed time for some actions in a single test for several attempts:
Action Mean elapsed time
Power on ~11 s
Start data connection ~4 s
Perform HTTP GET or POST ~0.7 s
Open FTP session ~3 s
Perform FTP upload 10 kB le ~7 s
Perform FTP download 10 kB
le
~6 s
Some of these actions approximately have a xed elapsed time like powering on the module. However, the actions
related to data transmission (HTTP, FTP, etc.) are dependent on external circumstances (MNO, coverage quality, etc) and show more variability from the mean value.
-11-
v7.3
Software
4. Software
4.1. Waspmote library
4.1.1. Waspmote 4G library
The les related to the 4G module library are:
/Wasp4G/Wasp4G.h /Wasp4G/Wasp4G.cpp /Wasp4G/utility/Wasp4G_constants.h /Wasp4G/utility/Wasp4G_error_codes.h
It is mandatory to include the 4G library when using this module. So the following line must be added at the beginning of the code:
#include <Wasp4G.h>
4.1.2. Class constructor
To start using the Waspmote 4G library, an object from the Wasp4G class must be created. This object, called _4G, is already created by default inside the Waspmote 4G library. It will be used along this guide to show how Waspmote works.
When using the class constructor, all variables are initialized to their default values.
4.1.3. API constants
The API constants used in functions are:
Constant Description
DEBUG_WASP4G
This denition enables/disables the debug mode via USB
port: 0: No debug mode enabled 1: Debug mode enabled for error output messages 2: Debug mode enabled for both error and OK messages
LE910_RATE
Module's communication baud rate
LE910_INCOMING_SMS
Constant to set incoming data type when SMS received
LE910_INCOMING_IP
Constant to set incoming data type when IP received
LE910_MAX_DL_PAYLOAD
Maximum data payload size to be stored in the data
buer
The are several enumeration denitions for the function inputs. Please refer to the corresponding section in order
to know more about the functions input parameters.
-12-
v7.3
Software
4.1.4. API variables
Variable Description
_buffer
The buer of memory used for storing the responses from the module (512
bytes)
_length
The length of the contents stored in _buffer
_def_delay
The time to wait after sending every command until listen for a response
_baudrate
The baudrate to be used when the module is switched on
_uart
The selected UART (regarding the socket used: SOCKET0 or SOCKET1)
_errorCode
It stores the error code returned by the module when calling a function with error response
_ip
IP address assigned to the 4G module when it is connected to the network
_temp
It stores temperature from the module
_tempInterval
It stores temperature interval from the module
_rssi
It stores the module's RSSI level
_networkType
It stores the network type which module is connected to
_incomingType
It stores the incoming data type to be read via serial
_smsIndex
It stores the SMS index where the incoming message was saved
_smsStatus
It stores the status of the SMS read from module's memory
_smsNumber
It stores the phone number of the SMS read from module's memory
_smsDate
It stores the date of the SMS read from module's memory
_smsTime
It stores the time of the SMS read from module's memory
_socketIndex
It stores the socket index which is getting data from UDP or TCP
_httpCode
It stores the HTTP status code
_lesize
It stores the size of the le when FTP upload/download is performed
_ftpWorkingDirectory
It stores the current working directory of the FTP session
socketInfo
Structure to dene the info to be stored for all sockets
socketStatus
Structure to dene the status to be stored for all sockets
socketStatusSSL
Structure to dene the status to be stored for all sockets
_latitude
It stores latitude from GPS
_latitudeNS
It stores the north/south indicator from GPS
_longitude
It stores longitude from GPS
_longitudeEW
It stores east/west indicator
_altitude
It stores altitude from GPS
_time
It stores time from GPS
_date
It stores date from GPS
_numSatellites
It stores the number of satellites “in sight” of the GPS
_xMode
It stores x mode set from GPS
_speedOG
It stores speed over ground from GPS
_courseOG
It stores course over ground from GPS
_hdop
It stores the horizontal dilution of precision from GPS
-13-
v7.3
Software
4.1.5. API functions
Through this guide there are lots of examples, showing the use of functions. In these examples, API functions are called to execute the commands, storing in their related variables the parameter value in each case. The functions
are called using the predened object _4G.
All public functions return dierent possible values:
0: OK
Otherwise: ERROR. See corresponding function error code
4.1.6. Error codes
When the 4G module returns an error code, the _errorCode variable stores the corresponding error meaning. Do not confuse this error code with the returning value from the API functions. There are other types of errors like “no response from the module” which are not included in the next list. For each function answer, please refer to the corresponding error values described for each function within the libraries.
The possible module’s error codes are described by constants as the table below:
Constant Value Error code description
WASP4G_CME_ERROR_0000
0 Phone failure
WASP4G_CME_ERROR_0001
1 No connection to phone
WASP4G_CME_ERROR_0002
2 Phone-adapter link reserved
WASP4G_CME_ERROR_0003
3 Operation not allowed
WASP4G_CME_ERROR_0004
4 Operation not supported
WASP4G_CME_ERROR_0005
5
Phone SIM (Subscriber Identity Module) PIN (Personal
Identication Number) required
WASP4G_CME_ERROR_0010
10 SIM not inserted
WASP4G_CME_ERROR_0011
11 SIM PIN required
WASP4G_CME_ERROR_0012
12 SIM PUK (Personal Unlocking Key) required
WASP4G_CME_ERROR_0013
13 SIM failure
WASP4G_CME_ERROR_0014
14 SIM busy
WASP4G_CME_ERROR_0015
15 SIM wrong
WASP4G_CME_ERROR_0016
16 Incorrect password
WASP4G_CME_ERROR_0017
17 SIM PIN2 required
WASP4G_CME_ERROR_0018
18 SIM PUK2 required
WASP4G_CME_ERROR_0020
20 Memory full
WASP4G_CME_ERROR_0021
21 Invalid index
WASP4G_CME_ERROR_0022
22 Not found
WASP4G_CME_ERROR_0023
23 Memory failure
WASP4G_CME_ERROR_0024
24 Text string too long
WASP4G_CME_ERROR_0025
25 Invalid characters in text string
WASP4G_CME_ERROR_0026
26 Dial string too long
WASP4G_CME_ERROR_0027
27 Invalid characters in dial string
WASP4G_CME_ERROR_0030
30 No network service
WASP4G_CME_ERROR_0031
31 Network time-out
WASP4G_CME_ERROR_0032
32 Network not allowed - emergency calls only
WASP4G_CME_ERROR_0040
40 Network personalization PIN required
WASP4G_CME_ERROR_0041
41 Network personalization PUK required
-14-
v7.3
Software
WASP4G_CME_ERROR_0042
42 Network subset personalization PIN required
WASP4G_CME_ERROR_0043
43 Network subset personalization PUK required
WASP4G_CME_ERROR_0044
44 Service provider personalization PIN required
WASP4G_CME_ERROR_0045
45 Service provider personalization PUK required
WASP4G_CME_ERROR_0046
46 Corporate personalization PIN required
WASP4G_CME_ERROR_0047
47 Corporate personalization PUK required
WASP4G_CME_ERROR_0100
100 Unknown
WASP4G_CME_ERROR_0770
770 SIM invalid
WASP4G_CME_ERROR_0103
103 Illegal Mobile Station (MS) (#3)*
WASP4G_CME_ERROR_0106
106 Illegal Mobile Equipment (ME) (#6)*
WASP4G_CME_ERROR_0107
107 GPRS service not allowed (#7)*
WASP4G_CME_ERROR_0111
111 PLMN not allowed (#11)*
WASP4G_CME_ERROR_0112
112 Location area not allowed (#12)*
WASP4G_CME_ERROR_0113
113 Roaming not allowed in this location area (#13)*
WASP4G_CME_ERROR_0132
132 Service option not supported (#32)*
WASP4G_CME_ERROR_0133
133 Requested service option not subscribed (#33)*
WASP4G_CME_ERROR_0134
134 Service option temporarily out of order (#34)*
WASP4G_CME_ERROR_0148
148 Unspecied GPRS error
WASP4G_CME_ERROR_0149
149 PDP authentication failure
WASP4G_CME_ERROR_0150
150 Invalid mobile class
WASP4G_CME_ERROR_0550
550 Generic undocumented error
WASP4G_CME_ERROR_0551
551 Wrong state
WASP4G_CME_ERROR_0552
552 Wrong mode
WASP4G_CME_ERROR_0553
553 Context already activated
WASP4G_CME_ERROR_0554
554 Stack already active
WASP4G_CME_ERROR_0555
555 Activation failed
WASP4G_CME_ERROR_0556
556 Context not opened
WASP4G_CME_ERROR_0557
557 Cannot setup socket
WASP4G_CME_ERROR_0558
558 Cannot resolve DN
WASP4G_CME_ERROR_0559
559 Time-out in opening socket
WASP4G_CME_ERROR_0560
560 Cannot open socket
WASP4G_CME_ERROR_0561
561 Remote disconnected or time-out
WASP4G_CME_ERROR_0562
562 Connection failed
WASP4G_CME_ERROR_0563
563 Transmission error
WASP4G_CME_ERROR_0564
564 Already listening
WASP4G_CME_ERROR_0568
568 Wrong PDP
WASP4G_CME_ERROR_0615
615 FTP not connected
WASP4G_CME_ERROR_0623
623 FTP write data closed
WASP4G_CME_ERROR_0643
643 FTP communication timeout
WASP4G_CME_ERROR_0657
657 Network survey error (No Carrier)*
WASP4G_CME_ERROR_0658
658 Network survey error (Busy)*
WASP4G_CME_ERROR_0659
659 Network survey error (Wrong request)*
WASP4G_CME_ERROR_0660
660 Network survey error (Aborted)*
WASP4G_CME_ERROR_0257
257 Network rejected request
WASP4G_CME_ERROR_0258
258 Retry operation
-15-
v7.3
Software
WASP4G_CME_ERROR_0259
259 Invalid deected to number
WASP4G_CME_ERROR_0260
260 Deected to own number
WASP4G_CME_ERROR_0261
261 Unknown subscriber
WASP4G_CME_ERROR_0262
262 Service not available
WASP4G_CME_ERROR_0263
263 Unknown class specied
WASP4G_CME_ERROR_0264
264 Unknown network message
WASP4G_CME_ERROR_0680
680 LU processing
WASP4G_CME_ERROR_0681
681 Network search aborted
WASP4G_CME_ERROR_0682
682 PTM mode
WASP4G_CME_ERROR_0683
683 Active call state
WASP4G_CME_ERROR_0684
684 SSL already activated
WASP4G_CMS_ERROR_0300
300 ME failure
WASP4G_CMS_ERROR_0301
301 SMS service of ME reserved
WASP4G_CMS_ERROR_0302
302 Operation not allowed
WASP4G_CMS_ERROR_0303
303 Operation not supported
WASP4G_CMS_ERROR_0304
304 Invalid PDU mode parameter
WASP4G_CMS_ERROR_0305
305 Invalid text mode parameter
WASP4G_CMS_ERROR_0310
310 SIM not inserted
WASP4G_CMS_ERROR_0311
311 SIM PIN required
WASP4G_CMS_ERROR_0312
312 Phone SIM PIN required
WASP4G_CMS_ERROR_0313
313 SIM failure
WASP4G_CMS_ERROR_0314
314 SIM busy
WASP4G_CMS_ERROR_0315
315 SIM wrong
WASP4G_CMS_ERROR_0316
316 SIM PUK required
WASP4G_CMS_ERROR_0317
317 SIM PIN2 required
WASP4G_CMS_ERROR_0318
318 SIM PUK2 required
WASP4G_CMS_ERROR_0320
320 Memory failure
WASP4G_CMS_ERROR_0321
321 Invalid memory index
WASP4G_CMS_ERROR_0322
322 Memory full
WASP4G_CMS_ERROR_0330
330 SMSC address unknown
WASP4G_CMS_ERROR_0331
331 No network service
WASP4G_CMS_ERROR_0332
332 Network time-out
WASP4G_CMS_ERROR_0340
340 No +CNMA acknowledgement expected
WASP4G_CMS_ERROR_0500
500 Unknown error
WASP4G_CME_ERROR_1001
1001 SSL certs and keys wrong or not stored
WASP4G_CME_ERROR_1003
1003 SSL already activated
WASP4G_CME_ERROR_1008
1008 SSL not connected
WASP4G_ERROR_TIMEOUT
65534 Timeout error when running a command
WASP4G_ERROR_MESSAGE
65535 Generic "ERROR" message from module
-16-
v7.3
Software
4.2. Switching on
The ON() function switches on the 4G module and it opens the MCU UART for communicating with the module. After this step, the module will be able to receive commands to manage it.
Example of use:
{ _4G.ON(); }
4.3. Switching o
The OFF() function allows the user to switch o the 4G module and close the UART. This function must be called in order to save battery when the module is not going to be used.
Example of use:
{ _4G.OFF(); }
4.4. SIM card
4.4.1. Entering PIN
The enterPIN() function allows the user to enter the PIN (Personal Identication Number) of the SIM (Subscriber Identication Module) card. If the SIM card has no PIN (or the PIN was disabled on the SIM card), it is not necessary
to use this function.
Example for entering the PIN:
{ _4G.enterPIN(“1234”); }
Besides, there is another function prototype in order to set a new one. It is mandatory to specify the current PIN number and the new one.
Example for setting a new PIN:
{ _4G.enterPIN(“1234”, ”1111”); }
Example of entering the PIN number:
www.libelium.com/development/waspmote/examples/4g-01-enter-pin-code
-17-
v7.3
Software
4.4.2. Getting IMEI, IMSI and ICCID
The getInfo() function can get more than one information eld to the module. This function needs one input to indicate the type of information requested. The resulting information is stored in _buffer, and _length is the
number of bytes in the buer. The information possibilities are:
Wasp4G::INFO_HW: To request the hardware revision
Wasp4G::INFO_MANUFACTURER_ID: To request the manufacturer identier
Wasp4G::INFO_MODEL_ID: To request the model identier
Wasp4G::INFO_REV_ID: To request the rmware revision
Wasp4G::INFO_IMEI: To request the IMEI (International Mobile Station Equipment Identity), which is the unique
identier of the module, similar to a MAC address
Wasp4G::INFO_IMSI: To request the IMSI
Wasp4G::INFO_ICCID: To request the ICCID
Examples of use:
{ // get IMEI number _4G.getInfo(Wasp4G::INFO_IMEI);
// get IMSI number _4G.getInfo(Wasp4G::INFO_IMSI);
// get ICCID number _4G.getInfo(Wasp4G::INFO_ICCID); }
Related variables:
_4G._buffer Buer which stores the information requested
_4G._length Number of bytes in buer
Example of getting module info:
www.libelium.com/development/waspmote/examples/4g-02-get-module-info
-18-
v7.3
Software
4.5. Checking network connection status
There are 2 functions to check the network connection status: checkConnection() and checkDataConnection().
The checkConnection() function checks the module’s network connection status and returns whether the module:
is connected to a network
is not connected to a network
is searching for a new operator to register to
registration was denied
This function will wait for the module to be connected to a network for the specied time in second units.
Example of use:
{ _4G.checkConnection(60); }
Possible error codes for this function:
1: not registered, the Mobile Equipment (ME) is not currently searching for a new operator to register to
2: not registered, but ME is currently searching for a new operator to register to
3: registration denied
4: unknown
The checkDataConnection() function checks the module’s network connection status, connects the module to data service and returns whether the module:
is connected to data service
is not connected to a network
is searching for a new operator to register to
registration was denied
This function will wait for the module to be connected to a network for the specied time in second units.
Example of use:
{ _4G.checkDataConnection(60); }
Possible error codes for this function:
1: not registered, ME is not currently searching for a new operator to register to
2: not registered, but ME is currently searching for a new operator to register to
3: registration denied
4: unknown
6: not registered, ME is not currently searching for a new operator to register to
8: not registered, but ME is currently searching for a new operator to register to
9: registration denied
10: unknown
12: if error setting APN
13: if error setting login
14: if error setting password
15: if error activating GPRS connection
-19-
v7.3
Software
4.6. Setting operator parameters
When the 4G module uses data services like TCP/UDP connections, HTTP services, SMTP or FTP transfers, it is
mandatory to congure the parameters provided by the user’s Mobile Network Operator (MNO): APN, login and password. The owner of a SIM should be notied with these parameters by the MNO.
The set_APN() function allows the user to save these parameters into Waspmote memory. Later, when data
connection functions are called, Waspmote will congure these parameters into the 4G module.
Example of use:
{ _4G.set_APN(“apn”, ”login”, ”password”); }
The show_APN() function allows the user to display the current settings stored in Waspmote’s memory which are used by the libraries when data connections are performed.
Example of use:
{ _4G.show_APN(); }
Related variable:
_4G._apn Stores the APN name
_4G._apn_login Stores the APN login
_4G._apn_password Stores the APN password
4.7. SMS
4.7.1. Setting SMS conguration
The congureSMS() function sets the SMS conguration to:
Correct SMS format to be read from the module
Select where SMSs are going to be stored
Congure the indication method for new SMS received
This function must be called before handling SMSs in the main code loop.
Example of use:
{
  _4G.congureSMS();
}
-20-
v7.3
Software
4.7.2. Sending SMSs
The sendSMS() function sends an SMS to the given phone number. The maximum length of the message to be sent is 164 bytes.
Example of use:
{ char phone_number[] = “*********”; char text_message[] = “This_is_a_text_message”; _4G.sendSMS(phone_number, text_message); }
Possible error codes for this function:
1: not registered, ME is not currently searching for a new operator to register to
2: not registered, but ME is currently searching for a new operator to register to
3: registration denied
4: unknown connection error
5: if error setting the phone number
6: if error sending the body
Example of sending a text message:
www.libelium.com/development/waspmote/examples/4g-04-sending-sms
4.7.3. Reading SMSs
The readSMS() function reads an SMS from the module storage. The user must give the index of the SMS to be read from memory. In the case a new SMS is received, all SMS related parameters are stored in the Waspmote’s
library structures: index number, status, sender number, date and time. The SMS text eld can be found in _4G._
buffer.
Example of use:
{ uint8_t index = 5; _4G.readSMS(index); }
The readNewSMS() function reads the last unread SMS received by the module. There are 2 function prototypes: with or without timeout. If the user needs to wait for a new text message for a period of time, the timeout must
be specied as input. If no input is dened, the request for new text messages is instantly performed. In the case
a new SMS is received, all SMS related parameters are stored in the Waspmote’s library structures: index number, status, sender number, date and time. The SMS text eld can be found in _4G._buffer.
Example of use:
{ _4G.readNewSMS(30000); }
-21-
v7.3
Software
Related variables:
_4G._smsIndex → Stores the SMS index in memory storage
_4G._smsStatus Stores the SMS status:
“REC UNREAD” - new received message unread
“REC READ” - received message read
“STO UNSENT” - message stored not yet sent
“STO SENT” - message stored already sent
_4G._smsNumber Stores the sender phone number
_4G._smsDate Stores the date SMS was sent
_4G._smsTime Stores the time SMS was sent
_4G._buffer Stores SMS text eld temporary, after calling the read function
_4G._length Stores the SMS message length
Example of receiving and deleting text messages:
www.libelium.com/development/waspmote/examples/4g-05-receiving-sms
4.7.4. Deleting SMSs
The deleteSMS() function deletes an SMS according to the given index number in the memory storage.
Examples of use:
{ uint8_t index = 2; _4G.deleteSMS(index); }
There is a second deleteSMS() function prototype which deletes all the SMSs in the storage memory according to
several possibilities. For this function, 2 inputs are introduced: the SMS index number and the delete ag. If delete ag is not set to delete one single message, then index is ignored and the module shall follow the rules for delete ag shown below:
Wasp4G::SMS_DELETE_MESSAGE: To delete the message specied in index
Wasp4G::SMS_DELETE_ALL_1: To delete all read messages from memory storage, leaving unread messages and stored mobile originated messages (whether sent or not) untouched
Wasp4G::SMS_DELETE_ALL_2: To delete all read messages from memory storage and sent mobile originated messages, leaving unread messages and unsent mobile originated messages untouched
Wasp4G::SMS_DELETE_ALL_3: To delete all read messages from memory storage, sent and unsent mobile originated messages, leaving unread messages untouched
Wasp4G::SMS_DELETE_ALL_4: To delete all messages from memory storage
Example of use:
{ _4G.deleteSMS(index, Wasp4G::SMS_DELETE_ALL_1); }
Example of receiving and deleting text messages:
www.libelium.com/development/waspmote/examples/4g-05-receiving-sms
-22-
v7.3
Software
4.8. HTTP client
4.8.1. HTTP connections
HTTP 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 4G, 3G, GPRS, GPRS+GPS or WiFi modules 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. These communication modules can send HTTP instances to our web service.
HTTP instances should have the following structures so that our web service can understand.
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 formatted)
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.1415
pruebas.libelium.com/getpost_frame_parser.php?var1=3.1415&view=html
pruebas.libelium.com/getpost_frame_parser.php?var1=3.1415&var2=123456&var3=hello&view=html
POST method
Unlike GET method, with POST method the data are sent to the server into an extra data eld. The URL only
includes the site name and the PHP direction:
pruebas.libelium.com/getpost_frame_parser.php
The data eld is very similar as the used in GET method:
<variable1=value1>&<variable2=value2>&<...>&view=html
Where:
<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 eld:
pruebas.libelium.com/getpost_frame_parser.php?variable1=3.141592 pruebas.libelium.com/getpost_frame_parser.php?var1=3.1415&var2=123456&var3=hello
-23-
v7.3
Software
Server response
If 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
Remember this PHP code is really simple and is oered 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 nd 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 le, or insert couples into a database, or include a timestamp...
4.8.2. HTTP request methods
The http() function congures HTTP parameters, performs the request selected by the user and handles the data returned from the server.
This function needs several parameters to work properly depending on the method used. The rst parameter required by the function is the request method. User can choose among ve methods: GET, HEAD, DELETE, POST
and PUT:
Wasp4G::HTTP_GET
Wasp4G::HTTP_HEAD
Wasp4G::HTTP_DELETE
Wasp4G::HTTP_POST
Wasp4G::HTTP_PUT
After choosing the method, the function needs the host URL, port and resource of the HTTP server requested. The
data eld is only necessary when POST or PUT methods are performed.
Example of use (GET, HEAD and DELETE methods):
{ char host[] = “test.libelium.com”; uint16_t port = 80; char resource[] = “/test-get-post.php?varA=1&varB=2&varC=3&varD=4”;
_4G.http(Wasp4G::HTTP_GET, host, port, resource); }
-24-
v7.3
Software
Example of use (POST and PUT methods):
{ char host[] = “test.libelium.com”; uint16_t port = 80; char resource[] = “/test-get-post.php”; char data[] = “varA=1&varB=2&varC=3&varD=4&varE=5”;
_4G.http(Wasp4G::HTTP_POST, host, port, resource, data); }
Once the request has been sent, the function waits for data from the server and stores it in _buffer. It also stores the HTTP status code from the server in _httpCode.
Related variable:
_4G._httpCode Stores the HTTP code from the server
_4G._buffer Stores data received from server
_4G._length Stores data length
Possible error codes for this function:
1: not registered, ME is not currently searching for a new operator to register to
2: not registered, but ME is currently searching for a new operator to register to
3: registration denied
4: unknown
6: not registered, ME is not currently searching for a new operator to register to
8: not registered, but ME is currently searching for a new operator to register to
9: registration denied
10: unknown
12: if error setting APN
13: if error setting login
14: if error setting password
15: if error activating GPRS connection
16: if error setting URL and port
17: if error sending the request
18: if error sending POST / PUT data
19: if wrong method has been selected
20: if timeout waiting the URC
21: if error reading the URC
22: if error reading the HTTP status
23: if error reading the HTTP data length
24: if error reading the HTTP data
25: if error code from 4G module while waiting for HTTP response
26: if timeout waiting for HTTP response
27: if HTTP response data length is zero
Example of HTTP GET:
www.libelium.com/development/waspmote/examples/4g-06-http-get
Example of HTTP POST:
www.libelium.com/development/waspmote/examples/4g-07-http-post
-25-
v7.3
Software
4.8.3. Sending Waspmote frames to Meshlium via HTTP
Since Meshlium Manager System v4.0.9, HTTPS method is the default method for sending data. HTTPS is the recommended technology because it provides many cyber security services. Therefore, the HTTPS service is always enabled on Meshlium.
However, Meshlium Manager System v4.1.0 and greater versions allow the user to enable the HTTP service in order to be able to receive HTTP non-secure requests. The user must go to: Manager System —› System —› Security —› HTTP Service:
Figure : Enable HTTP service in Meshlium Manager System
The sendFrameToMeshlium() function has been developed to send Waspmote frames from Waspmote to Meshlium via non-secure HTTP request. Meshlium will parse (chop) the frame and will store it in its internal MySQL database. This function requires the following parameters:
Meshlium’s IP address
Meshlium’s remote port
Data to send: frame.buffer will be used from the generated frame
Data length: frame.length will be used from the generated frame
-26-
v7.3
Software
Figure : Send frames to Meshlium via 4G
After calling the function, the response from Meshlium will be stored in _buffer. Besides, it will store the HTTP status code from server in _httpCode. Please refer to the Data Frame Guide in order to know more about how to create sensor frames with Waspmote libraries.
Example of use:
{ char host[] = “pruebas.libelium.com”; uint16_t port = 80;
// after frame has been created _4G.sendFrameToMeshlium(host, port, frame.buffer, frame.length); }
Related variable:
_4G._httpCode Stores the HTTP code from the server
_4G._buffer Stores data received from server
_4G._length Stores data length
frame.buffer Stores data frame that will be sent to Meshlium
frame.length Stores data frame length
-27-
v7.3
Software
4.8.4. Sending Waspmote frames to Meshlium via HTTPS
Since Meshlium Manager System v4.0.9, HTTPS is the default method for sending data.
For HTTPS, the user must keep in mind that the Meshlium’s certicate has to be installed in the Waspmote or
Plug & Sense! radio prior to opening secure connections. The next picture shows how the user can download the Meshlium’s certicate from Manager System —› System —› Users Manager —› Download Certicate:
Figure : Meshlium certicate export process
The downloaded certicate must be installed following the steps explained in the “SSL sockets” section and the
proper library function. Also, the example linked at the end of this section shows how to perform the installation.
Example of sending frames to Meshlium via HTTPS:
www.libelium.com/development/waspmote/examples/4g-08b-send-to-meshlium-https/
-28-
v7.3
Software
Possible error codes for this function:
1: not registered, ME is not currently searching for a new operator to register to
2: not registered, but ME is currently searching for a new operator to register to
3: registration denied
4: unknown
6: not registered, ME is not currently searching for a new operator to register to
8: not registered, but ME is currently searching for a new operator to register to
9: registration denied
10: unknown
12: if error setting APN
13: if error setting login
14: if error setting password
15: if error activating GPRS connection
16: if error setting URL and port
17: if error sending the request
18: if error sending POST / PUT data
19: if wrong method has been selected
20: if timeout waiting the URC
21: if error reading the URC
22: if error reading the HTTP status
23: if error reading the HTTP data length
24: if error reading the HTTP data
25: if error code from 4G module while waiting for HTTP response
26: if timeout waiting for HTTP response
27: if HTTP response data length is zero
Example of sending frames to Meshlium:
www.libelium.com/development/waspmote/examples/4g-08-send-frames-to-meshlium
4.9. FTP client
4.9.1. Opening an FTP session
The ftpOpenSession() function congures FTP parameters and opens the connection. Several inputs are needed:
FTP server: IP address or URL
FTP port number
Username
Password
Example of use:
{ char ftp_server[] = “pruebas.libelium.com”; uint16_t ftp_port = 21; char ftp_user[] = “t3g@libelium.com”; char ftp_pass[] = “ftp1234”;
_4G.ftpOpenSession(ftp_server, ftp_port, ftp_user, ftp_pass); }
-29-
v7.3
Software
Possible error codes for this function:
1: not registered, ME is not currently searching for a new operator to register to
2: not registered, but ME is currently searching for a new operator to register to
3: registration denied
4: unknown
6: not registered, ME is not currently searching for a new operator to register to
8: not registered, but ME is currently searching for a new operator to register to
9: registration denied
10: unknown
12: if error setting APN
13: if error setting login
14: if error setting password
15: if error activating GPRS connection
16: if error opening the FTP connection
17: if error setting the transfer type
After successfully calling this function, it will be possible to manage the rest of FTP functions for uploading and
downloading les.
4.9.2. FTP upload
The ftpUpload() function uploads a le from the Waspmote’s SD card to the FTP server. The FTP session must be already open. This function needs 2 dierent inputs: the complete path of the le to be created in the FTP server and the complete path of the le in the SD card to be uploaded.
Example of use for les in root directory:
{
  charsd_le[]=“FILE1.TXT”;   charserver_le[]=“FILE2.TXT”;
  _4G.ftpUpload(server_le,sd_le);
}
In the case the le should be uploaded into a subdirectory instead of the root directory, the server lename must be accordingly dened. The user must keep in mind that subdirectories have to be already created in order to upload les into them. In other words, it is not possible to create subdirectories in the FTP server.
Example of use for les in subdirectories:
{
  charsd_le[]=“/FOLDER1/FILE1.TXT”;   charserver_le[]=“/FOLDER2/FILE2.TXT”;
  _4G.ftpUpload(server_le,sd_le);
}
-30-
v7.3
Software
Possible error codes for this function:
1: if no SD present
2: if le does not exist
3: if error opening the le
4: if error setting the pointer of the le
5: if error getting the le size
6: if error opening the PUT connection
7: if error exiting from the data mode
8: if error sending data
Example of uploading les:
www.libelium.com/development/waspmote/examples/4g-09-ftp-upload
4.9.3. FTP download
The ftpDownload() function downloads a le from an FTP server to Waspmote’s SD card. The FTP session must be already open. This function needs 2 dierent inputs: the complete path of the le in the FTP server and the complete path of the le to be created in the SD card.
Example of use for les in root directory:
{
  charsd_le[]=“FILE1.TXT”;   charserver_le[]=“FILE2.TXT”;
  _4G.ftpDownload(server_le,sd_le);
}
In the case the le should be downloaded into an SD card’s subdirectory instead of the root directory, the SD lename must be accordingly dened. The user must keep in mind that subdirectories have to be already created in the SD card in order to create les into them.
Example of use for les in subdirectories:
{
  charsd_le[]=“/FOLDER1/FILE1.TXT”;   charserver_le[]=“/FOLDER2/FILE2.TXT”;
 _4G.ftpDownload(server_le,sd_le);
}
Possible error codes for this function:
1: if server le size is zero
2: if error reading the le size
3: if SD not present
4: if error creating the le in SD
5: if error opening the le
6: if error setting the pointer of the le
7: if error opening the GET connection
8: if the module returns error code after requesting data
9: if error getting packet size
10: if error in packet size mismatch
-31-
v7.3
Software
11: if error writing SD error
12: if no more retries getting data
13: if le size mismatch
Example of downloading les:
www.libelium.com/development/waspmote/examples/4g-10-ftp-download
4.9.4. FTP delete le
The ftpDelete() function deletes in the FTP server. The FTP session must be already open. The function expects
the name of the le to be deleted as input.
Example of deleting a le:
{ _4G.ftpDelete(“FILE_FTP.TXT”); }
4.9.5. FTP working directory
The ftpGetWorkingDirectory() function requests the current working directory of the previously open FTP session. The function updates the _ftpWorkingDirectory attribute which stores the information.
Example of getting the FTP working directory:
{ _4G.ftpGetWorkingDirectory(); }
Related variable:
_4G._ftpWorkingDirectory Stores the current working directory
The ftpChangeWorkingDirectory() function allows the user to change the current working directory. The user must keep in mind that the directory to access must be already created before attempting to call this function. The function expects the name of the directory to access to as input parameter.
Example of changing the working directory:
{ _4G.ftpChangeWorkingDirectory(“NEWDIR”); }
Related variable:
_4G._ftpWorkingDirectory Stores the new working directory if correctly changed
4.9.6. Closing an FTP session
The ftpCloseSession() function allows the user to close an active FTP session.
Example of closing an FTP session:
{ _4G.ftpCloseSession(); }
-32-
v7.3
Software
4.10. TCP/UDP connections
4.10.1. Socket identiers
The 4G module permits to have up to 6 simultaneous TCP/UDP connections. For that purpose, the libraries dene the following socket identiers to be used when handling the multi-socket connections:
Wasp4G::CONNECTION_1 Wasp4G::CONNECTION_2 Wasp4G::CONNECTION_3 Wasp4G::CONNECTION_4 Wasp4G::CONNECTION_5 Wasp4G::CONNECTION_6
The 4G libraries dene dierent structures in order to store the information related to all socket identiers. After
opening sockets or sending/receiving data, the structures are updated. So this is useful in order to manage the most important settings of the connection.
4.10.2. Socket information structure
The SocketInfo_t structure stores the information to be stored for all sockets. For each one of the connections, the information structure includes:
Socket identier
Total number of bytes sent since the socket was opened
Total number of bytes received since socket was opened
Total number of pending bytes to read which arrived through the socket
Total number of bytes sent and not yet acknowledged since the socket was opened
As there are six possible connections at the same time, the global variable is dened as follows:
SocketInfo_t socketInfo[6];
The denition of the structure is:
struct SocketInfo_t { uint8_t id; uint16_t sent; uint16_t received;
  uint16_t size;
uint16_t ack; };
The getSocketInfo() function allows the user to update the socket information structure from the 4G module. It
is mandatory to indicate the identier of the socket to be updated.
Example of use:
{ uint8_t socketId = Wasp4G::CONNECTION_1;
_4G.getSocketInfo(socketId); }
-33-
v7.3
Software
Related variables:
_4G.socketInfo[socketId].id Socket identier
_4G.socketInfo[socketId].sent Total number of bytes sent since the socket was opened
_4G.socketInfo[socketId].received Total number of bytes received
_4G.socketInfo[socketId].size Total number of pending bytes to read
_4G.socketInfo[socketId].ack Total number of bytes sent and not yet acknowledged
4.10.3. Socket status structure
The SocketStatus_t structure stores the status for all sockets. For each one of the connections, the status structure includes:
Socket identier
Current socket status. The API denes several constants to describe it:
- Wasp4G::STATUS_CLOSED
- Wasp4G::STATUS_ACTIVE
- Wasp4G::STATUS_SUSPENDED
- Wasp4G::STATUS_SUSPENDED_DATA
- Wasp4G::STATUS_LISTENING
- Wasp4G::STATUS_INCOMING
- Wasp4G::STATUS_OPENING
Local IP address
Local port
Remote IP address
Remote port
As it is possible to have up to 6 simultaneous connections, the global variable is dened as follows:
SocketStatus_t socketStatus[6];
The denition of the structure is:
struct SocketStatus_t { uint8_t id; uint8_t state; char localIp[16]; uint16_t localPort; char remoteIp[16]; uint16_t remotePort; };
The getSocketStatus() function allows the user to update the socket status structure from the 4G module. It is
mandatory to indicate the identier of the socket to be updated. It is possible to update all socket status by calling
the getAllSocketStatus() function which is faster than iterating through all dierent identiers.
Example of use:
{ uint8_t socketId = Wasp4G::CONNECTION_1; _4G.getSocketStatus(socketId); }
Related variables:
-34-
v7.3
Software
_4G.socketInfo[socketId].id Socket identier
_4G.socketInfo[socketId].state Socket status
_4G.socketInfo[socketId].localIp Local IP address
_4G.socketInfo[socketId].localPort Local port
_4G.socketInfo[socketId].remoteIp Remote IP address
_4G.socketInfo[socketId].remotePort Remote port
4.10.4. Creating a TCP/UDP client socket
The openSocketClient() function congures and opens a socket. This function expects several input parameters:
Socket ID: The rst parameter indicates the identier to be associated to the new TCP/UDP. connection. This
identier is needed in order to send or receive data through the corresponding socket after creating it.
Protocol: This parameter indicates whether use TCP or UDP protocol for the new socket. The possibilities are:
- Wasp4G::TCP
- Wasp4G::UDP
Host: Address of the remote host, string type. This parameter can be either:
- Any valid IP address in the format: “xxx.xxx.xxx.xxx”
- Any host name to be solved with a DNS query
- Any valid IPv6 address in the format: xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx or xxx.xxx.xxx.xxx.xxx.xxx. xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx
Remote port: Remote host port to contact from 1 to 65535.
Local port: Parameter is valid for UDP connections only and has no eect (if used) for TCP connections. UDP connections local port from 1 to 65535.
Example of creating a TCP client connection:
{ uint8_t socketId = Wasp4G::CONNECTION_1; char host[] = “xxx.xxx.xxx.xxx”; uint16_t remote_port = 15010;
_4G.openSocketClient(socketId, Wasp4G::TCP, host, remote_port); }
Example of creating a UDP client connection:
{ uint8_t socketId = Wasp4G::CONNECTION_2; char host[] = “xxx.xxx.xxx.xxx”; uint16_t remote_port = 15010; uint16_t local_port = 4000;
_4G.openSocketClient(socketId, Wasp4G::UDP, host, remote_port, local_port); }
Possible error codes for this function:
1: not registered, ME is not currently searching for a new operator to register to
2: not registered, but ME is currently searching for a new operator to register to
3: registration denied
4: unknown
6: not registered, ME is not currently searching for a new operator to register to
-35-
v7.3
Software
8: not registered, but ME is currently searching for a new operator to register to
9: registration denied
10: unknown
12: if error setting APN
13: if error setting login
14: if error setting password
15: if error activating GPRS connection
16: if error getting socket status
17: Socket with an active data transfer connection
18: Socket suspended
19: Socket suspended with pending data
20: Socket listening
21: Socket with an incoming connection. Waiting for the user accept or shutdown command
22: Socket in opening process. The socket is not closed but still not in Active or Suspended
23: if error in Socket Conguration
24: if error in Socket Conguration Extended 3
25: if error sending the open command
26: if timeout opening the socket
Example of creating TCP/UDP client sockets:
www.libelium.com/development/waspmote/examples/4g-11-tcp-client www.libelium.com/development/waspmote/examples/4g-13-udp-client
4.10.5. Creating a TCP/UDP server socket
The openSocketServer() function congures and opens a listening socket. This function expects several input parameters:
Socket ID: The rst parameter indicates the identier to be associated to the new TCP/UDP connection. This
identier is needed in order to send or receive data through the corresponding socket.
Protocol: This parameter indicates whether use TCP or UDP protocol for the new socket. The possibilities are:
- Wasp4G::TCP
- Wasp4G::UDP
Local port: Local listening port from 1 to 65535.
Keep-Alive: TCP keep-alive timer timeout -The interval between 2 keep-alive transmissions in idle condition:
- 0 TCP keep-alive timer is deactivated (default)
- 1..240 TCP keep-alive timer timeout in minutes
Example of creating a TCP server:
{ uint8_t socketId = Wasp4G::CONNECTION_1; uint16_t local_port = 5000; uint8_t keep_alive = 240;
_4G.openSocketServer(socketId, Wasp4G::TCP, local_port, keep_alive); }
-36-
v7.3
Software
Example of creating a UDP server:
{ uint8_t socketId = Wasp4G::CONNECTION_2; uint16_t local_port = 5000;
_4G.openSocketServer(socketId, Wasp4G::UDP, local_port); }
Once the server is created, the manageSockets() function permits the user to update all socket status and accept connections if needed. So when setting up a server or listening socket in Waspmote 4G the best way to handle
with connections is directly calling this function. If no input parameter is dened the calling is executed instantly. If
the timeout is inserted as new input, the function will block until a new incoming connection needs to be managed
or timeout. This timeout must be specied in milliseconds units.
Possible error codes for this function:
1: not registered, ME is not currently searching for a new operator to register to
2: not registered, but ME is currently searching for a new operator to register to
3: registration denied
4: unknown
6: not registered, ME is not currently searching for a new operator to register to
8: not registered, but ME is currently searching for a new operator to register to
9: registration denied
10: unknown
12: if error setting APN
13: if error setting login
14: if error setting password
15: if error activating GPRS connection
16: if error getting socket status
17: if error in Socket Conguration
18: if protocol input not valid
19: if error opening the socket
Example of creating TCP/UDP server sockets:
www.libelium.com/development/waspmote/examples/4g-12-tcp-server www.libelium.com/development/waspmote/examples/4g-14-udp-server
4.10.6. Sending data
The send() function allows the user to send TCP/UDP packets once the socket is active. The function needs 2
dierent inputs parameters:
Socket ID: the socket identier used for opening the connection.
Data: This is the stream of data to send to the TCP/UDP socket. This stream of data can be dened as a simple
string message. On the other hand, the data can be dened as an array of bytes, specifying a third input for
the length of the array of bytes to send.
Example for sending a string message:
{ _4G.send(Wasp4G::CONNECTION_1, “This_is_the_data_payload”); }
-37-
v7.3
Software
Example for sending an array of bytes:
{ uint8_t data[] = {0x31, 0x32, 0x33, 0x34, 0x35} _4G.send(Wasp4G::CONNECTION_1, data, 6); }
Possible error codes for this function:
1: if error checking socket status
2: if incorrect socket status
3: if error sending data
4: if error waiting conrmation from module
5: if error getting socket status
6: if timeout getting socket status
All examples related to TCP/UDP sockets (both client and server) show how to send data:
www.libelium.com/development/waspmote/examples/4g-11-tcp-client www.libelium.com/development/waspmote/examples/4g-12-tcp-server www.libelium.com/development/waspmote/examples/4g-13-udp-client www.libelium.com/development/waspmote/examples/4g-14-udp-server
4.10.7. Receiving data
The receive() function allows the user to receive TCP/UDP packets once the socket is active. The function needs
dierent inputs:
Socket ID: the socket identier used for opening the connection.
Timeout (optional input):
- If no timeout input is specied, the receive function is a non-blocking function which answers if data has been received.
- If the timeout is inserted as new input, the function will block until a new packet is received or time is up in
the case no packet is received. This timeout must be specied in milliseconds units.
Example for instant reception:
{ _4G.receive(Wasp4G::CONNECTION_1); }
Example for blocking reception (i.e. 30 seconds):
{ _4G.receive(Wasp4G::CONNECTION_1, 30000); }
Related variables:
_4G._buffer Pointer to the buer where received data is stored
_4G._length Length of the data received
-38-
v7.3
Software
Possible error codes for this function:
1: if no data received
2: if error getting socket info
3: if timeout waiting for data
4: if error receiving data from module
5: if error parsing length of data
6: if error reading incoming bytes
4.10.8. Closing a socket
The closeSocketClient() function allows the user to close a TCP/UDP client previously open. The function needs
an input parameter for the socket identier.
The closeSocketServer() function allows the user to close a TCP/UDP server previously open. The function needs 2 inputs:
Socket ID: the socket identier used for opening the connection.
Protocol: This parameter indicates the protocol used by the socket:
- Wasp4G::TCP
- Wasp4G::UDP
4.10.9. SSL sockets
The 4G module includes a stack for establishing SSL sockets. For this feature, the user must keep in mind that it is
necessary to install the proper security data in the module. For handling the SSL socket new functions are dened
for opening the socket, sending data, receiving data and closing the socket.
Currently, for SSL sockets only one single connection is permitted. So, regarding the socket identiers the only
available option is: Wasp4G::CONNECTION_1.
The manageSSL() function allows the user to store, delete and read security data (Certicate, CA certicate, private key) into the non volatile memory of the module. The function expects several inputs:
Socket ID: the socket identier used for opening the connection.
Action: the action to perform:
- Wasp4G::SSL_ACTION_DELETE: Delete data from memory
- Wasp4G::SSL_ACTION_STORE: Store data into memory
- Wasp4G::SSL_ACTION_READ: Read data from memory
Data type:
- Wasp4G::SSL_TYPE_CERT: Certicate
- Wasp4G::SSL_TYPE_CA_CERT: CA certicate
- Wasp4G::SSL_TYPE_RSA: RSA Private key
Data (optional): this input is needed when the user selects to store a new security data into module’s memory.
Possible error codes for this function:
1 if error setting security data
2 if error waiting module conrmation
3 if error getting security data
4 if error deleting security data
5 if invalid action input
-39-
v7.3
Software
The openSocketSSL() function allows the user to open a remote connection via socket secured through SSL. Several inputs are needed for calling this function:
Socket ID: the socket identier used for opening the connection
Host: Remote SSL server address
Remote port: Remote TCP port to contact from 1 to 65535.
Possible error codes for this function:
1: not registered, ME is not currently searching for a new operator to register to
2: not registered, but ME is currently searching for a new operator to register to
3: registration denied
4: unknown
6: not registered, ME is not currently searching for a new operator to register to
8: not registered, but ME is currently searching for a new operator to register to
9: registration denied
10: unknown
12: if error setting APN
13: if error setting login
14: if error setting password
15: if error activating GPRS connection
16: if error getting SSL Socket Status
17: if socket disabled
19: if socket already open
20: if error opening the socket
21: if no response from module
The sendSSL() function allows the user to send data through a secure socket. Several inputs are needed for calling this function:
Socket ID: the socket identier used for opening the connection.
Data: Data to send.
Possible error codes for this function:
1: if error checking socket status
2: if incorrect socket status
3: if error sending data
4: if no response from module
5: if error getting socket status
6: if timeout waiting for correct socket status
The receiveSSL() function allows the user to receive data through a secure socket. Several inputs are needed for calling this function:
Socket ID: the socket identier used for opening the connection.
Timeout (optional input):
- If no timeout input is specied, the receive function is a non-blocking function which answers if data has been received.
- If the timeout is inserted as new input, the function will block until a new packet is received or time is up in
the case no packet is received. This timeout must be specied in milliseconds units.
-40-
v7.3
Software
Possible error codes for this function:
1: if no answer from module
2: if SSL socket disconnected
3: if error code from module
4: if no response from module
5: if error parsing length of received data
6: if error getting received data
7: if error waiting module conrmation
The closeSocketSSL() function allows the user to close a secure socket. The function needs an input parameter
for the socket identier.
Example for SSL socket:
www.libelium.com/development/waspmote/examples/4g-15-ssl-sockets
-41-
v7.3
Software
4.11. GPS
Nowadays there are several positioning techniques to provide the localization to end devices. One of them is the A-GPS positioning technique based on the help of a cellular network deploying an A-GPS server.
Remember the AU version does not have a GPS receiver.
At this point, it is advisable to introduce the denition of Time to First Fix (TTFF): TTFF indicates the time and
process required for a GPS device to get adequate satellite signals and data to provide accurate navigation.
A-GPS uses the following sets of data to provide accurate position:
GPS satellite signals
Almanac data
Ephemeris data
If a GPS device has been turned o for a long period of time, when it is turned on it will take longer to acquire
these data sets and get a “Time to First Fix”. One way to speed up TTFF is to use the A-GPS Positioning Technique.
A “cold” start indicates the scenario in which the GPS must get all data in order to start navigation, and may take up to several minutes.
A “warm” start indicates the scenario in which the GPS has most of the data it needs in memory, and will start quickly, a minute or less.
Before dealing with the A-GPS service, a Standalone GPS solution is described. The gure below shows an overview
of the involved functional entities.
Figure : GPS overview
-42-
v7.3
Software
4.11.1. Standalone or Autonomous GPS (S-GPS)
Standalone or autonomous GPS mode (S-GPS) is a feature that allows the GPS receiver, installed on the 4G module, to perform its First Fixing activity without assistance data coming from cellular network. The GPS receiver estimates its position directly from GPS satellites in its line of sight. The S-GPS is sometime slower to compute
its First Fix; this phenomenon is evident in very poor signal conditions, for example in a city where the satellites
signals are corrupted by the multipath propagation.
4.11.2. Assisted GPS (A-GPS)
Assisted GPS mode is a feature that allows the GPS receiver, installed on the module, to perform its First Fix using assistance data provided by entities deployed by Cellular Network.
There are a couple of A-GPS standards. Waspmote libraries implement the Secure User Plane Location (SUPL) architecture. This Location Service architecture is composed of 2 basic elements: a SUPL Enabled Terminal (SET) and a SUPL Location Platform (SLP). The SET corresponds to the 4G module. The SLP manages several tasks: authentication, location request, etc. This module supports the SUPL ver. 1.0.
Waspmote libraries manage the SET Initiated Session scenario where the module, on its initiative, connects to an SLP Server through an IP network, 2 modes are available:
MS-Assisted
MS-Based
In MS-Assisted mode, the module receives acquisition assistance, reference time and other optional assistance data from the network. The mobile service provider continuously logs GPS information (mainly the almanac) from the GPS satellites using an A-GPS server in its system. With the help of this data, the A-GPS server calculates the position and sends it back to the module.
In MS-Based mode, the module receives ephemeris, reference location, reference time and other optional assistance data from the A-GPS server. With the help of this data, the module receives signals from the visible satellites and calculates the position.
Note: if the required satellites visibility is not available, no GPS position is provided by the A-GPS receiver.
4.11.3. Get GPS position
The gpsStart() function allows the user to power on the GPS engine. Depending on the input parameter a
dierent GPS mode is selected. The possibilities are:
Wasp4G::GPS_MS_ASSISTED: Assisted GPS in MS-Assisted mode
Wasp4G::GPS_MS_BASED: Assisted GPS in MS-Based mode
Wasp4G::GPS_MS_AUTONOMOUS: Standalone or Autonomous GPS mode
Possible error codes for this function:
1: if error setting the reset mode
2: if error checking current GPS status
3: if error starting the GPS engine in standalone mode
4: if error setting NETWORK_UTRAN mode
5: if error dening the PDP context
6: if error setting authentication user ID
-43-
v7.3
Software
7: if error setting authentication password
8: if error setting socket conguration
9: if error setting quality of service
10: if error setting the SLP server
11: if error setting the supported SUPL version
12: if error updating terminal information
13: if error enabling unsolicited response
14: if error locking context for LCS use
15: if error enabling GNSS (or GLONASS)
16: if error in GPS Start Location Service Request
17: if error checking data connection
18: if incorrect GPS mode
The waitForSignal() function waits until GPS signal is received for valid data. The input parameter denes the timeout to wait for signal in millisecond units. If the function returns a correct answer means that the GPS attributes have been updated:
Latitude
Latitude indicator: North or South
Longitude
Longitude indicator: East or West
Time
Date
Number of satellites
HDOP: Horizontal Dilution of precision. If this value is less than 1 indicates the highest possible condence level to be used for applications.
The convert2Degrees() function performs the conversion from the latitude and latitude variables given by the 4G module to degrees so it is more legible and intuitive. The input parameters must be the latitude/longitude and the corresponding indicator. The returning value is the converted value in degrees units.
The gpsStop() function powers down the GPS engine of the 4G module. It is possible to switch from a SUPL session to the autonomous GPS mode. Firstly, the GPS feature must be stopped, and then restart with the autonomous mode.
Example of GPS modes:
www.libelium.com/development/waspmote/examples/4g-16-gps-autonomous-mode www.libelium.com/development/waspmote/examples/4g-17-agps-ms-assisted www.libelium.com/development/waspmote/examples/4g-18-agps-ms-based
-44-
v7.3
Software
4.11.4. Indoor tracking using 4G and A-GPS mode (geolocation)
Assisted GPS, also known as A-GPS or AGPS, enhances the performance of standard GPS in devices connected to the cellular network. A-GPS improves the location performance of cell phones (and other connected devices) in two ways:
By helping obtain a faster “time to rst x” (TTFF). A-GPS acquires and stores information about the location of satellites via the cellular network so the information does not need to be downloaded via satellite.
By helping position a phone or mobile device when GPS signals are weak or not available such as indoor
locations. GPS satellite signals may be impeded by tall buildings, and do not penetrate building interiors well. A-GPS uses proximity to cellular towers to calculate position when GPS signals are not available.
In this section, the execution of the A-GPS in MS-Based mode is shown. For this purpose, the corresponding example was used:
www.libelium.com/development/waspmote/examples/4g-18-agps-ms-based
In this example, the GPS is started in MS-based mode. Once location is acquired, the GPS is stopped and started
again in Standalone mode. In the following gures, it is possible to see how the GPS module gets its rst position
41 seconds after switching on the 4G module. The green icon is the true device position. The red icon is the
position the 4G module returns along dierent iterations. Finally, we can see how the module achieves a great
location detection after 73 seconds.
Figure : First iteration (41 seconds after starting the 4G module). Distance error: 42 meters.
-45-
v7.3
Software
Figure : Figure: Second iteration (53 seconds after starting the 4G module): Distance error: 28 meters.
Figure : Figure: Third iteration (63 seconds after starting the 4G module): Distance error: 28 meters.
-46-
v7.3
Software
Figure : Fourth iteration (73 seconds after starting the 4G module): Distance error: 7 meters.
The location given by the A-GPS module may vary depending on the spot used to perform the test. The accuracy will improve when the device is situated in a high density or poor cellular antennas area. The location accuracy may vary from 10 to 100 meters so a real test in each case is mandatory before implementing a nal application.
-47-
v7.3
Software
4.12. e-mail management functions
4.12.1. Reseting e-mail parameters
The emailReset() function resets the current e-mail parameters in the memory of the module to the default ones. The values reset are:
e-mail user name
e-mail password
e-mail sender address
e-mail SMTP server
Example:
{ _4G.emailReset(); }
4.12.2. Setting the SMTP server
The emailSetServerSMTP() function sets the SMTP server address, used for e-mail sending. The function expects an input parameter for the SMTP server address. This parameter can be either:
Any valid IP address in the format: xxx.xxx.xxx.xxx
Any host name to be solved with a DNS query (factory default is the empty string “”)
Example:
{ _4G.emailSetServerSMTP(“smtp.mydomain.com”); }
4.12.3. Conguring SMTP parameters
The emailCongureSMTP() function sets the parameters needed to the SMTP connection. The input parameters for this function are:
Security: parameter indicating if the SSL encryption is enabled. The possibilities are:
- Wasp4G::EMAIL_NONSSL
- Wasp4G::EMAIL_SSL
Port: SMTP port to contact (default 25). Range is from 1 to 65535.
Example:
{
  _4G.emailCongureSMTP(Wasp4G::EMAIL_NONSSL,25);
}
Note: some servers support an obsolete implementation of SMTPS on port 465. The module only supports the standard implementation of SMTP over SSL/TLS described in RFC 3207. So do not use port 465 on servers with an obsolete implementation of SMTPS: the module will not work properly. Use instead port 25 or port 587.
-48-
v7.3
Software
4.12.4. Setting the sender parameters: address, username and password
The emailSetSender() function sets the sender parameters. The input parameters related are:
Address: the address string to be used for sending the e-mail.
Username: the username string to be used for sending the e-mail.
Password: the authentication password to be used during the authentication step of the SMTP.
Example:
{ char address[] = “me@email.box.com”; char user[] = “me@email.box.com”; char password[] = “myPassword”;
_4G.emailSetSender(address, user, password); }
Possible error codes for this function:
1: if error setting the sender address
2: if error setting the sender user
3: if error setting the sender password
4.12.5. Saving e-mail parameters
The emailSave() function saves the actual e-mail parameters in the memory of the module. The values reset are:
e-mail user name
e-mail password
e-mail sender address
e-mail SMTP server
Example:
{ _4G.emailSave(); }
4.12.6. Sending an e-mail
The emailSend() function sends an e-mail message. The input parameters needed for this function are:
Address: destination address.
Subject: subject of the message. The maximum length is 100 characters.
Body: the main text message of the e-mail.
Example:
{ char address[] = “receiver@email.box.com”; char subject[] = “Subject of email”; char message[] = “This is an e-mail message from Waspmote”;
_4G.emailSend(address, subject, message); }
Possible error codes for this function:
-49-
v7.3
Software
1: if error sending mail
2: if error waiting for module conrmation
Example of sending e-mail:
www.libelium.com/development/waspmote/examples/4g-19-send-email-smtp
-50-
v7.3
Certications
5. Certications
Libelium oers 2 types of sensor platforms, Waspmote OEM and Plug & Sense!:
Waspmote OEM is intended to be used for research purposes or as part of a major product so it needs nal certication on the client side. More info at: http://www.libelium.com/products/waspmote/
Plug & Sense! is the line ready to be used out of the box. It includes market certications. See below the specic list of regulations passed. More info at: http://www.libelium.com/products/plug-sense/
Plug & Sense! 4G is certied for:
CE (Europe)
FCC (US)
IC (Canada)
ANATEL (Brazil)
RCM (Australia)
PTCRB (US)
AT&T (US)
Figure : Certications of the Plug & Sense! 4G product line
The 4G module is also used on Meshlium, which was certied too.
You can nd all the certication documents at:
http://www.libelium.com/certications
-51-
v7.3
Code examples and extended information
6. Code examples and extended information
In the Waspmote Development section you can nd complete examples:
www.libelium.com/development/waspmote/examples
-52-
v7.3
API changelog
7. API changelog
Keep track of the software changes on this link:
www.libelium.com/development/waspmote/documentation/changelog/#4g
-53-
v7.3
Documentation changelog
8. Documentation changelog
From v7.2 to v7.3
Added indications to send frames to Meshlium via HTTP or HTTPS (HTTPS is the default mode for Meshlium Manager System version equal or greater than v4.0.9)
Added indications about the SIM card format for both OEM and Plug and Sense! product versions
From v7.1 to v7.2
Added description about the new V2 radio versions
From v7.0 to v7.1
Added a new section to show the user how to connect the module to waspmote
Loading...