My Cart

4G + GPS Shield for Arduino and Raspberry Pi Tutorial (LTE / WCDMA / HSPA+ / 3G / GPRS)

Difficulty Level: Expert -


The new 4G shield for Arduino and Raspberry Pi enables the connectivity to high speed LTE, HSPA+, WCDMA cellular networks in order to make possible the creation of the next level of worldwide interactivity projects inside the new "Internet of Things" era.

Most of the major cities are already turning their cellular networks to the new 4G LTE and at the same time shutting down the old technologies such as GPRS and GSM. 3G will survive a couple of years more but it is planned to be completely shut off too. For this reason from Libelium and our Open Source Division - Cooking Hacks - have decided to be the first to offer to the Maker community the possibility of using the amazing 4G cellular networks.

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 Certificates and setting TCP/IP private sockets. In the same way FTP protocol is also available which is really useful when your application requires handling files.

The 4G shield has a SD socket that it is controlled by the external MCU of the main board where we are connecting it (Arduino, Raspberry Pi, Waspmote) to save data coming or going to the 4G network. With the SD Card socket so you can handle a complete FAT16 file systems and store up to 32GB of information.

You can also use it as a standard 4G / LTE modem with a Download speed up to 100Mbps and an Upload speed of 50Mbps!. Just connect it through its specific mini-USB socket to your laptop (Linux, Windows, MacOS) and go!. And yes! you can also connect it through the USB port to your Raspberry Pi and get the full speed with it too.

The GPS / Glonass module also makes possible perform geolocation services using NMEA sentences offering information such as latitude, longitude, altitude and speed what makes it perfect to perform tracking applications.

The new 4G shield offers the maximum performance of the 4G network as it uses two different antennas (normal + diversity) for RX (MIMO DL 2x2) choosing the best received signal at any time and getting a maximum download speed of 100Mbps.

We choose the LE910 family from Telit as it comprises the most complete 4G LTE set of variants released up to date. It counts with many different models, one specifically designed for each market but all of them with the same footprint:

Buy now

Certifications

We chose the LE910 family from Telit for our developments due to the fact that it is the most tested and Certified 4G set of modules in the market. The different models ensure that they comply with the specific regulation in each country.

Click on the desired regulation of each model to download the certification documents:

Certifications for Final Products:

Libelium offers two types of sensor platforms: OEM lines (Waspmote , Arduino, Raspberry Pi) and Plug & Sense!.

  • OEM lines like Waspmote , Arduino and Raspberry Pi are intended to be used for research purposes. In this case the 4G modules already have the proper certifications but it is good to have in mind that the final products made with them can not be sold without going to Certification again. 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 certifications as final product. See below the specific list of regulations passed. (4G Version will see the light by the end of summer). http://www.libelium.com/products/plug-sense/

Choosing the right cellular module for Arduino and Raspberry Pi: 4G / 3G / GPRS / GSM

Model
Protocols
Frequency Bands
Certifications
Market
SIM908 GPRS / GSM 850, 900, 1800, 1900MHz CE Europe
SIM5215-E 3G / GPRS / GSM 850, 900, 1800, 2100MHz CE, GCF Europe
SIM5215-A 3G / GPRS / GSM 850, 900, 1800, 1900MHz FCC, IC, PTCRB US / Canada
LE910-EUG 4G / 3G / GPRS / GSM / WCDMA / HSPA+ / LTE 850, 900, 1800, 2100, 2600MHz CE, GCF, ANATEL Europe / Brasil
LE910-NAG 4G / 3G / GPRS / GSM / WCDMA / HSPA+ / LTE 700, 850, 900, 1700, 1900MHz FCC, IC, PTCRB, AT&T Compliant US / Canada
LE910-SKG 4G / LTE / HSPA+ 850, 1800MHz KCC South Korea
LE910-AU V2 4G / LTE / HSPA+ 850, 1500, 2100MHz RCM Australia
LE910-JN V2 4G / LTE / HSPA+ 850, 1500, 2100MHz NTT DoCoMo Japan
LE910-JK V2 4G / LTE / HSPA+ 850, 1500, 2100MHz KDDi Japan
Model
GPS
Camera Option
SD Card
USB Connnectivity
SIM908
Yes
No
No
No
SIM5215-E
No
Yes
Yes
Yes
SIM5215-A
No
Yes
Yes
Yes
LE910-EUG
Yes
No
Yes
Yes
LE910-NAG
Yes
No
Yes
Yes
LE910-SKG
No
No
Yes
Yes
LE910-AU V2
No
No
Yes
Yes
LE910-JN V2
No
No
Yes
Yes
LE910-JK V2
No
No
Yes
Yes
Model
Download Max Speed
Upload Max Speed
Antenna Diversity
Cellular Carriers
SIM908
80kbps
20kbps
No
Any
SIM5215-E
384Kbps
384Kbps
No
Any
SIM5215-A
384Kbps
384Kbps
No
Any
LE910-EUG
100Mbps
50Mbps
Yes
Any
LE910-NAG
100Mbps
50Mbps
Yes
Any + Specially tested with AT&T
LE910-SKG
100Mbps
50Mbps
Yes
Any + Specially tested with SK Telecom
LE910-AU V2
100Mbps
50Mbps
Yes
Any + Specially tested with Telstra
LE910-JN V2
100Mbps
50Mbps
Yes
Any + Specially tested with NTT DoCoMo
LE910-JK V2
100Mbps
50Mbps
Yes
Any + Specially tested with KDDi
Buy now


Features

The 4G module is managed by UART. The main features of the modules are listed below:

  • Output power
    • Class 4 (2 W, 33 dBm) @ GSM 900
    • Class 1 (1 W, 30 dBm) @ GSM 1800
    • Class E2 (0.5 W, 27 dBm) @ EDGE 900
    • Class E2 (0.4 W, 26 dBm) @ EDGE 1800
    • Class 3 (0.25 W, 24 dBm) @ UMTS
    • Class 3 (0.2 W, 23 dBm) @ LTE
  • Data Transmission:
    • LTE:
      • Downlink up to 100 Mbps
      • Uplink up 50 Mbps
    • HSPA+:
      • Downlink up to 42.0Mbps
      • Uplink up to 5.76Mbps
    • UMTS:
      • Uplink/Downlink up to 384 kbps
  • Protocols:
    • TCP/UDP
    • HTTP
    • FTP
    NOTE: All the code examples in this tutorial developed for Raspberry Pi use the arduPi library. You can see the documentation and download the library here.

    Kits and Accessories

    Kits

    Accesories

    NOTE: the accessories (antennas, SD...) are not included in the basic package. They may be acquired in any of the multi kits or by separate.

    NOTE: If you only need to send SMS or use a low bandwidth for data transfer you can use our cheaper GPRS+GPS Quadband SIM908 module for Arduino and Raspberry Pi.

    NOTE: The SD, FTP and SSL functions of the library work only with Arduino Mega and Raspberry Pi (not with Arduino Uno). This is due to memory restrictions of Arduino Uno as it counts only with 2KB of RAM.

    Does make sense a 4G module for a low speed microcontroller device such as Arduino?

    Definitively yes.

    On the one hand you can use the Arduino UART at full speed ~ 115kbps, so the communication of data will be at the same bandwidth as if you had the Arduino connected directly to the USB directly (obviously with more initial latency). With the 3G modules available in the market until now the speed limit was established by the 3G network ~ 384kbps, so now we get 266 times more download performance than before. The upload speed the increment 133 times from 384kbps (3G) to 50Mbps (4G).

    As pointed before the 4G module can also be used as and standalone 4G/LTE USB modem! It works in Linux, Windows and MacOS, just plug it through its specific microUSB connector to your laptop and follow the steps located in the current manual.

    You can control also the kind of network service and the quality of the signal received (RSSI) from the surrounding cells you are using even change among them: LTE / WCDMA / HSPA+ / 3G / GPRS depending on the coverage of the zone. Get detailed information about the frequency band you are using to connect to the carrier and the quality of the signal.

    Article Index

    1. Features

    Electrical features

    The 4G module uses TELIT technology (LE910). The power supply of LE910 is from a single voltage source of VBAT= 3.4v-4.2v. In some cases, the ripple in a transmit burst may cause voltage drops when current consumption rise to typical peaks of 2A. So the power supply must be able to provide sufficient current up to 2A. The maximum rating are VBAT=4,4v and 3A peak. The maximum value of voltage for digital or analogy pins is 2.8v.

    The 4G module is powered at 3.3 V. The next table shows the module’s average current consumption in different states of the module.

    State
    Power consumption
    ON
    100 mA
    Transmitting data
    400 mA
    Receiving data
    400 mA

    Time consumption

    The following table describes the mean elapsed time for some actions in a single test for several attempts:

    Action
    Time consumption
    Power ON
    ~10s
    Start data connection
    ~4s
    Perform HTTP GET or POST
    ~0,7s
    Open FTP session
    ~3s
    Perform FTP upload 10KB file
    ~7s
    Perform FTP download 10KB file
    ~6s

    Some of these actions approximately have a fixed elapsed time like powering on the module or performing HTTP/FTP operations. However, the actions related to join a network or open the FTP session are dependent on third parts and have more variability from the mean value.

    2. Hardware

    4G Shield PCB

    NOTE: The Arduino/Raspberry Pi jumper MUST be in Arduino position. The Raspberry Pi position should be used only if the shield is connected to a Raspberry Pi. A wrong position of this jumper can damage the 4G shield
  • TOP
  • Some of the most remarkable parts of the 4G's TOP shield are:

    • SIM Card Socket: This holder allows oyu to easily add and change a carrier SIM card in order to connect the device to any network.
    • ON/OFF Button: It allows you to switch ON/OFF the module in gateway mode.
    • 4G Antenna.
    • DIV Antenna.
    • GPS Antenna.
    • Power Pins: You can use them to power the board externally.
    • Arduino / Raspberry Pi Jumper: This jumper MUST be in Arduino position. The Raspberry Pi position should be used only if the shield is connected to a Raspberry Pi. A wrong position of this jumper can damage the 4G shield
    • Serial com. Switch: This determine how the 4G's serial communication connects to the serial communication between the microcontroller and USB.
    • Power Jumpers: If the shield is powered from the Arduino or Raspberry Pi, the power jumper must be in Arduino 5V position. If the shield is powered from the Vin input (in the shield), the power jumper must be in Vext position.
    • Micro USB Power Jumper: With it, you will power the shield from the micro USB. Without it, you will power de shield from the Arduino or the Raspberry Pi. Be sure that, if you use the microUSB cable to power the shield, you don't power the board from the Arduino or Raspbery Pi.
    • MicroUSB: With it, the 4G module can be used as a standalone 4G/LTE modem.
    • 4G GPIOs.
  • BOTTOM
  • Some of the most remarkable parts of the 4G's BOTTOM shield are:

    • MicroSD Holder: It is controlled by the external MCU of the main board where we are connecting it (Arduino, Raspberry Pi, Waspmote) to save data coming or going to the 4G network.
    • Serial com. Switch: This determine if the module can be programmed or not. To programm the Arduino you need to put it in Ard position, once the code is loaded, to run it correctly you need to put this switch in USB position.

    4G Shield over Arduino

    Get Arduino

    Get the 4G Shield

    4G Shield over Raspberry Pi

    Get Raspberry Pi

    Get the Raspberry Pi to Arduino shields connection bridge

    Get the 4G Shield

    3. Software

    3.1 The Library

    The 4G module counts with a C++ library that lets you manage the module in a simple way. This library offers a simple-to-use open source system.

  • Using the library with Arduino
  • The 4G module includes a high level library functions for an easy manage. Before start using this functions you should download the library. The next zip includes all the files needed in different folders. Copy these folders in the arduino IDE folder “libraries”. Don't forget include these libraries in your codes.

    Download the 4G Libraries for Arduino.

    Libraries are often distributed as a ZIP file or folder. The name of the folder is the name of the library. Inside the folder will be the .cpp files, .h files and a examples folder.

    To install the library, first quit the Arduino application. Then uncompress the ZIP file containing the library. For installing libraries, uncompress zip file. Drag these folders into your libraries folder. Under Windows, it will likely be called "My Documents\Arduino\libraries". For Mac users, it will likely be called "Documents/Arduino/libraries". On Linux, it will be the "libraries" folder in your sketchbook.

    The library won't work if you put the .cpp and .h files directly into the libraries folder or if they're tested in an extra folder. Restart the Arduino application. Make sure the new library appears in the Sketch->Import Library menu item of the software.


  • Using the library with Raspberry Pi
  • The 4G library for Raspberry Pi requires the ArduPi library and the rest of the libraries should be in the same path.

    Download the 4G Libraries for Raspberry Pi.

    http://www.cooking-hacks.com/media/cooking/images/documentation/tutorial_kit_4g/arduPi_api_4G_v1_3.zip && unzip -u arduPi_api_4G_v1_3.zip && cd cooking/examples/4G && chmod +x cook.sh && cd ../../..  
    		

    Creating a program that uses the library is as simple as putting your code in this template where it says "your Arduino code here"

    Code:
    /*
     *  4G module
     *
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L.
     *  http://www.libelium.com
     *
     *  This program is free software: you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation, either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program.  If not, see http://www.gnu.org/licenses/.
     *
     *  Version:           1.0
     *  Design:            David Gascón
     *  Implementation:    Yuri Carmona & Ruben Martin
     */ 
    
    
    /*********************************************************
     *  IF YOUR ARDUINO CODE HAS OTHER FUNCTIONS APART FROM  *
     *  setup() AND loop() YOU MUST DECLARE THEM HERE        *
     * *******************************************************/
    
    /**************************
     * YOUR ARDUINO CODE HERE *
     * ************************/
    
    void setup()
    {
    }
    
    void loop(void)
    {    
    }
    
    int main (){
    	setup();
    	while(1){
    		loop();
    	}
    	return (0);
    }                 
    
    //////////////////////////////////////////////
                    

    Follow the next steps to compile a sketch:

    • First, install ArduPi and 4G libraries.
      • ArduPi For Raspberry Pi:

        wget http://www.cooking-hacks.com/media/cooking/images/documentation/raspberry_arduino_shield/raspberrypi.zip && unzip raspberrypi.zip && cd cooking/arduPi && chmod +x install_arduPi && ./install_arduPi && rm install_arduPi && cd ../..
        			

        ArduPi For Raspberry Pi 2:

        wget http://www.cooking-hacks.com/media/cooking/images/documentation/raspberry_arduino_shield/raspberrypi2.zip && unzip raspberrypi2.zip && cd cooking/arduPi && chmod +x install_arduPi && ./install_arduPi && rm install_arduPi && cd ../..
        			

        4G Library:

        wget http://www.cooking-hacks.com/media/cooking/images/documentation/tutorial_kit_4g/arduPi_api_4G_v1_3.zip && unzip -u arduPi_api_4G_v1_3.zip && cd cooking/examples/4G && chmod +x cook.sh && cd ../../..  
        			
    • Go to examples:
      • cd cooking/examples/4G/ 
        				
    • Compile the example:
      • ./cook.sh my_example.cpp 
        				
    • Run the sketch:
      • ./my_example.cpp_exe 
        				

    The script "cook.sh" compiles everything in their folders and the link in the examples foldes with the "_exe" executable.

    • Help: ./cook.sh
    • Clean: ./cook.sh -clean (It deletes all the "*.o" files. This is only necessary if you make changes in the libraries)

    3.1.1. Class constructor

    To start using the 4G library, an object must be created. This object, called 4G, is already created by default inside 4G library. It will be used through this guide to show how it works.

    When using the class constructor, all variables are initialized to a default value.

    3.1.2. API constants

    The API constants used in functions are:

    Constant
    Description
    DEBUG_WASP4G This definition 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 baudrate
    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 payloadsize to be stored in the data buffer

    There are several enumeration definitions for the function inputs. Please refer to the corresponding section in order to know more about the function input parameters.

    3.1.3. API variables

    The variables used inside functions and codes are:

    Variable
    Description
    _buffer The buffer of memory used for storing the responses from the module
    _length The useful length of the 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 RSSI level from the module
    _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 scoket index which is getting data from UDP or TCP
    _httpCode It stores de HTTP status code
    _filesize It stores the size of the file when FTP upload/download is performed
    _ftpWorkingDirectory It stores the current working directory of the FTP session
    socketInfo Structure to define the info to be stored for all sockets
    socketStatus Structure to define the status to be stored for all sockets
    socketStatusSSL Structure to define the status to be stored for all sockets
    _latitude It stores latitude from GPS
    _latitudeNS It stores the north/south indicator
    _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 stallites “in sight” of the GPS
    _fixMode It stores fix mode set
    _speedOG It stores speed over ground
    _courseOG It stores course over ground
    _hdop It stores the horizontal dilution of precision

    3.1.4. API functions

    Through this guide there are lots of examples of using 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 predefined object 4G.

    All public functions return one of these possible values:

    • 0: OK
    • Otherwise: ERROR. See corresponding function error code

    3.1.5 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:

    Value
    Error code description
    0Phone failure
    1No connection to phone
    2Phone-adaptor link reserved
    3Operation not allowed
    4Operation not supported
    5PH-SIM PIN required
    10SIM not inserted
    11SIM PIN required
    12SIM PUK required
    13SIM failure
    14SIM busy
    15SIM wrong
    16Incorrect password
    17SIM PIN2 required
    18SIM PUK2 required
    20Memory full
    21Invalid index
    22Not found
    23Memory failure
    24Text string too long
    25Invalid characters in text string
    26Dial string too long
    27Invalid characters in dial string
    30No network service
    31Network time-out
    32Network not allowed - emergency calls only
    40Network personalization PIN required
    41Network personalization PUK required
    42Network subset personalization PIN required
    43Network subset personalization PUK required
    44Service provider personalization PIN required
    45Service provider personalization PUK required
    46Corporate personalization PIN required
    47Corporate personalization PUK required
    100Unknown
    770SIM invalid
    103Illegal MS (#3)*
    106Illegal ME (#6)*
    107GPRS service not allowed (#7)*
    111PLMN not allowed (#11)*
    112Location area not allowed (#12)*
    113Roaming not allowed in this location area (#13)*
    132Service option not supported (#32)*
    133Requested service option not subscribed (#33)*
    134Service option temporarily out of order (#34)*
    148Unspecified GPRS error
    149PDP authentication failure
    150Invalid mobile class
    550Generic undocumented error
    551Wrong state
    552Wrong mode
    553Context already activated
    554Stack already active
    555Activation failed
    556Context not opened
    557Cannot setup socket
    558Cannot resolve DN
    559Time-out in opening socket
    560Cannot open socket
    561Remote disconnected or time-out
    562Connection failed
    563Tx error
    564Already listening
    568Wrong PDP
    615FTP not connected
    623FTP write data closed
    643FTP communication timeout
    657Network survey error (No Carrier)*
    658Network survey error (Busy)*
    659Network survey error (Wrong request)*
    660Network survey error (Aborted)*
    257Network rejected request
    258Retry operation
    259Invalid deflected to number
    260Deflected to own number
    261Unknown subscriber
    262Service not available
    263Unknown class specified
    264Unknown network message
    680LU processing
    681Network search aborted
    682PTM mode
    683Active call state
    684SSL already activated
    300ME failure
    301SMS service of ME reserved
    302Operation not allowed
    303Operation not supported
    304Invalid PDU mode parameter
    305Invalid text mode parameter
    310SIM not inserted
    311SIM PIN required
    312PH-SIM PIN required
    313SIM failure
    314SIM busy
    315SIM wrong
    316SIM PUK required
    317SIM PIN2 required
    318SIM PUK2 required
    320Memory failure
    321Invalid memory index
    322Memory full
    330SMSC address unknown
    331No network service
    332Network time-out
    340No +CNMA acknowledgement expected
    500Unknown error
    1001SSL certs and keys wrong or not stored
    1003SSL already activated
    1008SSL not connected
    65534Timeout error when running a command
    65535Generic "ERROR" message from module

    3.2 Switch On

    The ON() function allows to switch 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./p>

    Example of use:

    {
    	_4G.ON();
    }
                

    3.3 Switch Off

    The OFF() function allows the user to switch off the 4G module and close the UART. This function must be called in order to keep battery level when the module is not going to be managed.

    Example of use:

    {
       _4G.OFF();
    }
                

    3.4 SIM Card

    3.4.1 Entering PIN

    The enterPIN() function allows the user to enter the PIN and set a new one.

    Example of use to enter PIN:

    {
       _4G.enterPIN(“1234”);
    }
                

    Example of use to set a new PIN:

    {
       _4G.enterPIN(“1234”,”1111”);
    }
                

    3.4.2 Getting IMEI, IMSI and ICCID

    The getInfo() function can query module more than one information field.

    This function can query IMEI, IMSI and ICCID.

    Regarding to module's information, hardware revision, manufacturer identification, model identification and revision identification can be queried as well with this function.

    The function stores the required information in the given string.

    Example of use:

    {
       char* imei[21];
       _4G.getInfo(4,imei); //get IMEI number
       char* imsi[21];
       _4G.getInfo(5,imsi); //get IMSI number
       char* iccid[21];
       _4G.getInfo(6,iccid); //get ICCID number
    }
                

    3.5 Check network connection status

    There are two 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:

    • It is connected to a network
    • It isn't connected to a network
    • It 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 during the specified time.

    Example of use:

    {
       _4G.checkConnection(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

    The checkDataConnetion() function checks the module's network connection status, connect the module to data service and returns whether the module:

    • It is connected to data service
    • It isn't connected to a network
    • It is searching for a new operator to register to
    • Registration was denied
    {
       _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

    3.6 Setting operator parameters

    When the 4G module uses some services like IP connections (TCP/UDP), HTTP services, SMTP/POP3 or FTP transfers, it's mandatory to configure operator parameters like APN, login and password.

    This configuration is done through the set_APN() function. When set_APN() function is called these parameters are saved to the memory and configured into the 4G module.

    Example of use:

    {
       _4G.set_APN(“apn”,”apn_login”,”apn_password”);
    }
                

    User can query APN configuration parameters using the function show_APN().

    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

    3.7 SMS

    3.7.1 Setting SMS configuration

    The configureSMS() function sets the SMS configuration to:

    • Correct the SMS format read from the module
    • Select where SMS are going to be stored
    • Configure the indication method for new SMS received

    This function must be called before handling SMS in the main code loop.

    Example of use:

    {
       _4G.configureSMS();
    }
                

    3.7.2 Sending SMS

    The sendSMS() function sends a SMS to the given phone number. The maximum length of the PDU 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

    3.7.3 Reading SMS

    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 library structures: index number, status, sender number, date and time. The SMS text field 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 two 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 specified as input. If no input is defined, 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 library structures: index number, status, sender number, date and time. The SMS text field can be found in _4G._buffer.

    Example of use:

    {
    	   _4G.readNewSMS(30000);
    }
                

    Related variables:

      _4G._smsIndex → Stores the SMS index in memory storage

      _4G._smsStatus → Stores the SMS status

      _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 field temporary, after calling the read function

      _4G._length → Stores the SMS message length

    3.7.4 Deleting SMS

    The deleteSMS() function deletes an SMS according to the given index number in the memory storage.

    Example of use:

    {
    	   uint8_t  index = 2;
    	   _4G.deleteSMS(index);
    }
                

    There is a second deleteSMS() function prototype which deletes all the SMS in the storage memory according to several possibilities. For this function, two inputs are introduced: the SMS index number and the delete flag. If delete flag is not set to delete one single message, then index is ignored and the module shall follow the rules for delete flag.

    3.8 HTTP client

    3.8.1 HTTP resquest methods

    The http() function configures HTTP parameters, performs the request selected by the user and handles data received from server.

    This function needs several parameters to work properly depending on the method used. The first parameter required by the function is the request method. User can choose amongst five 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 field 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);
    }
                

    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 variables:

      _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

    3.9 FTP client

    3.9.1 Open FTP session

    The ftpOpenSession() function configures 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);
    }
                

    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 files.

    3.9.2 FTP upload

    The ftpUpload() function uploads a file from the Waspmote's SD card to the FTP server. The FTP session must be already open. This function needs two different inputs: the complete path of the file to be created in the FTP server and the complete path of the file in the SD card to be uploaded.

    Example of use for files in root directory:

    {
    	   char sd_file[]     = "FILE1.TXT";
    	   char server_file[] = "FILE2.TXT";
    
    	   _4G.ftpUpload(server_file, sd_file);
    }
                

    In the case the file should be uploaded into a subdirectory instead of the root directory, the server filename must be accordingly defined. The user must keep in mind that subdirectories have to be already created in order to upload files into them. In other words, it is not possible to create subdirectories in the FTP server.

    Example of use for files in subdirectories:

    {
    	   char sd_file[]     = "/FOLDER1/FILE1.TXT";
    	   char server_file[] = "/FOLDER2/FILE2.TXT";
    
    	   _4G.ftpUpload(server_file, sd_file);
    }
                

    Possible error codes for this function:

    • 1: if no SD present
    • 2: if file does not exist
    • 3: if error opening the file
    • 4: if error setting the pointer of the file
    • 5: if error getting the file size
    • 6: if error opening the PUT connection
    • 7: if error exiting from the data mode
    • 8: if error sending data

    3.9.3 FTP download

    The ftpDownload() function downloads a file from an FTP server to Waspmote's SD card. The FTP session must be already open. This function needs two different inputs: the complete path of the file in the FTP server and the complete path of the file to be created in the SD card.

    Example of use for files in root directory:

    {
    	   char sd_file[]     = "FILE1.TXT";
    	   char server_file[] = "FILE2.TXT";
    
    	   _4G.ftpDownload(server_file, sd_file);
    }
                

    In the case the file should be downloaded into a SD card's subdirectory instead of the root directory, the SD filename must be accordingly defined. The user must keep in mind that subdirectories have to be already created in the SD card in order to create files into them.

    Example of use for files in subdirectories:

    {
    	   char sd_file[]     = "/FOLDER1/FILE1.TXT";
    	   char server_file[] = "/FOLDER2/FILE2.TXT";
    
    	   _4G.ftpDownload(server_file, sd_file);
    }
                

    Possible error codes for this function:

    • 1: if server file size is zero
    • 2: if error reading the file size
    • 3: if SD not present
    • 4: if error creating the file in SD
    • 5: if error opening the file
    • 6: if error setting the pointer of the file
    • 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
    • 11: if error writing SD error
    • 12: if no more retries getting data
    • 13: if file size mismatch

    3.9.4. FTP delete file

    The ftpDelete() function deletes in the FTP server. The FTP session must be already open. The function expects the name of the file to be deleted as input.

    Example of deleting a file:

    {
    	   _4G.ftpDelete(“FILE_FTP.TXT”);
    }
                

    3.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

    3.9.6 Close FTP session

    The ftpCloseSession() function allows the user to close an active FTP session.

    Example of closing an FTP session:

    {
       _4G.ftpCloseSession();
    }
                
    NOTE: The SD, FTP and SSL functions of the library work only with Arduino Mega and Raspberry Pi (not with Arduino Uno). This is due to memory restrictions of Arduino Uno as it counts only with 2KB of RAM.

    3.10 TCP/UDP connections

    3.10.1. Socket identifiers

    The 4G module permits to have up to 6 simultaneous TCP/UDP connections. For that purpose, the libraries define the following socket identifiers to be used when handling the multi-socket connections:

      Wasp4G::SOCKET_1

      Wasp4G::SOCKET_2

      Wasp4G::SOCKET_3

      Wasp4G::SOCKET_4

      Wasp4G::SOCKET_5

      Wasp4G::SOCKET_6

    The 4G libraries define different structures in order to store the information related to all socket identifiers. 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.

    3.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 identifier
    • 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 defined as follows:

    • SocketInfo_t socketInfo[6];

    The definition 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 identifier of the socket to be updated.

    Example of use:

    {
    	   uint8_t socketId = Wasp4G::SOCKET_1;
    
    	   _4G.getSocketInfo(socketId);
    }
                

    Related variables:

      _4G.socketInfo[socketId].id → Socket identifier

      _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

    3.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 identifier
    • Current socket status.
    • Local IP address
    • Local port
    • Remote IP address
    • Remote port

    As it is possible to have up to six simultaneous connections, the global variable is defined as follows:

    • SocketStatus_t socketStatus[6];

    The definition 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 identifier 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 different identifiers.

    Example of use:

    	{
    	   uint8_t socketId = Wasp4G::SOCKET_1;
    
    	   _4G.getSocketStatus(socketId);
    	}
                

    Related variables:

      _4G.socketInfo[socketId].id → Socket identifier

      _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

    3.10.4. Creating a TCP/UDP client socket

    The openSocketClient() function configures and opens a socket. This function expects several input parameters:

    • Socket ID: The first parameter indicates the identifier to be associated to the new TCP/UDP connection. This identifier 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.
    • Host: Address of the remote host, string type.
    • Remote port: Remote host port to contact from 1 to 65535.
    • Local port: Parameter is valid for UDP connections only and has no effect (if used) for TCP connections. UDP connections local port from 1 to 65535.

    Example of creating a TCP client connection:

    	{
    	   uint8_t socketId = Wasp4G::SOCKET_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::SOCKET_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
    • 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 Configuration
    • 24: if error in Socket Configuration Extended 3
    • 25: if error sending the open command
    • 26: if timeout opening the socket

    3.10.5. Creating a TCP/UDP server socket

    The openSocketServer() function configures and opens a listening socket. This function expects several input parameters:

    • Socket ID: The first parameter indicates the identifier to be associated to the new TCP/UDP connection. This identifier 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.
    • Local port: Local listening port from 1 to 65535
    • Keep-Alive: TCP keep-alive timer timeout -The interval between two 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::SOCKET_1;
    	   uint16_t local_port = 5000;
    	   uint8_t  keep_alive = 240;
    
    	   _4G.openSocketServer(socketId, Wasp4G::TCP, local_port, keep_alive);
    	}
                

    Example of creating a UDP server:

    	{
    	   uint8_t  socketId   = Wasp4G::SOCKET_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, the best way to handle with connections is directly calling this function. If no input parameter is defined 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 specified 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 Configuration
    • 18: if protocol input not valid
    • 19: if error opening the socket

    3.10.6. Sending data

    The send() function allows the user to send TCP/UDP packets once the socket is active. The function needs two different inputs parameters:

    • Socket ID: the socket identifier 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 defined as a simple string message. On the other hand, the data can be defined 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::SOCKET_1, “This_is_the_data_payload”);
    }
                

    Example for sending an array of bytes:

    {
    	   uint8_t  data[] = {0x31, 0x32, 0x33, 0x34, 0x35}
    	   _4G.send(Wasp4G::SOCKET_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 confirmation from module
    • 5: if error getting socket status
    • 6: if timeout getting socket status

    3.10.7. Receiving data

    The receive() function allows the user to receive TCP/UDP packets once the socket is active. The function needs different inputs:

    • Socket ID: the socket identifier used for opening the connection.
    • Timeout (optional input):
      • If no timeout input is specified, 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 specified in milliseconds units.

    Example for instant reception:

    {
    	   _4G.receive(Wasp4G::SOCKET_1);
    }
                

    Example for blocking reception (i.e. 30 seconds):

    {
    	   _4G.receive(Wasp4G::SOCKET_1, 30000);
    }
                

    Related variables:

      _4G._buffe → Pointer to the buffer where received data is stored

      _4G._length → Length of the data received

    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

    3.10.8. Close 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 identifier.

    The closeSocketServer()i> function allows the user to close a TCP/UDP server previously open. The function needs two inputs:

    • Socket ID: the socket identifier used for opening the connection.
    • Protocol: This parameter indicates the protocol used by the socket.

    3.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 defined for opening the socket, sending data, receiving data and closing the socket.

    The manageSSL() function allows the user to store, delete and read security data (Certificate, CA certificate, private key) into the non volatile memory of the module. The function expects several inputs:

    • Socket ID: the socket identifier used for opening the connection
    • Action: the action to perform
    • Data type:
    • 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 confirmation
    • 3 if error getting security data
    • 4 if error deleting security data
    • 5 if invalid action input

    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 identifier 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 identifier 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 identifier used for opening the connection
    • Timeout (optional input):
      • If no timeout input is specified, 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 specified in milliseconds units.

    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 confirmation

    The closeSocketSSL() function allows the user to close a secure socket. The function needs an input parameter for the socket identifier.

    3.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.

    At this point, it is advisable to introduce the definition 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 off 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 figure below shows an overview of the involved functional entities.

    3.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.

    3.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 two 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.

    The libraries manage the SET Initiated Session scenario where the module, on its initiative, connects to an SLP Server through an IP network, two 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.

    3.11.3. Get GPS position

    The gpsStart() function allows the user to power on the GPS engine. Depending on the input parameter a different GPS mode is selected.

    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 defining the PDP context
    • 6: if error setting authentication user ID
    • 7: if error setting authentication password
    • 8: if error setting socket configuration
    • 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 permits to wait until GPS signal is received for valid data. The input parameter defines 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 confidence 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.

    3.12. Email management functions

    3.12.1. Reset email parameters

    The emailReset() function resets the actual email 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();
    }
                

    3.12.2. Set 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");
    }
                

    3.12.3. Configure the SMTP parameters

    The emailConfigureSMTP() 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.
    • Port: SMTP port to contact (default 25). Range from 1 to 65535

    Example:

    {
    	   _4G.emailConfigureSMTP(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.

    3.12.4. Set 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

    3.12.5. Save email 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();
    }
                

    3.12.6. Send email

    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 email.

    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:

    • 1: if error sending mail
    • 2: if error waiting for module confirmation

    4. Using 4G module with AT commands

    Important issues:

    • Use capital letters for AT commands.
    • Send CR (Carriage return) and LF (Line feed) after the AT command.
    • Place the serial communication switches in USB position.
    • Use an external power supply and place the power jumper in the Vin position. If the shield is powered from the Arduino or Raspberry Pi, the power jumper must be in Arduino 5V position.

    Important type commands in capital letters and with CR (carriage return) and LF (line feed)!!!

    Command Response Description
    AT OK If you get OK, the communication with the module is working
    AT+CPIN="****" OK If the SIM card is locked with PIN (**** is the pin number)
    AT+COPS?   Operator information

    NOTE: If your 4G module doesn't answer to AT commands, maybe it is configured in a different baudrate. Try differents baudrates (300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800,921600, 3200000,3686400,4000000 ) until you get to communicate. Once you can communicate, you can configure it in the baudrate you want.

    Using 4G module with AT commands in Arduino

    The first thing we are going to do with the module is to connect the module to a PC directly (using an Arduino as gateway) and check the basic AT commands. In this case, serial communication switches have to be set on USB gateway position.

    Remember take out the ATmega microcontroller from the Arduino gateway.

    Basic configuration:

    Connect the shield to the Arduino gateway.

    Then connect the SIM card and the USB cable.

    Finally plug the USB cable to the computer and open a serial port terminal to communicate via the usb port (e.g: hyperterminal (win), cutecom / gtkterm (linux)).

    If you use the Arduino IDE serial monitor for sending AT commands – Be sure that you are sending CR (Carriage return) and LF (Line Feed).

    Set the baudrate to 115200 bps and open the serial port, then press the ON button for two seconds. Then if you type AT you'll get OK, this means that the communication with the module is working fine. Now, with the module working you can check some AT commands to control the module.

    NOTE: With some sketches, the buffer of the UART may be small, to increase the length of the buffer you need to change these lines in the file HardwareSerial.h in /arduino-1.0.X/hardware/arduino/avr/cores/arduino/ (or in file HardwareSerial.cpp depending on the Arduino IDE version)

    #if (RAMEND < 1000)
    #define SERIAL_TX_BUFFER_SIZE 16
    #define SERIAL_RX_BUFFER_SIZE 16
    #else
    #define SERIAL_TX_BUFFER_SIZE 64
    #define SERIAL_RX_BUFFER_SIZE 64
    #endif
    #endif
                    

    to

    #if (RAMEND < 1000)
    #define SERIAL_TX_BUFFER_SIZE 400
    #define SERIAL_RX_BUFFER_SIZE 400
    #else
    #define SERIAL_TX_BUFFER_SIZE 400
    #define SERIAL_RX_BUFFER_SIZE 400
    #endif
    #endif
                    

    Using 4G module with AT commands in Raspberry Pi

    The first thing we are going to do with the module is to check the basic AT commands in gateway mode. Using gateway mode, commands can be sent from our Raspberry Pi directly to any serial module. To stablish UART connection with the module you can use several programs as cutecom in Raspbian graphical environment or minicom in a terminal window in order to use it via SSH . For using minicom follow these steps:

    1. Place the Arduino/RPI jumper in the 4G shield to the right, in RPI position.
    2. Place the two Serial com. switches in the 4G in Arduino position. These switches always have to be in this position, in gateway mode and when you run codes.
    3. We recommend to power externally the shield, but it's not necessary in all cases.

    4. Connect the shield to the Raspberry Pi connection bridge and the antennas to the shield. Now press the ON button in the shield, you will see a green LED.
    5. Open a Terminal window on Raspberry Pi, or connect to Raspberry Pi through SSH. In order to enter via SSH change here the IP from your Raspberry Pi. The default user is pi.
      ssh -X pi@192.168.1.X

      Now you will have to type your password. The default password is “raspberry”.

    6. Install minicom (only if you haven't done it before):
      sudo apt-get install minicom
    7. Open comunication with the module UART, the baudrate is 115200:
      minicom -b 115200 -o -D /dev/ttyAMA0
    8. Then if you type AT you'll get OK, this means that the communication with the module is working fine. Now, with the module working you can check some AT commands to control the module.
    9. To exit minicom press CTRL+A, then press X and Yes.

    5. Using 4G module like a modem

    You can also use the module as a standard 4G / LTE modem with a Download speed up to 100Mbps and a Upload speed of 50Mbps!. Just connect it through its specific mini-USB socket to your laptop (Linux, Windows, MacOS) and go!. And yes! you can also connect it through the USB por to your Raspberry Pi and get the full speed with it too.

    NOTE: Be sure that you put the jumpers in the correct position. You can damage the board

    5.1 Using 4G module like a modem with a computer

    5.1.1 Windows

    NOTE: Be sure that you put the jumpers in the correct position. You can damage the board:
    · Power Jumper: 5V.
    · Micro USB Power jumper: Put it.

    If you want to use the 4G module like a modem with a Windows computer, please follow the next steps:

    1. Plug in the 4G Shield to a USB port, pres the ON button, you will see the LED ON.
    2. Open the Device Manager, if you have connected correctly the device it will look similar to the screenshot below.


    3. As seen in “other devices” there are five that are not assigned any driver, and therefore can not be detected by the operating system. Download the drivers and install them.

    4. Download Windows Drivers.




    5. Now, drivers are installed. The device is recognized.


    6. Everything is ready to use the device as a modem

    5.1.2 Linux

    NOTE: Be sure that you put the jumpers in the correct position. You can damage the board:
    · Power Jumper: 5V.
    · Micro USB Power jumper: Put it.

    If you want to use the 4G module like a modem with a Linux computer, please follow the next steps:

    1. Open a terminal:
    2. Install required software:
    3. sudo apt-get update
      sudo apt-get install wvdial ppp usb-modeswitch
                      
    4. Get the USB switching codes. Connect your USB modem and reboot the computer.
    5. Once rebooted, press the ON button, you will se the LED ON.
    6. Plug in the device, and execute:
    7. dmesg
                      

      With this we can see if we have the drivers of the device installed or not. If it is not recognized, install the necessary drivers.

    8. Get a list of devices connected to USB port.
    9. lsusb
                      

      The output will look similar to the screenshot below. Your modem should be listed as one of the USB devices.


    10. Now that the 4G shield is correctly recognized, we can start the auto detection with the wvdial programm. This programm will write to the file /etc/wvdial.conf so it needs administrators permitions to run. Type the following on the terminal:
    11. sudo wvdialconf /etc/wvdial.conf 
                      
    12. The output will look similar to the screenshot below.

    13. This configuration process writes to the /etc/wvdial.conf the most important settings for the modem, but we have to manually set some specific settings related to our internet service provider, like apn and phone number. Open the /etc/wvdial.conf file:
    14. sudo nano /etc/wvdial.conf 
                      

      The output will look similar to the screenshot below. Set your APN, you username and your password.


    15. Now we can open the internet connection by typing the following command:
    16. sudo wvdial 
                      

      The output will look similar to the screenshot below.


    17. Everything is ready to use the device as a modem

    5.1.3 Mac OS

    First, download and install a virtual machine, VirtualBox in this case.



    Select the virtual machine application and install Windows.



    Run Windows into the virtual machine. Connect your USB modem and press the ON button, you will se the LED ON. Click on the usb icon into the virtual machine screen, and select USB Settings. In this menu add a new device and select USB Host controller.



    One you have done this, you can continue with the Windows tutorial (5.1.1)

    5.2 Using 4G module like a modem with Raspberry Pi

    NOTE: Be sure that you put the jumpers in the correct position. You can damage the board:
    · Arduino/Raspberry Jumper: Raspberry position.
    · Power Jumper: 5V.
    · Micro USB Power jumper: Put it.
    · Bridge Switch: Power off it (put it in the opposite side of the Raspberry's GPIOs).

    If you want to use the 4G module like a modem with Raspberry Pi, please follow the next steps:

    1. Open a terminal on the Raspberry Pi, or connect to Raspberry Pi through SSH.
    2. Install required software:
    3. sudo apt-get update
      sudo apt-get install wvdial ppp usb-modeswitch
                      
    4. Get the USB switching codes. Connect your USB modem and reboot the Raspberry.
    5. Once rebooted, press the ON button, you will se the LED ON.
    6. Plug in the device, and execute:
    7. dmesg
                      

      With this we can see if we have the drivers of the device installed or not. If it is not recognized, install the necessary drivers.

    8. Get a list of devices connected to USB port.
    9. lsusb
                      

      The output will look similar to the screenshot below. Your modem should be listed as one of the USB devices.


    10. Now that the 4G shield is correctly recognized, we can start the auto detection with the wvdial programm. This programm will write to the file /etc/wvdial.conf so it needs administrators permitions to run. Type the following on the terminal:
    11. sudo wvdialconf /etc/wvdial.conf 
                      
    12. The output will look similar to the screenshot below.

    13. This configuration process writes to the /etc/wvdial.conf the most important settings for the modem, but we have to manually set some specific settings related to our internet service provider, like apn and phone number. Open the /etc/wvdial.conf file:
    14. sudo nano /etc/wvdial.conf 
                      

      The output will look similar to the screenshot below. Set your APN, you username and your password.


    15. Now we can open the internet connection by typing the following command:
    16. sudo wvdial 
                      

      The output will look similar to the screenshot below.


    17. Everything is ready to use the device as a modem

    6. GPS

    This example shows how to use de GPS in autonomous mode.

    Arduino:

    Code:
    /*
        --------------- 4G_14 - GPS Autonomous mode  ---------------
    
        Explanation: This example shows how to use de GPS in autonomous mode
        Notes: 
         - To work poperly, GPS module needs a 2A(at least) power supply.
         - GPS antennae needs direct skyview to fix satellites; work outdoor.
    
        Important: in Arduino UNO the same UART is used for Debug User Interface 
        and LE910 AT commands. Handle with care, user interface messages could 
        interfere with AT commands.
    
        Example: 
              Serial.print("operATo"); 
        It is seen as wrong AT command by the LE910 module.
    
        Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
        http://www.libelium.com
    
        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
        Version:           1.0
        Design:            David Gascón
        Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
                           & Ruben Martin
    */
    
    #include "arduino4G.h"
    
    // define variables
    uint8_t error;
    uint8_t gps_status;
    bool gps_fix;
    
    float latitude;
    float longitude;
    
    void setup()
    {
      Serial.println("Start program");
    
      //////////////////////////////////////////////////
      // 1. Switch on the 4G module
      //////////////////////////////////////////////////
      error = _4G.ON();
    
      // check answer
      if (error == 0)
      {
        Serial.println(F("1. 4G module ready..."));
    
        ////////////////////////////////////////////////
        // 2. Start GPS feature
        ////////////////////////////////////////////////
    
        gps_status = _4G.startGPS();
    
        // check answer
        if (gps_status == 0)
        {
          Serial.println(F("2. Starting GPS in autonomous mode... done!"));
        }
        else
        {
          Serial.print(F("2. Error calling the 'startGPS' function. Code: "));
          Serial.println(gps_status, DEC);
        }
      }
      else
      {
        // Problem with the communication with the 4G module
        Serial.println(F("1. 4G module not started"));
        Serial.print(F("Error code: "));
        Serial.println(error, DEC);
        Serial.println(F("The code stops here."));
        while (1);
      }
    }
    
    
    void loop()
    {
      ////////////////////////////////////////////////
      // 3. Wait for satellite signals and get values
      ////////////////////////////////////////////////
      if (gps_status == 0)
      {
        error = _4G.waitForSignal(20000);
        if (error == 0)
        {
          Serial.println(F("----------------------------"));
          Serial.print(F("Ltitude: "));
          Serial.print(_4G._latitude);
          Serial.print(F(","));
          Serial.println(_4G._latitudeNS);
          Serial.print(F("Longitude: "));
          Serial.print(_4G._longitude);
          Serial.print(F(","));
          Serial.println(_4G._longitudeEW);
          Serial.print(F("UTC_time: "));
          Serial.println(_4G._time);
          Serial.print(F("day: "));
          Serial.println(_4G._date);
          Serial.print(F("Number of stellites: "));
          Serial.println(_4G._numSatellites, DEC);
          Serial.print(F("HDOP: "));
          Serial.println(_4G._hdop);
          Serial.println(F("----------------------------"));
    
          // get degrees
          latitude  = _4G.convert2Degrees(_4G._latitude, _4G._latitudeNS);
          longitude = _4G.convert2Degrees(_4G._longitude, _4G._longitudeEW);
          
          Serial.println("Conversion to degrees:");
          Serial.print(F("Ltitude: "));
          Serial.println(latitude);
          Serial.print(F("Longitude: "));
          Serial.println(longitude);  
          Serial.println();
          delay(10000);
        }
        else
        {
          Serial.println("no stellites fixed");
        }
      }
      else
      {
        Serial.println(F("Restarting the GPS engine"));
        _4G.stopGPS();
        delay(1000);
    
        gps_status = _4G.startGPS();
      }
    }
            

    Raspberry Pi:

    Code:
    /*  
     *  --------------- 4G_14 - GPS Autonomous mode  ---------------
     *
     *  Explanation: This example shows how to use de GPS in autonomous mode
     *
     *  Notes: 
     *   - To work poperly, GPS module needs a 2A(at least) power supply.
     *   - GPS antennae needs direct skyview to fix satellites; work outdoor.
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L.
     *  http://www.libelium.com
     *
     *  This program is free software: you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation, either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program.  If not, see http://www.gnu.org/licenses/.
     *
     *  Version:           1.0
     *  Design:            David Gascón
     *  Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
     *                     & Ruben Martin
     */
    
    #include "arduPi4G.h"
    
    // define variables
    uint8_t error;
    uint8_t gps_status;
    bool gps_fix;
    
    float latitude;
    float longitude;
    
    
    void setup()
    {
      printf("Start program\n");
    
    
      //////////////////////////////////////////////////
      // 1. Switch on the 4G module
      //////////////////////////////////////////////////
      error = _4G.ON();
    
      // check answer
      if (error == 0)
      {
        printf("1. 4G module ready...\n");
    
    
        ////////////////////////////////////////////////
        // 2. Start GPS feature
        ////////////////////////////////////////////////
    
        gps_status = _4G.startGPS();
    
        // check answer
        if (gps_status == 0)
        {
          printf("2. Starting GPS in autonomous mode... done!\n");
        }
        else
        {
          printf("2. Error calling the 'startGPS' function. Code: %d\n", gps_status);
        }
    
      }
      else
      {
        // Problem with the communication with the 4G module
        printf("1. 4G module not started\n");
        printf("Error code: %d\n", error);
        printf("The code stops here.\n");
        while (1);
      }
    }
    
    
    
    void loop()
    {
      ////////////////////////////////////////////////
      // 3. Wait for satellite signals and get values
      ////////////////////////////////////////////////
      if (gps_status == 0)
      {
        error = _4G.waitForSignal(20000);
        if (error == 0)
        {
          printf("----------------------------\n");
          printf("Latitude: %s, LatitudeNS: %c, Longitude: %s, LongitudeEW: %c, "\
                 "UTC_time:%s, date:%s, Number of satellites: %u, HDOP: %f\n",
                  _4G._latitude, 
                  _4G._latitudeNS, 
                  _4G._longitude, 
                  _4G._longitudeEW, 
                  _4G._time, 
                  _4G._date, 
                  _4G._numSatellites, 
                  _4G._hdop);
          printf("----------------------------\n");
    
          // get degrees
          latitude  = _4G.convert2Degrees(_4G._latitude, _4G._latitudeNS);
          longitude = _4G.convert2Degrees(_4G._longitude, _4G._longitudeEW);
          
          printf("Conversion to degrees:\n");
          printf("Latitude: %f\n", latitude);
          printf("Longitude: %f\n\n", longitude);
          delay(10000);
        }
        else
        {
          printf("no satellites fixed\n");
        }
      }
      else
      {
        printf("Restarting the GPS engine\n");
        _4G.stopGPS();
    
        delay(1000);
    
        gps_status = _4G.startGPS();
      }
    
    }
    
    //////////////////////////////////////////////
    // Main loop setup() and loop() declarations
    //////////////////////////////////////////////
    int main()
    {
        setup();
        while(1) loop();
        return (0);
    }
    //////////////////////////////////////////////
    
            
    NOTE: GPS is only available for LE910-EUG and LE910-NAG modules not for LE910-AU V2, LE910-SKG, LE910-JB V2 and LE910-JK V2 modules.
  • GPS External antenna - (Passive)
  • 7. Indoor Tracking using 4G and A-GPS mode with Arduino and Raspberry Pi (Geo-Location)

    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 first fix" (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:

    Arduino:

    Code:
    /*
        --------------- 4G_18 - A-GPS (MS-Based GPS)  ---------------
    
        Explanation: This example shows how to use de A-GPS in MS-Based mode
    
        Note 1: in Arduino UNO the same UART is used for user debug interface 
        and LE910 AT commands. Handle with care, user interface messages could 
        interfere with AT commands.
    
        Example: 
              Serial.print("operATo"); 
        It is seen as wrong AT command by the LE910 module.
    
        Note 2: to run this example properly you must increase the reception 
        serial buffer to 128 bytes. 
        -> go to: <arduino_dir>/hardware/arduino/avr/cores/arduino
        -> edit:  HardwareSerial.h 
    
         If you are using Arduino Uno:
        -> merge: #define SERIAL_RX_BUFFER_SIZE 128
    
         If you are using Arduino Mega:
        -> merge: #define SERIAL_TX_BUFFER_SIZE 128
        -> merge: #define SERIAL_RX_BUFFER_SIZE 128
    
        Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
        http://www.libelium.com
    
        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
        Version:           1.1
        Design:            David Gascon
        Implementation:    Alejandro Gallego, Yuri Carmona, Luis Miguel Marti
        Port to Arduino:   Ruben Martin
    */
    
    #include "arduino4G.h"
    
    // APN settings
    ///////////////////////////////////////
    char apn[] = "";
    char login[] = "";
    char password[] = "";
    ///////////////////////////////////////
    
    // define variables
    uint8_t error;
    uint8_t gps_status;
    float gps_latitude;
    float gps_longitude;
    uint32_t previous;
    bool gps_autonomous_needed = true;
    
    
    void setup()
    {
      //////////////////////////////////////////////////
      // Set operator parameters
      //////////////////////////////////////////////////
      _4G.set_APN(apn, login, password);
    
      //////////////////////////////////////////////////
      // Show APN settings via Serial port
      //////////////////////////////////////////////////
      _4G.show_APN();
    
      //////////////////////////////////////////////////
      // 1. Switch on the 4G module
      //////////////////////////////////////////////////
      error = _4G.ON();
    
      // check answer
      if (error == 0)
      {
        Serial.println(F("1. 4G module ready..."));
    
        ////////////////////////////////////////////////
        // 2. Start GPS feature
        ////////////////////////////////////////////////
    
        // get current time
        previous = millis();
    
        gps_status = _4G.gpsStart(arduino4G::GPS_MS_BASED);
    
        // check answer
        if (gps_status == 0)
        {
          Serial.print(F("2. GPS started in MS-BASED. Time(secs) = "));
          Serial.println((millis()-previous)/1000);
        }
        else
        {
          Serial.print(F("2. Error calling the 'gpsStart' function. Code: "));
          Serial.println(gps_status, DEC);
        }
      }
      else
      {
        // Problem with the communication with the 4G module
        Serial.println(F("1. 4G module not started"));
        Serial.print(F("Error code: "));
        Serial.println(error, DEC);
        Serial.println(F("The code stops here."));
        while (1);
      }
    }
    
    
    void loop()
    {
      ////////////////////////////////////////////////
      // Wait for satellite signals and get values
      ////////////////////////////////////////////////
      if (gps_status == 0)
      {
        error = _4G.waitForSignal(20000);
    
        if (error == 0)
        {
          Serial.print(F("3. GPS signal received. Time(secs) = "));
          Serial.println((millis()-previous)/1000);
    
          Serial.println(F("Acquired position:"));
          Serial.println(F("----------------------------"));
          Serial.print(F("Ltitude: "));
          Serial.print(_4G._latitude);
          Serial.print(F(","));
          Serial.println(_4G._latitudeNS);
          Serial.print(F("Longitude: "));
          Serial.print(_4G._longitude);
          Serial.print(F(","));
          Serial.println(_4G._longitudeEW);
          Serial.print(F("UTC_time: "));
          Serial.println(_4G._time);
          Serial.print(F("UTC_dte: "));
          Serial.println(_4G._date);
          Serial.print(F("Number of stellites: "));
          Serial.println(_4G._numSatellites, DEC);
          Serial.print(F("HDOP: "));
          Serial.println(_4G._hdop);
          Serial.println(F("----------------------------"));
    
          // get degrees
          gps_latitude  = _4G.convert2Degrees(_4G._latitude, _4G._latitudeNS);
          gps_longitude = _4G.convert2Degrees(_4G._longitude, _4G._longitudeEW);
    
          Serial.println("Conversion to degrees:");
          Serial.print(F("Ltitude: "));
          Serial.println(gps_latitude, 6);
          Serial.print(F("Longitude: "));
          Serial.println(gps_longitude, 6);
          Serial.println();
    
    
          ////////////////////////////////////////////////
          // Change to AUTONOMOUS mode if needed
          ////////////////////////////////////////////////
    
          if (gps_autonomous_needed == true)
          {
            _4G.gpsStop();
    
            gps_status = _4G.gpsStart(arduino4G::GPS_AUTONOMOUS);
    
            // check answer
            if (gps_status == 0)
            {
              Serial.println(F("GPS started in AUTONOMOUS mode"));
    
              // update variable
              gps_autonomous_needed = false;
            }
            else
            {
              Serial.print(F("Error calling the 'gpsStart' function. Code: "));
              Serial.println(gps_status, DEC);
            }
          }
          delay(10000);
        }
        else
        {
          Serial.print("no stellites fixed. Error: ");
          Serial.println(error, DEC);
        }
      }
      else
      {
        ////////////////////////////////////////////////
        // Restart GPS feature
        ////////////////////////////////////////////////
    
        Serial.println(F("Restarting the GPS engine"));
    
        // stop GPS
        _4G.gpsStop();
        delay(1000);
    
        // start GPS
        gps_status = _4G.gpsStart(arduino4G::GPS_MS_BASED);
    
        // check answer
        if (gps_status == 0)
        {
          Serial.print(F("GPS started in MS-BASED. Time(ms) = "));
          Serial.println(millis() - previous);
        }
        else
        {
          Serial.print(F("Error calling the 'gpsStart' function. Code: "));
          Serial.println(gps_status, DEC);
        }
      }
    }
            

    Raspberry Pi:

    Code:
    /*
     *  --------------- 4G_18 - A-GPS (MS-Based GPS)  ---------------
     *
     *  Explanation: This example shows how to use de A-GPS in MS-Based mode
     *
     *  Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
     *  http://www.libelium.com
     *
     *  This program is free software: you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation, either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
     *
     *  Version:           1.1
     *  Design:            David Gascón
     *  Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
     *  Port to Raspberry: Ruben Martin
     */
    
    #include "arduPi4G.h"
    
    // APN settings
    ///////////////////////////////////////
    char apn[] = "m2m.tele2.com";
    char login[] = "";
    char password[] = "";
    ///////////////////////////////////////
    
    // define variables
    uint8_t error;
    uint8_t gps_status;
    float gps_latitude;
    float gps_longitude;
    uint32_t previous;
    bool gps_autonomous_needed = true;
    
    
    void setup()
    {
      printf("Start program\n");
    
      //////////////////////////////////////////////////
      // Set operator parameters
      //////////////////////////////////////////////////
      _4G.set_APN(apn, login, password);
    
      //////////////////////////////////////////////////
      // Show APN settings via USB port
      //////////////////////////////////////////////////
      _4G.show_APN();
    
      //////////////////////////////////////////////////
      // 1. Switch on the 4G module
      //////////////////////////////////////////////////
      error = _4G.ON();
    
      // check answer
      if (error == 0)
      {
        printf("1. 4G module ready...\n");
    
        ////////////////////////////////////////////////
        // 2. Start GPS feature
        ////////////////////////////////////////////////
    
        // get current time
        previous = millis();
    
        gps_status = _4G.gpsStart(arduPi4G::GPS_MS_BASED);
    
        // check answer
        if (gps_status == 0)
        {
          printf("2. GPS started in MS-BASED. Time(secs) = %d\n", (millis()-previous)/1000);
        }
        else
        {
          printf("2. Error calling the 'gpsStart' function. Code: %d\n", gps_status);
        }
      }
      else
      {
    
        // Problem with the communication with the 4G module
        printf("1. 4G module not started\n");
        printf("Error code: %d\n", error);
        printf("The code stops here.\n");
        while (1);
      }
    }
    
    
    void loop()
    {
    
      ////////////////////////////////////////////////
      // Wait for satellite signals and get values
      ////////////////////////////////////////////////
      if (gps_status == 0)
      {
        error = _4G.waitForSignal(20000);
    
        if (error == 0)
        {
          printf("3. GPS signal received. Time(secs) = %d\n", (millis()-previous)/1000);
    
          printf("Acquired position:\n");
          printf("----------------------------\n");
          printf("Latitude: %s, LatitudeNS: %c, Longitude: %s, LongitudeEW: %c, "\
                 "UTC_time:%s, date:%s, Number of satellites: %u, HDOP: %f\n",
                  _4G._latitude, 
                  _4G._latitudeNS, 
                  _4G._longitude, 
                  _4G._longitudeEW, 
                  _4G._time, 
                  _4G._date, 
                  _4G._numSatellites, 
                  _4G._hdop);
          printf("----------------------------\n");
    
          // get degrees
          gps_latitude  = _4G.convert2Degrees(_4G._latitude, _4G._latitudeNS);
          gps_longitude = _4G.convert2Degrees(_4G._longitude, _4G._longitudeEW);
          
          printf("Conversion to degrees:\n");
          printf("Latitude: %f\n", gps_latitude);
          printf("Longitude: %f\n\n", gps_longitude);
    
          ////////////////////////////////////////////////
          // Change to AUTONOMOUS mode if needed
          ////////////////////////////////////////////////
          if (gps_autonomous_needed == true)
          {
            _4G.gpsStop();
    
            gps_status = _4G.gpsStart(arduPi4G::GPS_AUTONOMOUS);
    
            // check answer
            if (gps_status == 0)
            {
              printf("GPS started in AUTONOMOUS mode\n");
    
              // update variable
              gps_autonomous_needed = false;
            }
            else
            {
              printf("Error calling the 'gpsStart' function. Code: %d\n", gps_status);
            }
          }
    
          delay(10000);
        }
        else
        {
          printf("no satellites fixed. Error: %d\n", error);
        }
      }
      else
      {
        ////////////////////////////////////////////////
        // Restart GPS feature
        ////////////////////////////////////////////////
        printf("Restarting the GPS engine\n");
    
        // stop GPS
        _4G.gpsStop();
        delay(1000);
    
        // start GPS
        gps_status = _4G.gpsStart(arduPi4G::GPS_MS_BASED);
    
        // check answer
        if (gps_status == 0)
        {
          printf("GPS started in MS-BASED. Time(ms) = %d\n", millis() - previous);
        }
        else
        {
          printf("Error calling the 'gpsStart' function. Code: %d\n", gps_status);
        }
      }
    }
    
    
    //////////////////////////////////////////////
    // Main loop setup() and loop() declarations
    //////////////////////////////////////////////
    int main()
    {
        setup();
        while(1) loop();
        return (0);
    }
    //////////////////////////////////////////////
    
            

    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 figures, it is possible to see how the GPS module gets its first 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 different iterations. Finally, we can see how the module achieves a great location detection after 73 seconds.

    First iteration (41 seconds after starting the 4G module). Distance error: 42 meters.


    Second iteration (53 seconds after starting the 4G module). Distance error: 28 meters.


    Third iteration (63 seconds after starting the 4G module). Distance error: 28 meters.


    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 detection accuracy may vary from 10 to 100 meters so a real test in each case is mandatory before implementing a final application.

    NOTE: GPS is only available for LE910-EUG and LE910-NAG modules not for LE910-AU V2, LE910-SKG, LE910-JB V2 and LE910-JK V2 modules.
  • GPS External antenna - (Passive)
  • 8. SMS

    Sending SMS

    This example shows how to set up the module to use SMS and send text messages

    Arduino:

    Code:
    /*  
     *  --------------- 4G_04 - Sending SMS   --------------- 
     *  
     *  Explanation: This example shows how to set up the module to use
     *  SMS and send text messages
     *  
     *  Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L. 
     *  http://www.libelium.com 
     *  
     *  This program is free software: you can redistribute it and/or modify 
     *  it under the terms of the GNU General Public License as published by 
     *  the Free Software Foundation, either version 3 of the License, or 
     *  (at your option) any later version. 
     *  
     *  This program is distributed in the hope that it will be useful, 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     *  GNU General Public License for more details. 
     *  
     *  You should have received a copy of the GNU General Public License 
     *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     *  
     *  Version:           1.0
     *  Design:            David Gascón 
     *  Implementation:    Alejandro Gállego & Rubén Martín
     */
    /*  
        ---------------------- 4G_04 - Sending SMS ---------------------- 
       
        Explanation: This example shows how to set up the module to use
        SMS and send text messages
    
        Important: in Arduino UNO the same UART is used for Debug User Interface 
        and LE910 AT commands. Handle with care, user interface messages could 
        interfere with AT commands.
    
        Example: 
              Serial.print("operATo"); 
        It is seen as wrong AT command by the LE910 module.
    
        Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
        http://www.libelium.com
    
        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>. 
    
        Version:           1.0
        Design:            David Gascón
        Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
                           & Ruben Martin
     */
    
    #include "arduino4G.h"
    
    //////////////////////////////////////////////////
    char phone_number[] = "+34666777888";
    char sms_body[] = "Hello from CookingHacks!!!";
    //////////////////////////////////////////////////
    
    uint8_t error;
    uint8_t counter;
    
    void setup()
    {
    }
    
    void loop()
    {
      //////////////////////////////////////////////////
      // 1. Switch on the 4G module
      //////////////////////////////////////////////////
      error = _4G.ON();
    
      if (error == 0)
      {
        Serial.println(F("1. 4G module ready..."));
    
        ////////////////////////////////////////////////
        // 2. Waiting for Connection
        ////////////////////////////////////////////////
    
        // Waiting for network registration
        counter = 7;
        error = _4G.checkConnection(60);
        while ((counter > 0) && (error != 0))
        {
            delay(5000);
            error = _4G.checkConnection(60);
            counter--;      
        }
    
        if (error == 0)
        {
          Serial.println(F("2.1. Connected to network"));
        }
        else
        {
          Serial.print(F("2.1. Error connecting to network. Code: "));
          Serial.println(error, DEC);
        } 
    
        ////////////////////////////////////////////////
        // 3. Configure SMS options
        ////////////////////////////////////////////////
        error = _4G.configureSMS();
    
        if (error == 0)
        {
          Serial.println(F("3.1. 4G module configured to use SMS"));		
        }
        else
        {
          Serial.print(F("3.1. Error calling 'configureSMS' function. Code: "));
          Serial.println(error, DEC);
        } 
    
    
        ////////////////////////////////////////////////
        // 4. Send SMS
        ////////////////////////////////////////////////
        Serial.println(F("4.2. Sending SMS..."));
        error = _4G.sendSMS( phone_number, sms_body);
    
        if (error == 0)
        {
          Serial.println(F(" done"));	
        }
        else
        {
          Serial.print(F("error. Code: "));
          Serial.println(error, DEC);
        }    
      }
      else
      {
        // Problem with the communication with the 4G module
        Serial.print(F("1. 4G module not started. Error code: "));
        Serial.println(error, DEC);
      }
    
    
      ////////////////////////////////////////////////
      // 5. Powers off the 4G module
      ////////////////////////////////////////////////
      Serial.println(F("5. Switch OFF 4G module"));
      _4G.OFF();
    
    
      ////////////////////////////////////////////////
      // 6. Sleep
      ////////////////////////////////////////////////
      delay(60000);
    }
            

    Raspberry Pi:

    Code:
    /*  
     *  --------------- 4G_04 - Sending SMS   --------------- 
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L.
     *  http://www.libelium.com
     *
     *  This program is free software: you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation, either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program.  If not, see http://www.gnu.org/licenses/.
     *
     *  Version:           1.0
     *  Design:            David Gascón
     *  Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
     *                     & Ruben Martin
     */
    
    #include "arduPi4G.h"
    
    //////////////////////////////////////////////////
    char phone_number[] = ""; //example.- "+34666555444"
    char sms_body[] = "Hello from CookingHacks!!!";
    //////////////////////////////////////////////////
    
    uint8_t error;
    uint8_t counter;
    
    void setup()
    {
    }
    
    
    void loop()
    {
      //////////////////////////////////////////////////
      // 1. Switch on the 4G module
      //////////////////////////////////////////////////
      error = _4G.ON();
    
      if (error == 0)
      {
        printf("1. 4G module ready...\n");
    
        ////////////////////////////////////////////////
        // 2. Waiting for Connection
        ////////////////////////////////////////////////
    
        // Waiting for network registration
        counter = 3;
        error = _4G.checkConnection(60);
        while ((counter > 0) && (error != 0))
        {
            delay(5000);
            error = _4G.checkConnection(60);
            counter--;      
        }
    
        if (error == 0)
        {
            printf("2.1. Connected to network\n");
        }
        else
        {
            printf("2.1. Error connecting to network. Code: %d\n",error);
        } 
    
        ////////////////////////////////////////////////
        // 2. Configure SMS options
        ////////////////////////////////////////////////
        error = _4G.configureSMS();
    
        if (error == 0)
        {
          printf("2.1. 4G module configured to use SMS\n");		
        }
        else
        {
          printf("2.1. Error calling 'configureSMS' function. Code: %d\n", error);
        } 
    
    
        ////////////////////////////////////////////////
        // 3. Send SMS
        ////////////////////////////////////////////////
        printf("2.2. Sending SMS...\n");
        error = _4G.sendSMS( phone_number, sms_body);
    
        if (error == 0)
        {
          printf("done\n");	
        }
        else
        {
          printf("error. Code: %d\n", error);
        }    
      }
      else
      {
        // Problem with the communication with the 4G module
        printf("1. 4G module not started. Error code: %d\n", error);
      }
    
    
      ////////////////////////////////////////////////
      // 3. Powers off the 4G module
      ////////////////////////////////////////////////
      printf("3. Switch OFF 4G module\n");
      _4G.OFF();
    
    
      ////////////////////////////////////////////////
      // 4. Sleep
      ////////////////////////////////////////////////
      printf("4. Enter deep sleep...\n");
    
      delay(10000);
      
      printf("5. Wake up!!\n\n");
    
    }
    
    //////////////////////////////////////////////
    // Main loop setup() and loop() declarations
    //////////////////////////////////////////////
    int main()
    {
        setup();
        while(1) loop();
        return (0);
    }
    //////////////////////////////////////////////
    
    
            

    Receiving SMS

    This example shows how to set up the module to use SMS and receive text messages

    Arduino:

    Code:
    /*  
        ----------------------- 4G_03 - Receiving SMS  -------------------- 
        
        Explanation: This example shows how to set up the module to use
        SMS and receive text messages
    
        Important: in Arduino UNO the same UART is used for Debug User Interface 
        and LE910 AT commands. Handle with care, user interface messages could 
        interfere with AT commands.
    
        Example: 
              Serial.print("operATo"); 
        It is seen as wrong AT command by the LE910 module.
    
        Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
        http://www.libelium.com
    
        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
        Version:           1.0
        Design:            David Gascón
        Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
                           & Ruben Martin
     */
    
    #include "arduino4G.h"
    
    
    // define variables
    uint8_t error;
    char sms_received[50];
    
    
    void setup()
    {    
      
      Serial.println(F("Start program"));
      
      //////////////////////////////////////////////////
      // 1. Switch on the 4G module
      //////////////////////////////////////////////////
      error = _4G.ON();
    
      if (error == 0)
      {
        Serial.println(F("1. 4G module ready..."));
    
    
        ////////////////////////////////////////////////
        // 2. Set PIN code
        ////////////////////////////////////////////////  
        error = _4G.enterPIN("");
    
        if (error == 1) 
        {
          Serial.println(F("2. PIN code accepted"));
        }
        else
        {
          Serial.println(F("2. PIN code incorrect"));
        }
    
    
        ////////////////////////////////////////////////
        // 2.2. Configure SMS options
        ////////////////////////////////////////////////
        error = _4G.configureSMS();
    
        if (error == 0)
        {
          Serial.println(F("3. 4G module configured to use SMS"));
        }
        else
        {
          Serial.print(F("3. Error calling 'configureSMS' function. Code: "));
          Serial.println(error, DEC);
        } 
    
    
        ////////////////////////////////////////////////
        // 2.3. Configure SMS options
        ////////////////////////////////////////////////
        error = _4G.checkConnection(60);
    
        if (error == 0)
        {
          Serial.println(F("4. Module connected to network"));   		
        }
        else
        {
          Serial.print(F("4. Module not connected. Connection:"));
          Serial.println(error, DEC);
        }
      }
      else
      {
        // Problem with the communication with the 4G module
        Serial.println(F("4G module not started"));
        Serial.print(F("Error code: "));
        Serial.println(error, DEC);
        Serial.println(F("The code stops here."));
        while(1);
      }
      
      Serial.println();
      Serial.println();
    
    }
    
    void loop()
    {
      ////////////////////////////////////////////////
      // Check connection to network
      ////////////////////////////////////////////////
      error = _4G.checkConnection(60);
    
      if (error == 0)
      {
        Serial.println(F("Wait for incoming SMS..."));
    
        //////////////////////////////////////////////
        // Manage incoming data
        //////////////////////////////////////////////
        error = _4G.manageIncomingData(60000);
    
        if ((error == 0) && (_4G._incomingType == LE910_INCOMING_SMS))
        {     
          Serial.print(F("SMS index: "));
          Serial.println(_4G._smsIndex, DEC);
    
          // clear buffer
          memset(sms_received, '\0', sizeof(sms_received));
          
          // Read incoming SMS
          error = _4G.readSMS(_4G._smsIndex, sms_received);
    
          if (error == 0)
          {
            Serial.print(F("SMS body: "));
            Serial.println(sms_received);
          }
          else
          {
            Serial.print(F("Error reading the sms. Code: "));
            Serial.println(error, DEC);
          }
        }
      }
      else
      {
        Serial.print(F("Waiting connection. Connection:"));
        Serial.println(error, DEC);
      }
    }
            

    Raspberry Pi:

    Code:
    /*  
     *  --------------- 4G_03 - Receiving SMS  --------------- 
     *  
     *  Explanation: This example shows how to set up the module to use
     *  SMS and receive text messages
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L.
     *  http://www.libelium.com
     *
     *  This program is free software: you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation, either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program.  If not, see http://www.gnu.org/licenses/.
     *
     *  Version:           1.0
     *  Design:            David Gascón
     *  Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
     *                     & Ruben Martin
     */
    
    #include "arduPi4G.h"
    
    // define variables
    uint8_t error;
    char sms_received[150];
    
    
    void setup()
    {    
      
      printf("Start program\n");
      
      //////////////////////////////////////////////////
      // 1. Switch on the 4G module
      //////////////////////////////////////////////////
      error = _4G.ON();
    
      if (error == 0)
      {
        printf("1. 4G module ready...\n");
    
    
        ////////////////////////////////////////////////
        // 2. Set PIN code
        ////////////////////////////////////////////////  
        error = _4G.enterPIN((char *)"");
    
        if (error == 1) 
        {
          printf("2. PIN code accepted\n");
        }
        else
        {
          printf("2. PIN code incorrect\n");
        }
    
    
        ////////////////////////////////////////////////
        // 2.2. Configure SMS options
        ////////////////////////////////////////////////
        error = _4G.checkConnection(60);
    
        if (error == 0)
        {
          printf("2. Module connected to network\n");
        }
        else
        {
          printf("2. Module not connected. Connection status: %d\n", error);
        }
    
        ////////////////////////////////////////////////
        // 2.3. Configure SMS options
        ////////////////////////////////////////////////
        error = _4G.configureSMS();
    
        if (error == 0)
        {
          printf("4. 4G module configured to use SMS\n");
        }
        else
        {
          printf("4. Error calling 'configureSMS' function. Code: %d\n", error);
        } 
    
      }
      else
      {
        // Problem with the communication with the 4G module
        printf("4G module not started\n");
        printf("Error code: %d\n", error);
        printf("The code stops here.\n");
        while(1);
      }
     
    }
    
    void loop()
    {
      ////////////////////////////////////////////////
      // Check connection to network
      ////////////////////////////////////////////////
      error = _4G.checkConnection(60);
    
      if (error == 0)
      {
        printf("Wait for incoming SMS...\n");
    
        //////////////////////////////////////////////
        // Manage incoming data
        //////////////////////////////////////////////
        error = _4G.manageIncomingData(60000);
    
        if ((error == 0) && (_4G._incomingType == LE910_INCOMING_SMS))
        {     
          printf("SMS index: %d\n", error);
    
          // clear buffer
          memset(sms_received, '\0', sizeof(sms_received));
          
          // Read incoming SMS
          error = _4G.readSMS(_4G._smsIndex, sms_received);
    
          if (error == 0)
          {
            printf("SMS body: \n%s\n",sms_received);
          }
          else
          {
            printf("Error reading the sms. Code: %d\n", error);
          }
        }
      }
      else
      {
        printf("Waiting connection. Connection status: %d\n", error);
      }
    
    }
    
    //////////////////////////////////////////////
    // Main loop setup() and loop() declarations
    //////////////////////////////////////////////
    int main()
    {
        setup();
        while(1) loop();
        return (0);
    }
    //////////////////////////////////////////////
    
            

    9. FTP

    This example shows how to upload a file from a FTP server to SD card

    Arduino:

    Code:
    /*
        --- 4G_09 - Uploading files to a FTP server  ---
    
        Explanation: This example shows how to upload a file to a FTP server
        from Arduino.
    
        Important: in Arduino the same UART is used for Debug User Interface 
        and LE910 AT commands. Handle with care, user interface messages could 
        interfere with AT commands.
    
        Example: 
              Serial.print("operATo"); 
        It is seen as wrong AT command by the LE910 module.
    
        Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
        http://www.libelium.com
    
        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
        Version:           1.0
        Design:            David Gascón
        Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
                           & Ruben Martin
    */
    
    #include <arduino4G.h>
    #include <PI.h>
    #include <SD.h>
    
    // APN settings
    ///////////////////////////////////////
    char apn[] = "";
    char login[] = "";
    char password[] = "";
    ///////////////////////////////////////
    
    // SERVER settings
    ///////////////////////////////////////
    char ftp_server[] = "";
    uint16_t ftp_port = 21;
    char ftp_user[] = "";
    char ftp_pass[] = "";
    ///////////////////////////////////////
    
    ///////////////////////////////////////////////////////////////////////
    // Define filenames for SD card and FTP server: (FAT16 NAMES:"AAAAAAAA.EEE")
    ///////////////////////////////////////////////////////////////////////
    char SD_FILE[]     = "SENT.TXT";
    char SERVER_FILE[] = "COOKING.TXT";
    ///////////////////////////////////////////////////////////////////////
    
    // SD settings
    ///////////////////////////////////////
    # define SD_CS (4)
    ///////////////////////////////////////
    
    // define variables
    int error;
    uint32_t previous;
    uint8_t sd_answer;
    File myFile;
    
    void setup()
    {
      error = _4G.ON();
      
      Serial.println(F("Start program"));
    
      //////////////////////////////////////////////////
      // 1. sets operator parameters
      //////////////////////////////////////////////////
      _4G.set_APN(apn, login, password);
    
      //////////////////////////////////////////////////
      // 2. Show APN settings via USB port
      //////////////////////////////////////////////////
      _4G.show_APN();
    
      //////////////////////////////////////////////////
      // 1. Create a new file to upload
      //////////////////////////////////////////////////
    
      ///////////////////////////////////
      // 1.1. Init SD card
      ///////////////////////////////////
      Serial.println("Initializing SD card...");
    
      sd_answer = SD.begin(SD_CS);
      if (sd_answer != 0) 
      {
        Serial.println("1. SD init OK");
      }
      else
      {
        Serial.println("1. SD init ERROR");
      }
      
      ///////////////////////////////////
      // 1.2. Delete file if exists
      ///////////////////////////////////
    
      sd_answer = SD.exists(SD_FILE);
      if (sd_answer == 1)
      {
        SD.remove(SD_FILE);
        Serial.println(F("2. File deleted"));
      }
      else
      {
        Serial.println(F("2. File NOT deleted"));
      }
    
      ///////////////////////////////////
      // 1.3. Create file
      ///////////////////////////////////
      myFile = SD.open(SD_FILE, FILE_WRITE);
    
      sd_answer = SD.exists(SD_FILE);
      if (sd_answer == 1)
      {
        Serial.println(F("3. New file"));
      }
      else
      {
        Serial.println(F("3. NO new file"));
      }
    
      ///////////////////////////////////
      // 1.4. Append contents
      ///////////////////////////////////
      Serial.println(F("4. Appending text..."));
      for (int i = 0; i < 10; i++)
      {
        if (SD_FILE)
        {
          myFile.println("This is a new message from Cooking-Hacks");
        }
      }
    
      ///////////////////////////////////
      //1.5. Close SD
      ///////////////////////////////////
      myFile.close();
      Serial.println(F("5. SD off"));
      Serial.println(F("Setup done\n\n"));
    
    }
    
    
    void loop()
    {
      //////////////////////////////////////////////////
      // 1. Switch ON
      //////////////////////////////////////////////////
      error = _4G.ON();
    
      if (error == 0)
      {
        Serial.println(F("1. 4G module ready..."));
    
        ////////////////////////////////////////////////
        // 2.1. FTP open session
        ////////////////////////////////////////////////
    
        error = _4G.ftpOpenSession(ftp_server, ftp_port, ftp_user, ftp_pass);
    
        // check answer
        if (error == 0)
        {
          Serial.println(F("2.1. FTP open session OK"));
    
          previous = millis();
    
          //////////////////////////////////////////////
          // 2.2. FTP upload
          //////////////////////////////////////////////
          
          error = _4G.ftpUpload(SERVER_FILE, SD_FILE);
    
          if (error == 0)
          {
    
            Serial.print(F("2.2. Uploading SD file to FTP server done! "));
            Serial.print(F("Upload time: "));
            Serial.print((millis() - previous) / 1000, DEC);
            Serial.println(F(" s"));
          }
          else
          {
            Serial.print(F("2.2. Error calling 'ftpUpload' function. Error: "));
            Serial.println(error, DEC);
          }
          
    
          //////////////////////////////////////////////
          // 2.3. FTP close session
          //////////////////////////////////////////////
    
          error = _4G.ftpCloseSession();
    
          if (error == 0)
          {
            Serial.println(F("2.3. FTP close session OK"));
          }
          else
          {
            Serial.print(F("2.3. Error calling 'ftpCloseSession' function. error: "));
            Serial.println(error, DEC);
            Serial.print(F("CMEE error: "));
            Serial.println(_4G._errorCode, DEC);        
          }
        }
        else
        {
          Serial.print(F( "2.1. FTP connection error: "));
          Serial.println(error, DEC);
        }
      }
      else
      {
        // Problem with the communication with the 4G module
        Serial.println(F("1. 4G module not started"));
      }
    
      ////////////////////////////////////////////////
      // 3. Powers off the 4G module
      ////////////////////////////////////////////////
      Serial.println(F("3. Switch OFF 4G module"));
      _4G.OFF();
    
      ////////////////////////////////////////////////
      // 4. Sleep
      ////////////////////////////////////////////////
        delay(60000);
    }
            

    Raspberry Pi:

    Code:
    /*
     *  --- 4G_09 - Uploading files to a FTP server  ---
     *
     *  Explanation: This example shows how to upload a file to a FTP server
     *  from Waspmote
     *  
     *  This program is free software: you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation, either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program.  If not, see http://www.gnu.org/licenses/.
     *
     *  Version:           1.0
     *  Design:            David Gascón
     *  Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
     *                     & Ruben Martin
     */
    #include "arduPi4G.h"
    
    // APN settings
    ///////////////////////////////////////
    char apn[] = "";
    char login[] = "";
    char password[] = "";
    ///////////////////////////////////////
    
    // SERVER settings
    ///////////////////////////////////////
    char ftp_server[] = "";
    uint16_t ftp_port = 21;
    char ftp_user[] = "";
    char ftp_pass[] = "";
    ///////////////////////////////////////
    
    ///////////////////////////////////////////////////////////////////////
    // Define filenames for Raspberry SD card and FTP server:
    //  - If the file is in the root directory: "FILE.TXT" or "/FILE.TXT"
    //  - If the file is inside a folder: "/FOLDER/FILE.TXT"
    ///////////////////////////////////////////////////////////////////////
    char SD_FILE[]     = "./FTP_FILES/SENT.TXT";
    char SERVER_FILE[] = "COOKING.TXT";
    ///////////////////////////////////////////////////////////////////////
    
    // define variables
    int error;
    uint32_t previous;
    uint8_t sd_answer;
    
    void setup()
    {
      printf("Start program\n");
    
      //////////////////////////////////////////////////
      // 1. sets operator parameters
      //////////////////////////////////////////////////
      _4G.set_APN(apn, login, password);
    
    
      //////////////////////////////////////////////////
      // 2. Show APN settings via USB port
      //////////////////////////////////////////////////
      _4G.show_APN();
    }
    
    
    void loop()
    {
      //////////////////////////////////////////////////
      // 1. Switch ON
      //////////////////////////////////////////////////
      error = _4G.ON();
    
      if (error == 0)
      {
        printf("1. 4G module ready...\n");
    
        ////////////////////////////////////////////////
        // 2.1. FTP open session
        ////////////////////////////////////////////////
    
        error = _4G.ftpOpenSession(ftp_server, ftp_port, ftp_user, ftp_pass);
    
        // check answer
        if (error == 0)
        {
          printf("2.1. FTP open session OK\n");
    
          previous = millis();
    
          //////////////////////////////////////////////
          // 2.2. FTP upload
          //////////////////////////////////////////////
          
          error = _4G.ftpUpload(SERVER_FILE, SD_FILE);
    
          if (error == 0)
          {
    
            printf("2.2. Uploading SD file to FTP server done! \n");
            printf("Upload time: %d s\n",(millis() - previous) / 1000);
          }
          else
          {
            printf("2.2. Error calling 'ftpUpload' function. Error: %d\n", error);
          }
          
    
          //////////////////////////////////////////////
          // 2.3. FTP close session
          //////////////////////////////////////////////
    
          error = _4G.ftpCloseSession();
    
          if (error == 0)
          {
            printf("2.3. FTP close session OK\n");
          }
          else
          {
            printf("2.3. Error calling 'ftpCloseSession' function. error: %d\n", error);
            printf("CMEE error: %d\n", _4G._errorCode);
          }
        }
        else
        {
          printf( "2.1. FTP connection error: %d\n", error);
        }
      }
      else
      {
        // Problem with the communication with the 4G module
        printf("1. 4G module not started\n");
      }
    
    
      ////////////////////////////////////////////////
      // 3. Powers off the 4G module
      ////////////////////////////////////////////////
      printf("3. Switch OFF 4G module\n");
      _4G.OFF();
    
      ////////////////////////////////////////////////
      // 4. Sleep
      ////////////////////////////////////////////////
      printf("4. Enter deep sleep...\n");
    
      delay(10000);
    
      printf("5. Wake up!!\n\n");
    
    }
    
    
    //////////////////////////////////////////////
    // Main loop setup() and loop() declarations
    //////////////////////////////////////////////
    int main()
    {
        setup();
        while(1) loop();
        return (0);
    }
    //////////////////////////////////////////////
    
            

    This example shows how to download a file from a FTPserver to SD card

    Arduino:

    Code:
    /*
        --- 4G_10 - Downloading files to a FTP server  ---
    
        Explanation: This example shows how to download a file from a FTP
        server to Arduino SD card
    
        Important: in Arduino UNO the same UART is used for Debug User Interface 
        and LE910 AT commands. Handle with care, user interface messages could 
        interfere with AT commands.
    
        Example: 
              Serial.print("operATo"); 
        It is seen as wrong AT command by the LE910 module.
    
        Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
        http://www.libelium.com
    
        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
        Version:           1.0
        Design:            David Gascón
        Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
                           & Ruben Martin
    */
    
    #include <arduino4G.h>
    #include <SPI.h>
    #include <SD.h>
    
    // APN settings
    ///////////////////////////////////////
    char apn[] = "";
    char login[] = "";
    char password[] = "";
    ///////////////////////////////////////
    
    // SERVER settings
    ///////////////////////////////////////
    char ftp_server[] = "";
    uint16_t ftp_port = 21;
    char ftp_user[] = "";
    char ftp_pass[] = "";
    ///////////////////////////////////////
    
    ///////////////////////////////////////////////////////////////////////
    // Define filenames for SD card and FTP server: (FAT16 NAMES:"AAAAAAAA.EEE")
    ///////////////////////////////////////////////////////////////////////
    char SD_FILE[] = "RECEIVED.TXT";
    char SERVER_FILE[] = "COOKING.TXT";
    ///////////////////////////////////////////////////////////////////////
    
    // SD settings
    ///////////////////////////////////////
    # define SD_CS (4)
    ///////////////////////////////////////
    
    // define variables
    int error;
    uint32_t previous;
    
    
    void setup()
    {
      error = _4G.ON();
    
      Serial.println(F("Start program"));
    
      //////////////////////////////////////////////////
      // 1. sets operator parameters
      //////////////////////////////////////////////////
      _4G.set_APN(apn, login, password);
    
      //////////////////////////////////////////////////
      // 2. Show APN settings via USB port
      //////////////////////////////////////////////////
      _4G.show_APN();
    }
    
    void loop()
    {
      //////////////////////////////////////////////////
      // 1. Switch ON
      //////////////////////////////////////////////////
      error = _4G.ON();
    
      if (error == 0)
      {
        Serial.println(F("1. 4G module ready..."));
    
        ////////////////////////////////////////////////
        // 2.1. FTP open session
        ////////////////////////////////////////////////
    
        error = _4G.ftpOpenSession(ftp_server, ftp_port, ftp_user, ftp_pass);
    
        if (error == 0)
        {
          Serial.println(F("2.1. FTP open session OK"));
    
          previous = millis();
    
          //////////////////////////////////////////////
          // 2.2. FTP download
          //////////////////////////////////////////////
          error = _4G.ftpDownload(SD_FILE, SERVER_FILE);
    
          if (error == 0)
          {
    
            Serial.print(F("2.2. Download SD file from FTP server done! "));
            Serial.print(F("Download time: "));
            Serial.print((millis() - previous) / 1000, DEC);
            Serial.println(F(" s"));
          }
          else
          {
            Serial.print(F("2.2. Error calling 'ftpDownload' function. Error: "));
            Serial.println(error, DEC);
          }
    
          //////////////////////////////////////////////
          // 2.3. FTP close session
          //////////////////////////////////////////////
    
          error = _4G.ftpCloseSession();
    
          if (error == 0)
          {
            Serial.println(F("2.3. FTP close session OK"));
          }
          else
          {
            Serial.print(F("2.3. Error calling 'ftpCloseSession' function. error: "));
            Serial.println(error, DEC);
          }
        }
        else
        {
          Serial.print(F( "FTP connection error: "));
          Serial.println(error, DEC);
        }
      }
      else
      {
        // Problem with the communication with the 4G module
        Serial.println(F("4G module not started"));
      }
    
      ////////////////////////////////////////////////
      // 3. Powers off the 4G module
      ////////////////////////////////////////////////
      Serial.println(F("3. Switch OFF 4G module"));
      _4G.OFF();
    
      ////////////////////////////////////////////////
      // 4. Sleep
      ////////////////////////////////////////////////
      delay(60000);
    }
    
            

    Raspberry Pi:

    Code:
    /*
     *  --- 4G_10 - Downloading files to a FTP server  ---
     *
     *  Explanation: This example shows how to download a file from a FTP
     *  server to Waspmote SD card
     *
     *  Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
     *  http://www.libelium.com
     *
     *  This program is free software: you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation, either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program.  If not, see http://www.gnu.org/licenses/.
     *
     *  Version:           1.0
     *  Design:            David Gascón
     *  Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
     *                     & Ruben Martin
     */
    #include "arduPi4G.h"
    
    // APN settings
    ///////////////////////////////////////
    char apn[] = "";
    char login[] = "";
    char password[] = "";
    ///////////////////////////////////////
    
    // SERVER settings
    ///////////////////////////////////////
    char ftp_server[] = "";
    uint16_t ftp_port = 21;
    char ftp_user[] = "";
    char ftp_pass[] = "";
    ///////////////////////////////////////
    
    ///////////////////////////////////////////////////////////////////////
    // Define filenames for Raspberry SD card and FTP server:
    //  - If the file is in the root directory: "FILE.TXT" or "/FILE.TXT"
    //  - If the file is inside a folder: "/FOLDER/FILE.TXT"
    ///////////////////////////////////////////////////////////////////////
    char SD_FILE[] = "./FTP_FILES/RECEIVED.TXT";
    char SERVER_FILE[] = "COOKING.TXT";
    ///////////////////////////////////////////////////////////////////////
    
    int error;
    uint32_t previous;
    
    
    void setup()
    {
      printf("Start program\n");
    
      //////////////////////////////////////////////////
      // 1. sets operator parameters
      //////////////////////////////////////////////////
      _4G.set_APN(apn, login, password);
    
    
      //////////////////////////////////////////////////
      // 2. Show APN settings via USB port
      //////////////////////////////////////////////////
      _4G.show_APN();
    }
    
    void loop()
    {
    
      //////////////////////////////////////////////////
      // 1. Switch ON
      //////////////////////////////////////////////////
      error = _4G.ON();
    
      if (error == 0)
      {
        printf("1. 4G module ready...\n");
    
    
        ////////////////////////////////////////////////
        // Enter PIN code
        ////////////////////////////////////////////////    
        printf("Enter PIN code...\n");
       
        if (_4G.enterPIN((char *)"") == 1)
        {
          printf("PIN code accepted\n");
        }
        else
        {
          printf("PIN code incorrect\n");
        }
        
        ////////////////////////////////////////////////
        // 2.1. FTP open session
        ////////////////////////////////////////////////
    
        error = _4G.ftpOpenSession(ftp_server, ftp_port, ftp_user, ftp_pass);
    
        if (error == 0)
        {
          printf("2.1. FTP open session OK\n");
    
          previous = millis();
    
    
          //////////////////////////////////////////////
          // 2.2. FTP download
          //////////////////////////////////////////////
          error = _4G.ftpDownload(SD_FILE, SERVER_FILE);
    
          if (error == 0)
          {
    
            printf("2.2. Download SD file from FTP server done! ");
            printf("Download time: %d s\n", (millis() - previous) / 1000);
          }
          else
          {
            printf("2.2. Error calling 'ftpDownload' function. Error: %d\n", error);
          }
    
    
          //////////////////////////////////////////////
          // 2.3. FTP close session
          //////////////////////////////////////////////
    
          error = _4G.ftpCloseSession();
    
          if (error == 0)
          {
            printf("2.3. FTP close session OK\n");
          }
          else
          {
            printf("2.3. Error calling 'ftpCloseSession' function. error: %d\n", error);
          }
        }
        else
        {
          printf( "FTP connection error: %d\n", error);
        }
      }
      else
      {
        // Problem with the communication with the 4G module
        printf("4G module not started\n");
      }
    
      ////////////////////////////////////////////////
      // 3. Powers off the 4G module
      ////////////////////////////////////////////////
      printf("3. Switch OFF 4G module\n");
      _4G.OFF();
    
    
      ////////////////////////////////////////////////
      // 4. Sleep
      ////////////////////////////////////////////////
      printf("4. Enter deep sleep...\n");
    
      delay(10000);
    
      printf("5. Wake up!!\n\n");
    
    }
    
    //////////////////////////////////////////////
    // Main loop setup() and loop() declarations
    //////////////////////////////////////////////
    int main()
    {
        setup();
        while(1) loop();
        return (0);
    }
    //////////////////////////////////////////////
    
            
    NOTE: The SD, FTP and SSL functions of the library work only with Arduino Mega and Raspberry Pi (not with Arduino Uno). This is due to memory restrictions of Arduino Uno as it counts only with 2KB of RAM.

    10. TCP and UDP

    UDP client

    This example shows how to open a UDP client socket to the specified server address and port. Besides, the functions for sending/receiving data are used.

    Arduino:

    Code:
    /*
        --- 4G_12 - UDP client  ---
    
        Explanation: This example shows how to open a UDP client socket
        to the specified server address and port. Besides, the functions
        for sending/receiving data are used.
    
        Important: in Arduino UNO the same UART is used for Debug User Interface 
        and LE910 AT commands. Handle with care, user interface messages could 
        interfere with AT commands.
    
        Example: 
              Serial.print("operATo"); 
        It is seen as wrong AT command by the LE910 module.
    
        Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
        http://www.libelium.com
    
        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
        Version:           1.0
        Design:            David Gascón
        Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
                           & Ruben Martin
    */
    
    #include "arduino4G.h"
    
    // APN settings
    ///////////////////////////////////////
    char apn[] = "";
    char login[] = "";
    char password[] = "";
    ///////////////////////////////////////
    
    // SERVER settings
    ///////////////////////////////////////
    char host[] = "";
    uint16_t remote_port = 0;
    uint16_t local_port  = 0;
    ///////////////////////////////////////
    
    // FRAME
    ///////////////////////////////////////
    char frame[] = "Node01:20h30m41s:dato2";
    ///////////////////////////////////////
    
    // define Socket ID (from 'SOCKET_1' to 'SOCKET_6')
    ///////////////////////////////////////
    uint8_t socketId = arduino4G::SOCKET_1;
    ///////////////////////////////////////
    
    // define variables
    uint8_t  error;
    uint32_t previous;
    uint8_t  socketIndex;
    
    void setup()
    {
      error = _4G.ON();
    
      if (error == 0)
        Serial.println(F("module ON..."));
      else
        Serial.println(F("module OFF"));
    
      Serial.println(F("Start program"));
    
      //////////////////////////////////////////////////
      // 1. sets operator parameters
      //////////////////////////////////////////////////
      _4G.set_APN(apn, login, password);
    
    
      //////////////////////////////////////////////////
      // 2. Show APN settings via USB port
      //////////////////////////////////////////////////
      _4G.show_APN();
    }
    
    void loop()
    {
      //////////////////////////////////////////////////
      // 1. Switch ON
      //////////////////////////////////////////////////
      error = _4G.ON();
    
      if (error == 0)
      {
        Serial.println(F("1. 4G module ready..."));
    
        ////////////////////////////////////////////////
        // 2. TCP socket
        ////////////////////////////////////////////////
    
        error = _4G.openSocket(socketId, UDP_CLIENT, host, remote_port, local_port);
    
        if (error == 0)
        {
          Serial.println(F("2.1. Opening a socket... done!"));
    
          Serial.print(F("IP address:"));
          Serial.println(_4G._ip);
    
          //////////////////////////////////////////////
          // 2.2. Send data
          //////////////////////////////////////////////
    
          error = _4G.send(socketId, "This is a UDP frame from Cooking Hacks!\n");
    
          if (error == 0)
          {
            Serial.println(F("2.2. Sending a string... done!"));
          }
          else
          {
            Serial.print(F("2.2. Error sending. Code: "));
            Serial.println(error, DEC);
          }
    
    
          //////////////////////////////////////////////
          // 2.3. Create a frame and send it through the connection
          //////////////////////////////////////////////
    
          error = _4G.send(socketId, (uint8_t *)frame, sizeof(frame));
          if (error == 0)
          {
            Serial.println(F("2.3. Sending a frame... done!"));
          }
          else
          {
            Serial.print(F("2.3. Error sending a frame. Code: "));
            Serial.println(error, DEC);
          }
    
        }
        else
        {
          Serial.print(F("2.1. Error opening socket. Error code: "));
          Serial.println(error, DEC);
        }
    
        //////////////////////////////////////////////
        // 2.5. Close socket
        //////////////////////////////////////////////
        error = _4G.closeSocket(socketId);
    
        if (error == 0)
        {
          Serial.println(F("2.5. Socket closed OK"));
        }
        else
        {
          Serial.print(F("2.5. Error closing socket. Error code: "));
          Serial.println(error, DEC);
        }
      }
      else
      {
        // Problem with the communication with the 4G module
        Serial.println(F("1. 4G module not started"));
      }
    
      ////////////////////////////////////////////////
      // 3. Powers off the 4G module
      ////////////////////////////////////////////////
      Serial.println(F("3. Switch OFF 4G module"));
      _4G.OFF();
    
      ////////////////////////////////////////////////
      // 4. Sleep
      ////////////////////////////////////////////////
      
      delay(60000);
    }
            

    Raspberry Pi:

    Code:
    /*
     *  ------------------------ 4G_12 - UDP client  --------------------------
     *
     *  Explanation: This example shows how to open a UDP client socket
     *  to the specified server address and port. Besides, the functions
     *  for sending/receiving data are used.
     *
     *
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L.
     *  http://www.libelium.com
     *
     *  This program is free software: you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation, either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program.  If not, see http://www.gnu.org/licenses/.
     *
     *  Version:           1.0
     *  Design:            David Gascón
     *  Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
     *                     & Ruben Martin
     */
    
    #include "arduPi4G.h"
    
    // APN settings
    ///////////////////////////////////////
    char apn[] = "";
    char login[] = "";
    char password[] = "";
    ///////////////////////////////////////
    
    // SERVER settings
    ///////////////////////////////////////
    char host[] = "";
    uint16_t remote_port = 15011;
    uint16_t local_port  = 4000;
    ///////////////////////////////////////
    
    // FRAME
    ///////////////////////////////////////
    char frame[] = "Node02-2016/10/6-Value:30";
    ///////////////////////////////////////
    
    // define Socket ID (from 'SOCKET_1' to 'SOCKET_6')
    ///////////////////////////////////////
    uint8_t socketId = arduPi4G::SOCKET_1;
    ///////////////////////////////////////
    
    
    // define variables
    uint8_t  error;
    uint32_t previous;
    uint8_t  socketIndex;
    
    
    void setup()
    {
      printf("Start program\n");
    
      //////////////////////////////////////////////////
      // 1. sets operator parameters
      //////////////////////////////////////////////////
      _4G.set_APN(apn, login, password);
    
    
      //////////////////////////////////////////////////
      // 2. Show APN settings via USB port
      //////////////////////////////////////////////////
      _4G.show_APN();
    
    }
    
    void loop()
    {
      //////////////////////////////////////////////////
      // 1. Switch ON
      //////////////////////////////////////////////////
      error = _4G.ON();
    
      if (error == 0)
      {
        printf("1. 4G module ready...\n");
    
    
        ////////////////////////////////////////////////
        // 2. TCP socket
        ////////////////////////////////////////////////
    
        error = _4G.openSocket(socketId, UDP_CLIENT, host, remote_port, local_port);
    
        if (error == 0)
        {
          printf("2.1. Opening a socket... done!\n");
    
          printf("IP address: %s\n", _4G._ip);
    
          //////////////////////////////////////////////
          // 2.2. Send data
          //////////////////////////////////////////////
    
          error = _4G.send(socketId, (char*)"This is a test message from Cooking Hacks!\n\n");
    
          if (error == 0)
          {
            printf("2.2. Sending a string... done!\n");
          }
          else
          {
            printf("2.2. Error sending data. Code: %d\n", error);
          }
    
    
          //////////////////////////////////////////////
          // 2.3. Create a frame and send it through the connection
          //////////////////////////////////////////////
    
          error = _4G.send(socketId, (uint8_t*)frame, sizeof(frame));
          if (error == 0)
          {
            printf("2.3. Sending a frame... done!\n");
          }
          else
          {
            printf("2.3. Error sending a frame. Code: %d\n", error);
          }
    
        }
        else
        {
          printf("2.1. Error opening socket. Error code: %d\n", error);
        }
    
        //////////////////////////////////////////////
        // 2.5. Close socket
        //////////////////////////////////////////////
        error = _4G.closeSocket(socketId);
    
        if (error == 0)
        {
          printf("2.5. Socket closed OK\n");
        }
        else
        {
          printf("2.5. Error closing socket. Error code: %d\n", error);
        }
      }
      else
      {
        // Problem with the communication with the 4G module
        printf("1. 4G module not started\n");
      }
    
      ////////////////////////////////////////////////
      // 3. Powers off the 4G module
      ////////////////////////////////////////////////
      printf("3. Switch OFF 4G module\n");
      _4G.OFF();
    
    
      ////////////////////////////////////////////////
      // 4. Sleep
      ////////////////////////////////////////////////
      printf("4. Enter deep sleep...\n");
    
      delay(10000);  
    
      printf("5. Wake up!!\n\n");
    
    }
    
    //////////////////////////////////////////////
    // Main loop setup() and loop() declarations
    //////////////////////////////////////////////
    int main()
    {
        setup();
        while(1) loop();
        return (0);
    }
    //////////////////////////////////////////////
    
            

    TCP client

    This example shows how to open a TCP client socket to the specified server address and port. Besides, the functions for sending/receiving data are used.

    Arduino:

    Code:
    /*
        ------------------------ 4G_11 - TCP client  --------------------------
    
        Copyright (C) Libelium Comunicaciones Distribuidas S.L.
        http://www.libelium.com
    
        Important: in Arduino UNO the same UART is used for Debug User Interface 
        and LE910 AT commands. Handle with care, user interface messages could 
        interfere with AT commands.
    
        Example: 
              Serial.print("operATo"); 
        It is seen as wrong AT command by the LE910 module.
    
        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
        Version:           1.0
        Design:            David Gascón
        Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
                           & Ruben Martin
    */
    
    #include "arduino4G.h"
    
    // APN settings
    ///////////////////////////////////////
    char apn[] = "";
    char login[] = "";
    char password[] = "";
    ///////////////////////////////////////
    
    // SERVER settings
    ///////////////////////////////////////
    char host[] = "";
    uint16_t remote_port = 0;
    uint16_t local_port  = 0;
    ///////////////////////////////////////
    
    // FRAME
    ///////////////////////////////////////
    char frame[] = "Node01-2016/10/6-Value_1\n";
    ///////////////////////////////////////
    
    // define Socket ID (from 'SOCKET_1' to 'SOCKET_6')
    ///////////////////////////////////////
    uint8_t socketId = arduino4G::SOCKET_1;
    ///////////////////////////////////////
    
    // define variables
    uint8_t  error;
    uint32_t previous;
    uint8_t  socketIndex;
    
    void setup()
    {
      error = _4G.ON();
      if (error == 0)
        Serial.println(F("module ON..."));
      else
        Serial.println(F("module OFF"));
    
      Serial.println(F("Start program"));
    
      //////////////////////////////////////////////////
      // 1. sets operator parameters
      //////////////////////////////////////////////////
      _4G.set_APN(apn, login, password);
    
    
      //////////////////////////////////////////////////
      // 2. Show APN settings via USB port
      //////////////////////////////////////////////////
      _4G.show_APN();
    }
    
    void loop()
    {
      //////////////////////////////////////////////////
      // 1. Switch ON
      //////////////////////////////////////////////////
      error = _4G.ON();
    
      if (error == 0)
      {
        Serial.println(F("1. 4G module ready..."));
    
        ////////////////////////////////////////////////
        // 2. TCP socket
        ////////////////////////////////////////////////
    
        error = _4G.openSocket(socketId, TCP_CLIENT, host, remote_port, local_port);
    
        if (error == 0)
        {
          Serial.println(F("2.1. Opening a socket... done!"));
    
          Serial.print(F("IP address:"));
          Serial.println(_4G._ip);
    
    
          //////////////////////////////////////////////
          // 2.2. Send data
          //////////////////////////////////////////////
    
          error = _4G.send(socketId, "This is a test frame from Cooking Hacks!\n");
    
          if (error == 0)
          {
            Serial.println(F("2.2. Sending a string... done!"));
          }
          else
          {
            Serial.print(F("2.2. Error sending. Code: "));
            Serial.println(error, DEC);
          }
    
    
          //////////////////////////////////////////////
          // 2.3. Send a frame and send it through the connection
          //////////////////////////////////////////////
    
          error = _4G.send(socketId, (uint8_t *)frame, sizeof(frame));
          if (error == 0)
          {
            Serial.println(F("2.3. Sending a frame... done!"));
          }
          else
          {
            Serial.print(F("2.3. Error sending a frame. Code: "));
            Serial.println(error, DEC);
          }
    
    
          //////////////////////////////////////////////
          // 2.4. Receive data
          //////////////////////////////////////////////
    
          // Wait for incoming data from the socket (if the other side responds)
          Serial.print(F("2.4. Waiting to receive..."));
    
          error = _4G.receive(socketId, 60000);
    
          if (error == 0)
          {
            if (_4G.socketInfo[socketId].size > 0)
            {
              Serial.println(F("\n-----------------------------------"));
              Serial.print(F("Received:"));
              Serial.println((const char *)_4G._buffer);
              Serial.println(F("-----------------------------------"));
            }
            else
            {
              Serial.println(F("Nothing received"));
            }
          }
          else
          {
            Serial.println(F("Nothing received."));
            Serial.println(error, DEC);
          }
        }
        else
        {
          Serial.print(F("2.1. Error opening socket. Error code: "));
          Serial.println(error, DEC);
        }
    
        //////////////////////////////////////////////
        // 2.5. Close socket
        //////////////////////////////////////////////
        error = _4G.closeSocket(socketId);
    
        if (error == 0)
        {
          Serial.println(F("2.5. Socket closed OK"));
        }
        else
        {
          Serial.print(F("2.5. Error closing socket. Error code: "));
          Serial.println(error, DEC);
        }
      }
      else
      {
        // Problem with the communication with the 4G module
        Serial.println(F("1. 4G module not started"));
      }
    
      ////////////////////////////////////////////////
      // 3. Powers off the 4G module
      ////////////////////////////////////////////////
      Serial.println(F("3. Switch OFF 4G module"));
      _4G.OFF();
    
      ////////////////////////////////////////////////
      // 4. Sleep
      ////////////////////////////////////////////////
    
      delay(60000);
    
    }
            

    Raspberry Pi:

    Code:
    /*
     *  ------------------------ 4G_11 - TCP client  --------------------------
     *
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L.
     *  http://www.libelium.com
     *
     *  This program is free software: you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation, either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program.  If not, see http://www.gnu.org/licenses/.
     *
     *  Version:           1.0
     *  Design:            David Gascón
     *  Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
     *                     & Ruben Martin
     */
    
    #include "arduPi4G.h"
    
    // APN settings
    ///////////////////////////////////////
    char apn[] = "";
    char login[] = "";
    char password[] = "";
    ///////////////////////////////////////
    
    char frame[] = "Node01-2016/10/6-Value_1";
    
    // SERVER settings
    ///////////////////////////////////////
    char host[] = "";
    uint16_t remote_port = 15010;
    uint16_t local_port  = 4000; 
    ///////////////////////////////////////
    
    // define Socket ID (from 'SOCKET_1' to 'SOCKET_6')
    ///////////////////////////////////////
    uint8_t socketId = arduPi4G::SOCKET_1;
    ///////////////////////////////////////
    
    // define variables
    uint8_t  error;
    uint32_t previous;
    uint8_t  socketIndex;
    
    void setup()
    {
      printf("Start program\n");
    
      //////////////////////////////////////////////////
      // 1. sets operator parameters
      //////////////////////////////////////////////////
      _4G.set_APN(apn, login, password);
    
    
      //////////////////////////////////////////////////
      // 2. Show APN settings via USB port
      //////////////////////////////////////////////////
      _4G.show_APN();
    
    }
    
    void loop()
    {
      //////////////////////////////////////////////////
      // 1. Switch ON
      //////////////////////////////////////////////////
      error = _4G.ON();
    
      if (error == 0)
      {
        printf("1. 4G module ready...\n");
    
        ////////////////////////////////////////////////
        // 2. TCP socket
        ////////////////////////////////////////////////
    
        error = _4G.openSocket(socketId, TCP_CLIENT, host, remote_port, local_port);
    
        if (error == 0)
        {
          printf("2.1. Opening a socket... done!\n");
    
          printf("IP address:%s\n", _4G._ip);
    
          //////////////////////////////////////////////
          // 2.2. Send data
          //////////////////////////////////////////////
    
          error = _4G.send(socketId, (char*)"This is a test message from Cooking Hacks!\n\n");
    
          if (error == 0)
          {
            printf("2.2. Sending a string... done!\n");
          }
          else
          {
            printf("2.2. Error sending data. Code: %d\n", error);
          }
    
    
          //////////////////////////////////////////////
          // 2.3. Create a frame and send it through the connection
          //////////////////////////////////////////////
    
          error = _4G.send(socketId, (uint8_t*)frame, sizeof(frame));
          if (error == 0)
          {
            printf("2.3. Sending a frame... done!\n");
          }
          else
          {
            printf("2.3. Error sending a frame. Code: %d\n", error);
          }
    
    
          //////////////////////////////////////////////
          // 2.4. Receive data
          //////////////////////////////////////////////
    
          // Wait for incoming data from the socket (if the other side responds)
          printf("2.4. Waiting to receive data...\n");
    
          error = _4G.receive(socketId, 60000);
    
          if (error == 0)
          {
            if (_4G.socketInfo[socketId].size > 0)
            {
              printf("\n-----------------------------------\n");
              printf("Data received:\n %s\n", _4G._buffer);
              printf("-----------------------------------\n");
            }
            else
            {
              printf("NO data received\n");
            }
          }
          else
          {
            printf("No data received. Error code: %d\n", error);
          }
        }
        else
        {
          printf("2.1. Error opening socket. Error code: %d\n", error);
        }
    
        //////////////////////////////////////////////
        // 2.5. Close socket
        //////////////////////////////////////////////
        error = _4G.closeSocket(socketId);
    
        if (error == 0)
        {
          printf("2.5. Socket closed OK\n");
        }
        else
        {
          printf("2.5. Error closing socket. Error code: %d\n", error);
        }
      }
      else
      {
        // Problem with the communication with the 4G module
        printf("1. 4G module not started\n");
      }
    
      ////////////////////////////////////////////////
      // 3. Powers off the 4G module
      ////////////////////////////////////////////////
      printf("3. Switch OFF 4G module\n");
      _4G.OFF();
    
    
      ////////////////////////////////////////////////
      // 4. Sleep
      ////////////////////////////////////////////////
      printf("4. Enter deep sleep...\n");
    
      delay(10000);
    
      printf("5. Wake up!!\n\n");
    
    }
    
    //////////////////////////////////////////////
    // Main loop setup() and loop() declarations
    //////////////////////////////////////////////
    int main()
    {
        setup();
        while(1) loop();
        return (0);
    }
    //////////////////////////////////////////////
    
            

    11. HTTP

    HTTP GET

    This example shows how to send HTTP GET requests.

    Arduino:

    Code:
    /*  
        -------------------------- 4G_06 - HTTP GET  ------------------------- 
        
        Explanation: This example shows how to send HTTP GET requests
    
        Important: in Arduino UNO the same UART is used for Debug User Interface 
        and LE910 AT commands. Handle with care, user interface messages could 
        interfere with AT commands.
    
        Example: 
              Serial.print("operATo"); 
        It is seen as wrong AT command by the LE910 module.
    
        Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
        http://www.libelium.com
    
        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>. 
    
        Version:           1.0
        Design:            David Gascón
        Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
                           & Ruben Martin
     */
    
    #include "arduino4G.h"
    
    // include the SD library:
    #include <SPI.h>. 
    #include <SD.h>. 
    
    // set up variables using the SD utility library functions:
    Sd2Card card;
    SdVolume volume;
    SdFile root;
    
    // APN settings
    ///////////////////////////////////////
    char apn[] = "";
    char login[] = "";
    char password[] = "";
    ///////////////////////////////////////
    
    // SERVER settings
    ///////////////////////////////////////
    char host[] = "";
    uint16_t port = 80;
    char resource[] = "";
    ///////////////////////////////////////
    
    // variables
    uint8_t error;
    uint8_t counter;
    
    void setup()
    {
      card.init(SPI_HALF_SPEED, 4);
      error = _4G.ON();
      if (error == 0)
        Serial.println(F("module ON..."));
      else
        Serial.println(F("module OFF"));
      
      Serial.println(F("Start program"));
      
      //////////////////////////////////////////////////
      // 1. sets operator parameters
      //////////////////////////////////////////////////
      _4G.set_APN(apn, login, password);
    
    
      //////////////////////////////////////////////////
      // 2. Show APN settings via USB port
      //////////////////////////////////////////////////
      _4G.show_APN();
    }
    
    
    void loop()
    {
      //////////////////////////////////////////////////
      // 1. Switch ON
      //////////////////////////////////////////////////  
      error = _4G.ON();
    
      if (error == 0)
      {
        Serial.println(F("1. 4G module ready..."));
    
        ////////////////////////////////////////////////
        // 2. Waiting for Connection
        ////////////////////////////////////////////////
    
        // Waiting for network registration
        counter = 7;
        error = _4G.checkConnection(60);
        while ((counter > 0) && (error != 0))
        {
            delay(5000);
            error = _4G.checkConnection(60);
            counter--;      
        }
    
        if (error == 0)
        {
          Serial.println(F("2.1. Connected to network"));
        }
        else
        {
          Serial.print(F("2.1. Error connecting to network. Code: "));
          Serial.println(error, DEC);
        } 
    
        ////////////////////////////////////////////////
        // 2. HTTP GET
        ////////////////////////////////////////////////
        Serial.println(F("2. Getting URL with GET method..."));
    
        // send the request
        counter = 3;
        error = _4G.http( GET_METHOD, host, port, resource);
        while ((counter > 0) && (error != 0))
        {
            delay(5000);
            error = _4G.http( GET_METHOD, host, port, resource);
            counter--;      
        }
    
    
        // Check the answer
        if (error == 0)
        {
          Serial.print(F("Done. HTTP code: "));
          Serial.println(_4G._httpCode);
          Serial.print("Server response: ");
          Serial.println((char *)_4G._buffer);
        }
        else
        {
          Serial.print(F("Failed. Error code: "));
          Serial.println(error, DEC);
        }    
      }
      else
      {
        // Problem with the communication with the 4G module
        Serial.println(F("4G module not started"));
        Serial.print(F("Error code: "));
        Serial.println(error, DEC);
      }
    
      ////////////////////////////////////////////////
      // 3. Powers off the 4G module
      ////////////////////////////////////////////////
      Serial.println(F("3. Switch OFF 4G module"));
      _4G.OFF();
    
      ////////////////////////////////////////////////
      // 4. Sleep
      ////////////////////////////////////////////////
      delay(10000);
    }
    
            

    Raspberry Pi:

    Code:
    /*  
     *  --------------- 4G_06 - HTTP GET  --------------- 
     *  
     *  Copyright (C) Libelium Comunicaciones Distribuidas S.L.
     *  http://www.libelium.com
     *
     *  This program is free software: you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation, either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program.  If not, see http://www.gnu.org/licenses/.
     *
     *  Version:           1.0
     *  Design:            David Gascón
     *  Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
     *                     & Ruben Martin
     */
    
    #include "arduPi4G.h"
    
    // APN settings
    ///////////////////////////////////////
    char apn[] = "";
    char login[] = "";
    char password[] = "";
    ///////////////////////////////////////
    
    // SERVER settings
    ///////////////////////////////////////
    char host[] = "";
    uint16_t port = 80;
    char resource[] = "/test-get-post.php?varA=1&varB=2&varC=3&varD=4&varE=5&varF=6"\
             "&varG=7&varH=8&varI=9&varJ=10&varK=11&varL=12&varM=13&varN=14&varO=15";
    ///////////////////////////////////////
    
    // variable
    uint8_t error;
    uint8_t counter;
    
    void setup()
    {
      printf("Start program\n");
    
      printf("********************************************************************\n");
      printf("GET method to the Libelium's test url\n");
      printf("You can use this php to test the HTTP connection of the module.\n");
      printf("The php returns the parameters that the user sends with the URL.\n");
      printf("********************************************************************\n");
    
    
      //////////////////////////////////////////////////
      // 1. sets operator parameters
      //////////////////////////////////////////////////
      _4G.set_APN(apn, login, password);
    
    
      //////////////////////////////////////////////////
      // 2. Show APN settings via USB port
      //////////////////////////////////////////////////
      _4G.show_APN();
    }
    
    
    void loop()
    {
    
      //////////////////////////////////////////////////
      // 1. Switch ON
      //////////////////////////////////////////////////  
      error = _4G.ON();
    
      if (error == 0)
      {
        printf("1. 4G module ready...\n");
    
        ////////////////////////////////////////////////
        // 2. Waiting for Connection
        ////////////////////////////////////////////////
    
        // Waiting for network registration
        counter = 3;
        error = _4G.checkConnection(60);
        while ((counter > 0) && (error != 0))
        {
            delay(5000);
            error = _4G.checkConnection(60);
            counter--;      
        }
    
        if (error == 0)
        {
          printf("2.1. Connected to network\n");
        }
        else
        {
          printf("2.1. Error connecting to network. Code: %d\n", error);
        } 
    
        ////////////////////////////////////////////////
        // 3. HTTP GET
        ////////////////////////////////////////////////
    
        printf("3. Getting URL with GET method...");
    
        // send the request
        counter = 3;
        error = _4G.http( GET_METHOD, host, port, resource);
        while ((counter > 0) && (error != 0))
        {
            delay(5000);
            error = _4G.http( GET_METHOD, host, port, resource);
            counter--;      
        }
    
        // Check the answer
        if (error == 0)
        {
          printf("Done.\nHTTP code: %i\n", _4G._httpCode);
          printf("Server response: %s\n", _4G._buffer);
        }
        else
        {
          printf("Failed.\nError code: %d\n", error);
        }    
      }
      else
      {
        // Problem with the communication with the 4G module
        printf("4G module not started\n");
        printf("Error code: %d\n", error);
      }
    
      ////////////////////////////////////////////////
      // 3. Powers off the 4G module
      ////////////////////////////////////////////////
      printf("4. Switch OFF 4G module\n");
      _4G.OFF();
    
    
      ////////////////////////////////////////////////
      // 4. Sleep
      ////////////////////////////////////////////////
      printf("5. Enter deep sleep...\n");
    
      delay(10000);
    
      printf("6. Wake up!!\n\n");
    
    }
    
    //////////////////////////////////////////////
    // Main loop setup() and loop() declarations
    //////////////////////////////////////////////
    int main()
    {
        setup();
        while(1) loop();
        return (0);
    }
    //////////////////////////////////////////////
    
            

    HTTP POST

    This example shows how to send HTTP POST requests.

    Arduino:

    Code:
    /*  
        -------------------- 4G_07 - HTTP POST  ---------------------- 
        
        Explanation: This example shows how to send HTTP GET requests
    
        Important: in Arduino UNO the same UART is used for Debug User Interface 
        and LE910 AT commands. Handle with care, user interface messages could 
        interfere with AT commands.
    
        Example: 
              Serial.print("operATo"); 
        It is seen as wrong AT command by the LE910 module.
    
        Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
        http://www.libelium.com
    
        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>. 
    
        Version:           1.0
        Design:            David Gascón
        Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
                           & Ruben Martin
     */
    
    #include "arduino4G.h"
    
    // APN settings
    ///////////////////////////////////////
    char apn[] = "";
    char login[] = "";
    char password[] = "";
    ///////////////////////////////////////
    
    // SERVER settings
    ///////////////////////////////////////
    char host[] = "";
    unsigned int port = 80;
    char resource[] = "";
    char data[] = "";
    ///////////////////////////////////////
    
    // variables
    int error;
    
    void setup()
    {
      error = _4G.ON();
      if (error == 0)
        Serial.println(F("module ON..."));
      else
        Serial.println(F("module OFF"));
    
      Serial.println(F("Start program"));
    
    
      //////////////////////////////////////////////////
      // 1. sets operator parameters
      //////////////////////////////////////////////////
      _4G.set_APN(apn, login, password);
    
    
      //////////////////////////////////////////////////
      // 2. Show APN settings via USB port
      //////////////////////////////////////////////////
      _4G.show_APN();
    }
    
    
    void loop()
    {
      //////////////////////////////////////////////////
      // 1. Switch ON
      //////////////////////////////////////////////////  
      error = _4G.ON();
    
      Serial.println(F("Start program"));
    
      if (error == 0)
      {
        Serial.println(F("1. 4G module ready..."));
    
    
        ////////////////////////////////////////////////
        // 2. HTTP POST
        ////////////////////////////////////////////////
    
        Serial.println(F("2. HTTP POST request..."));
    
        // send the request
        error = _4G.http( POST_METHOD, host, port, resource, data);
    
        // check the answer
        if (error == 0)
        {
          Serial.print(F("Done. HTTP code: "));
          Serial.println(_4G._httpCode);
          Serial.print("Server response: ");
          Serial.println((const char *)_4G._buffer);
        }
        else
        {
          Serial.print(F("Failed. Error code: "));
          Serial.println(error, DEC);
        }
      }
      else
      {
        // Problem with the communication with the 4G module
        Serial.println(F("4G module not started"));
        Serial.print(F("Error code: "));
        Serial.println(error, DEC);
      }
    
      ////////////////////////////////////////////////
      // 3. Powers off the 4G module
      ////////////////////////////////////////////////
      Serial.println(F("3. Switch OFF 4G module"));
      _4G.OFF();
    
      ////////////////////////////////////////////////
      // 4. Sleep
      ////////////////////////////////////////////////
      delay(1000);
    
    }
            

    Raspberry Pi:

    Code:
    /*  
     *  --------------- 4G_07 - HTTP POST  --------------- 
     *  
     *  Explanation: This example shows how to send HTTP GET requests
     *  
     *  This program is free software: you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation, either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program.  If not, see http://www.gnu.org/licenses/.
     *
     *  Version:           1.0
     *  Design:            David Gascón
     *  Implementation:    Alejandro Gállego, Yuri Carmona, Luis Miguel Marti
     *                     & Ruben Martin
     */
    
    #include "arduPi4G.h"
    
    // APN settings
    ///////////////////////////////////////
    char apn[] = "";
    char login[] = "";
    char password[] = "";
    ///////////////////////////////////////
    
    // SERVER settings
    ///////////////////////////////////////
    char host[] = "";
    unsigned int port = 80;
    char resource[] = "/test-get-post.php";
    char data[] = "/test-get-post.php?varA=1&varB=2&varC=3&varD=4&varE=5&varF=6"\
         "&varG=7&varH=8&varI=9&varJ=10&varK=11&varL=12&varM=13&varN=14&varO=15";
    ///////////////////////////////////////
    
    // variables
    int error;
    uint8_t counter;
    
    void setup()
    {
      printf("Start program\n");
    
      printf("********************************************************************\n");
      printf("POST method to the Libelium's test url\n");
      printf("You can use this php to test the HTTP connection of the module.\n");
      printf("The php returns the parameters that the user sends with the URL.\n");
      printf("********************************************************************\n");
    
    
      //////////////////////////////////////////////////
      // 1. sets operator parameters
      //////////////////////////////////////////////////
      _4G.set_APN(apn, login, password);
    
    
      //////////////////////////////////////////////////
      // 2. Show APN settings via USB port
      //////////////////////////////////////////////////
      _4G.show_APN();
    }
    
    
    void loop()
    {
    
      //////////////////////////////////////////////////
      // 1. Switch ON
      //////////////////////////////////////////////////  
      error = _4G.ON();
    
      if (error == 0)
      {
        printf("1. 4G module ready...\n");
        ////////////////////////////////////////////////
        // 2. HTTP POST
        ////////////////////////////////////////////////
    
        printf("2. HTTP POST request...");
    
        // send the request
        counter = 3;
        error = _4G.http(POST_METHOD, host, port, resource, data);
        while ((counter > 0) && (error != 0))
        {
            delay(5000);
            error = _4G.http(POST_METHOD, host, port, resource, data);
            counter--;      
        }
    
        // check the answer
        if (error == 0)
        {
          printf("Done.\nHTTP code: %i\n", _4G._httpCode);
          printf("Server response: %s\n", _4G._buffer);
        }
        else
        {
          printf("Failed. Error code: %d\n", error);
        }
      }
      else
      {
        // Problem with the communication with the 4G module
        printf("4G module not started\n");
        printf("Error code: %d\n", error);
      }
    
      ////////////////////////////////////////////////
      // 3. Powers off the 4G module
      ////////////////////////////////////////////////
      printf("3. Switch OFF 4G module\n");
      _4G.OFF();
    
      ////////////////////////////////////////////////
      // 4. Sleep
      ////////////////////////////////////////////////
      printf("4. Enter deep sleep...\n");
    
      delay(10000);
    
      printf("4. Wake up!!\n\n");
      
    }
    
    //////////////////////////////////////////////
    // Main loop setup() and loop() declarations
    //////////////////////////////////////////////
    int main()
    {
        setup();
        while(1) loop();
        return (0);
    }
    //////////////////////////////////////////////
    
            

    12. SD

    The 4G shield has a SD socket that it is controlled by the external MCU of the main board where we are connecting it (Arduino, Raspberry Pi, Waspmote) to save data coming or going to the 4G network. With the SD Card socket so you can handle a complete FAT16 file systems and store up to 32GB of information.

  • MicroSD 2GB card
  • NOTE: The SD, FTP and SSL functions of the library work only with Arduino Mega and Raspberry Pi (not with Arduino Uno). This is due to memory restrictions of Arduino Uno as it counts only with 2KB of RAM.

    13. Device Compatibility

    The 4G Shield is tested and fully compatible with the following boards:

    Arduino Boards

    • Arduino Uno
    • Arduino Mega

    Raspberry Pi Boards

    • Raspberry Pi 2
    • Raspberry Pi 3
    NOTE: The SD, FTP and SSL functions of the library work only with Arduino Mega and Raspberry Pi (not with Arduino Uno). This is due to memory restrictions of Arduino Uno as it counts only with 2KB of RAM.

    14. Certifications

    We chose the LE910 family from Telit for our developments due to the fact that it is the most tested and Certified 4G set of modules in the market. The different models ensure that they comply with the specific regulation in each country.

    Click on the desired regulation of each model to download the certification documents:

    Certifications for Final Products:

    Libelium offers two types of sensor platforms: OEM lines (Waspmote , Arduino, Raspberry Pi) and Plug & Sense!.

    • OEM lines like Waspmote , Arduino and Raspberry Pi are intended to be used for research purposes. In this case the 4G modules already have the proper certifications but it is good to have in mind that the final products made with them can not be sold without going to Certification again. 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 certifications as final product. See below the specific list of regulations passed. (4G Version will see the light by the end of summer). http://www.libelium.com/products/plug-sense/

    15. Choosing the right cellular module for Arduino and Raspberry Pi: 4G / 3G / GPRS / GSM

    Model
    Protocols
    Frequency Bands
    Certifications
    Market
    SIM908 GPRS / GSM 850, 900, 1800, 1900MHz CE Europe
    SIM5215-E 3G / GPRS / GSM 850, 900, 1800, 2100MHz CE, GCF Europe
    SIM5215-A 3G / GPRS / GSM 850, 900, 1800, 1900MHz FCC, IC, PTCRB US / Canada
    LE910-EUG 4G / 3G / GPRS / GSM / WCDMA / HSPA+ / LTE 850, 900, 1800, 2100, 2600MHz CE, GCF, ANATEL Europe / Brasil
    LE910-NAG 4G / 3G / GPRS / GSM / WCDMA / HSPA+ / LTE 700, 850, 900, 1700, 1900MHz FCC, IC, PTCRB, AT&T Compliant US / Canada
    LE910-SKG 4G / LTE / HSPA+ 850, 1800MHz KCC South Korea
    LE910-AU V2 4G / LTE / HSPA+ 850, 1500, 2100MHz RCM Australia
    LE910-JN V2 4G / LTE / HSPA+ 850, 1500, 2100MHz NTT DoCoMo Japan
    LE910-JK V2 4G / LTE / HSPA+ 850, 1500, 2100MHz KDDi Japan
    Model
    GPS
    Camera Option
    SD Card
    USB Connnectivity
    SIM908
    Yes
    No
    No
    No
    SIM5215-E
    No
    Yes
    Yes
    Yes
    SIM5215-A
    No
    Yes
    Yes
    Yes
    LE910-EUG
    Yes
    No
    Yes
    Yes
    LE910-NAG
    Yes
    No
    Yes
    Yes
    LE910-SKG
    No
    No
    Yes
    Yes
    LE910-AU V2
    No
    No
    Yes
    Yes
    LE910-JN V2
    No
    No
    Yes
    Yes
    LE910-JK V2
    No
    No
    Yes
    Yes
    Model
    Download Max Speed
    Upload Max Speed
    Antenna Diversity
    Cellular Carriers
    SIM908
    80kbps
    20kbps
    No
    Any
    SIM5215-E
    384Kbps
    384Kbps
    No
    Any
    SIM5215-A
    384Kbps
    384Kbps
    No
    Any
    LE910-EUG
    100Mbps
    50Mbps
    Yes
    Any
    LE910-NAG
    100Mbps
    50Mbps
    Yes
    Any + Specially tested with AT&T
    LE910-SKG
    100Mbps
    50Mbps
    Yes
    Any + Specially tested with SK Telecom
    LE910-AU V2
    100Mbps
    50Mbps
    Yes
    Any + Specially tested with Telstra
    LE910-JN V2
    100Mbps
    50Mbps
    Yes
    Any + Specially tested with NTT DoCoMo
    LE910-JK V2
    100Mbps
    50Mbps
    Yes
    Any + Specially tested with KDDi
    NOTE: The SD, FTP and SSL functions of the library work only with Arduino Mega and Raspberry Pi (not with Arduino Uno). This is due to memory restrictions of Arduino Uno as it counts only with 2KB of RAM.



    If you are interested in Internet of Things (IoT) or M2M projects check our open source sensor platform Waspmote which counts with more than 100 sensors available to use 'off the shelf', a complete API with hundreds of ready to use codes and a low consumption mode of just 0.7µA to ensure years of battery life.

    Know more at:

    Get the Starter Kits at: