Callbacks
Understanding when an event has triggered and what it means is essential for a connection. Therefore we have callbacks to notify you of this. There are 3 different callbacks in the network class:
Bluetooth callback - All bluetooth events go through here e.g. bonding success
WiFi callback - All WiFi events go through here e.g. HTTP connection success
Each one of these is talked about more thoroughly in their respective section.
When you receive data on one of your connections this will call the data callback. The data callback will pass the connection object that just received the data to your function.
Setting the callback
The data callback can be set using the set_data_cb() function. As mentioned above the function you pass to this needs to be able to have the parameter to receive a connection object.
network.set_data_cb(data_cb_func)
You can then set this up to get the data that you have just received:
def data_cb_func(connection_obj):
print("RECEIVED: {}".format(connection_obj.get_recent_data()))