Protocol

Every four seconds, the application running on the megaAVR sends out an UDP packet on port 6789 to the broadcast address 255.255.255.255. This packet consists of a predefined buffer, which is also known by the Android application.
/** Key buffer - must match with Android app */
uint8_t key_buf[] = KEY_BUFFER;

This makes the Android application able to distinguish between UDP broadcast packets from the demo application and any other broadcasts on the network. Broadcasts that matches the key buffer will be added to the list of available devices the Android application displays after a scan.

The megaAVR will open a TCP socket to listen for incoming requests as soon as it is connected to the Wi-Fi. When the IP address of a device is pressed in the Android application, it will connect to the Xplained Mini via a TCP socket on port 1234, and send a message including the word "toggle", which is the keyword the megaAVR will look for when receiving messages on the TCP socket. When this is received by the megaAVR, it will toggle the LED and the toggle pin. When this is done, it will send a confirmation message back to the Android application. If this message is not received, or any other error occurs during the transmission, the Android application will highlight the IP address with a red box, indicating that something went wrong.