Post a new topicPost a reply Page 1 of 2   [ 20 posts ]
Go to page 1, 2  Next
Author Message
 Post subject: Interacting with the Events Board
PostPosted: Wed Jun 20, 2012 7:52 am 

Joined: Wed Jun 06, 2012 7:03 pm
Posts: 68
Hi everybody!

I have an Events Board and I am trying to get a PIR sensor, temperature sensor, and humidity sensor to communicate with the Android Wifi application. However, using the code below, the Android application only displays a value of 0 for these sensors (the rest are dummy test values). I've tested using the Smart Cities board and it worked out fine, but I know that there are coding differences for the Events Board. What am I doing wrong here?
Image
Code:
// Specifies the message that is sent to the WiFi module.
char tosend[128];
char sTem[12];
char sLum[12];
char sPir[12];

void setup(){
  // Initialize the accelerometer
  ACC.begin();
  ACC.setMode(ACC_ON);
  SensorEvent.setBoardMode(SENS_ON);
  RTC.ON();
  SensorEvent.setThreshold(SENS_SOCKET3, 2);
  SensorEvent.setThreshold(SENS_SOCKET5, 2);
  SensorEvent.setThreshold(SENS_SOCKET7, 0.5);
 
  WIFI.begin();
  // Then switch on the WIFI module on the desired socket.
  WIFI.ON(socket0);
  // If we don't know what configuration had the module, reset it.
  WIFI.resetValues();
 
  // 1. Configure the transport protocol (UDP, TCP, FTP, HTTP...)
  WIFI.setConnectionOptions(UDP);
  // 2. Configure the way the modules will resolve the IP address.
  WIFI.setDHCPoptions(DHCP_ON);
}

void loop(){
  // 3. Configure how to connect the AP.
  WIFI.setJoinMode(MANUAL);
  float temperature;
  //float humidity;
  float luminosity;
  float pir;
  //Enable interruptions from the board
      
SensorEvent.attachInt();
      
//Put the mote to sleep
      
//PWR.sleep(UART0_OFF | UART1_OFF | BAT_OFF | RTC_OFF);
      
//Disable interruptions from the board
      
SensorEvent.detachInt();
      
//Load the interruption register
      
SensorEvent.loadInt();
      
//Compare the interruption received with the sensor identifier
      
//if (SensorEvent.intFlag & SENS_SOCKET7)
//{
  while(1){
    // 3.1 Call join giving the name of the AP.
    while(!WIFI.join("ANDROID")){}
    // Switches on green led to show us it's connected.
    Utils.setLED(LED0, LED_ON);
    // 4. Creates UDP connection.
    if (WIFI.setUDPclient("255.255.255.255",12345,2000))
    {
      // 5. Now we can use send and read functions to send and
      // receive UDP messages.
      while(1){
        // 6. Send data to the IOS smartphone
        temperature = SensorCities.readValue(SENS_SOCKET5);
        Utils.float2String(temperature,sTem,2);
        luminosity = SensorCities.readValue(SENS_SOCKET3);
        Utils.float2String(luminosity,sLum,2);
        pir = SensorEvent.readValue(SENS_SOCKET7);
        Utils.float2String(pir,sPir,2);
        sprintf(tosend,"Wasp-1;%s;%d;%s;22;23;%s;%d;%d;%d;",sTem,10,sLum,sPir,ACC.getX(),ACC.getY(),ACC.getZ());
//        sprintf(tosend,"Wasp-1;%f;%f;%f;22;23;24;%d;%d;%d;",
//                SensorCities.readValue(SENS_CITIES_TEMPERATURE),SensorCities.readValue(SENS_CITIES_HUMIDITY),SensorCities.readValue(SENS_CITIES_LDR),ACC.getX(),ACC.getY(),ACC.getZ());
        WIFI.send(tosend);
        // Reads data to the IOS smartphone
        WIFI.read(NOBLO);
        // Waspmote acts depending on the answer.
        uint8_t period = (WIFI.answer[6] - 48) * 10 + (WIFI.answer[7] - 48);
        if (period<11){
          // Switches on a lamp with intensity= period %
        }
      }
    }
  }
//  }
}


Thanks for your help!


Top
 Profile  
 
 Post subject: Re: Interacting with the Events Board
PostPosted: Wed Jun 20, 2012 9:07 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7785
uilt,

A few recommendations:

  1. Try sending data as integer instead of strings.
  2. Pir values is only '0' or '1'. adjust length.
  3. You can use ACC.ON() which includes begin() and setMode().
  4. Maybe it is a good idea to test sensor values separately (to see if they measure OK) before trying to send it by wifi.

Let us know.

Regards.


Top
 Profile  
 
 Post subject: Re: Interacting with the Events Board
PostPosted: Wed Jun 20, 2012 6:59 pm 

Joined: Wed Jun 06, 2012 7:03 pm
Posts: 68
Thanks for the recommendations. What should I set as the threshold for the PIR sensor?


Top
 Profile  
 
 Post subject: Re: Interacting with the Events Board
PostPosted: Thu Jun 21, 2012 1:19 am 

Joined: Wed Jun 06, 2012 7:03 pm
Posts: 68
I realized from another post that the PIR sensor is a digital sensor and doesn't need a threshold. I followed your suggestions and used a simpler program to test the sensors through the USB rather than sending them through Wifi. However, I am still receiving 0 for both luminosity and PIR, while I receive a very small number for temperature. Have I set the thresholds wrongly? I've posted a picture of my hardware setup, my serial monitor output, and my code below. Any help would be appreciated!
Image
Code:
 float pir = 0;
 float temperature = 0;
 float luminosity = 0;
  void setup()
 {
 
//Turn on the Events Sensor Board
 
SensorEvent.setBoardMode(SENS_ON);
 
//Init the RTC
 
RTC.ON();
//Configure?the?sensor?threshold
 
//SensorEvent.setThreshold(SENS_SOCKET1, 0.5);
SensorEvent.setThreshold(SENS_SOCKET6, 1.5);
SensorEvent.setThreshold(SENS_SOCKET5, 1.5);
USB.begin();
USB.println("Start");
 }
 
void loop()
{
SensorEvent.attachInt();
SensorEvent.detachInt();
SensorEvent.loadInt();
//pir = SensorEvent.readValue(SENS_SOCKET7);
//temperature = SensorEvent.readValue(SENS_SOCKET5);
//luminosity = SensorEvent.readValue(SENS_SOCKET3);
USB.begin();
//USB.println(pir);
//USB.println(temperature);
//USB.println(luminosity);
USB.println("PIR:");
USB.println(SensorEvent.readValue(SENS_SOCKET7));
USB.println("Temperature:");
USB.println(SensorEvent.readValue(SENS_SOCKET5));
USB.println("Luminiosity:");
USB.println(SensorEvent.readValue(SENS_SOCKET6));

if (SensorEvent.intFlag && SENS_SOCKET7)
  {
    USB.println("PIR interruption");
  }
if (SensorEvent.intFlag && SENS_SOCKET5)
  {
    USB.println("Temperature interruption");
  }
if (SensorEvent.intFlag && SENS_SOCKET6)
  {
    USB.println("Luminosity interruption");
  } 
  SensorEvent.intFlag = 0;
  SensorEvent.attachInt();
  delay(1000);
}


Top
 Profile  
 
 Post subject: Re: Interacting with the Events Board
PostPosted: Thu Jun 21, 2012 4:52 am 

Joined: Wed Jun 06, 2012 7:03 pm
Posts: 68
Oh and by the way, I was using the RFID/NFC 13.56MHz code and WaspRFID.cpp/WaspRFID.h from this post "http://www.libelium.com/forum/viewtopic.php?f=16&t=9184."


Top
 Profile  
 
 Post subject: Re: Interacting with the Events Board
PostPosted: Thu Jun 21, 2012 9:15 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7785
uilt,

Please check DIP switch. You should turn on the corresponding switches for that sensors. It is described in the Event Sensor programming guide.

Maybe this post is useful for you.

Regards.


Top
 Profile  
 
 Post subject: Re: Interacting with the Events Board
PostPosted: Thu Jun 21, 2012 11:33 pm 

Joined: Wed Jun 06, 2012 7:03 pm
Posts: 68
Thanks! The post was very useful and I managed to receive data for luminosity and PIR. However, the temperature still shows up as a decimal as shown below. How do you interpret this result? It doesn't seem like it is measuring in degrees celsius.
Also, I noticed that the interruptions always come together. What do interruptions exactly mean? How does the threshold affect the measurements or interruptions?

Code:
PIR:
1.0000000000
Temperature:
0.1999999904
Luminiosity:
0.0193548383
PIR:
1.0000000000
Temperature:
0.2064516067
Luminiosity:
0.0225806450
PIR:
1.0000000000
Temperature:
0.2064516067
Luminiosity:
0.0354838705
PIR:
1.0000000000
Temperature:
0.2032258033
Luminiosity:
0.0322580623
PIR:
1.0000000000
Temperature:
0.2064516067
Luminiosity:
0.0354838705
PIR:
1.0000000000
Temperature:
0.2096774101
Luminiosity:
0.0258064508
PIR:
1.0000000000
Temperature:
0.2096774101
Luminiosity:
0.0258064508
PIR:
1.0000000000
Temperature:
0.2032258033
Luminiosity:
0.0354838705
PIR:
1.0000000000
Temperature:
0.2096774101
Luminiosity:
0.0258064508
PIR:
1.0000000000
Temperature:
0.2064516067
Luminiosity:
0.0354838705
PIR:
1.0000000000
Temperature:
1.5967741966
Luminiosity:
3.2838709354
PIR interruption
Temperature interruption
Luminosity interruption
PIR:
1.0000000000
Temperature:
0.5806451320
Luminiosity:
0.1064516186
PIR interruption
Temperature interruption
Luminosity interruption
PIR:
1.0000000000
Temperature:
0.3483870983
Luminiosity:
0.0645161247
PIR interruption
Temperature interruption
Luminosity interruption
PIR:
1.0000000000
Temperature:
1.6580644607
Luminiosity:
3.2645158767
PIR interruption
Temperature interruption
Luminosity interruption
PIR:
1.0000000000
Temperature:
1.9774193763
Luminiosity:
3.2580645084
PIR interruption
Temperature interruption
Luminosity interruption
PIR:
1.0000000000
Temperature:
1.8064516067
Luminiosity:
2.5193548202
PIR interruption
Temperature interruption
Luminosity interruption
PIR:
1.0000000000
Temperature:
1.0806451988
Luminiosity:
1.1032258272
PIR interruption
Temperature interruption
Luminosity interruption
PIR:
1.0000000000
Temperature:
0.9774192810
Luminiosity:
1.0870966911
PIR:
1.0000000000
Temperature:
0.9451612472
Luminiosity:
1.0870966911
PIR:
1.0000000000
Temperature:
0.9322580337
Luminiosity:
1.0935482978



Top
 Profile  
 
 Post subject: Re: Interacting with the Events Board
PostPosted: Fri Jun 22, 2012 12:11 am 

Joined: Wed Jun 06, 2012 7:03 pm
Posts: 68
Adding onto my previous questions:
I went back to the program that sends the information through wifi. The data doesn't show up as 0 anymore, but the temperature still displayed as a very small decimal. I tried to add some USB.println() statements to compare the output to the android phone and to the serial monitor, but the waspmote never joined the network when USB commands and wifi commands were present at the same time (if I comment out the lines involving USB commands, the code works fine). Does this mean that the waspmote can't use both at the same time? Here is the code below:
Code:
 float pir = 0;
 float temperature = 0;
 float luminosity = 0;
  void setup()
 {
 
//Turn on the Events Sensor Board
 
SensorEvent.setBoardMode(SENS_ON);
 
//Init the RTC
 
RTC.ON();
//Configure?the?sensor?threshold
 
//SensorEvent.setThreshold(SENS_SOCKET1, 0.5);
SensorEvent.setThreshold(SENS_SOCKET1, 1.5);
SensorEvent.setThreshold(SENS_SOCKET5, 1.5);
USB.begin();
USB.println("Start");
 }
 
void loop()
{
SensorEvent.attachInt();
SensorEvent.detachInt();
SensorEvent.loadInt();
//pir = SensorEvent.readValue(SENS_SOCKET7);
//temperature = SensorEvent.readValue(SENS_SOCKET5);
//luminosity = SensorEvent.readValue(SENS_SOCKET3);
USB.begin();
//USB.println(pir);
//USB.println(temperature);
//USB.println(luminosity);
USB.println("PIR:");
USB.println(SensorEvent.readValue(SENS_SOCKET7));
USB.println("Temperature:");
USB.println(SensorEvent.readValue(SENS_SOCKET5));
USB.println("Luminiosity:");
USB.println(SensorEvent.readValue(SENS_SOCKET1));

if (SensorEvent.intFlag && SENS_SOCKET7)
  {
    USB.println("PIR interruption");
  }
if (SensorEvent.intFlag && SENS_SOCKET5)
  {
    USB.println("Temperature interruption");
  }
if (SensorEvent.intFlag && SENS_SOCKET1)
  {
    USB.println("Luminosity interruption");
  } 
  SensorEvent.intFlag = 0;
  SensorEvent.attachInt();
  delay(1000);
}



Top
 Profile  
 
 Post subject: Re: Interacting with the Events Board
PostPosted: Fri Jun 22, 2012 1:07 am 

Joined: Wed Jun 06, 2012 7:03 pm
Posts: 68
Sorry for the triple post, but I meant to post this code instead:
Code:
/*
 *  ------Waspmote WIFI Android smartphone application Example--------
 *
 *  Explanation: This example shows the way to communicate with
 *  the Waspmote Wifi Demo Android app.
 *
 *  Copyright (C) 2012 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:         Joaquin Ruiz
 */
 
// Specifies the message that is sent to the WiFi module.
char tosend[128];
char sTem[12];
char sLum[12];
char sPir[12];

void setup(){
  // Initialize the accelerometer
  ACC.begin();
  ACC.setMode(ACC_ON);
  SensorEvent.setBoardMode(SENS_ON);
  RTC.ON();
  SensorEvent.setThreshold(SENS_SOCKET3, 1.5);
  SensorEvent.setThreshold(SENS_SOCKET5, 1.5);
 
 
  WIFI.begin();
  // Then switch on the WIFI module on the desired socket.
  WIFI.ON(socket0);
  // If we don't know what configuration had the module, reset it.
  WIFI.resetValues();
 
  // 1. Configure the transport protocol (UDP, TCP, FTP, HTTP...)
  WIFI.setConnectionOptions(UDP);
  // 2. Configure the way the modules will resolve the IP address.
  WIFI.setDHCPoptions(DHCP_ON);
  USB.begin();
  USB.println("Start");
}

void loop(){
  // 3. Configure how to connect the AP.
  WIFI.setJoinMode(MANUAL);
  float temperature;
  //float humidity;
  float luminosity;
  float pir;
  //Enable interruptions from the board
      
SensorEvent.attachInt();
      
//Put the mote to sleep
      
//PWR.sleep(UART0_OFF | UART1_OFF | BAT_OFF | RTC_OFF);
      
//Disable interruptions from the board
      
SensorEvent.detachInt();
      
//Load the interruption register
      
SensorEvent.loadInt();
   
//Compare the interruption received with the sensor identifier

  while(1){
    // 3.1 Call join giving the name of the AP.
    while(!WIFI.join("ANDROID")){}
    // Switches on green led to show us it's connected.
    Utils.setLED(LED0, LED_ON);
    // 4. Creates UDP connection.
    if (WIFI.setUDPclient("255.255.255.255",12345,2000))
    {
      // 5. Now we can use send and read functions to send and
      // receive UDP messages.
      while(1){
        // 6. Send data to the IOS smartphone
        temperature = SensorEvent.readValue(SENS_SOCKET5);
        Utils.float2String(temperature,sTem,2);
        USB.println("temperature:");
        USB.println(temperature);
        USB.println(sTem);
        luminosity = SensorEvent.readValue(SENS_SOCKET1);
        Utils.float2String(luminosity,sLum,2);
        USB.println("luminiosity:");
        USB.println(luminosity);
        USB.println(sLum);
        pir = SensorEvent.readValue(SENS_SOCKET7);
        Utils.float2String(pir,sPir,2);
        //USB.println("PIR:");
        //USB.println(pir);
        //USB.println(sPir);       
        sprintf(tosend,"Wasp-1;%s;%d;%s;22;23;%s;%d;%d;%d;",sTem,10,sLum,sPir,ACC.getX(),ACC.getY(),ACC.getZ());
       
        WIFI.send(tosend);
        // Reads data to the IOS smartphone
        WIFI.read(NOBLO);
        // Waspmote acts depending on the answer.
        uint8_t period = (WIFI.answer[6] - 48) * 10 + (WIFI.answer[7] - 48);
        if (period<11){
          // Switches on a lamp with intensity= period %
        }
      }
    }
  }
}





Top
 Profile  
 
 Post subject: Re: Interacting with the Events Board
PostPosted: Mon Jun 25, 2012 9:11 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7785
uilt,

Maybe the sensor is not contacting well with the connector, please test it pressing sensor to the connector (but no so hard, be careful).

Besides that, you should use a conversion factor to obtain measured values into celsius degrees.

You can use this one:
// --- coversion equation---
valueTemp = ( valueTemp - 0.5 ) * 100;


Also read into this forum about this, there are some post about it.

Regards.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 2   [ 20 posts ]
Go to page 1, 2  Next


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use