Low Cost PCB's Low Cost Components

Author Topic: WSNDemo tutorial  (Read 1318 times)

0 Members and 1 Guest are viewing this topic.

Offline Kyrul

  • Contributor
  • Posts: 13
  • Country: my
WSNDemo tutorial
« on: April 21, 2017, 08:12:25 PM »
Hi guys,

Hope someone can answer my question.
I have LWMesh Developer Guide and Wireless Product Development using Atmel.
For guide me to understand more about WSNDemo between this two guide e-book
Is it Wireless Product Development same as LWMesh Developer Guide?
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 3270
  • Country: us
  • I informed you thusly
    • Personal site
Re: WSNDemo tutorial
« Reply #1 on: April 22, 2017, 02:37:45 AM »
If they have different titles, the no, they are not the same. LwMesh is just one of many wireless products, and not even the biggest one.

What exactly you don't understand about WSNDemo? What hardware you plan to use? What's your application?
Alex
 

Offline Kyrul

  • Contributor
  • Posts: 13
  • Country: my
Re: WSNDemo tutorial
« Reply #2 on: April 26, 2017, 11:13:51 AM »
Thanks Alexru for replied,

Im not clear about lqi and rssi?
Could you explain for me?

Im using ATMEGA256rfr2 XPRO to send the data from the coordinator to the router.
Now I try to do something like this forum link: http://community.atmel.com/forum/sending-data-coordinator-routers-and-end-devices.
What I saw in this forum the code for WSNDemo is from the ASF.
So if I want to modify the stand alone WSNDemo it can work or not?

Regard
Ky
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 3270
  • Country: us
  • I informed you thusly
    • Personal site
Re: WSNDemo tutorial
« Reply #3 on: April 26, 2017, 11:20:09 AM »
Im not clear about lqi and rssi?
Datasheet for the part clearly explains what they are. It would take too long to explain it here again.

If you have some specific questions about them, please ask.

What I saw in this forum the code for WSNDemo is from the ASF.
What makes you think that? The code there is from the standalone version, the thread is started way before LwMesh was a part of ASF.

So if I want to modify the stand alone WSNDemo it can work or not?
The thread is way too long to read, and covers too many topics. What exactly you want to do?
Alex
 

Offline Kyrul

  • Contributor
  • Posts: 13
  • Country: my
Re: WSNDemo tutorial
« Reply #4 on: April 26, 2017, 12:00:14 PM »

Quote
What exactly you want to do?

Actually I want to sent some random data like 0x17  from the coordinator to router and display it on Tera Terminal.
What can I do to change the code so the coordinator can sent the data 0x17 and receive to the router?



 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 3270
  • Country: us
  • I informed you thusly
    • Personal site
Re: WSNDemo tutorial
« Reply #5 on: April 26, 2017, 12:03:42 PM »
Actually I want to sent some random data like 0x17  from the coordinator to router and display it on Tera Terminal.
Look at Peer2Peer application, it sends data over a serial port.

What can I do to change the code so the coordinator can sent the data 0x17 and receive to the router?
This is a really broad question. You need to write an application that does this. There is no way to answer this, without actually writing the code for you.

Also, even WSNDemo has commands that are sent from the coordinator to the devices. Right now there is only one command - identify. All you really need to do is find a handler for that command, and instead of blinking, send some stuff into UART.
Alex
 

Offline Kyrul

  • Contributor
  • Posts: 13
  • Country: my
Re: WSNDemo tutorial
« Reply #6 on: April 26, 2017, 12:10:53 PM »
Thank you Alex.

I try writing the code first and if I still can make it Ill ask you again.

Thank you again Alex

Ky
 

Offline Kyrul

  • Contributor
  • Posts: 13
  • Country: my
Re: WSNDemo tutorial
« Reply #7 on: April 26, 2017, 01:14:32 PM »
Hai Alex,

If I dont have WSNMonitor in my Atmel Studio what should I do to see the result of the WSNDemo application?
I already tried Tera Terminal but the data is not in number at all or any character that I can read.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 3270
  • Country: us
  • I informed you thusly
    • Personal site
Re: WSNDemo tutorial
« Reply #8 on: April 26, 2017, 01:19:38 PM »
If I dont have WSNMonitor in my Atmel Studio what should I do to see the result of the WSNDemo application?

Here is one from more or less recent BitCloud SDK, since it is no longer available for download https://www.dropbox.com/s/qe9342fu5g7rw56/WSNMonitor_Setup_2.2.1.93.exe?dl=0

I already tried Tera Terminal but the data is not in number at all or any character that I can read.

There is a Python script in that thread that can also receive that data.

In general, you just need start to adopting that to your specific application. So do whatever you plan to do with the real data.
Alex
 

Offline Kyrul

  • Contributor
  • Posts: 13
  • Country: my
Re: WSNDemo tutorial
« Reply #9 on: April 26, 2017, 01:24:20 PM »

Thank you so much Alex. :-+ :-+ :-+
 

Offline Kyrul

  • Contributor
  • Posts: 13
  • Country: my
Re: WSNDemo tutorial
« Reply #10 on: April 27, 2017, 12:44:17 PM »
Hai again Alex,

For the WSNDemo can combine  with Peer2Peer application?
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 3270
  • Country: us
  • I informed you thusly
    • Personal site
Re: WSNDemo tutorial
« Reply #11 on: April 27, 2017, 12:47:25 PM »
For the WSNDemo can combine  with Peer2Peer application?
It is programming, you can do whatever you want.

In general, you want to plan what you want to do and figure out your state machines. It is not as simple as merging two files or copy-pasting chunks of code.

In general, it is not even obvious what combined WSNDemo/Peer2Peer application will do.
Alex
 

Offline Kyrul

  • Contributor
  • Posts: 13
  • Country: my
Re: WSNDemo tutorial
« Reply #12 on: May 09, 2017, 11:31:34 AM »
Hi again Alexru,

I hope you can help me Alexru.
Here I tried to sent the data of T to the router.
I want the result show in Tera Term but there is nothing happen on Tera Term.
Could you take look my code for while?
Here the code:

/***********************************************************/
Sender Part:
Code: [Select]
#include <avr/io.h>
#include <asf.h>
#include <util/delay.h>
#include "phy.h"
#include "nwk.h"
#include "config.h"
#include "sys.h"
#include "sysTimer.h"

#define FOSC 8000000
#define BAUD 9600
#define MYBAUD (FOSC/16/BAUD-1)



static uint8_t msg  = 'B';
static bool networkStatus;
static NWK_DataReq_t nwkDataReq;
static SYS_Timer_t nwkStatusTimer;



void usart_init (unsigned int ubrr)
{
UBRR0H = (unsigned char)(ubrr>>8);
UBRR0L = (unsigned char) ubrr;
/* Enable receiver and transmitter */
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
/* Set frame format: 8data, 2stop bit */
UCSR0C = (1<<USBS0)|(3<<UCSZ00);
}

void usart_transmit (unsigned char data)
{
while (!(UCSR0A & (1<<UDRE0)));
UDR0 =  data;
}

// static void dataConfigure (uint8_t *req)
// {
// if(NWK_SUCCESS_STATUS)
// {
// if(!networkStatus)
// {
// PORTB |= (1<<PINB4);
// SYS_TimerStop(&nwkStatusTimer);
// networkStatus = true;
// }
// }
// else
// {
// if(networkStatus)
// {
// PORTB &= (1<<PINB4);
// SYS_TimerStart(&nwkStatusTimer);
// networkStatus = false;
// }
// }
// }




static void sendFrameData (void)
{
nwkDataReq.dstAddr = 1;
nwkDataReq.dstEndpoint = APP_ENDPOINT;
nwkDataReq.data =  &msg;
nwkDataReq.size = sizeof(msg);
nwkDataReq.confirm();
NWK_DataReq(&nwkDataReq);

PORTB ^= (1<<PINB4);
}

static bool dataIndex (NWK_DataInd_t *ind)
{

return true;
NWK_OpenEndpoint(1, dataIndex);
}


static void SendingTaskHandler (void)
{
sendFrameData();
}

static void nwkInit (void)
{
NWK_SetAddr(APP_ADDR);
NWK_SetPanId(0x4321);
PHY_SetChannel(0x0f);
PHY_SetRxState(true);
NWK_OpenEndpoint(APP_ENDPOINT, dataIndex);
}

int main(void)
{
board_init();
DDRB |= (1<<PINB4);
PORTB |= (1<<PINB4);
SYS_Init();
nwkInit();
cli();
usart_init(MYBAUD);
sei();
usart_transmit('K');

while (1)
{
SYS_TaskHandler();
SendingTaskHandler();
}


}



/*****************************************************************/
Receive Part:
Code: [Select]
#include <avr/io.h>
#include <asf.h>
#include <util/delay.h>
#include "phy.h"
#include "nwk.h"
#include "config.h"
#include "sys.h"
#include "sysTimer.h"

#define FOSC 8000000
#define BAUD 9600
#define MYBAUD (FOSC/16/BAUD-1)

static uint8_t receivedData;
/*static bool acknowledgement = false;*/
static NWK_DataReq_t nwkDataReq;
// static SYS_Timer_t nwkStatusTimer;

static void usart_init (unsigned int ubrr)
{
UBRR0H = (unsigned char)(ubrr>>8);
UBRR0L = (unsigned char) ubrr;
/* Enable receiver and transmitter */
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
/* Set frame format: 8data, 2stop bit */
UCSR0C = (1<<USBS0)|(3<<UCSZ00);
}

unsigned char USART_Receive( void )
{
/* Wait for data to be received */
while ( !(UCSR0A & (1<<RXC0)) );
/* Get and return received data from buffer */
return UDR0;
}


static bool dataIndex (NWK_DataInd_t *ind)
{
PORTB &= (1<<PINB4);
for(uint8_t i = 0; i<=ind->size; i++)
{
while ( !(UCSR0A & (1<<UDRE0)) );
UDR0 = ind->data[i];
}
return true;
NWK_OpenEndpoint(1, dataIndex);
}

static void receivedFrameData (void)
{
nwkDataReq.srcAddr = 0;
/*nwkDataReq.dstAddr = 0;*/
nwkDataReq.dstEndpoint = APP_ENDPOINT;
nwkDataReq.srcEndpoint = APP_ENDPOINT;
nwkDataReq.data =  &receivedData;
nwkDataReq.size = sizeof(receivedData);


PORTB ^= (1<<PINB4);
}

static void receivedInit (void)
{
NWK_SetAddr(APP_ADDR);
NWK_SetPanId(0x4321);
PHY_SetChannel(0x0f);
PHY_SetRxState(true);
NWK_OpenEndpoint(APP_ENDPOINT, dataIndex);
}

int main(void)
{
board_init();
DDRB |= (1<<PINB4);
cli();
usart_init(MYBAUD);
sei();
USART_Receive();
receivedInit();

while (1)
{
SYS_TaskHandler();
receivedFrameData();
}
}



 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 3270
  • Country: us
  • I informed you thusly
    • Personal site
Re: WSNDemo tutorial
« Reply #13 on: May 09, 2017, 12:08:06 PM »
There is more wrong with this code, than right:
1. You never call SYS_Init();
2. receivedFrameData() makes no sense and does absolutely nothing.
3. All those "NWK_OpenEndpoint(1, dataIndex);" after return statement do nothing. You only need one call to NWK_OpenEndpoint() anyway.
4. You call USART_Receive() on the receiver end, but this will block if you don't actually send a character.
5. "nwkDataReq.confirm();" is a total nonsense.
6. You can't just call sendFrameData(), you need to wait for the confirmation.

Seriously, look at sample code and documentation, don't just guess what APIs do and hoe to use them.

There is a Peer2Peer application that does exactly what you want to do.

Alex
 

Offline Kyrul

  • Contributor
  • Posts: 13
  • Country: my
Re: WSNDemo tutorial
« Reply #14 on: May 09, 2017, 12:25:45 PM »
Thank you Alex,

I will do the correction and read the documentation about Peer 2 peer application.
 

Offline Kyrul

  • Contributor
  • Posts: 13
  • Country: my
Re: WSNDemo tutorial
« Reply #15 on: May 16, 2017, 10:17:19 AM »
Hai,

I hope someone can help me.
I got the rssi value in hex but I the rssi value in dBm.
How can I convert the rssi value from hex to dbm?

Thank you.
 

Offline Kyrul

  • Contributor
  • Posts: 13
  • Country: my
Re: WSNDemo tutorial
« Reply #16 on: May 16, 2017, 10:18:27 AM »
Here is the code:

Code: [Select]
char hex[] = "123456789abcdef";

put_string(rssi_tag);
HAL_UartWriteByte(hex[(ind->rssi>>4) & 0x0f]);
HAL_UartWriteByte(hex[ind->rssi & 0x0f]);
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 3270
  • Country: us
  • I informed you thusly
    • Personal site
Re: WSNDemo tutorial
« Reply #17 on: May 16, 2017, 10:36:46 AM »
Do you want to do that by hand, or in the code?

If by hand, then the value is just a negative number in two's complement form.

If from the code, then use itoa(), or snprintf(), or similar functions.
Alex
 

Offline Kyrul

  • Contributor
  • Posts: 13
  • Country: my
Re: WSNDemo tutorial
« Reply #18 on: May 16, 2017, 10:40:50 AM »
Hi Alex,

Thank you for your quick reply.
The function of itoa() will directly convert the hex to dbm or I need create the equation so the rssi value will in dbm?
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 3270
  • Country: us
  • I informed you thusly
    • Personal site
Re: WSNDemo tutorial
« Reply #19 on: May 16, 2017, 10:43:43 AM »
Hex is just a representation. itoa() will convert value of the argument into a decimal representation. It will essentially do what your code does, but in a decimal system.

RSSI value provided by the stack is already in dBm, so direct conversion will yield the correct number.
Alex
 

Offline Kyrul

  • Contributor
  • Posts: 13
  • Country: my
Re: WSNDemo tutorial
« Reply #20 on: May 16, 2017, 10:48:21 AM »

Thank you so much Alex.

Now I understand.

Thank you. :-+ :-+ :-+
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf