Development

Communication / 3G + GPS:

» 3G 32: OTA

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 GPRS/3G antenna
1 x SIM card
1 x SD card in 3G + GPS module

Notes

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

Code

/*
    ------Waspmote 3G 32 OTA 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) 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 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:          1.0
    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 succesfully
  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);


  // 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

H#
Start program
RTC TIME ==> Wed, 16/08/24, 15:15:09
RESTARTING
-----------------------------
Program id: _3G_32_
Program version: 25
-----------------------------
*****************************
APN: gprs-service.com
LOGIN:
PASSWORD:
*****************************
1. 3G module ready...
==> Request OTA...

H#
[dbg] Enter OTA
[dbg] File size: 56704
[dbg] OTA done
[dbg] Read flash OK
[dbg] Start program
Start program
RTC TIME ==> Wed, 16/08/24, 15:15:53
REPROGRAMMING OK
-----------------------------
Program id: _3G_32_
Program version: 25
-----------------------------
*****************************
APN: gprs-service.com
LOGIN:
PASSWORD:
*****************************
1. 3G module ready...
==> Request OTA...

H#
....

Quick Publish: