-
Implementing WiFi-Direct in Arduino library WiFi101
05/17/2016 at 11:17 • 3 commentsAtmel website says that the chip WINC1500 supports WiFi-Direct. The WiFi101 software library that comes with Arduino IDE has no API that indicate WiFi-Direct support. The first step is to add WiFi-Direct functionality into WiFi101 library.
I forked the WiFi101 on github and soon discovered that the file WiFi.cpp is the best place to implement the additional APIs needed to connect to WiFi-Direct. I added the follwing APIs:
/* * Start Wifi as P2P device. P2P is also known as Wi-Fi Direct. * * param name: Set your device name which will be shown in the peer device. * param channel: Wifi channel to use. Valid values are 0, 5 and 10. * */ uint8_t beginP2P(const char *name); uint8_t beginP2P(const char *name, uint8_t channel);
This follows the same design pattern as the other APIs for configuring WiFi in station mode or Access Point mode.
There is already an infrastructure in place to handle callbacks. I reused the same logic and implemented the WiFi-Direct API. I added a new example to demonstrate how to connect to WiFi-Direct, it is:
#include <WiFi101.h> char name[] = "wifi101-p2p"; // P2P device name void setup() { // attempt to connect to Wifi-Direct: if ( WiFi.beginP2P(name) != WL_CONNECTED) { // don't continue: while (true); } // you're connected now, so print out the data: printCurrentNet(); printWifiData(); } void loop() { // communicate normally }
When I coded everything and ran it, it did not connect. On investigation it turned out that I cannot use channel values between 1 to 12 as is the case for Access Point mode. The only allowed channel values are 0, 5 and 10. On using the correct channels it worked like a charm. Please see the connection dialog from Android below:
You can find the updated library and working example at github https://github.com/asadziach/WiFi101