Author Topic: Lwmesh Cordinator Data Receive  (Read 1429 times)

0 Members and 1 Guest are viewing this topic.

Offline PeiliTopic starter

  • Regular Contributor
  • *
  • Posts: 108
  • Country: in
Lwmesh Cordinator Data Receive
« on: January 25, 2021, 03:31:31 am »
Hi,
I have 8 routers which send data with 1sec delay. Coordinator receives data from these routers. But some times the data from routers are Mixed up. At the Coordinator side i used to write the Receiving packets using the function
Code: [Select]
static bool appDataInd(NWK_DataInd_t *ind)
{

for (uint8_t i = 0; i < ind->size; i++)
HAL_UartWriteByte(ind->data[i]);

return true;

}
but data are mixing with one another.
For example data from Router 1 is
"ID_1001_00.003_0.04_2.5*"
and Data from Router 2 is
"ID_1008_TS_2.5*".
But at the receiving side of coordinator the data received like
 "ID_1001_00ID_1008_TS_2.5*.003_0.04_2.5*".
i don't know why this happening. Please help me to solve this.  Please help me. here I'm Attaching my code for Coordinator(WSNDemoC.c) and Router(WSNDemoR.c)
« Last Edit: January 25, 2021, 03:45:33 am by Peili »
 

Offline PeiliTopic starter

  • Regular Contributor
  • *
  • Posts: 108
  • Country: in
Re: Lwmesh Cordinator Data Receive
« Reply #1 on: January 25, 2021, 04:09:49 am »
Anyone have idea about this. please help me to solve this. This type of Mixing up Data never faced. So please help me to solve this.
« Last Edit: January 25, 2021, 04:14:15 am by Peili »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11286
  • Country: us
    • Personal site
Re: Lwmesh Cordinator Data Receive
« Reply #2 on: January 25, 2021, 04:41:30 am »
It is pretty obvious. You are setting the flag on the first byte you receive from the UART. So the packet is sent as soon as execution gets to appSendData(). So the data from one router is split into two frames, and another router may send its frame between the frames from the first device.

You need to wait for the whole data to be received. For example have a timeout  that you reset every time you receive a character. If there is no new character in 100 ms, for example, then set the flag to send the whole buffer.
Alex
 
The following users thanked this post: Peili

Offline PeiliTopic starter

  • Regular Contributor
  • *
  • Posts: 108
  • Country: in
Re: Lwmesh Cordinator Data Receive
« Reply #3 on: January 27, 2021, 09:21:44 am »
here I'm checking some delimiters in my data.
For example if the character is "*", then need to write all the characters to UART.( in coordinator side)
Code: [Select]

static bool appDataInd(NWK_DataInd_t *ind)
{


for (uint8_t i=0;i<ind->size;i++)
{
if(ind->data[i]==0x40)
{
atvalue=i;
checkflag=1;
break;
}
}

if(checkflag==1)
{
for (uint8_t k=atvalue;k<ind->size;k++)
{
appDataRFBuffer[appRFBufferPtr++]= ind->data[k];
if(ind->data[k]==0x2A)
{
rfflag=1;
break;
}

}
}
if(rfflag==1)
{
for (uint8_t j=0;j<appRFBufferPtr;j++)
{
HAL_UartWriteByte(appDataRFBuffer[j]);
}

}
checkflag=0;
appRFBufferPtr=0;
rfflag=0;
atvalue=0;
return true;
}



also in Router side I'm checking if "*" then send the packet to Coordinator.
Code: [Select]
void HAL_UartBytesReceived(uint16_t bytes)
{
for (uint16_t i = 0; i < bytes; i++)
{
uint8_t byte = HAL_UartReadByte();
HAL_UartWriteByte(byte);

if (appUartBufferPtr < sizeof(appUartBuffer))
appUartBuffer[appUartBufferPtr++] = byte;
if(byte==0x2A)
{
flag=1;
break;
}

}


  }

Code: [Select]
static void appSendData(void)
{
#ifdef NWK_ENABLE_ROUTING
  msg.parentShortAddr = NWK_RouteNextHop(0,0);
#else
  msg.parentShortAddr = 0;
#endif

  //msg.sensors.battery     = rand();
  msg.sensors.temperature = rand() & 0x7f;

   if(flag==1){
memcpy(appDataReqBuffer, appUartBuffer, appUartBufferPtr);
int brkflag=0;
int i=0,j=0,a=5;
for(i=0;i<appUartBufferPtr;i++)
{
appDataReqBuffer[j]=appUartBuffer[i];
if(appUartBuffer[i]==0x23)
{

break;
}
j++;


}
//}
int k=j;
appUartBufferPtr=k;


nwkDataReq.dstAddr=a;
    nwkDataReq.dstEndpoint = APP_ENDPOINT;
    nwkDataReq.srcEndpoint = APP_ENDPOINT;
    nwkDataReq.options = NWK_OPT_ACK_REQUEST | NWK_OPT_ENABLE_SECURITY;
    nwkDataReq.data =appDataReqBuffer;//(uint8_t *)&msg; //appDataReqBuffer;//
    nwkDataReq.size =appUartBufferPtr;//sizeof(msg); //appUartBufferPtr;//sizeof(msg);
    nwkDataReq.confirm = appDataConf;
    appUartBufferPtr=0;
    flag=0;
 
  NWK_DataReq(&nwkDataReq);

  appState = APP_STATE_WAIT_CONF;
  }
   else
  appState=APP_STATE_SENDING_DONE;
}


attaching my code. But now also data mixing up occurs
« Last Edit: January 27, 2021, 09:29:24 am by Peili »
 

Offline PeiliTopic starter

  • Regular Contributor
  • *
  • Posts: 108
  • Country: in
Re: Lwmesh Cordinator Data Receive
« Reply #4 on: January 27, 2021, 09:34:20 am »
It is pretty obvious. You are setting the flag on the first byte you receive from the UART. So the packet is sent as soon as execution gets to appSendData(). So the data from one router is split into two frames, and another router may send its frame between the frames from the first device.

You need to wait for the whole data to be received. For example have a timeout  that you reset every time you receive a character. If there is no new character in 100 ms, for example, then set the flag to send the whole buffer.



Is this checking cause error? I have 8 routers which send continuously data. All routers send packets in the same format
@ID_001_Xg_-0.00_-0.00_-0.00_-0.00_-0.00_-0.00_-0.00_-0.00_-0.00_0.00_*
So " @ " the starting and  "  *  " is ending delimiter.


Where to add those timeout? Coordinator receives data from 8 routers at same time. How can i set that timeout here?
« Last Edit: January 27, 2021, 10:00:06 am by Peili »
 

Offline PeiliTopic starter

  • Regular Contributor
  • *
  • Posts: 108
  • Country: in
Re: Lwmesh Cordinator Data Receive
« Reply #5 on: January 27, 2021, 01:28:57 pm »
I found that at receiving side, ie, Coordinator side, the whole packet is not receiving some times.
Around 40 byte of data is sending from Nodes to Coordinator at a time.
Is that is the issue?
i tried to send
"@_A_B_C_D_E_F_G_H_I_J_K_L_M_N_O_P_Q_R_S_T_U_V_W_X_Y_Z_1_2_3_4_5_6_7_8_9*
from Router to Coordinator continuously .
At the Coordinator side it receive like

"@_A_B_C_D_E_F_G_H_I_J_K_L_M_N_O_P_Q_R_S_T_U_V_W_X_Y_Z_1_2_3_4_5_6_7_8_9*"
@_A_B_C_D_E_F_G1_2_3_4_5_6_7_8_9*
@_A_B_C_D_E_F_G_H_I_J_K_L_M_N_O_P_Q_R_S_T_U_V_W_X_Y_Z_1_2_3_4_5_6_7_8_9*
@_A_B_C_R_S_T_U_V_W_X_Y_Z_1_2_3_4_5_6_7_8_9*
 

Offline PeiliTopic starter

  • Regular Contributor
  • *
  • Posts: 108
  • Country: in
Re: Lwmesh Cordinator Data Receive
« Reply #6 on: January 27, 2021, 03:20:10 pm »
Is this related to Payload size? or receiver side UART problem?
Please help me to solve this
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11286
  • Country: us
    • Personal site
Re: Lwmesh Cordinator Data Receive
« Reply #7 on: January 27, 2021, 05:16:03 pm »
NWK_DataReq() is atomic. It either sends everything or nothing. Your appDataInd() code is a complete mess and I have no desire to read it, no idea what it tries to do. It should not be necessary to have any of those loops.

In the HAL_UartBytesReceived() you need to check that request buffer is not currently busy (flag=0). Otherwise the same code would be called on the next iteration of the task loop.

Why don't you just debug this?
Alex
 

Offline PeiliTopic starter

  • Regular Contributor
  • *
  • Posts: 108
  • Country: in
Re: Lwmesh Cordinator Data Receive
« Reply #8 on: January 27, 2021, 05:39:30 pm »
Now i changed my code to Orginal Lwmesh. Just use Router to read and send packet to Cordinator.
WSNDemoC.c is Cordinator and WSNDemoR.c is Router.
Router send packet to Coordinator. but some junk charcters in data at receiving side. and also data packet is missing.
In the router side device write data to uart as FLOAT. and my Router read uart and send that to Coordinator.
this is the data format
@ID_001_Xg_-0.00_-0.00_-0.00_-0.00_-0.00_-0.00_-0.00_-0.00_-0.00_0.00_*

but using without any condition or loops i have issue with receiving
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11286
  • Country: us
    • Personal site
Re: Lwmesh Cordinator Data Receive
« Reply #9 on: January 27, 2021, 05:44:00 pm »
I don't understand any of that. What junk characters?

Again, have you tried to DEBUG anything at all?
Alex
 

Offline PeiliTopic starter

  • Regular Contributor
  • *
  • Posts: 108
  • Country: in
Re: Lwmesh Cordinator Data Receive
« Reply #10 on: January 27, 2021, 05:46:00 pm »
Yes i debug that.
@ID_001_Xg_-0.00_-0.00_-0.00_-0.00_-0.00_-0.00_-0.00_-0.00_-0.00_0.00_*
this is the data dens from Router .But at receiver side it receives as
@ID_001_Xg_-0.00_-0.00_-0.00_-0.00_-$%0_-0.00_-0.00_-0.00_-0.00_0.00_*
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11286
  • Country: us
    • Personal site
Re: Lwmesh Cordinator Data Receive
« Reply #11 on: January 27, 2021, 05:47:48 pm »
Do you receive it this way in the data indication function or on the serial port? You may have baudrate issues, for example.
Alex
 

Offline PeiliTopic starter

  • Regular Contributor
  • *
  • Posts: 108
  • Country: in
Re: Lwmesh Cordinator Data Receive
« Reply #12 on: January 27, 2021, 05:56:12 pm »
Do you receive it this way in the data indication function or on the serial port? You may have baudrate issues, for example.
yes in the appDataind() function write data to UART.
Code: [Select]
static bool appDataInd(NWK_DataInd_t *ind)
{
  AppMessage_t *msg = (AppMessage_t *)ind->data;

  HAL_LedToggle(APP_LED_DATA);

  msg->lqi = ind->lqi;
  msg->rssi = ind->rssi;

  appUartSendMessage(ind->data, ind->size);

  if (APP_CommandsPending(ind->srcAddr))
    NWK_SetAckControl(APP_COMMAND_PENDING);

  return true;
}

my router Baudrate is 9600 and Coordinator Baud Rate is 38400.

When i change my Router packet as
@ID_008_OT_23.78*
no  problem with receiving side.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11286
  • Country: us
    • Personal site
Re: Lwmesh Cordinator Data Receive
« Reply #13 on: January 27, 2021, 05:58:15 pm »
This does not answer the question. Do you see the data corrupted when you stop the debugger in appDataInd()?

I don't care what happens on UART.

If the data is fine in appDataInd(), then something is wrong with your UART. Get the scope and check the baudrate.
Alex
 

Offline PeiliTopic starter

  • Regular Contributor
  • *
  • Posts: 108
  • Country: in
Re: Lwmesh Cordinator Data Receive
« Reply #14 on: January 27, 2021, 06:01:28 pm »
Do you see the data corrupted when you stop the debugger in appDataInd()?

Sorry i didn't understand with Debugger?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11286
  • Country: us
    • Personal site
Re: Lwmesh Cordinator Data Receive
« Reply #15 on: January 27, 2021, 06:03:09 pm »
Do you have an actual debugger tool? What is your development process?
Alex
 

Offline PeiliTopic starter

  • Regular Contributor
  • *
  • Posts: 108
  • Country: in
Re: Lwmesh Cordinator Data Receive
« Reply #16 on: January 27, 2021, 06:04:39 pm »
I Don't have any tools. I'm just confirming with UART. When appDataInd Receives and then write to UART
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11286
  • Country: us
    • Personal site
Re: Lwmesh Cordinator Data Receive
« Reply #17 on: January 27, 2021, 06:05:20 pm »
How do you program the devices?
Alex
 

Offline PeiliTopic starter

  • Regular Contributor
  • *
  • Posts: 108
  • Country: in
Re: Lwmesh Cordinator Data Receive
« Reply #18 on: January 27, 2021, 06:06:19 pm »
I'm using ATMEGA256RFR2. devices are programming using AVR Dragon via Atmel Studio
« Last Edit: January 27, 2021, 06:08:35 pm by Peili »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11286
  • Country: us
    • Personal site
Re: Lwmesh Cordinator Data Receive
« Reply #19 on: January 27, 2021, 06:11:08 pm »
Dragon support debugging as far as I know. So use Atmel Studio and start and actual debugging session, setup some breakpoints and do actual debugging.

It is possible to get by without the debugger, but it is a skill you need to develop, and I can't help you here.

If you want to debug things like this without a debugger, just check in the indication function that payload does not contain any garbage characters and toggle a pin if ti does. If pin does not toggle, but you see garbage on the output, then the issue is with the UART output.


Alex
 
The following users thanked this post: Peili

Offline PeiliTopic starter

  • Regular Contributor
  • *
  • Posts: 108
  • Country: in
Re: Lwmesh Cordinator Data Receive
« Reply #20 on: January 28, 2021, 07:48:34 am »
Fixed garbage character issue. thank you. it was due to Baud Rate .
But still i have Mixing Up of data.
i can't figure out where I'm getting these issues.
Some packets receiving correctly and some packets are Mixing
 

Offline PeiliTopic starter

  • Regular Contributor
  • *
  • Posts: 108
  • Country: in
Re: Lwmesh Cordinator Data Receive
« Reply #21 on: January 28, 2021, 07:51:02 am »
Sometimes the received packet write to Coordinator correctly. But some time missing of characters and mixing up is occurring.
Code: [Select]

/**
 * \file WSNDemo.c
 *
 * \brief WSNDemo application implementation
 *
 * Copyright (C) 2012-2014, Atmel Corporation. All rights reserved.
 *
 * \asf_license_start
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * 3. The name of Atmel may not be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * 4. This software may only be redistributed and used in connection with an
 *    Atmel microcontroller product.
 *
 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * \asf_license_stop
 *
 * Modification and other use of this code is subject to Atmel's Limited
 * License Agreement (license.txt).
 *
 * $Id: WSNDemo.c 9267 2014-03-18 21:46:19Z ataradov $
 *
 */

/*- Includes ---------------------------------------------------------------*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "config.h"
#include "hal.h"
#include "phy.h"
#include "sys.h"
#include "nwk.h"
#include "nwkRoute.h"
#include "nwkSecurity.h"
#include "sysTimer.h"
#include "halUart.h"
#include "halSleep.h"
#include "halBoard.h"
#include "halLed.h"
#include "commands.h"

/*- Definitions ------------------------------------------------------------*/
#if defined(APP_COORDINATOR)
  #define APP_NODE_TYPE     0
#elif defined(APP_ROUTER)
  #define APP_NODE_TYPE     1
#else
  #define APP_NODE_TYPE     2
#endif

#define APP_CAPTION_SIZE    (sizeof(APP_CAPTION) - 1)
#define APP_COMMAND_PENDING 0x01

#define APP_ENDPOINT        1

#define APP_LED_NETWORK     0
#define APP_LED_DATA        1

/*- Types ------------------------------------------------------------------*/
typedef struct PACK
{
  uint8_t      commandId;
  uint8_t      nodeType;
  uint64_t     extAddr;
  uint16_t     shortAddr;
  uint32_t     softVersion;
  uint32_t     channelMask;
  uint16_t     panId;
  uint8_t      workingChannel;
  uint16_t     parentShortAddr;
  uint8_t      lqi;
  int8_t       rssi;

  struct PACK
  {
    uint8_t    type;
    uint8_t    size;
    int32_t    battery;
    int32_t    temperature;
    int32_t    light;
  } sensors;

  struct PACK
  {
    uint8_t    type;
    uint8_t    size;
    char       text[APP_CAPTION_SIZE];
  } caption;
} AppMessage_t;

typedef enum AppState_t
{
  APP_STATE_INITIAL,
  APP_STATE_SEND,
  APP_STATE_WAIT_CONF,
  APP_STATE_SENDING_DONE,
  APP_STATE_WAIT_SEND_TIMER,
  APP_STATE_WAIT_COMMAND_TIMER,
  APP_STATE_PREPARE_TO_SLEEP,
  APP_STATE_SLEEP,
  APP_STATE_WAKEUP,
} AppState_t;
static void appSendData(void);
/*- Variables --------------------------------------------------------------*/
static AppState_t appState = APP_STATE_INITIAL;
#define APP_BUFFER_SIZE     NWK_MAX_PAYLOAD_SIZE
#if defined(APP_ROUTER) || defined(APP_ENDDEVICE)
static NWK_DataReq_t appNwkDataReq;
static SYS_Timer_t appNetworkStatusTimer;
static SYS_Timer_t appCommandWaitTimer;
static bool appNetworkStatus;
#endif

static AppMessage_t appMsg;
static SYS_Timer_t appDataSendingTimer;
static uint8_t appDataReqBuffer[255];
static uint8_t appUartBuffer[255];
static uint8_t appUartBufferPtr = 0;
static uint8_t flag=0;
/*- Implementations --------------------------------------------------------*/

/*************************************************************************//**
*****************************************************************************/
void HAL_UartBytesReceived(uint16_t bytes)
{
 for (uint16_t i = 0; i < bytes; i++)
  {
    uint8_t byte = HAL_UartReadByte();
    if (len(bytes)==0)
flag=1;
    //if (appUartBufferPtr == sizeof(appUartBuffer))
      //appSendData();

    if (appUartBufferPtr < sizeof(appUartBuffer))
      appUartBuffer[appUartBufferPtr++] = byte;
   
  }

}

/*************************************************************************//**
*****************************************************************************/
static void appUartSendMessage(uint8_t *data, uint8_t size)
{
  uint8_t cs = 0;

  //HAL_UartWriteByte(0x10);
  //HAL_UartWriteByte(0x02);

  for (uint8_t i = 0; i < size; i++)
  {
    if (data[i] == 0x10)
    {
//      HAL_UartWriteByte(0x10);
      cs += 0x10;
    }
    HAL_UartWriteByte(data[i]);
    cs += data[i];
  }

//  HAL_UartWriteByte(0x10);
  //HAL_UartWriteByte(0x03);
  cs += 0x10 + 0x02 + 0x10 + 0x03;

//  HAL_UartWriteByte(cs);
}

/*************************************************************************//**
*****************************************************************************/
static bool appDataInd(NWK_DataInd_t *ind)
{
  AppMessage_t *msg = (AppMessage_t *)ind->data;

  HAL_LedToggle(APP_LED_DATA);

  msg->lqi = ind->lqi;
  msg->rssi = ind->rssi;

  appUartSendMessage(ind->data, ind->size);

  if (APP_CommandsPending(ind->srcAddr))
    NWK_SetAckControl(APP_COMMAND_PENDING);

  return true;
}

/*************************************************************************//**
*****************************************************************************/
static void appDataSendingTimerHandler(SYS_Timer_t *timer)
{
  if (APP_STATE_WAIT_SEND_TIMER == appState)
    appState = APP_STATE_SEND;
  else
    SYS_TimerStart(&appDataSendingTimer);

  (void)timer;
}

#if defined(APP_ROUTER) || defined(APP_ENDDEVICE)
/*************************************************************************//**
*****************************************************************************/
static void appNetworkStatusTimerHandler(SYS_Timer_t *timer)
{
  HAL_LedToggle(APP_LED_NETWORK);
  (void)timer;
}

/*************************************************************************//**
*****************************************************************************/
static void appCommandWaitTimerHandler(SYS_Timer_t *timer)
{
  appState = APP_STATE_SENDING_DONE;
  (void)timer;
}
#endif

/*************************************************************************//**
*****************************************************************************/
#if defined(APP_ROUTER) || defined(APP_ENDDEVICE)
static void appDataConf(NWK_DataReq_t *req)
{
  HAL_LedOff(APP_LED_DATA);

  if (NWK_SUCCESS_STATUS == req->status)
  {
    if (!appNetworkStatus)
    {
      HAL_LedOn(APP_LED_NETWORK);
      SYS_TimerStop(&appNetworkStatusTimer);
      appNetworkStatus = true;
    }
  }
  else
  {
    if (appNetworkStatus)
    {
      HAL_LedOff(APP_LED_NETWORK);
      SYS_TimerStart(&appNetworkStatusTimer);
      appNetworkStatus = false;
    }
  }

  if (APP_COMMAND_PENDING == req->control)
  {
    SYS_TimerStart(&appCommandWaitTimer);
    appState = APP_STATE_WAIT_COMMAND_TIMER;
  }
  else
  {
    appState = APP_STATE_SENDING_DONE;
  }
}
#endif

/*************************************************************************//**
*****************************************************************************/
static void appSendData(void)
{
#ifdef NWK_ENABLE_ROUTING
  appMsg.parentShortAddr = NWK_RouteNextHop(0, 0);
#else
  appMsg.parentShortAddr = 0;
#endif

  appMsg.sensors.battery     = rand() & 0xffff;
  appMsg.sensors.temperature = rand() & 0x7f;
  appMsg.sensors.light       = rand() & 0xff;

#if defined(APP_COORDINATOR)
  //appUartSendMessage((uint8_t *)&appMsg, sizeof(appMsg));
  SYS_TimerStart(&appDataSendingTimer);
  appState = APP_STATE_WAIT_SEND_TIMER;
#else
if(flag==1)
{
  memcpy(appDataReqBuffer, appUartBuffer, appUartBufferPtr);
appDataReqBuffer[appUartBufferPtr+1]=0x23;
  appNwkDataReq.dstAddr = 0;
  appNwkDataReq.dstEndpoint = APP_ENDPOINT;
  appNwkDataReq.srcEndpoint = APP_ENDPOINT;
  appNwkDataReq.options = NWK_OPT_ACK_REQUEST | NWK_OPT_ENABLE_SECURITY;
  appNwkDataReq.data = appDataReqBuffer;
  appNwkDataReq.size = appUartBufferPtr;
  appNwkDataReq.confirm = appDataConf;
appUartBufferPtr = 0;
  HAL_LedOn(APP_LED_DATA);
  NWK_DataReq(&appNwkDataReq);

  appState = APP_STATE_WAIT_CONF;
}
else
appState = APP_STATE_SENDING_DONE;
#endif
}

/*************************************************************************//**
*****************************************************************************/
static void appInit(void)
{
  appMsg.commandId            = APP_COMMAND_ID_NETWORK_INFO;
  appMsg.nodeType             = APP_NODE_TYPE;
  appMsg.extAddr              = APP_ADDR;
  appMsg.shortAddr            = APP_ADDR;
  appMsg.softVersion          = 0x01010100;
  appMsg.channelMask          = (1L << APP_CHANNEL);
  appMsg.panId                = APP_PANID;
  appMsg.workingChannel       = APP_CHANNEL;
  appMsg.parentShortAddr      = 0;
  appMsg.lqi                  = 0;
  appMsg.rssi                 = 0;

  appMsg.sensors.type        = 1;
  appMsg.sensors.size        = sizeof(int32_t) * 3;
  appMsg.sensors.battery     = 0;
  appMsg.sensors.temperature = 0;
  appMsg.sensors.light       = 0;

  appMsg.caption.type         = 32;
  appMsg.caption.size         = APP_CAPTION_SIZE;
  memcpy(appMsg.caption.text, APP_CAPTION, APP_CAPTION_SIZE);

  HAL_BoardInit();
  HAL_LedInit();

  NWK_SetAddr(APP_ADDR);
  NWK_SetPanId(APP_PANID);
  PHY_SetChannel(APP_CHANNEL);
#ifdef PHY_AT86RF212
  PHY_SetBand(APP_BAND);
  PHY_SetModulation(APP_MODULATION);
#endif
  PHY_SetRxState(true);

#ifdef NWK_ENABLE_SECURITY
  NWK_SetSecurityKey((uint8_t *)APP_SECURITY_KEY);
#endif

  NWK_OpenEndpoint(APP_ENDPOINT, appDataInd);

  appDataSendingTimer.interval = APP_SENDING_INTERVAL;
  appDataSendingTimer.mode = SYS_TIMER_INTERVAL_MODE;
  appDataSendingTimer.handler = appDataSendingTimerHandler;

#if defined(APP_ROUTER) || defined(APP_ENDDEVICE)
  appNetworkStatus = false;
  appNetworkStatusTimer.interval = 500;
  appNetworkStatusTimer.mode = SYS_TIMER_PERIODIC_MODE;
  appNetworkStatusTimer.handler = appNetworkStatusTimerHandler;
  SYS_TimerStart(&appNetworkStatusTimer);

  appCommandWaitTimer.interval = NWK_ACK_WAIT_TIME;
  appCommandWaitTimer.mode = SYS_TIMER_INTERVAL_MODE;
  appCommandWaitTimer.handler = appCommandWaitTimerHandler;
#else
  HAL_LedOn(APP_LED_NETWORK);
#endif

#ifdef PHY_ENABLE_RANDOM_NUMBER_GENERATOR
  srand(PHY_RandomReq());
#endif

  APP_CommandsInit();

  appState = APP_STATE_SEND;
}

/*************************************************************************//**
*****************************************************************************/
static void APP_TaskHandler(void)
{
  switch (appState)
  {
    case APP_STATE_INITIAL:
    {
      appInit();
    } break;

    case APP_STATE_SEND:
    {
      appSendData();
    } break;

    case APP_STATE_SENDING_DONE:
    {
#if defined(APP_ENDDEVICE)
      appState = APP_STATE_PREPARE_TO_SLEEP;
#else
      SYS_TimerStart(&appDataSendingTimer);
      appState = APP_STATE_WAIT_SEND_TIMER;
#endif
    } break;

    case APP_STATE_PREPARE_TO_SLEEP:
    {
      if (!NWK_Busy())
      {
        NWK_SleepReq();
        appState = APP_STATE_SLEEP;
      }
    } break;

    case APP_STATE_SLEEP:
    {
      HAL_LedClose();
      HAL_Sleep(APP_SENDING_INTERVAL);
      appState = APP_STATE_WAKEUP;
    } break;

    case APP_STATE_WAKEUP:
    {
      NWK_WakeupReq();

      HAL_LedInit();
      HAL_LedOn(APP_LED_NETWORK);

      appState = APP_STATE_SEND;
    } break;

    default:
      break;
  }
}

/*************************************************************************//**
*****************************************************************************/
int main(void)
{
  SYS_Init();
  HAL_UartInit(9600);

  while (1)
  {
    SYS_TaskHandler();
    HAL_UartTaskHandler();
    APP_TaskHandler();
  }
}







I'm using this code for Router and Coordinator.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11286
  • Country: us
    • Personal site
Re: Lwmesh Cordinator Data Receive
« Reply #22 on: January 28, 2021, 07:53:59 am »
Start by eliminating USRAT entirely and just sending the same fixed buffer filled with the same value from every device. Make the value different for each R.

On the C check that every frame that is received is filled with the same data. If it is the case, then you know that the issue is in a way USART formats and splits the data. This is easy enough to test. Just check the length of the received data on the C.


One other thing that is wrong with your original code. You are setting "flag = 0;" right after you call NWK_DataReq(), but the buffer is really free once confirmation callback is called.

And get the debugging to work. You clearly have no idea how to debug indirectly.
Alex
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf