Code examples and extended information

In the Waspmote Development section you can find complete examples:

www.libelium.com/development/waspmote/examples

/*  
 *  ------ WIFI Example -------- 
 *  
 *  Explanation: This example shows how to join an access point (AP)
 *
 *  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:           0.1
 *  Design:            David Gascon 
 *  Implementation:    Yuri Carmona
 */

#include <WaspWIFI_PRO.h>

uint8_t socket = SOCKET0;
uint8_t error;
uint8_t status;
unsigned long previous;

void setup() 
{
  USB.println(F("Start program"));  
}

void loop()
{
  //////////////////////////////////////////////////
  // 1. Switch ON
  //////////////////////////////////////////////////  
  error = WIFI_PRO.ON(socket);

  if (error == 0)
  {    
    USB.println(F("1. WiFi switched ON"));
  }
  else
  {
    USB.println(F("1. WiFi did not initialize correctly"));
  }


  //////////////////////////////////////////////////
  // 2. Join AP
  //////////////////////////////////////////////////  

  // get actual time
  previous = millis();

  // check connectivity
  status = WIFI_PRO.isConnected();

  // Check if module is connected
  if (status == true)
  { 
    USB.print(F("2. WiFi is connected OK."));
    USB.print(F(" Time(ms):"));
    USB.println(millis()-previous);

    error = WIFI_PRO.ping("www.google.com");

    if (error == 0)
    {
      USB.print(F("3. PING OK. Round Trip Time(ms)="));
      USB.println( WIFI_PRO._rtt, DEC );
    }
    else
    {
      USB.println(F("3. Error calling 'ping' function"));
    }
  }
  else
  {
    USB.print(F("2. WiFi is connected ERROR."));
    USB.print(F(" Time(ms):"));
    USB.println(millis()-previous);
  }


  //////////////////////////////////////////////////
  // 3. Switch OFF
  //////////////////////////////////////////////////
  WIFI_PRO.OFF(socket);
  USB.println(F("4. WiFi switched OFF\n\n"));
  delay(10000);
}

Last updated