WSNDemo.c in Lightweight Mesh

Go To Last Post
143 posts / 0 new

Pages

  • 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

Pages