WSNDemo tutorial - Page 1
Forum section: electronics / beginners

author: Kyrul
author_rank: Contributor
timestamp: April 21, 2017, 10:12:25 am
content: 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-bookIs it Wireless Product Development same as LWMesh Developer Guide?

author: ataradov
author_rank: Super Contributor
timestamp: April 21, 2017, 04:37:45 pm
content: 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?

author: Kyrul
author_rank: Contributor
timestamp: April 26, 2017, 01:13:51 am
content: 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?RegardKy

author: ataradov
author_rank: Super Contributor
timestamp: April 26, 2017, 01:20:09 am
content: Quote from: Kyrul on April 26, 2017, 01:13:51 amDatasheet 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.Quote from: Kyrul on April 26, 2017, 01:13:51 amWhat makes you think that? The code there is from the standalone version, the thread is started way before LwMesh was a part of ASF.Quote from: Kyrul on April 26, 2017, 01:13:51 amThe thread is way too long to read, and covers too many topics. What exactly you want to do?

author: Kyrul
author_rank: Contributor
timestamp: April 26, 2017, 02:00:14 am
content: QuoteActually 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?

author: ataradov
author_rank: Super Contributor
timestamp: April 26, 2017, 02:03:42 am
content: Quote from: Kyrul on April 26, 2017, 02:00:14 amLook at Peer2Peer application, it sends data over a serial port.Quote from: Kyrul on April 26, 2017, 02:00:14 amThis 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.

author: Kyrul
author_rank: Contributor
timestamp: April 26, 2017, 02:10:53 am
content: Thank you Alex.I try writing the code first and if I still can make it Ill ask you again.Thank you again AlexKy

author: Kyrul
author_rank: Contributor
timestamp: April 26, 2017, 03:14:32 am
content: 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.

author: ataradov
author_rank: Super Contributor
timestamp: April 26, 2017, 03:19:38 am
content: Quote from: Kyrul on April 26, 2017, 03:14:32 amHere is one from more or less recent BitCloud SDK, since it is no longer available for downloadhttps://www.dropbox.com/s/qe9342fu5g7rw56/WSNMonitor_Setup_2.2.1.93.exe?dl=0Quote from: Kyrul on April 26, 2017, 03:14:32 amThere 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.

author: Kyrul
author_rank: Contributor
timestamp: April 26, 2017, 03:24:20 am
content: Thank you so much Alex.

author: Kyrul
author_rank: Contributor
timestamp: April 27, 2017, 02:44:17 am
content: Hai again Alex,For the WSNDemo can combine with Peer2Peer application?

author: ataradov
author_rank: Super Contributor
timestamp: April 27, 2017, 02:47:25 am
content: Quote from: Kyrul on April 27, 2017, 02:44:17 amIt 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.

author: Kyrul
author_rank: Contributor
timestamp: May 09, 2017, 01:31:34 am
content: 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:#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:#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;}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();}}

author: ataradov
author_rank: Super Contributor
timestamp: May 09, 2017, 02:08:06 am
content: 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.

author: Kyrul
author_rank: Contributor
timestamp: May 09, 2017, 02:25:45 am
content: Thank you Alex,I will do the correction and read the documentation about Peer 2 peer application.

author: Kyrul
author_rank: Contributor
timestamp: May 16, 2017, 12:17:19 am
content: 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.

author: Kyrul
author_rank: Contributor
timestamp: May 16, 2017, 12:18:27 am
content: Here is the code:Code:char hex[] = "123456789abcdef";put_string(rssi_tag);HAL_UartWriteByte(hex[(ind->rssi>>4) & 0x0f]);HAL_UartWriteByte(hex[ind->rssi & 0x0f]);

author: ataradov
author_rank: Super Contributor
timestamp: May 16, 2017, 12:36:46 am
content: 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.

author: Kyrul
author_rank: Contributor
timestamp: May 16, 2017, 12:40:50 am
content: 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?

author: ataradov
author_rank: Super Contributor
timestamp: May 16, 2017, 12:43:43 am
content: 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.

author: Kyrul
author_rank: Contributor
timestamp: May 16, 2017, 12:48:21 am
content: Thank you so much Alex.Now I understand.Thank you.