send the temperature reading to the gateway

Post Reply
Anas
Posts: 12
Joined: Wed May 10, 2017 8:55 am

send the temperature reading to the gateway

Post by Anas » Sat May 13, 2017 3:53 pm

DearAll,
I want to send the temperature that measured by the sensor to the gateway.
my understanding is in this simple code:

// Turn on the sensor and wait for stabilization and response time
SensorCities.setSensorMode(SENS_ON, SENS_CITIES_TEMPERATURE);
delay(10);

// Read the temperature sensor
value = SensorCities.readValue(SENS_CITIES_TEMPERATURE);
xbeeZB.ON();
delay(10);
//then check XBee's network parameters
checkNetworkParams();
//then
error = xbeeZB.send( ?????);

// check TX flag
if( error == 0 )
{
USB.println(F("send ok"));

However, i don't know what should i put inside xbeeZB.send(????) to send the value of the temperature.
Any help will be appreciated.
Regards
Anas

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

Re: send the temperature reading to the gateway

Post by libelium-dev » Mon May 15, 2017 11:38 am

Hi,

You can create a frame and send the frame with this function

Code: Select all

xbeeZB.send( RX_ADDRESS, frame.buffer, frame.length ); 
Or you can send the data with the format you want.

Code: Select all

xbeeZB.send( RX_ADDRESS, data ); 
data is a string, so you should convert the temp value to string.

Regards

Anas
Posts: 12
Joined: Wed May 10, 2017 8:55 am

Re: send the temperature reading to the gateway

Post by Anas » Wed May 17, 2017 3:55 am

Hi,
I tried to use(String data = String.valueOf(x_acc);) to convert ineger to string, but it doesn't work
#include <WaspXBeeZB.h>
#include <WaspFrame.h>
char RX_ADDRESS[] = "000000000000FFFF";
int x_acc;


void setup()
{
ACC.ON();
USB.ON(); // starts using the serial port
USB.println(F("ACC_01 example"));

xbeeZB.ON();

delay(3000);

}

void loop()
{
x_acc = ACC.getX();
String data = String.valueOf(x_acc); ////////////important//////
xbeeZB.send( RX_ADDRESS,data ); ////////////important//////
delay(5000);
}

I got this error

//////////////////////

ACC_01_reading_acceleration:66: error: 'String' was not declared in this scope

String data = String.valueOf(x_acc);

^

ACC_01_reading_acceleration:87: error: 'data' was not declared in this scope

xbeeZB.send( RX_ADDRESS,data );

^

exit status 1
'String' was not declared in this scope

////////////////

Does there another way to convert to string?
Thanks in advance
Anas

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

Re: send the temperature reading to the gateway

Post by libelium-dev » Wed May 17, 2017 8:43 am

Hi,

You can use snprintf() function to convert from integer to string. For example,

Code: Select all

int x_acc_int;
char x_acc_string[10];
snprintf( x_acc_string, sizeof(x_acc_string), "%d", x_acc_int);
Hope this help
Regards

Anas
Posts: 12
Joined: Wed May 10, 2017 8:55 am

Re: send the temperature reading to the gateway

Post by Anas » Wed May 17, 2017 8:48 am

In my case, i need to send it not just print it. what should i put in here
xbeeZB.send( RX_ADDRESS, ????????? );
regards,
Anas

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

Re: send the temperature reading to the gateway

Post by libelium-dev » Wed May 17, 2017 12:03 pm

Hi,

snprintf() function creates a string, it doesn't print the value.

You should put x_acc_string in the send function

Code: Select all

int x_acc_int;
char x_acc_string[10];
snprintf( x_acc_string, sizeof(x_acc_string), "%d", x_acc_int);
xbeeZB.send( RX_ADDRESS, x_acc_string ); 
Regards

Anas
Posts: 12
Joined: Wed May 10, 2017 8:55 am

Re: send the temperature reading to the gateway

Post by Anas » Wed May 17, 2017 3:14 pm

Thanks a lot. it's work now, but i have a small issue
https://drive.google.com/open?id=0B3IE7 ... 1Y2LTVqZFk

the link of the screenshot above shows the sent and received data. my question is that why I got these strange symbols with the data? and how can I remove it?
Regards,
Anas

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

Re: send the temperature reading to the gateway

Post by libelium-dev » Thu May 18, 2017 12:15 pm

Hi,

Those strange symbols may be internal data of the communication protocol.

Please check if you're still seeing those characters using XCTU sotware.

Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest