[Reference] Waspmote Plug & Sense! start program

Post Reply
libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

[Reference] Waspmote Plug & Sense! start program

Post by libelium-dev » Thu Feb 14, 2013 2:02 pm

Dear all,

Below is the Waspmote Plug & Sense! start program.
/*
 *  ------Waspmote starting program------
 *
 *  Explanation: Send basic parameters through the corresponding 
 *  XBee module.
 *  For other communication modules please use on line code generator.
 *
 *  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 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 Gascón
 *  Implementation:         Yuri Carmona
 */

// Include libraries
#include <WaspXBee802.h>
#include <WaspXBee868.h>
#include <WaspXBeeZB.h>
#include <WaspXBeeDM.h>


// Define the authentication key
#define key_access "LIBELIUM"

// Declare global variables
packetXBee* packet;
int8_t state=0; 
long previous=0;
char aux[200];
char* macHigh=" ";
char* macLow=" ";
char* myMac=" ";
int aux_1 = 0;
int aux_2 = 0;
char* temp = " ";

// Broadcast address
uint8_t direccion[8]={0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF};

// Declare the XBEE_type
// 0 - 802.15.4 
// 1 - 900 MHz - 868 MHz
// 2 - DigiMesh
// 3 - XBee ZB
// 4 - No XBee
int XBEE_type = 0;


void setup()
{
  /////////////////////////////////
  // 1. set up the XBee module
  /////////////////////////////////
  xbee802.ON();
  
  /////////////////////////////////
  // 2. Store key access in EEPROM
  /////////////////////////////////
  Utils.setAuthKey(key_access);

  /////////////////////////////////
  // 3. Set up RTC and ACC
  /////////////////////////////////
  delay(500);
  RTC.ON();
  ACC.ON();
  /////////////////////////////////
  // 4. Set Waspmote setting for XBee module for first time
  /////////////////////////////////
  Utils.setMuxSocket0();
  delay(500);
  Serial.begin(9600,0);
  Serial.print("+++",0);
  delay(2000);
  Serial.println("ATBD7,AP2,WR,CN",0);
  delay(150);
   
 
  /////////////////////////////////
  // 5. LEDs management
  /////////////////////////////////
  Utils.setLED(LED0, LED_ON);
  Utils.setLED(LED1, LED_ON);
  delay(2000);
  Utils.setLED(LED0, LED_OFF);
  Utils.setLED(LED1, LED_OFF);
  for (int i=0;i<24;i++)
  {
    Utils.blinkLEDs(125);
  }
  
  /////////////////////////////////
  // 6. Get the XBee MAC address
  /////////////////////////////////
  xbee802.ON();
  delay(1000);
  xbee802.flush();
  
  // Get the XBee MAC address
  int counter = 0;
  while((xbee802.getOwnMac()!=0) && (counter<12))
  {
    xbee802.getOwnMac();
    counter++;
  }
  
  // convert mac address from array to string
  Utils.hex2str(xbee802.sourceMacHigh,macHigh,4);
  Utils.hex2str(xbee802.sourceMacLow,macLow,4); 

  
  /////////////////////////////////
  // 7. Get the XBee firmware version
  /////////////////////////////////
  counter = 0; 
  while((xbee802.getSoftVersion()!=0)&&(counter<12))
  {
    xbee802.getSoftVersion();
    counter++;
  }
  
  // Set the XBee firmware type
  if( (xbee802.softVersion[0]<0x20) && (xbee802.softVersion[1]>0x80) )
  {
    XBEE_type = 0; // 802.15.4
  }
  else if( (xbee802.softVersion[0]<0x20) && (xbee802.softVersion[0]>0x00) )
  {
    XBEE_type = 1; // 868Mhz - 900Mhz
  }
  else if( xbee802.softVersion[0]>=0x80 )
  {
    XBEE_type = 2; // DM
  }
  else if( (xbee802.softVersion[0]>=0x20) && (xbee802.softVersion[0]<0x80) )
  {
    XBEE_type = 3; //ZB
  }
  else
  {
    // no XBee
    XBEE_type = 4;
  }
  
  /////////////////////////////////
  // 8. Print XBee module information
  /////////////////////////////////
  USB.ON();
  if( XBEE_type < 4 )
  {
    USB.print("mac address:");
    USB.print(macHigh);
    USB.println(macLow);
    USB.print("firmware version:");
  USB.print(xbee802.softVersion[0],HEX);
  USB.println(xbee802.softVersion[1],HEX);
  }
  USB.print("XBEE_type (0:802.15.4; 1:900/868; 2:DM; 3:ZB; 4:No XBee):");
  USB.println(XBEE_type,DEC);
  USB.OFF();
 
}

void loop()
{
  ////////////////////////////////////////////////
  // 9. Message composition
  ////////////////////////////////////////////////

  // getting the RTC temperature
  Utils.float2String(RTC.getTemperature(),temp,2);
  
  // build frame
  sprintf(aux,"-mac:%s%s -x:%d,y:%d,z:%d -temp:%s -bat: %d%c%c%c",macHigh,macLow,ACC.getX(),ACC.getY(),ACC.getZ(),temp,PWR.getBatteryLevel(),'%','\r','\n');
  USB.println(aux);
  
  
  ////////////////////////////////////////////////
  // 10. Send the packet
  ////////////////////////////////////////////////
 
  // set packet to send
  packet=(packetXBee*) calloc(1,sizeof(packetXBee)); // memory allocation
  packet->mode=BROADCAST; // set Unicast / broadcast mode
  
    // 10.2 send the packet via the correct object depending on the protocol
  
    // case 802.15.4
  if (XBEE_type==0)
  {
      // turn XBee on
      xbee802.ON();  
    // sets Destination parameters
    xbee802.setDestinationParams(packet, "000000000000FFFF", aux, MAC_TYPE);
    // send data
    xbee802.sendXBee(packet);
      // check TX flag
      if( xbee802.error_TX == 0 )
      {
        USB.println(F("sending ok"));
  }
      else
      {
        USB.println(F("sending error"));
      }    
    } 

    // case DM or 868/900
    if( (XBEE_type==1)||(XBEE_type==2) )
  {
      // turn XBee on
    xbeeDM.ON();
   
    // sets Destination parameters
    xbeeDM.setDestinationParams(packet, "000000000000FFFF", aux, MAC_TYPE);
    // send data
    xbeeDM.sendXBee(packet);

      // check TX flag
      if( xbeeDM.error_TX == 0 )
      {
        USB.println(F("sending ok"));
  }
      else
      {
        USB.println(F("sending error"));
      }
    }  
  
    // case ZB
    if (XBEE_type==3)
  {
      // turn XBee on
    
    xbeeZB.ON();
    
    // sets Destination parameters
    xbeeZB.setDestinationParams(packet, "000000000000FFFF", aux, MAC_TYPE);
    // send data
    xbeeZB.sendXBee(packet);
      // check TX flag
      if( xbeeZB.error_TX == 0 )
      {
        USB.println(F("sending ok"));
  }
      else
      {
        USB.println(F("sending error"));
      }
    }
    // 10.3 free memory
  free(packet);
  packet = NULL;
  
    
  Utils.externalLEDBlink(50);
  delay(1000);
}
Best regards.

tvcric321
Posts: 1
Joined: Mon Jan 27, 2014 5:08 pm
Location: pakistan
Contact:

Re: Waspmote Plug & Sense! start program

Post by tvcric321 » Mon Jan 27, 2014 5:48 pm

Thanks for sharing it is very helpful. :)
keep it up

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Waspmote Plug & Sense! start program

Post by libelium-dev » Tue Jan 28, 2014 8:28 am

tvcric321,

you will find also useful this updated version.

http://www.libelium.com/development/was ... test-code/

remusko
Posts: 9
Joined: Wed Nov 26, 2014 4:17 pm

Re: [Reference] Waspmote Plug & Sense! start program

Post by remusko » Fri Mar 20, 2015 12:33 pm

Hi libelium,

I have problems with my plug&sense waspmote.
I tried your test_code and the output was "XBee type: No XBee plugged on SOCKET 0"
and than some frames (frames are OK). I dont know how to connect my waspmote (P&S) to meshlium althought other waspmotes (no P&S) could connect to that network (Meshlium).

It is possible to solve my issue ??

Thanks......

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: [Reference] Waspmote Plug & Sense! start program

Post by libelium-dev » Fri Mar 20, 2015 2:51 pm

Hello remusko,

which model of P&S do you have?

Here you have information about P&S and Waspmote, it will be helpful.
http://www.libelium.com/forum/viewtopic ... 26&t=10911
http://www.libelium.com/forum/viewtopic ... 26&t=15445

To connect your P&S to your Meshlium network you have to do the same process that you do with waspmote.
1. Configure it with the same parameters in Meshlium (PANID,Channel)
2. Upload the code to send data and configure the correct MAC, you can see the Meshlium's MAC in Manager System.
3. Check the battery is charged.
4. Make sure antennas are well connected.

If it doesn't work, could you post your code? Thanks.

Regards.

remusko
Posts: 9
Joined: Wed Nov 26, 2014 4:17 pm

Re: [Reference] Waspmote Plug & Sense! start program

Post by remusko » Fri Apr 10, 2015 9:39 am

Hi libelium-dev,

There is still problem. I charged the P&S (97% battery).
SN:366409275

My question is when i start this part of code:
I added this into example ZB_10

xbeeZB.ON();

if( xbeeZB.error_AT == 0 )
{
USB.println(F("ZB on"));
}
else
{
USB.println(F("ZB off"));
}

the output on serial monitor should be ZB on ?? cos i have ZB off.

I think that this P&S is not working corretly.
Thanks for your reply.

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: [Reference] Waspmote Plug & Sense! start program

Post by libelium-dev » Fri Apr 10, 2015 2:05 pm

Hello remusko,

Take a look to the funcion ON() in the library, there is not any error_AT value .
Function: Connect XBee, activating switch in Waspmote
Returns: Integer that determines if there has been any error
error=2 --> The command has not been executed
error=1 --> There has been an error while executing the command
error=0 --> The command has been executed with no errors
If you want to see the error value in order to check if the xbeeZB.ON() is ok, you can try this example :
 int answer = xbeeZB.ON();
 if (answer == 0)
 {
   USB.println("on");
 }
 else{
   USB.println("error");
 }
Regards.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest