Listen to CC3100 Events
응답
17. 7. 7 오전 5:36

Hello,
I'm using the XDK in Access Point mode and have hosted a TCP server on it. I am able to successfully connect my phone to the device and TCP server, and get sensor values from the XDK.


How do I listen to the event "SL_OPCODE_WLAN_STA_DISCONNECTED" which is sent by CC3100?
This would let me know if a client has disconnected from the Hotspot.

Thanks.

0 (0 투표)
RE: Listen to CC3100 Events
응답
17. 7. 7 오후 1:26 as a reply to Arati Mekaraj.

Hello Arati,

WLAN connection/disconnection events are asynchronous, and they require the implementation of a handler. After detailed examination on how and where the events are processed, I can you give you the following outline on what to do:

For this, I assume that you already have set the WiFi module to Access Point mode and I recommend to make a backup of your SDK before making any of the following changes, in case things go wrong. Also, after modifying the SDK, clean and rebuild the project, so that the changes are committed.

The first interesting thing you need to know is, that there is already an event handler that listens to the event-type you mentioned. You can find this event handler in your project in WlanConnect.c at the following location:

SDK > xdk110 > Platform > Wlan > source > WlanConnect

It's called WlanConnect_SLWlanEventHdlr and it is defined on line 264. You will notice, that the two event types this function handles are Connect Events or Disconnect Events. The WlanDisconnectCallback could be used to print information to the console, when disconnects occur.

But, so far the WlanDisconnectCallback is only modified by the function WlanConnect_Disconnect(). But as the name suggests, that function's purpose is not only setting the disconnect-callback, but also actually disconnecting. I'm not sure about the side-effects of this function when the XDK is running in Access Point mode for WiFi, but I assume that it will not behave as intended, if the function is called. It seems that the API was only intended for use in cases where the XDK itself tries to connect to hotspots.

Now, you also notice that the Disconnect Events additionally sets the status of two variables that concern networking and wlan. But, as I assume that you are working with the underlying simplelink API, and not with the higher level WlanConnect API, these two might not affect the application, which makes it possible to reuse the already implemented event handler.

The downside of this is, that you have to implement an interface to set your own disconnect-callback. Additionally, the Disconnect Callback will be limited in such a way, that it cannot access all the information that the disconnect-event actually includes. Additional information could be Mac-addresses of the devices that disconnected, or the reason for disconnect (manual disconnect, or an error). The Disconnect-Callback can only accept one status as input.

Alternatively, you can modify the Event Handler in such a way, that it checks whether the XDK is running in Access Point mode. If it is not, the old implementation of the callback is executed. If it is in AP mode, your new custom event handling is executed.

Pseudo Code:
void WlanConnect_SLWlanEventHdlr(SlWlanEvent_t *pWlanEvents){
  if(AP_mode) {
    handle events
  } else {
    old implementation
  }
}

Of course, you can also change the body of the function entirely, but keep in mind that changes you make in the SDK also propagate to all other projects.

Finally, you can find some information on how to access event data, especially concerning disconnect and connect events, in the file simplelink.h on lines 780 to  851, which is located in

SDK > xdk110 > Library > WiFi > TI > simplelink > include.

Please tell me know if this was helpful, and do not hesitate to ask if you have further questions.

Kind regards,
Franjo

0 (0 투표)
RE: Listen to CC3100 Events
응답
17. 7. 10 오전 4:50 as a reply to Franjo Stjepandic.

Hello Franjo,

For now, I have commented out the Event Handler which in implemented in WlanConnect.c and made my own implementation in my source file. I'll uncomment it if I have to use the device in Station mode.
For now, it works as intended!

Thanks a lot for your really detailed answer, it solved my problem of a long time!

0 (0 투표)
RE: Listen to CC3100 Events
응답
17. 7. 10 오전 11:56 as a reply to Arati Mekaraj.

Hello Arati,

I glad to hear that I could help you with that.

Additionally, since you chose the option of implementing your own handler, I recommend to do the following, to avoid always commenting/uncommenting the function you don't require:

In user.h on line 967, located at

SDK > xdk110 > Platform > Wlan > include

the TI module is essentially told what function to use for handling Wlan Connection Events. You can replace that line with

#ifdef CUSTOM_WLAN_HANDLER
#define sl_WlanEvtHdlr                                Custom_SLWlanEventHdlr
#endif
#ifndef CUSTOM_WLAN_HANDLER
#define sl_WlanEvtHdlr                              WlanConnect_SLWlanEventHdlr
#endif

This will tell the compiler that it should use the function Custom_SLWlanEventHdlr, if CUSTOM_WLAN_HANDLER is defined. The last step will be to insert #define CUSTOM_WLAN_HANDLER in your implementation.

This should help separate the standard function from custom implementations.

Please tell me if this was helpful and do not hesitate to ask if you have further questions.

Kind regards,
Franjo

0 (0 투표)