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:
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:
Libelium offers two types of sensor platforms: OEM lines (Waspmote , Arduino, Raspberry Pi) and Plug & Sense!.
| 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 |
| SIM908 | ||||
| SIM5215-E | ||||
| SIM5215-A | ||||
| LE910-EUG | ||||
| LE910-NAG | ||||
| LE910-SKG | ||||
| LE910-AU V2 | ||||
| LE910-JN V2 | ||||
| LE910-JK V2 |
| SIM908 | ||||
| SIM5215-E | ||||
| SIM5215-A | ||||
| LE910-EUG | ||||
| LE910-NAG | ||||
| LE910-SKG | ||||
| LE910-AU V2 | ||||
| LE910-JN V2 | ||||
| LE910-JK V2 |
The 4G module is managed by UART. The main features of the modules are listed below:
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.
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.
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.
The following table describes the mean elapsed time for some actions in a single test for several attempts:
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.
Some of the most remarkable parts of the 4G's TOP shield are:
Some of the most remarkable parts of the 4G's BOTTOM shield are:
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.
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.
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"
/*
* 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:
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 ../../..
cd cooking/examples/4G/
./cook.sh my_example.cpp
./my_example.cpp_exe
The script "cook.sh" compiles everything in their folders and the link in the examples foldes with the "_exe" executable.
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.
The API constants used in functions are:
| 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.
The variables used inside functions and codes are:
| _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 |
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:
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:
| 0 | Phone failure |
| 1 | No connection to phone |
| 2 | Phone-adaptor link reserved |
| 3 | Operation not allowed |
| 4 | Operation not supported |
| 5 | PH-SIM PIN required |
| 10 | SIM not inserted |
| 11 | SIM PIN required |
| 12 | SIM PUK required |
| 13 | SIM failure |
| 14 | SIM busy |
| 15 | SIM wrong |
| 16 | Incorrect password |
| 17 | SIM PIN2 required |
| 18 | SIM PUK2 required |
| 20 | Memory full |
| 21 | Invalid index |
| 22 | Not found |
| 23 | Memory failure |
| 24 | Text string too long |
| 25 | Invalid characters in text string |
| 26 | Dial string too long |
| 27 | Invalid characters in dial string |
| 30 | No network service |
| 31 | Network time-out |
| 32 | Network not allowed - emergency calls only |
| 40 | Network personalization PIN required |
| 41 | Network personalization PUK required |
| 42 | Network subset personalization PIN required |
| 43 | Network subset personalization PUK required |
| 44 | Service provider personalization PIN required |
| 45 | Service provider personalization PUK required |
| 46 | Corporate personalization PIN required |
| 47 | Corporate personalization PUK required |
| 100 | Unknown |
| 770 | SIM invalid |
| 103 | Illegal MS (#3)* |
| 106 | Illegal ME (#6)* |
| 107 | GPRS service not allowed (#7)* |
| 111 | PLMN not allowed (#11)* |
| 112 | Location area not allowed (#12)* |
| 113 | Roaming not allowed in this location area (#13)* |
| 132 | Service option not supported (#32)* |
| 133 | Requested service option not subscribed (#33)* |
| 134 | Service option temporarily out of order (#34)* |
| 148 | Unspecified GPRS error |
| 149 | PDP authentication failure |
| 150 | Invalid mobile class |
| 550 | Generic undocumented error |
| 551 | Wrong state |
| 552 | Wrong mode |
| 553 | Context already activated |
| 554 | Stack already active |
| 555 | Activation failed |
| 556 | Context not opened |
| 557 | Cannot setup socket |
| 558 | Cannot resolve DN |
| 559 | Time-out in opening socket |
| 560 | Cannot open socket |
| 561 | Remote disconnected or time-out |
| 562 | Connection failed |
| 563 | Tx error |
| 564 | Already listening |
| 568 | Wrong PDP |
| 615 | FTP not connected |
| 623 | FTP write data closed |
| 643 | FTP communication timeout |
| 657 | Network survey error (No Carrier)* |
| 658 | Network survey error (Busy)* |
| 659 | Network survey error (Wrong request)* |
| 660 | Network survey error (Aborted)* |
| 257 | Network rejected request |
| 258 | Retry operation |
| 259 | Invalid deflected to number |
| 260 | Deflected to own number |
| 261 | Unknown subscriber |
| 262 | Service not available |
| 263 | Unknown class specified |
| 264 | Unknown network message |
| 680 | LU processing |
| 681 | Network search aborted |
| 682 | PTM mode |
| 683 | Active call state |
| 684 | SSL already activated |
| 300 | ME failure |
| 301 | SMS service of ME reserved |
| 302 | Operation not allowed |
| 303 | Operation not supported |
| 304 | Invalid PDU mode parameter |
| 305 | Invalid text mode parameter |
| 310 | SIM not inserted |
| 311 | SIM PIN required |
| 312 | PH-SIM PIN required |
| 313 | SIM failure |
| 314 | SIM busy |
| 315 | SIM wrong |
| 316 | SIM PUK required |
| 317 | SIM PIN2 required |
| 318 | SIM PUK2 required |
| 320 | Memory failure |
| 321 | Invalid memory index |
| 322 | Memory full |
| 330 | SMSC address unknown |
| 331 | No network service |
| 332 | Network time-out |
| 340 | No +CNMA acknowledgement expected |
| 500 | Unknown error |
| 1001 | SSL certs and keys wrong or not stored |
| 1003 | SSL already activated |
| 1008 | SSL not connected |
| 65534 | Timeout error when running a command |
| 65535 | Generic "ERROR" message from module |
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();
}
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();
}
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”);
}
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
}
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:
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:
The checkDataConnetion() function checks the module's network connection status, connect the module to data service and returns whether the module:
{
_4G.checkDataConnection(60);
}
Possible error codes for this function:
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
The configureSMS() function sets the SMS configuration to:
This function must be called before handling SMS in the main code loop.
Example of use:
{
_4G.configureSMS();
}
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:
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
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.
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:
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:
The ftpOpenSession() function configures FTP parameters and opens the connection. Several inputs are needed:
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:
After successfully calling this function, it will be possible to manage the rest of FTP functions for uploading and downloading files.
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:
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:
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”);
}
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
The ftpCloseSession() function allows the user to close an active FTP session.
Example of closing an FTP session:
{
_4G.ftpCloseSession();
}
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.
The SocketInfo_t structure stores the information to be stored for all sockets. For each one of the connections, the information structure includes:
As there are six possible connections at the same time, the global variable is defined as follows:
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
The SocketStatus_t structure stores the status for all sockets. For each one of the connections, the status structure includes:
As it is possible to have up to six simultaneous connections, the global variable is defined as follows:
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
The openSocketClient() function configures and opens a socket. This function expects several input parameters:
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:
The openSocketServer() function configures and opens a listening socket. This function expects several input parameters:
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:
The send() function allows the user to send TCP/UDP packets once the socket is active. The function needs two different inputs parameters:
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:
The receive() function allows the user to receive TCP/UDP packets once the socket is active. The function needs different inputs:
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:
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:
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:
Possible error codes for this function:
The openSocketSSL() function allows the user to open a remote connection via socket secured through SSL. Several inputs are needed for calling this function:
Possible error codes for this function:
The sendSSL() function allows the user to send data through a secure socket. Several inputs are needed for calling this function:
Possible error codes for this function:
The receiveSSL() function allows the user to receive data through a secure socket. Several inputs are needed for calling this function:
Possible error codes for this function:
The closeSocketSSL() function allows the user to close a secure socket. The function needs an input parameter for the socket identifier.
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
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.
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.
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
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.
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:
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:
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.
The emailReset() function resets the actual email parameters in the memory of the module to the default ones. The values reset are:
Example:
{
_4G.emailReset();
}
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:
Example:
{
_4G.emailSetServerSMTP("smtp.mydomain.com");
}
The emailConfigureSMTP() function sets the parameters needed to the SMTP connection. The input parameters for this function are:
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.
The emailSetSender() function sets the sender parameters. The input parameters related are:
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:
The emailSave() function saves the actual e-mail parameters in the memory of the module. The values reset are:
Example:
{
_4G.emailSave();
}
The
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:
Important issues:
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.
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
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:
We recommend to power externally the shield, but it's not necessary in all cases.
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”.
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.
If you want to use the 4G module like a modem with a Windows computer, please follow the next steps:
If you want to use the 4G module like a modem with a Linux computer, please follow the next steps:
sudo apt-get update
sudo apt-get install wvdial ppp usb-modeswitch
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.
lsusb
The output will look similar to the screenshot below. Your modem should be listed as one of the USB devices.
sudo wvdialconf /etc/wvdial.conf
sudo nano /etc/wvdial.conf
The output will look similar to the screenshot below. Set your APN, you username and your password.
sudo wvdial
The output will look similar to the screenshot below.
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)
If you want to use the 4G module like a modem with Raspberry Pi, please follow the next steps:
sudo apt-get update
sudo apt-get install wvdial ppp usb-modeswitch
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.
lsusb
The output will look similar to the screenshot below. Your modem should be listed as one of the USB devices.
sudo wvdialconf /etc/wvdial.conf
sudo nano /etc/wvdial.conf
The output will look similar to the screenshot below. Set your APN, you username and your password.
sudo wvdial
The output will look similar to the screenshot below.
This example shows how to use de GPS in autonomous mode.
Arduino:
/*
--------------- 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:
/*
* --------------- 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);
}
//////////////////////////////////////////////
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:
In this section, the execution of the A-GPS in MS-Based mode is shown. For this purpose, the corresponding example was used:
Arduino:
/*
--------------- 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:
/*
* --------------- 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.
This example shows how to set up the module to use SMS and send text messages
Arduino:
/*
* --------------- 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:
/*
* --------------- 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);
}
//////////////////////////////////////////////
This example shows how to set up the module to use SMS and receive text messages
Arduino:
/*
----------------------- 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:
/*
* --------------- 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);
}
//////////////////////////////////////////////
This example shows how to upload a file from a FTP server to SD card
Arduino:
/*
--- 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:
/*
* --- 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:
/*
--- 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:
/*
* --- 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);
}
//////////////////////////////////////////////
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:
/*
--- 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:
/*
* ------------------------ 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);
}
//////////////////////////////////////////////
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:
/*
------------------------ 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:
/*
* ------------------------ 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);
}
//////////////////////////////////////////////
This example shows how to send HTTP GET requests.
Arduino:
/*
-------------------------- 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:
/*
* --------------- 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);
}
//////////////////////////////////////////////
This example shows how to send HTTP POST requests.
Arduino:
/*
-------------------- 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:
/*
* --------------- 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);
}
//////////////////////////////////////////////
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.
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:
Libelium offers two types of sensor platforms: OEM lines (Waspmote , Arduino, Raspberry Pi) and Plug & Sense!.
| 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 |
| SIM908 | ||||
| SIM5215-E | ||||
| SIM5215-A | ||||
| LE910-EUG | ||||
| LE910-NAG | ||||
| LE910-SKG | ||||
| LE910-AU V2 | ||||
| LE910-JN V2 | ||||
| LE910-JK V2 |
| SIM908 | ||||
| SIM5215-E | ||||
| SIM5215-A | ||||
| LE910-EUG | ||||
| LE910-NAG | ||||
| LE910-SKG | ||||
| LE910-AU V2 | ||||
| LE910-JN V2 | ||||
| LE910-JK V2 |
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: