diff --git a/WiFi/examples/wifi_Server_example_WEP/wifi_Server_example_WEP.pde b/WiFi/examples/wifi_Server_example_WEP/wifi_Server_example_WEP.pde new file mode 100644 index 000000000..5a74d235e --- /dev/null +++ b/WiFi/examples/wifi_Server_example_WEP/wifi_Server_example_WEP.pde @@ -0,0 +1,171 @@ +/* + WiFi Server example + + A simple connection with WiFi AP with Wireless Security + information try to access with WPA or WEP security keys + A simple server is setup to exchange data. + + created 13 July 2010 + by Domenico La Fauci + */ +#include +#include + +byte mac[6] = { 0 }; +IPAddress ip; +IPAddress gateway; +IPAddress subnet; +byte dataBuf[80] = { 0 }; +char ssid[32] = { 0 }; +int status = WL_IDLE_STATUS; +#define MAX_NUM_SSID 10 +char ssidList[MAX_NUM_SSID][32] = { {0} }; + + +Server server(23); + +void printIpData() +{ + ip = WiFi.localIp(); + + Serial.print("IP: "); + Serial.print(ip[3],10);Serial.print("."); + Serial.print(ip[2],10);Serial.print("."); + Serial.print(ip[1],10);Serial.print("."); + Serial.println(ip[0],10); + + subnet = WiFi.subnetMask(); + Serial.print("NETMASK: "); + Serial.print(subnet[3],10);Serial.print("."); + Serial.print(subnet[2],10);Serial.print("."); + Serial.print(subnet[1],10);Serial.print("."); + Serial.println(subnet[0],10); + + gateway = WiFi.gatewayIP(); + Serial.print("GATEWAY: "); + Serial.print(gateway[3],10);Serial.print("."); + Serial.print(gateway[2],10);Serial.print("."); + Serial.print(gateway[1],10);Serial.print("."); + Serial.println(gateway[0],10); + + WiFi.macAddress(mac); + Serial.print("MAC: "); + Serial.print(mac[5],16);Serial.print(":"); + Serial.print(mac[4],16);Serial.print(":"); + Serial.print(mac[3],16);Serial.print(":"); + Serial.print(mac[2],16);Serial.print(":"); + Serial.print(mac[1],16);Serial.print(":"); + Serial.println(mac[0],16); +} + +void printCurrNet() +{ + char* ssid = WiFi.SSID(); + Serial.print("SSID: "); + Serial.println(ssid); + + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + Serial.print(bssid[5],16);Serial.print(":"); + Serial.print(bssid[4],16);Serial.print(":"); + Serial.print(bssid[3],16);Serial.print(":"); + Serial.print(bssid[2],16);Serial.print(":"); + Serial.print(bssid[1],16);Serial.print(":"); + Serial.println(bssid[0],16); + + int32_t rssi = WiFi.RSSI(); + Serial.print("RSSI:"); + Serial.println(rssi,10); + + uint8_t enct = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(enct,16); +} + +void scanNetworks() +{ + Serial.println("** Scan Networks **"); + byte numSsid = WiFi.scanNetworks(); + if (numSsid > MAX_NUM_SSID) numSsid = MAX_NUM_SSID; + Serial.print("SSID List:"); + Serial.println(numSsid, 10); + for (int i = 0; i0) + { + dataBuf[idx]=0; + Serial.println((char*)&dataBuf[0]); + server.write((char*)&dataBuf[0]); + } + return; + } + } +} + + diff --git a/WiFi/examples/wifi_Server_example_WPA/wifi_Server_example_WPA.pde b/WiFi/examples/wifi_Server_example_WPA/wifi_Server_example_WPA.pde new file mode 100644 index 000000000..deacbbb23 --- /dev/null +++ b/WiFi/examples/wifi_Server_example_WPA/wifi_Server_example_WPA.pde @@ -0,0 +1,172 @@ +/* + WiFi Server example + + A simple connection with WiFi AP with Wireless Security + information try to access with WPA or WEP security keys + A simple server is setup to exchange data. + + created 13 July 2010 + by Domenico La Fauci + */ +#include +#include + +byte mac[6] = { 0 }; +IPAddress ip; +IPAddress gateway; +IPAddress subnet; +byte dataBuf[80] = { 0 }; +char ssid[32] = { 0 }; +int status = WL_IDLE_STATUS; +#define MAX_NUM_SSID 10 +char ssidList[MAX_NUM_SSID][32] = { {0} }; + + +Server server(23); + +void printIpData() +{ + ip = WiFi.localIp(); + + Serial.print("IP: "); + Serial.print(ip[3],10);Serial.print("."); + Serial.print(ip[2],10);Serial.print("."); + Serial.print(ip[1],10);Serial.print("."); + Serial.println(ip[0],10); + + subnet = WiFi.subnetMask(); + Serial.print("NETMASK: "); + Serial.print(subnet[3],10);Serial.print("."); + Serial.print(subnet[2],10);Serial.print("."); + Serial.print(subnet[1],10);Serial.print("."); + Serial.println(subnet[0],10); + + gateway = WiFi.gatewayIP(); + Serial.print("GATEWAY: "); + Serial.print(gateway[3],10);Serial.print("."); + Serial.print(gateway[2],10);Serial.print("."); + Serial.print(gateway[1],10);Serial.print("."); + Serial.println(gateway[0],10); + + WiFi.macAddress(mac); + Serial.print("MAC: "); + Serial.print(mac[5],16);Serial.print(":"); + Serial.print(mac[4],16);Serial.print(":"); + Serial.print(mac[3],16);Serial.print(":"); + Serial.print(mac[2],16);Serial.print(":"); + Serial.print(mac[1],16);Serial.print(":"); + Serial.println(mac[0],16); +} + +void printCurrNet() +{ + char* ssid = WiFi.SSID(); + Serial.print("SSID: "); + Serial.println(ssid); + + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + Serial.print(bssid[5],16);Serial.print(":"); + Serial.print(bssid[4],16);Serial.print(":"); + Serial.print(bssid[3],16);Serial.print(":"); + Serial.print(bssid[2],16);Serial.print(":"); + Serial.print(bssid[1],16);Serial.print(":"); + Serial.println(bssid[0],16); + + int32_t rssi = WiFi.RSSI(); + Serial.print("RSSI:"); + Serial.println(rssi,10); + + uint8_t enct = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(enct,16); +} + +void scanNetworks() +{ + Serial.println("** Scan Networks **"); + byte numSsid = WiFi.scanNetworks(); + if (numSsid > MAX_NUM_SSID) numSsid = MAX_NUM_SSID; + Serial.print("SSID List:"); + Serial.println(numSsid, 10); + for (int i = 0; i0) + { + dataBuf[idx]=0; + Serial.println((char*)&dataBuf[0]); + server.write((char*)&dataBuf[0]); + } + return; + } + } +} + + diff --git a/WiFi/examples/wifi_WEP_example/wifi_WEP_example.pde b/WiFi/examples/wifi_WEP_example/wifi_WEP_example.pde index 557c5039c..5a74d235e 100644 --- a/WiFi/examples/wifi_WEP_example/wifi_WEP_example.pde +++ b/WiFi/examples/wifi_WEP_example/wifi_WEP_example.pde @@ -85,12 +85,15 @@ void printCurrNet() void scanNetworks() { + Serial.println("** Scan Networks **"); byte numSsid = WiFi.scanNetworks(); if (numSsid > MAX_NUM_SSID) numSsid = MAX_NUM_SSID; Serial.print("SSID List:"); Serial.println(numSsid, 10); for (int i = 0; i0) { dataBuf[idx]=0; - //Serial.println((char*)&dataBuf[0]); + Serial.println((char*)&dataBuf[0]); server.write((char*)&dataBuf[0]); } return; } } - */ } diff --git a/WiFi/examples/wifi_WPA_example/wifi_WPA_example.pde b/WiFi/examples/wifi_WPA_example/wifi_WPA_example.pde index 498cf1191..916e020c7 100644 --- a/WiFi/examples/wifi_WPA_example/wifi_WPA_example.pde +++ b/WiFi/examples/wifi_WPA_example/wifi_WPA_example.pde @@ -101,7 +101,7 @@ void scanNetworks() int startWiFiWpa() { Serial.println("Setup WiFi Wpa..."); - strcpy(ssid, "Cariddiwep"); + strcpy(ssid, "Cariddi"); Serial.print("SSID: "); Serial.println(ssid); const char *pass = "1234567890"; @@ -117,9 +117,10 @@ void setup() { Serial.begin(9600); Serial.println("*** Start WiFi example ***"); - - //scanNetworks(); delay(3000); + WiFi.begin(); + scanNetworks(); + int _status = startWiFiWpa(); diff --git a/WiFi/utility/server_drv.cpp b/WiFi/utility/server_drv.cpp index 6de08b207..ae9429347 100644 --- a/WiFi/utility/server_drv.cpp +++ b/WiFi/utility/server_drv.cpp @@ -12,10 +12,10 @@ extern "C" { // Start server TCP on port specified void ServerDrv::StartServer(uint16_t port, uint8_t sock) { - SpiDrv::spiSlaveSelect(); + WAIT_FOR_SLAVE_SELECT(); // Send Command SpiDrv::sendCmd(START_SERVER_TCP_CMD, PARAM_NUMS_2); - SpiDrv::sendParam(port); + SpiDrv::sendParam(port);SpiDrv::spiSlaveSelect(); SpiDrv::sendParam(&sock, 1, LAST_PARAM); //Wait the reply elaboration @@ -34,7 +34,7 @@ void ServerDrv::StartServer(uint16_t port, uint8_t sock) uint8_t ServerDrv::getState(uint8_t sock) { - SpiDrv::spiSlaveSelect(); + WAIT_FOR_SLAVE_SELECT(); // Send Command SpiDrv::sendCmd(GET_STATE_TCP_CMD, PARAM_NUMS_1); SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM); @@ -51,14 +51,13 @@ uint8_t ServerDrv::getState(uint8_t sock) } SpiDrv::spiSlaveDeselect(); - delayMicroseconds(DELAY_POST_CMD); return _data; } uint8_t ServerDrv::availData(uint8_t sock) { - SpiDrv::spiSlaveSelect(); + WAIT_FOR_SLAVE_SELECT(); // Send Command SpiDrv::sendCmd(AVAIL_DATA_TCP_CMD, PARAM_NUMS_1); SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM); @@ -75,8 +74,6 @@ uint8_t ServerDrv::availData(uint8_t sock) } SpiDrv::spiSlaveDeselect(); - delayMicroseconds(DELAY_POST_CMD); - if (_dataLen!=0) { return (_data == 1); @@ -86,7 +83,7 @@ uint8_t ServerDrv::availData(uint8_t sock) bool ServerDrv::getData(uint8_t sock, uint8_t *data) { - SpiDrv::spiSlaveSelect(); + WAIT_FOR_SLAVE_SELECT(); // Send Command SpiDrv::sendCmd(GET_DATA_TCP_CMD, PARAM_NUMS_1); SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM); @@ -112,7 +109,7 @@ bool ServerDrv::getData(uint8_t sock, uint8_t *data) bool ServerDrv::getDataBuf(uint8_t sock, uint8_t *_data, uint16_t *_dataLen) { - SpiDrv::spiSlaveSelect(); + WAIT_FOR_SLAVE_SELECT(); // Send Command SpiDrv::sendCmd(GET_DATABUF_TCP_CMD, PARAM_NUMS_1); SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM); @@ -136,7 +133,7 @@ bool ServerDrv::getDataBuf(uint8_t sock, uint8_t *_data, uint16_t *_dataLen) bool ServerDrv::sendData(uint8_t sock, const uint8_t *data, uint16_t len) { - SpiDrv::spiSlaveSelect(); + WAIT_FOR_SLAVE_SELECT(); // Send Command SpiDrv::sendCmd(SEND_DATA_TCP_CMD, PARAM_NUMS_2); SpiDrv::sendParam(&sock, sizeof(sock)); @@ -163,7 +160,7 @@ bool ServerDrv::sendData(uint8_t sock, const uint8_t *data, uint16_t len) uint8_t ServerDrv::isDataSent(uint8_t sock) { - SpiDrv::spiSlaveSelect(); + WAIT_FOR_SLAVE_SELECT(); // Send Command SpiDrv::sendCmd(DATA_SENT_TCP_CMD, PARAM_NUMS_1); SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM); @@ -180,7 +177,6 @@ uint8_t ServerDrv::isDataSent(uint8_t sock) } SpiDrv::spiSlaveDeselect(); - delayMicroseconds(DELAY_POST_CMD); return _data; } diff --git a/WiFi/utility/spi_drv.h b/WiFi/utility/spi_drv.h index 5f9ed37a2..4511f15dd 100644 --- a/WiFi/utility/spi_drv.h +++ b/WiFi/utility/spi_drv.h @@ -14,6 +14,9 @@ #define DUMMY_DATA 0xFF +#define WAIT_FOR_SLAVE_SELECT() \ + SpiDrv::waitForSlaveReady(); \ + SpiDrv::spiSlaveSelect(); class SpiDrv { diff --git a/WiFi/utility/wifi_drv.cpp b/WiFi/utility/wifi_drv.cpp index c204e2232..fd5050594 100644 --- a/WiFi/utility/wifi_drv.cpp +++ b/WiFi/utility/wifi_drv.cpp @@ -25,11 +25,6 @@ uint8_t WiFiDrv::_gatewayIp[] = {0}; // Private Methods -#define WAIT_FOR_SLAVE_SELECT() \ - SpiDrv::waitForSlaveReady(); \ - SpiDrv::spiSlaveSelect(); - - void WiFiDrv::getNetworkData(uint8_t *ip, uint8_t *mask, uint8_t *gwip) { tParam params[PARAM_NUMS_3] = { {0, (char*)ip}, {0, (char*)mask}, {0, (char*)gwip}}; @@ -161,7 +156,6 @@ uint8_t WiFiDrv::getConnectionStatus() //Wait the reply elaboration SpiDrv::waitForSlaveReady(); - //delayMicroseconds(DELAY_RX_TX); // Wait for reply uint8_t _data = 0; @@ -334,7 +328,6 @@ char* WiFiDrv::getSSIDNetoworks(uint8_t networkItem) if (networkItem >= WL_NETWORKS_LIST_MAXNUM) return NULL; - //TODO make an RPC call to get the ssid associated with networkItem return _networkSsid[networkItem]; } diff --git a/WiFi/utility/wifi_spi.h b/WiFi/utility/wifi_spi.h index 2d0b1e2cd..841aff0f7 100644 --- a/WiFi/utility/wifi_spi.h +++ b/WiFi/utility/wifi_spi.h @@ -10,8 +10,6 @@ #define WIFI_SPI_ERR 0xFF #define TIMEOUT_CHAR 1000 -#define DELAY_RX_TX 200 //usec -#define DELAY_POST_CMD 0 //usec //#define MAX_SOCK_NUM 4 /**< Maxmium number of socket */ #define NO_SOCKET_AVAIL 255