jefffhaynes / XBee

A .NET library for XBee wireless controllers
MIT License
40 stars 17 forks source link

Please help... #21

Closed bshowket closed 7 years ago

bshowket commented 7 years ago

Hi Jeff, Thanks for this lib, i am planning to use this for for my project. I am familiar with xbee/zigbee and how this work. I have a mesh network where i use only api frame packet to send to node/end device to coordinator or vise-versa. I can successfully receive data by this below:

private static async void Run()
        {
            _xbee = await XBeeController.FindAndOpenAsync(SerialPort.GetPortNames(), 115200);

            _xbee.DataReceived += _controller_DataReceived;
            //await node.TransmitDataAsync(Encoding.UTF8.GetBytes("hi here is some data"));
            //await node.TransmitDataAsync(Encoding.UTF8.GetBytes("Hello!"));
        }

        private static void _controller_DataReceived(object sender, SourcedDataReceivedEventArgs e)
        {
            Console.WriteLine("CReceived: {0}", ((e.Address).LongAddress));
            Console.WriteLine("recevied from: " + sender.ToString());
            Console.WriteLine("Data Received: {0}", Encoding.UTF8.GetString(e.Data));

        }

But struggling to simply send a packet, I was just wondering if you can show me what would be the best practice to get:

Type of received data frame? send frame using different packet frame, such as 0x10, 0x11 with Long address or broadcast?

Thanks for your help, and keep up the good work.

update: forget to mention the coordinator is ZigBeeS2.

Now i am able to send and receive the package using of your example as below. I wasn't able at the start because of router(A0=1) was configured as Explicit mode. when i use "TransmitDataAsync", data was ignored by router (as received data was no Explicit addressing command mode (0x11)). after change back to A0=0, received raw data as below:

{'options': b'\x01', 'id': 'rx', 'source_addrlong': b'\x00\x13\xa2\x00@\xaf\xb7', 'source_addr': b'\x00\x00', 'rf_data': b'hi here is some data'}

private static async void _xbee_Run(string whatToSend, ulong xbeeAddress)
        { _xbee = new XBeeController();
            var _xbee = await XBeeController.FindAndOpenAsync(SerialPort.GetPortNames(), 115200);
            if (_xbee != null)
            {
                var node = await _xbee.GetRemoteNodeAsync(new NodeAddress(new LongAddress(xbeeAddress)));
                await node.TransmitDataAsync(Encoding.UTF8.GetBytes(whatToSend), true);
                _xbee.DataReceived += _xbee_DataReceived;
                 node.DataReceived += Node_DataReceived;
             )
            else{ ................. }

Sorry for the noob question, if i receive a new packet by _xbee.Datareceive, i want to send some Data to another Xbeenode. how can i handle this? how can i get a new instance of _xbee.GetRemoteNodeAsync? Thanks for your help!

jefffhaynes commented 7 years ago

Sorry, I haven't had a chance to look at this yet. I'll try to get to it this weekend. Thanks.

bshowket commented 7 years ago

Thanks, no rush at all.

jefffhaynes commented 7 years ago

If I'm understanding correctly, you should be able to call GetRemoteNodeAsync from inside your DataReceived handler. Are you not able to? Can you post what you're trying?

bshowket commented 7 years ago

I have few xbee 2S(zigbee, API 2 with escape). 1xcoordinator and rest all router. Coordinator connected to connected to PC. And all router connected to RPI(use xbee-python lib). Coordinator read data and type of frame and reply (0x11, or broadcast) some data back.

bshowket commented 7 years ago

All I am trying to do is connect my xbee, read incoming packet and send data using different type of frame.

jefffhaynes commented 7 years ago

Ok, I thought your original comment said that you were ok not using explicit framing. I don't have support for 0x10 or 0x11 in the library right now. I can add them, I'm just trying to understand the use case. For example, the only difference between 0x00 and 0x10 is the ability to specify additional options. Can you tell me what options you need in 0x10? Similarly, what are the features you need that are provided in 0x11?

Thanks

bshowket commented 7 years ago

Ah.... ha. sorry I didn't make myself clear and didn't know that library don't support 0x10, 0x11. I am not sure why other people use this frame. As the payload is limited in size, I send different frameID, clusterID, frame Type to use as an tool for parsing and sending the data to right method. such as, frameID(auto generated for each packet) to confirm receive from application level. ClusterID for different group of router, so when server broadcast something, I can set particular ClusterID to get attention of the group i want to listen. There could be better way to do what i am using this frame type for, not sure.

jefffhaynes commented 7 years ago

I understand. Ok, let me see if I can work them into the API.


I much prefer the sharpest criticism of a single intelligent man to the thoughtless approval of the masses - Johannes Kepler


From: bshowket notifications@github.com Sent: Sunday, April 30, 2017 5:08:01 PM To: jefffhaynes/XBee Cc: Jeff Haynes; Comment Subject: Re: [jefffhaynes/XBee] Please help... (#21)

Ah.... ha. sorry I didn't make myself clear and didn't know that library don't support 0x10, 0x11. I am not sure why other people use this frame. As the payload is limited in size, I send different frameID, clusterID, frame Type to use as an tool for parsing and sending the data to right method. such as, frameID(auto generated for each packet) to confirm receive from application level. ClusterID for different group of router, so when server broadcast something, I can set particular ClusterID to get attention of the group i want to listen. There could be better way to do what i am using this frame type for, not sure.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/jefffhaynes/XBee/issues/21#issuecomment-298257211, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJSKR3WCZGmyTfYO3mN5nm3Ip0-gJeHLks5r1PgxgaJpZM4NFKKQ.

bshowket commented 7 years ago

Thanks!!!

jefffhaynes commented 7 years ago

I just realized it does support 0x10 for devices that support it and will automatically default to that. I'll look at adding 0x11.


I much prefer the sharpest criticism of a single intelligent man to the thoughtless approval of the masses - Johannes Kepler


From: bshowket notifications@github.com Sent: Sunday, April 30, 2017 5:12:29 PM To: jefffhaynes/XBee Cc: Jeff Haynes; Comment Subject: Re: [jefffhaynes/XBee] Please help... (#21)

Thanks!!!

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/jefffhaynes/XBee/issues/21#issuecomment-298257445, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJSKRw6IDJYaxKTfGGlVIWsL9N_50_FKks5r1Pk9gaJpZM4NFKKQ.

jefffhaynes commented 7 years ago

Ok, I added an overloaded TransmitDataAsync method that will send 0x11 in 4.1.1. Let me know if you have any problems with it.


I much prefer the sharpest criticism of a single intelligent man to the thoughtless approval of the masses - Johannes Kepler


From: Jeff Haynes feedyurhed@gmail.com Sent: Sunday, April 30, 2017 5:39:01 PM To: jefffhaynes/XBee; jefffhaynes/XBee Cc: Comment Subject: Re: [jefffhaynes/XBee] Please help... (#21)

I just realized it does support 0x10 for devices that support it and will automatically default to that. I'll look at adding 0x11.


I much prefer the sharpest criticism of a single intelligent man to the thoughtless approval of the masses - Johannes Kepler


From: bshowket notifications@github.com Sent: Sunday, April 30, 2017 5:12:29 PM To: jefffhaynes/XBee Cc: Jeff Haynes; Comment Subject: Re: [jefffhaynes/XBee] Please help... (#21)

Thanks!!!

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/jefffhaynes/XBee/issues/21#issuecomment-298257445, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJSKRw6IDJYaxKTfGGlVIWsL9N_50_FKks5r1Pk9gaJpZM4NFKKQ.

bshowket commented 7 years ago

Great!! Thanks.