Development v12

Warning - Product Update

All the resources present on this section belong to Waspmote v12, Waspmote Plug & Sense! v12 and Meshlium v3.8.

If you have a Waspmote v15, Waspmote Plug & Sense! v15 or Meshlium v4.0 please go to the new Development Section.

Check what is your version and what are the differences between the old and the new one in this document.

» OTA 07: OTA via 3G module

This example shows how perform OTA programming using the 3G+GPS module. It is necessary to specify the correct FTP settings.

Required Materials

1 x Waspmote
1 x battery
1 x 3G+GPS module
1 x 3G/GPRS antenna
1 x SIM card

Notes

- GPRS_Pro module must be powered with a battery
- When GPRS_Pro module is in use, interrupts can't be used
- This example can be executed in Waspmote v12

Code

/*
 *  ------Waspmote OTA_07 Example--------
 *
 *  Explanation: This example shows how perform OTA programming using the
 *  3G+GPS module. It is necessary to specify the correct FTP settings.
 *
 *  Copyright (C) 2013 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 2 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:                0.1
 *  Design:                 David Gascón
 *  Implementation:         Alejandro Gallego
 */

// include 3G+GPS library
#include <Wasp3G.h>
int answer, counter;

void setup(){
    
    //*****************************************************************
    //  Check if the program has been programmed successfully
    //*****************************************************************

    answer = Utils.checkNewProgram();    
    switch(answer)
    {
        case 0:
            USB.println(F("REPROGRAMMING ERROR"));
            break;    
        case  1:        
            USB.println(F("REPROGRAMMING OK"));
            break;    
        default:
            USB.println(F("RESTARTING"));
    }
    USB.print(F("Program version: "));
    USB.println(Utils.getProgramVersion(), DEC);
    
    //*****************************************************************
    //   User setup
    //*****************************************************************    

    // put your setup code here, to run once:
    
}


void loop(){
    
    //*****************************************************************
    //    User loop program
    //*****************************************************************
    
    // put your main code here, to run repeatedly:
    
    
    //*****************************************************************
    //    OTA standart loop
    //*****************************************************************
    
    //Starts the 3G + GPS module
    answer = _3G.ON();
    
    //Checks the start sequence: 1 for correct start and -3 for correct start with low battery level
    if ((answer == 1) || (answer == -3))
    {
        USB.println(F("3G+GPS module ready..."));
        USB.println(F("Connecting to the network")); 
        
        answer = _3G.check(60);
        
        if (answer == 1)
        {              
            USB.println(F("3G+GPS module connected to the network")); 
            USB.println(F("Starting OTA process")); 
            
            answer = _3G.requestOTA("FTP_address", "FTP_port", "FTP_user_name", "FTP_password");
            
            // If OTA process fails, show the error code
            USB.print(F("Error code:"));
            USB.println( answer, DEC);
        }
        else
        {
            USB.println(F("Error connecting to the network"));                
        }
    }
    else
    {
        USB.println(F("Error starting the 3G+GPS module"));        
    }
        
    _3G.OFF();
}


Output

E#
RESTARTING
Program version: 1
3G+GPS module ready...
Connecting to the network
3G+GPS module connected to the network
Starting OTA process
REPROGRAMMING OK
Program version: 2

Quick Publish: