uart communication between zigbee devices

Hi,

I'm trying to write a program which uses wireless XBee uart communication between microcontrollers to identify the location of a user within a residence. The user wears a tag (lets call it the blind node since position is initially unknown), there are tags within each room (fixed nodes) which have state info indicating which room they are associated with, and the PC has a wireless USB device which listens for new state info and displays it via software. The current setup is: 1) the blind node sends the byte "1" (2) the nearest fixed node (hopefully only one) sends back a"C" followed by the state info to the blind node (3) the blind node sends the byte "A" (4) and finally, the software gets the state from the blind node.

That's how its supposed to work in theory. However, it takes a considerably long time for the software to receive an "A" even though it is being sent multiple times. In addition, it intermittently receives an "A" as the state variable instead of the expected numerical value which is sent after the "A" is received. Additionally, when switching between fixed nodes, the software does not detect the change in state and continues to display the same state or the default ("A").

Here's the C++ code for the PC software

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
try
            {
                textBoxCommStatus->Text = "Waiting...";
                state = _serialPort->ReadChar();
                if(state == 'A')
                {
                    _serialPort->DiscardInBuffer();       //discard any characters currently //being received
                    _serialPort->Write(buffer, 0, 1);  //let blind node know that an A has been //received
                   
                    //do
                    //{
                    Sleep(100);
                    state = _serialPort->ReadChar();   //read the current position of the blind //node
                    //_serialPort->Write(buffer, 0, 1);
                    //} while(state < 49 || state > 52 || state == 0);

                    _serialPort->DiscardOutBuffer();
                    textBoxCommStatus->Text = "Comm Established";
                    //_serialPort->WriteLine("H");
                    if(!((state >= 49 && state <= 52) || state == 0))  //assign state to              //previous state if its not 1-4 or 0
                        state = prev_state;
                    //textBoxCommStatus->Text = _serialPort->ReadLine();
                    //textBoxCommStatus->Text = _serialPort->ReadLine();
                    //state = _serialPort->ReadChar();
                    if(state != prev_state)
                    {
                        switch(state)
                        {
                            case KITCHEN:
                            {
                                pictureBoxUserIcon->Location = Point(70,50);
                                break;
                            }
                            case LIVING_ROOM:
                            {
                                pictureBoxUserIcon->Location = Point(260,50);
                                break;
                            }
                            case BATHROOM:
                            {
                                pictureBoxUserIcon->Location = Point(200,200);
                                break;
                            }
                            case BEDROOM:
                            {
                                pictureBoxUserIcon->Location = Point(70,200);
                                break;
                            }
                            default:
                            {
                                pictureBoxUserIcon->Location = Point(0,0);
                                break;
                            }
                        }
                        prev_state = state;
                    }
               
                   
                }

            }
            catch(TimeoutException^ ex)
            {
                 textBoxCommStatus->Text = "Waiting for data.";
            }
        }

Its difficult to explain without a demonstration, but basically I need to find a more robust and responsive method of wireless communication between multiple devices, so that there is always a clear idea of who is talking to who at each point in time. Please let me know if you have any ideas for improving this scheme.

Thanks in advance,
Mike
Topic archived. No new replies allowed.