WSNDemo.c in Lightweight Mesh

Go To Last Post
143 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a few questions about the demonstration code for Lightweight Mesh.
Here are two functions:
HAL_UartBytesReceived and
HAL_UartWriteByte.

I not quite sure about the purpose of these two function. I don't know the UART communication is used for RS232 or for the transceiver itself.

Thanks if anyone can gives me some hints

Last Edited: Fri. Oct 16, 2015 - 01:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

UART is not used for transceiver at all. Those functions are used to receive and send application data over the UART, as it follows from their name.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

alexru wrote:
UART is not used for transceiver at all. Those functions are used to receive and send application data over the UART, as it follows from their name.

It seems like the UART function is used for control the FIFO. Am I right ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

FIFO buffers are used for UART communications, yes. But they still have nothing to do with the radio.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

alexru wrote:
FIFO buffers are used for UART communications, yes. But they still have nothing to do with the radio.

Thanks Alexru. By the way, I saw your video about the introduction of Lightweight Mesh. Are you the one who created the WSNDemo code for Lightweight Mesh?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've created everything in LwMesh.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

alexru wrote:
I've created everything in LwMesh.

The PDF file of "getting started" says the LwMesh SDK contains precompiled binary.

I searched the file entirely but found nothing related with precompiled binary.

Do you know where can I get these precompiled binary?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

They were not included in the package because it is very easy to create your own. In version v1.1.0 information about precompiled binaries was removed.

Just open a project for your platform from the application you like in Atmel Studio 6 and build your own binaries.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

alexru wrote:
They were not included in the package because it is very easy to create your own. In version v1.1.0 information about precompiled binaries was removed.

Just open a project for your platform from the application you like in Atmel Studio 6 and build your own binaries.

I think the default configuration for WSNDemo is coordinator type because the APP_ADDR is set to 0.

But when I connect my PC to the board and use WSNMonitor, noting displayed on the main panel. Does it mean I need to make further modifications in order to get my devices displayed on the WSNMonitor?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What board are you using? Have you checked Fuse settings?

It should just work if the hardware is set up correctly.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

alexru wrote:
What board are you using? Have you checked Fuse settings?

It should just work if the hardware is set up correctly.

I'm using STK-600 + ATMEGA128RFA1, I change the fuse bit based on the documentation provided by the SDK

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

STK600 requires to connect UART port pins to the on-board level shifter. Did you do that?

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

alexru wrote:
STK600 requires to connect UART port pins to the on-board level shifter. Did you do that?

Yeah, I'm using RS232. Sorry, I thought the fuse bit setting between BitCloud and Lightweight Mesh should be identical. But they are different. I change the fuse bit setting based on LwMesh SDK, it worked.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The only [important] difference is CKDIV8 bit and in the latest release of LwMesh it is no longer important, stack clears this bit. Download the latest version.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I'm trying to use WSNMonitor to learn about LW Mesh. I have programmed the coordinator with the correct fuses (provided by the SDK) and running the WSNDemo app. However, when I click on connect (on WSNMonitor), with the correct COM selected (and also correct speed 38400), I get the message Can't Connect, and sometimes, even this message doesn't appear. Please, do you have any other idea of what is happening? Thank You :D

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Operating system? Hardware platform?

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Alex. I am using my own hardware, that has an Atmega1281 and a AT86RF231, and the communication with the computer is made using Atmega8u2 connected to the Atmega1281 by UART. The computer recognizes the board as an Arduino Uno because it was made using the arduino schematics. My friend who developed the board hardware could read data through UART, using this board, so I guess the hardware is ok. I know that using the own hardware is not the ideal scenario, but it's for a university project. Thank you

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So it looks like WSNMonitor can't connect to the Xmega CDC. I have no idea how to solve this. It might be drivers that OS picked up for this device, or how Java interacts with those drivers.

Try to open this port in a terminal and see if you get any output that way.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I tried to do this, but I got nothing. I don't know how WSNMonitor works, but I have to find a way to read the data using the UART. I will keep working on that, thanks Alex

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you get nothing in the terminal, are you even sure that code in Xmega works correctly?

Before running WSNMonitor, make sure that you get something on a simple terminal.

A few things to check on the mega side:
1. HAL_UART_CHANNEL is set to a correct value.
2. Fuses are set correctly.
3. MCU and radio are connected correctly.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, sorry for delat to answer, I was travelling. HAL_UART_CHANNEL was wrong but I fixed it before posting here. Fuses I have setted accordingly to the guide of LWMESH:
Extended: FE
High: 9D
Low: C2
And about the connection between the mcu and the radio, I found the code to read a register from the radio (PART_NUM) and I have done (if value==3) where value is the value read from the register, the led is on. So.. the led went on.. so I think the connection is okay.. but it's still not working with WSNMonitor..

Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try to open corresponding COM port in the terminal first and see if you receive anything, then move on to WSNMonitor.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes.. I will do that.. if I have success I will let you know.. Thanks Alex

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alex, should WSNDemo application output anything to the UART after the MCU is reset or does it wait for an initial request from WSNMonitor?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I could estabilish a connection with port COM3, but nothing appears on screen.. :(

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alex, what should I get on the terminal when I connect to the COM port? what kind of information ? Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Usually it s a bunch of garbage characters, but if baudrate is set correctly, among those characters you will see a device name, for example "Coordinator" or "Router".

If you have only one device, then you will only see "Coordinator".

The good sign would be to see anything in a first place.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, for the first test i'm trying to see anything.. but it's not working.. I will try to solve this problem. Anyway, let me ask you something. I'm trying to study the code, but I ha ve seen this part:

#if defined(PLATFORM_RCB231)
DDRC = (1 << 4) | (1 << 6) | (1 << 7);
PORTC = (0 << 4) | (1 << 6) | (1 << 7);
#endif

why you configure those bits on port C ? I'm asking because I think maybe it can be important since I'm using a different hardware.

Thank you :D

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is for RCB board with RCB_BB extension boards. RCB_BB uses MAX232-like level shifter that has its pins connected to the MCU, so MCU needs to enable level shifter before use.

It is not likely that it affects you. RCB+RCB_BB is the only combination that I've seen that uses this method.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Humm.. So.. maybe I can comment this lines of code.
Thank you Alex, this LWMESH is a really good job, I'm impressed as long as I go studying the code haha I wish I could do something like that some day.

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alex, I tried to find a code to test only the Uart communication of my board. It worked.. I could write something and then see the echo in the terminal.. but when I use the WSNdemo code I don`t get anything on the HyperTerminal.. maybe I have to change something in the UART configuration of this code.. I will try :D

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you sure it is an echo from the device and not a local echo from the terminal?

Can you post your test code?

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, I`m not sure, but I think it is right. I just used the source code from this article: http://www.appelsiini.net/2011/s...

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The only change that I have done is change F_CPU to 8 instead of 16

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You should start from setting HAL_UART_CHANNEL to 0 (default is 1).

Also note baudrate difference (38400 vs. 9600).

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I did this change (HAL_UART_CHANNEL 0) in the config.h file .
About the baud rate, if I put 9600 on WSNDemo code it will generate a problem, no ? On hyper terminal, a connected using 38400 when running WSNDemo.. I will try one more time. Thanks a lot Alex

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alex.. one little thing.. where is defined the value of F_CPU in the code? I searched the information but I couldn't find.. Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is defined in the project settings or in the Makefile, depending on what system you are using to build the application.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am using Atmel Studio 6.1 on windows 7. Do you think I have to use the option "Use external makefile" when compiling the code?

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, just look in the existing project settings. There will be a section with compiler definitions.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks. About that problem on UART, I'm running the code with debbuger, step by step, and the code is getting stucked on this part:

void HAL_TimerDelay(uint16_t us)
{
PRAGMA(diag_suppress=Pa082);

OCR4B = TCNT4 + us;
if (OCR4B > OCR4A)
OCR4B -= OCR4A;

halTimerDelayInt = 0;
TIMSK4 |= (1 << OCIE4B);
while (0 == halTimerDelayInt);
TIMSK4 &= ~(1 << OCIE4B);

PRAGMA(diag_default=Pa082);
}
the application does not exit from that while condition.. it seems it stays forever in that condition. So I think that is the reason why WSNMonitor does not recognize the board.. because the code is not running to the end.. or, maybe I'm wrong.. I don't know very much about this

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try a newer version of the stack. I don't know any specific reason why this code won't work for you, but the new one is different and it might just solve the problem.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, I promise I will try to stop bothering here :) but I'm kind of running out of time. I'm using version LwMesh_1_1_1 . I will try to use a newer version though, if this one is not the newer. I'm trying to understand the code.. some parts I don't understand. For example, I'm reconfigured de LED0 Port.. to fit on my pins.. so LED0 is conected on Port A2 on my mcu, I did:

#if defined(PLATFORM_RCB231)
HAL_GPIO_PIN(LED0, A, 2);

but the led is not turning on (the led is working, I have tested with another simples code). So when I checked the LedOn method:

INLINE void HAL_LedOn(uint8_t i)
{
if (0 == i)
HAL_GPIO_LED0_clr();

.. and this method erases the bit, not activate. Maybe I'm understanding it wrong because I'm a begginer.. Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ahh! now I see that version 1.2 has been launched.. I will take a look on it! Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

renanmrg wrote:
I'm using version LwMesh_1_1_1.
The most recent one is v1.2.0.

renanmrg wrote:
.. and this method erases the bit, not activate. Maybe I'm understanding it wrong because I'm a begginer..
And that is why this code is located in a board-specific part. On RCB boards LED's anode is connected to +3.3v and cathode is connected to the MCU. So control is high for LED OFF and low for LED ON.

If your board uses different LED connection, then you will also have to change '_clr' to '_set' and vise versa.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh.. I didn't think about it.. you are totally right! I will do this.. Thanks, and sorry for bothering too much :D

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Omg!! The UART now is working!! I can see Coordinator written on hyper terminal, and also the led is working too with the change clr to set!! I can't believe it! haha Thanks Alex :D

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now the coordinator appears on screen. I configured one board with Adress 0x0001, so is a router. It appears on screen too, and a gray line between the router and the coordinator is shown, it works fine. But I configured another board as router too, adress 0x0002, it appears on screen, but no gray line and after about 20 seconds it disappears, but the led indicating that the board is connected keeps on, without blinking... do you have any idea why this second router is disappearing ? Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

renanmrg wrote:
do you have any idea why this second router is disappearing ?

Run that second router under the debugger. and see what it is doing.

The gray line will only appear on the second report, so it does not look like that second report is happening. Device sends one frame and then just hangs.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Humm ok.. I will try this. but I'm almost sure it's a hardware problem, soldering this small components at home is really dificult.. I will also try to check the solder.. Thanks :D

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

On the previous version of the stack, I would have assumed hardware problem instantly. This behavior is indication of the interrupt malfunction. On the new stack interrupt line is not used, so it is harder to blame the hardware. But it still might be something like power supply problem.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I will try new batteries and check the solder.. because it doesn't make sense not working, because the first board has exactly the same configuration, just the adress was changed.. and it's working fine

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alex, I don't know if you can help with this.. and I even don't know if it is the correct topic for it, but taking advantage that we were already talking about this, it is worth trying. The situation is.. I have the coordinator, it works fine.. appears on WSNMonitor, and I also have 3 boards that are configures as routers.. board 0x0001 0x0002 and 0x0003.. they have exactly the same hardware (including the coordinator).. So, when I put the battery.. board 3 connects just after plugin the battery... and the led keeps on, indicating connection was done and it also appear on WSNMonitor. The thing is, boards 1 and 2 just keep blinking and don't connect... I know it's a hard question but.. do you have any idea what's going on? the mcu and transceiver are communicating... and I used a spectrum analyzer to see if any RF signal are emitted by the boards.. and it's ok.. they are emitting. The only parts in the hardware are mcu, transceiver, the oscillator, and some capacitors that shows on AT86RF231 datasheet.... Thanks :D

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would say that you need a debugger and have a look at the status code returned in the appNwkDataConf() function. After that it should be possible to track back to the reason for that status code.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh.. I have a debugger.. I will try to do that and compare with the same status code returned on the board that works fine.. Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is no need to compare. On the board that works fine the status is going to be SUCCESS (0). Just let me know what the status is on the board that is not working.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm trying to use the search tool to find insert the break point (in Entire Solution) but AtmelStudio returned that no entry was found :(

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't understand what do you mean.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry I wrote wrong.. I searched the function appNwkDataConf on AtmelStudio search tool, to insert the break point to use the debbug.. but this function couldn't be found on the code, I don't know why

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't blindly use search, use logic. The function is called appDataConf() and located in the application, as name would suggest.

You always need to go back from the observed behavior. In your case it is "LED does not go steady". Then start looking for something that makes it blink. By doing so you will end up in that function.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes.. that's true.. I'm worried about time, I'm afraid I can't do this on time, that I couldn't see the logic.. I will work on it and post here what I find out.. thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry Alex, I can't run the debugger because the device is not reading the correct voltage of mcu... it's showing 1.1V but when I put the multimeter it shows 2.6V.. maybe it's a soldering problem, I will try to fix that .. thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now I could run it.. I used watch on this var appState = APP_STATE_SENDING_DONE; and inserted a break point exactly on this line of code.. so I run the debug and before this line, the value of appState is APP_STATE_WAIT_CONF and after this part it becomes APP_STATE_SENDING_DONE .. I don't know if is this what you told me to do.. Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You need to check the value of req->status in the appDataConf().

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Alex.. I don't know if this is a good test, but in this part of code:

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

I have inserted a break point on the first if condition, what I think it is "if connection was successful, enter in the first if, if not, then execute the else command" right ?
So, I went step by step debugging, and on the board that works fine, the debug goes into the if condition if (!appNetworkStatus), so.. it's working.... But on the boards that are not connecting.. the debbug goes into the else.. so they are running different..

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And when watching the value of req->status:
On the board that works:
req->status = 0

On the board that doesn't works:
req->status = 17;

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

17 is NWK_NO_ROUTE_STATUS (0x11). What settings do you have in your configuration file?

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The standard configuration.. I have just made this changes:
#define APP_ADDR 0x0001
and I also have uncommented this line

#define NWK_ENABLE_ROUTE_DISCOVERY

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

renanmrg wrote:
and I also have uncommented this line
#define NWK_ENABLE_ROUTE_DISCOVERY

Well, have you uncommented it on all other devices in the network?

All devices in the network must use the same route discovery mechanism.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I did that.. I first uploaded the code to the coordinator with this lines uncommented, and after that I programmed all boards just changing the address

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First of all, check if how it works without NWK_ENABLE_ROUTE_DISCOVERY.

Debugging AODV discovery without a sniffer might be hard.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So I shall comment again this lines on the coordinator and the boards right? I will do this now

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Same thing, it didn't work.. I just don't understand why board 3 works fine.. And also the hardware of boards 1 and 2 seems to work fine.. I used a spectrum analyser.. and they are emitting RF signal... is possible to emit RF signal and the transceiver is not working? Thanks Alex

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It does not matter if it works or not. What is the status code?

Also, can you show pictures of your boards, antennas, schematics.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When running the debugger with Route Discovery disabled, the code seems to be stucked somewhere, so I couldn't get the status code on the router, just on the coordinator and it was 16... Also.. I uploaded the hardware schematic and board:
Schematic: https://dl.dropboxusercontent.co...

Board: https://dl.dropboxusercontent.co...

Just a note.. on the schematic it's showing Mega128A.. but I have replaced by Atmega1281.. that's because it's and old schematic..
Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

renanmrg wrote:
When running the debugger with Route Discovery disabled, the code seems to be stucked somewhere, so I couldn't get the status code on the router,
Well, that's time to find out where. It will probably lead you to a reason.

renanmrg wrote:
just on the coordinator and it was 16...
Coordinator is not sending the data, it is impossible to get a status code on the coordinator.

As far as schematic goes, I don't think you need C3. And of course, it is always possible that antenna is not matched.

But you need to take care of that loop first.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wasn't responsible for the antenna development.. my friend did that, and a teacher helped him, I think it's not the ideal antenna but it works since board 3 can connect at a good distance.... Yes.. I will try to find out why board 3 is not stucked and works fine and board 1 and 2 are stucked.. I hope it works :D thanks a lot Alex

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Theoretical design of the antenna is just a start. After it is implemented, antenna has to be tuned and matched.For tuning a good design helps, but does not guarantee a success on a first try. Matching depends on the components used, quality of soldering and other external factors that cannot be predicted at design time.

But all this usually does not matter no short distances and won't cause device to freeze.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Huum.. it must be hard to develop a good antenna.. but since I don't need a big distance, there's no problem if they work close to each other.. I just need to find out why some boards works and others don't.. Now I have 3 boards that can connect.. and 2 that can't..

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alex, as you said.. on the boards that doesn't work, the req->status is 17, which I can see on the code that means NWK_NO_ROUTE_STATUS.. it means this board can't find the route? or can't "see" the coordinator.. or something like that? Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have read this on the manual:
Then node should create a new entry in the Route Discovery Table with parameters from the current data transmission
request. If the Route Discovery Table is full and a new entry cannot be added, then data transmission request should be
confirmed with NWK_NO_ROUTE_STATUS status.

So, maybe it is not creating and entry on the router discovery table, but I don't know why since there is only one board turned on. Maybe I should program the coordinator again with a bigger router discovery table ?

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

On a high level, it can't find the route. This process consists of sending a request and receiving a response. Any of there can fail.

Without route discovery, device will send a broadcast request and wait for an ACK. This lets you check the system part by part. If C will receive the frame, it means that transmitter is working. If R won't receive an ACK, it means that receiver is broken.

If some error status code is returned, then it will tell exactly how any of them is broken.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Huum.. Thanks, I will try to disable route discovery and try again to debug :D

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried to debbug with Route Discovery disabled, and the debbuger seems do be stucked in this part of the code:

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

I don't think it means the Tx has a problem, because I think before sending this random datas, the board sends another code to sink or something like that.. maybe I'm wrong

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah! It was the transceiver... Although it seems to work, I replaced it and now board 1 is working too :D

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is no way to get stuck in this code even in theory. There is no loops here or in called rand() functions.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I see.. but I clicked next step and the debugger does not advance to the next step.. but now that I changed the transceiver board 1 it's working.. I will try the same with board 2 :D

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now they are all working! Thanks Alex... I think they are working fine now. In the end it was a hardware problem. In WSNMonitor each node has this kind of lamp that when you click it turns yellow. Like in this print screen that I have taken: https://dl.dropboxusercontent.co... ..
what is this for? haha Thanks.. now I'm going to read all the SDK manual to learn how to develop my application..

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is lamp sends a command to the node and it blinks. In the current version of WSNDemo it is not supported. It is supported in the next version, which I just submitted for review, so it should hit the web within a week or two.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Huum, since my board has only 1 led I think I cannot see it, but the code I will try to do involves sending a command to a node.. so maybe I can see how it works.. but it is for the next weeks.. firts I have to read the manual as I said.. thanks :D

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Alex.. I'm reading about the 2 routing algorithms.. Native and AODV, let just me ask you a opinion... which one you think is better for a small network? about 5 nodes? The only requirement is that the network has to be self organized.. Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For small node count (let's say less than 20) it does not really matter, they both will works almost the same. For larger networks AODV is better.

If it does not make any difference for your application, use AODV, since it is better in theory.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Huum.. yes.. thanks :)

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there any place where I can find a graphical explanation of AODV, like the one for Native Routing on developer's guide? I'm trying to create one based on what I understood reading the AODV Routing, but I'm not sure my understading is correct. Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alex, on AODV I'm not sure about something.. is there one Route Discovery Table for each node or just one for the whole process of discovering ? I have read the page many times and I still can't be sure... Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

renanmrg wrote:
Is there any place where I can find a graphical explanation of AODV, like the one for Native Routing on developer's guide?

Here you go.

Comments to slides about AODV:

Numbers on the links show LQI of a link
We will focus on the node 0, the rest of them behave similarly

Step 1:
Numbers on the arrows - /.
Route Discovery is a local broadcast frame, each node creates a new Route Request frame with updated LQ information.

Node 0 sends out a Route Discovery Request frame with LQ set to 255, since it is an original frame.
Nodes 1, 3 and 4 receive this frame and update LQ value based on the received LQ and LQI of the received frame.

Step 2:
Nodes 1 and 3 send a Route Discovery Request with updated LQ value
Node 4 sends a Route Discovery Response to the node 0 with a final LQ of the route 0-4.
Node 0 receives the response and updates Route Discovery Table

Step 3:
Node 2 send a Route Discovery Request with updated LQ value
Node 4 sends a Route Discovery Response to the node 3 with a final LQ of the route 0-3-4.

Step 4:
Node 4 sends a Route Discovery Response to the node 2 with a final LQ of the route 0-1-2-4.
Node 3 routes a Route Discovery Response for the route 0-3-4.
Node 0 receives this response and updates its Route Discovery Table since LQ in the response is higher than LQ in the table.

Step 5:
Node 2 routes a Route Discovery Response for the route 0-1-2-4.

Step 6:
Node 2 routes a Route Discovery Response for the route 0-1-2-4.
Node 0 receives this response and does not update its Route Discovery Table since LQ in the response is lower than LQ in the table.
Route discovery is complete. Route 0-3-4 was selected as the most optimal.
Information from the Route Discovery Response is transferred into the Routing Table.

Attachment(s): 

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

renanmrg wrote:
is there one Route Discovery Table for each node or just one for the whole process of discovering ?
There is one RD Table on each node. It contains a number of records, one for each new discovery process.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Huum, I think now I can understand everything.. Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also, AODV is not specific to LwMesh. It is a well-described protocol - see RFC 3561. Frame formats are obviously different, but the idea is the same.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So... it means in AODV once the best route is selected it never changes right? So, let's say the nodes change their physical location, is better to use native routing algorithm right ?

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

renanmrg wrote:
So... it means in AODV once the best route is selected it never changes right?
It never changes if there is no need to, so it is not "optimized".

renanmrg wrote:
So, let's say the nodes change their physical location, is better to use native routing algorithm right ?
Both algorithms will behave them in this case - they will wait until route is declared dead and perform a new discovery.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Also, AODV is not specific to LwMesh. It is a well-described protocol - see RFC 3561. Frame formats are obviously different, but the idea is the same.

Ah.. I see, I studied a little bit of RFC in the past.. I will take a look again

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alex, what really is an EndPoint on the stack context?

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you mean "endpoint" in data request parameters, then it is a logical address of the application inside the device. Device might run multiple logical applications running in parallel. One might handle main traffic, another one might handle network discovery and commissioning, yet another one might be handling over the air updates.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's what Endpoint means in network header, the fields Source Endpoint and Destination Endpoint? And about this definition of endpoint con config file?
#define APP_ENDPOINT 1
Sorry, but I just have to be sure what I'm talking about.. Thanks Alex

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, it is. Most applications are so simple that they only need one endpoint. For more complex applications you will need more.

Note that EP=0 is reserved for stack commands and should not be used in the application.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Huum I see.. I will try to understand better this concept of Endpoint, it's new to me.. thanks again

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, if you like RFCs, endpoints are like ports in TCP or UDP.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Huum.. with this comparison it became much easier to understand.. thanks :D

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alex, if I develop my own application using the LwMesh SDK, let's say my application is for example, when I press a button on one of my nodes, a led blinks on my coordinator. If a write the code to do this task, Will I still be able to see the nodes on WSNMonitor ? Or WSNmonitor only works for WSNDemo application ? Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

WSNmonitor only works with WSNDemo. It displays stuff based on the information supplied by WSNDemo via a serial port. If you can mimic that information, it will display your network as well.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hum, Ok... I have to simulate a security system with the nodes, I mean, I have soldered a button on the nodes and my idea is when a press the button, let's say, on sensor 0x003 then led blue blinks on my coordinador ( I will solder pins and use a protoboard), when button is pressed on node 0x002, led orange blinks.. and goes on. But I would like to still be able to see the network topology on WsnMonitor, but for now is just an idea, I don't even know if it's possible to do this system. Thanks :D

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Of course it is possible. You need a very simple modification to the WSNDemo program. In the data indication on the coordinator check the source address of the sending device and light an LED accordingly. Everything else will work as it worked before.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I was think exactly this, doing a simple modification.. Although for my graduation project I just have to show that is possible to monitor an enviroment using wireless sensors, I would like to know how to do more complex application because I'm really enjoying this. Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Alex, just a theorical question, to check my thoughts.. why AODV is better with a greater number of nodes? That's because once the route is estabilished it does never change (unless necessary due to node problem of course) so the traffic is not "flooded" with routing process every time ? Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, both algorithms remember discovered routes. Run-time optimizations in the native algorithm will lead to longer routes. Even with AODV it is not unusual to see 2-3 hops for devices located in one room. With native algorithm it gets even worse.

Over a long time AODV will stabilize on shorter routes and ideally no route discoveries will be done. Native on the other hand will always tend to "optimize" towards longer routes.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah.. I understand, thanks for the awesome explanation :D

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Alex, I'm trying to develop that code that I told yo, but for now is just a sketch. I am trying to understand how to receive and process data. Let me tell you I have done and if you can, please tell me if I'm on the correct way.

on appInit(), I added this line:
#if APP_COORDINATOR
NWK_OpenEndpoint(APP_ENDPOINT_COORD, appDataIndCoord);
#endif //where APP_ENDPOINT_COORD defined as 2

and under the appDataInd, I created appDataIndCoord function, as follows:

static bool appDataIndCoord(NWK_DataInd_t *ind)
{
NWK_DataInd_t *msg = ind;

DDRC |= (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5);

if(msg->srcAddr == 0x0001){
PORTC |= (1<<5);
_delay_ms(1000);
PORTC |= ~(1<<5);
}

return true;
}

This is the correct idea? or I understand wrong? Thanks a lot

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry to ask, but, since my hardware is "homemade" I am afraid that if I reprogram many times to test, It will broke down.. so I'm trying to make as few mistakes as possible

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

'ind' already has type NWK_DataInd_t, there is no need for 'msg', just use ind->srcAddr.

Delaying for a second like this will work for a test, but should not be done in a real application.

I don't understand how you can break the hardware with reprogramming. Guaranteed Flash endurance is 10000 erase/write cycles. And it is much higher at a room temperature. I can not imagine anyone exceeding this limit. Even if you will reprogram your board every second, it will take about a week to reach that limit.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, but I don't know why, when I try to program let's say for 3 or 4 times, Atmel Studio starts to read the wrong voltage, or says it was unable to enter in the programming mode.
I would ask you exactly this, about this delay.. I suppose it might cause some problems because it stops the processor just to blink the LED... so I was thinking to use interruption, but I don't know how to work with interuption yet.. I will have to learn.. thanks :D

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But the main idea is correct right? To open an endpoint with number 2 and write a new corresponding appDataInd for that EndPoint ?

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't see why you would need to open another endpoint for this application, but there is no harm in doing that. Overall the idea is correct.

It is better to fix the hardware or get the one that works. You won't learn much by guessing, only by doing.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes I think so, I have plans to do that, after finishing this project, but for now I have a deadline, so I have to hurry, and import this kind of hardware to my country is quite expensive, besides, I don't have time to wait them to arrive :( Thanks.. I will keep trying here

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alex, on the router nodes..I should handle the button that I want to press to blink onde led on coordinator as a interruption? Otherwise I was thinking to put the code "if button == 1" etc inside appSendData() but somethings tells me that it's not a good idea, because it will only work if the code is processing that part of code.. no? Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I did not understand any of this.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Haha.. Sorry, I was excited when writting... the question is.. the place there I have seen where Nodes sends data, is the function appSendData(), I need to send another data, different from Light Temperature, etc.. I want to send one frame containing let's say number 1 (just to make coordinator check the srcAdress and flash de LED corresponding to node 1). But this frame has to be sended only when I press the button on my node. Should I write this code inside appSendData() or a new function? haha sorry, I'm trying now

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please, Let me just say what I've done and if possible give your opinion. I have created another appSendData() function called appSendDataButton() and the only change was the Endpoint, I have setted as 2 (because on appDataIndCoord I am using another end point.. 2)

nwkDataReq.dstEndpoint = APP_ENDPOINT_COORD;
nwkDataReq.srcEndpoint = APP_ENDPOINT_COORD;

and then on the switch case that controls the state machine, I have added:

case APP_STATE_SEND:
appSendData();

#if APP_ROUTER
DDRA |= (0<<3); //set PortA Pin 3 as input
PORTA |= (1<<3); //set pull up resistor
if((PINA & (1<<3))==0) //where button is connected
appSendDataButton();
#endif

} break;

I think it's not the best way to implement this, since this way I have to press the button exactly when the code is on the if clause.. but even though is not working, but I don't know if it's problem on the code that sends or the code on de coordinator that receives... Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Check how button read is implemented in the SimpleRemote application.

This code, if run, will cause nwkDataReq to be used twice before waiting for the confirmation. If at any point in time you want to send two requests in parallel, then you need to have two different NWK_DataReq_t structures. Alternatively you can introduce a flag that indicates if structure is busy and won't allow double use.

Why are you looking at the button state only in the SENDING state? It will make more sense to look in a WAIT state.

"DDRA |= (0<<3);" does absolutely nothing, but pin is an input by default, so it should work. I'd recommend using macros from halGpio.h to do GPIO operations.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Huum, yeah, I didn't understand very well about APP_STATE_WAIT_CONF, I mean, I didn't find yet exactly where it changes appState to a new state...
I will use macros from halGpio.h it's really better, and I will also take a look at the application that you suggested.
Can I send 2 differents NWK_DataReq_t structures inside appSendData?

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

APP_STATE_WAIT_CONF denotes that request is pending and application is waiting confirmation. Confirmation function is appDataConf(), which changes state to the next one.

You really need to understand how state machines and even-driven design work. Until you do, you won't be able to write sensible applications. At least you need to have a clear understanding of WSNDemo sate machine.

The state application spends mode of the time in is APP_STATE_WAIT_SEND_TIMER. And that's the state where it makes sense to wait for a button press.

Quote:
Can I send 2 differents NWK_DataReq_t structures inside appSendData?
Yes, but from application design point of view it does not make much sense.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm really trying to understand the state machine.. I know without understand it I will not be able to do what I want. But some parts I couldn't understand very well yet... like when appDataConf is called, and then the state is changed to APP_STATE_SENDING_DONE in the end. So, ok.. and then? the program should go back to appSendData where appState is changed to APP_STATE_WAIT_CONF later.. and then I can't see where appState is changed again to another state.. But it's not fait to ask explanation about this.. I shall study and find out... Thanks Alex

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

renanmrg wrote:
So, ok.. and then?

Then handler for this state is executed:

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

End device goes to sleep, router starts a timer and goes to a timer waiting state.

Then timer callback (appDataSendingTimerHandler) is called and it transitions application into a APP_STATE_SEND state.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's why I was not understanding.. I didn't know what time callback handler was for (SYS_TimerStart(&appDataSendingTimer);)..
it like when appState = APP_STATE_SENDING_DONE, then after a time appDataSendingTimer is called and the state is changed to APP_STATE_SEND again.. that's it ? Thanks

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

renanmrg wrote:
I didn't know what time callback handler was for
It is not hard to find in the code:

  appDataSendingTimer.handler = appDataSendingTimerHandler;

renanmrg wrote:
that's it ? Thanks
Yes.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I could find it, but I couldn't guess what was it for, I'm not very advanced in microprogramming, I'm a beginner.. Thanks Alex.. I will study more and try to do the modifications

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah.. it's kinda of working now... it's blinking the led on coordinator.. although I have done it in the most correctly way.
I have done this:

static void appDataSendingTimerHandler(SYS_Timer_t *timer)
{
  uint8_t buttonState = HAL_GPIO_BUTTON_read();
	
  if (APP_STATE_WAIT_SEND_TIMER == appState)
	if(buttonState==0)
	  appState = APP_STATE_SEND_BUTTON;
        else
	  appState = APP_STATE_SEND;
  else
    SYS_TimerStart(&appDataSendingTimer);

  (void)timer;
}

and created a new state:

case APP_STATE_SEND_BUTTON:
	{
         appSendDataButton();
	}break;

I Think it's not perfect because, it's not all the times that I press the button that the led flashes on coordinator, so it might be due to delay of transmission, or the code wasn't on the part that read the button when I pressed.

Renan Margon

Computer Engineer

Last Edited: Thu. Apr 3, 2014 - 04:40 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please use code tags around your code, otherwise it is unreadable.

This is a very strange code. It will only sample button on the timer boundary. Usually button presses should be handled at the moment of pressing, not on some relatively long timer edge.

You also need to put braces properly in the conditions. Right now logic is not correct for what it supposed to do,

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes.. It's strange haha although is the only when I can think now, but of course I will try to do better.
I don't know the best place to put the code to read the button, I will think more about it...
And, you are right, the logic is wrong, I forgot to put braces.. Thanks :D

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alex, just for understand a bit more.. this function

static void appDataSendingTimerHandler(SYS_Timer_t *timer)

it's kind of keep running in parelallel with the code checking every time if appState = APP_STATE_WAIT_SEND_TIMER ?

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, this function is called after a specified time interval. Nothing in the system runs in parallel.

"If" condition in the function is there to prevent invalid state machine transition. Normally by the time it is called appState will always be APP_STATE_WAIT_SEND_TIMER.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah.. I understand now :D.. now is working.. the 4 leds on coordinator are Toggling when I press the button on each node :D Thanks very much Alex...
IT's working, although I might find a better place to read the buttonState.. because sometimes I have to hold the button for it to send the frame.. or maybe is just because I haven't done any process of debounce on the button...

Renan Margon

Computer Engineer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How can we use HAL_UartWriteByte() function to write a float value to the UART