mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-20 14:54:31 +01:00
Bugfix for Open and WEP nets
This commit is contained in:
parent
765e848fdb
commit
d640f9c77a
@ -2,9 +2,12 @@
|
||||
#include "WiFi.h"
|
||||
#include "wiring.h"
|
||||
|
||||
#define _DEBUG_
|
||||
|
||||
extern "C" {
|
||||
#include "utility/wl_definitions.h"
|
||||
#include "utility/wl_types.h"
|
||||
#include "debug.h"
|
||||
}
|
||||
|
||||
// XXX: don't make assumptions about the value of MAX_SOCK_NUM.
|
||||
@ -19,7 +22,6 @@ wl_status_t WiFiClass::_status;
|
||||
|
||||
WiFiClass::WiFiClass()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
void WiFiClass::init()
|
||||
@ -41,42 +43,66 @@ uint8_t WiFiClass::getSocket()
|
||||
|
||||
int WiFiClass::begin()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
int WiFiClass::begin(char* ssid)
|
||||
{
|
||||
uint8_t status = WL_IDLE_STATUS;
|
||||
init();
|
||||
|
||||
if (WiFiDrv::wifiSetNetwork(ssid, strlen(ssid)) != WL_FAILURE)
|
||||
{
|
||||
delay(WL_DELAY_START_CONNECTION);
|
||||
return WiFiDrv::getConnectionStatus();
|
||||
|
||||
do
|
||||
{
|
||||
delay(WL_DELAY_START_CONNECTION);
|
||||
status = WiFiDrv::getConnectionStatus();
|
||||
}
|
||||
while (( status == WL_IDLE_STATUS)||(status == WL_SCAN_COMPLETED));
|
||||
}else
|
||||
{
|
||||
return WL_CONNECT_FAILED;
|
||||
status = WL_CONNECT_FAILED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int WiFiClass::begin(char* ssid, uint8_t key_idx, const char *key)
|
||||
{
|
||||
uint8_t status = WL_IDLE_STATUS;
|
||||
init();
|
||||
// set encryption key
|
||||
if (WiFiDrv::wifiSetKey(ssid, strlen(ssid), key_idx, key, strlen(key)) != WL_FAILURE)
|
||||
{
|
||||
delay(WL_DELAY_START_CONNECTION);
|
||||
return WiFiDrv::getConnectionStatus();
|
||||
do
|
||||
{
|
||||
delay(WL_DELAY_START_CONNECTION);
|
||||
status = WiFiDrv::getConnectionStatus();
|
||||
}
|
||||
while (( status == WL_IDLE_STATUS)||(status == WL_SCAN_COMPLETED));
|
||||
}else{
|
||||
return WL_CONNECT_FAILED;
|
||||
status = WL_CONNECT_FAILED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int WiFiClass::begin(char* ssid, const char *passphrase)
|
||||
{
|
||||
uint8_t status = WL_IDLE_STATUS;
|
||||
init();
|
||||
// set passphrase
|
||||
if (WiFiDrv::wifiSetPassphrase(ssid, strlen(ssid), passphrase, strlen(passphrase))!= WL_FAILURE)
|
||||
{
|
||||
delay(WL_DELAY_START_CONNECTION);
|
||||
return WiFiDrv::getConnectionStatus();
|
||||
do
|
||||
{
|
||||
delay(WL_DELAY_START_CONNECTION);
|
||||
status = WiFiDrv::getConnectionStatus();
|
||||
}
|
||||
while (( status == WL_IDLE_STATUS)||(status == WL_SCAN_COMPLETED));
|
||||
}else{
|
||||
return WL_CONNECT_FAILED;
|
||||
status = WL_CONNECT_FAILED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int WiFiClass::disconnect()
|
||||
@ -86,7 +112,8 @@ int WiFiClass::disconnect()
|
||||
|
||||
uint8_t* WiFiClass::macAddress(uint8_t* mac)
|
||||
{
|
||||
mac = WiFiDrv::getMacAddress();
|
||||
uint8_t* _mac = WiFiDrv::getMacAddress();
|
||||
memcpy(mac, _mac, WL_MAC_ADDR_LENGTH);
|
||||
return mac;
|
||||
}
|
||||
|
||||
@ -118,7 +145,8 @@ char* WiFiClass::SSID()
|
||||
|
||||
uint8_t* WiFiClass::BSSID(uint8_t* bssid)
|
||||
{
|
||||
bssid = WiFiDrv::getCurrentBSSID();
|
||||
uint8_t* _bssid = WiFiDrv::getCurrentBSSID();
|
||||
memcpy(bssid, _bssid, WL_MAC_ADDR_LENGTH);
|
||||
return bssid;
|
||||
}
|
||||
|
||||
@ -153,4 +181,10 @@ uint8_t WiFiClass::encryptionType(uint8_t networkItem)
|
||||
return WiFiDrv::getEncTypeNetowrks(networkItem);
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::status()
|
||||
{
|
||||
return WiFiDrv::getConnectionStatus();
|
||||
}
|
||||
|
||||
|
||||
WiFiClass WiFi;
|
||||
|
@ -83,6 +83,9 @@ public:
|
||||
// Return the current RSSI /Received Signal Strength in dBm) associated with the network identified with networkItem
|
||||
int32_t RSSI(uint8_t networkItem);
|
||||
|
||||
// Return Connection status
|
||||
uint8_t status();
|
||||
|
||||
friend class Client;
|
||||
friend class Server;
|
||||
};
|
||||
|
@ -94,7 +94,7 @@ void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("Setup WiFi...");
|
||||
char ssid[] = "Cariddi";
|
||||
strcpy(ssid, "Vodafone-10289870");
|
||||
Serial.println(ssid);
|
||||
int status = WiFi.begin(ssid);
|
||||
if ( status != WL_CONNECTED)
|
||||
@ -131,6 +131,8 @@ void setup()
|
||||
void loop()
|
||||
{
|
||||
static uint8_t count = 0;
|
||||
Serial.println("Retry connect...");
|
||||
status = WiFi.begin(ssid);
|
||||
if (status == WL_CONNECTED)
|
||||
{
|
||||
byte status = 0;
|
||||
|
172
WiFi/examples/wifi_WEP_example/wifi_WEP_example.pde
Normal file
172
WiFi/examples/wifi_WEP_example/wifi_WEP_example.pde
Normal file
@ -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 <WiFi.h>
|
||||
#include <IPAddress.h>
|
||||
|
||||
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()
|
||||
{
|
||||
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; i<numSsid; ++i)
|
||||
{
|
||||
Serial.println(WiFi.SSID(i));
|
||||
}
|
||||
}
|
||||
|
||||
int startWiFiWep()
|
||||
{
|
||||
Serial.println("Setup WiFi Wep...");
|
||||
strcpy(ssid, "Cariddiwep");
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(ssid);
|
||||
uint8_t key_idx = 0;
|
||||
const char *key = "1234567890";
|
||||
Serial.println("Connecting...");
|
||||
status = WiFi.begin(ssid,key_idx, key);
|
||||
if ( status != WL_CONNECTED)
|
||||
{
|
||||
Serial.println("Connection Failed");
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("*** Start WiFi example ***");
|
||||
|
||||
delay(3000);
|
||||
|
||||
int _status = startWiFiWep();
|
||||
|
||||
if ( _status == WL_CONNECTED)
|
||||
{
|
||||
Serial.println("Wifi Connected!");
|
||||
|
||||
printIpData();
|
||||
|
||||
printCurrNet();
|
||||
|
||||
scanNetworks();
|
||||
/*
|
||||
Serial.println("Starting server...");
|
||||
server.begin();
|
||||
delay(1000);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
/*
|
||||
static uint8_t count = 0;
|
||||
Serial.println("Retry connect...");
|
||||
status = WiFi.begin(ssid);
|
||||
if (status == WL_CONNECTED)
|
||||
{
|
||||
byte status = 0;
|
||||
Client client = server.available(&status);
|
||||
if (client) {
|
||||
//Serial.print("Status: ");
|
||||
//Serial.println(status, 16);
|
||||
byte idx = 0;
|
||||
while (client.available())
|
||||
{
|
||||
dataBuf[idx++] = client.read();
|
||||
}
|
||||
|
||||
if (idx>0)
|
||||
{
|
||||
dataBuf[idx]=0;
|
||||
//Serial.println((char*)&dataBuf[0]);
|
||||
server.write((char*)&dataBuf[0]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
174
WiFi/examples/wifi_WPA_example/wifi_WPA_example.pde
Normal file
174
WiFi/examples/wifi_WPA_example/wifi_WPA_example.pde
Normal file
@ -0,0 +1,174 @@
|
||||
/*
|
||||
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 <WiFi.h>
|
||||
#include <IPAddress.h>
|
||||
|
||||
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; i<numSsid; ++i)
|
||||
{
|
||||
Serial.print(i,10);
|
||||
Serial.print(") Network: ");
|
||||
Serial.println(WiFi.SSID(i));
|
||||
}
|
||||
}
|
||||
|
||||
int startWiFiWpa()
|
||||
{
|
||||
Serial.println("Setup WiFi Wpa...");
|
||||
strcpy(ssid, "Cariddiwep");
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(ssid);
|
||||
const char *pass = "1234567890";
|
||||
status = WiFi.begin(ssid, pass);
|
||||
if ( status != WL_CONNECTED)
|
||||
{
|
||||
Serial.println("Connection Failed");
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("*** Start WiFi example ***");
|
||||
|
||||
//scanNetworks();
|
||||
delay(3000);
|
||||
|
||||
int _status = startWiFiWpa();
|
||||
|
||||
if ( _status == WL_CONNECTED)
|
||||
{
|
||||
Serial.println("Wifi Connected!");
|
||||
|
||||
printIpData();
|
||||
|
||||
printCurrNet();
|
||||
|
||||
scanNetworks();
|
||||
/*
|
||||
Serial.println("Starting server...");
|
||||
server.begin();
|
||||
delay(1000);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
/*
|
||||
static uint8_t count = 0;
|
||||
Serial.println("Retry connect...");
|
||||
status = WiFi.begin(ssid);
|
||||
if (status == WL_CONNECTED)
|
||||
{
|
||||
byte status = 0;
|
||||
Client client = server.available(&status);
|
||||
if (client) {
|
||||
//Serial.print("Status: ");
|
||||
//Serial.println(status, 16);
|
||||
byte idx = 0;
|
||||
while (client.available())
|
||||
{
|
||||
dataBuf[idx++] = client.read();
|
||||
}
|
||||
|
||||
if (idx>0)
|
||||
{
|
||||
dataBuf[idx]=0;
|
||||
//Serial.println((char*)&dataBuf[0]);
|
||||
server.write((char*)&dataBuf[0]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
/*
|
||||
WiFi example
|
||||
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 <WiFi.h>
|
||||
#include <IPAddress.h>
|
||||
|
||||
@ -15,52 +15,32 @@ 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 setup()
|
||||
void printIpData()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("Setup WiFi...");
|
||||
char ssid[] = "Cariddi";
|
||||
Serial.println(ssid);
|
||||
int status = WiFi.begin(ssid);
|
||||
if ( status != WL_CONNECTED)
|
||||
{
|
||||
// Using WPA
|
||||
Serial.println("Trying with Passphrase...");
|
||||
const char *pass = "12345678";
|
||||
status = WiFi.begin(ssid, pass);
|
||||
if ( status != WL_CONNECTED)
|
||||
{
|
||||
// using WEP
|
||||
Serial.println("Trying with Key...");
|
||||
uint8_t key_idx = 0;
|
||||
const char *key = "12345678";
|
||||
status = WiFi.begin(ssid,key_idx, key);
|
||||
if ( status != WL_CONNECTED)
|
||||
{
|
||||
Serial.println("Wifi Connection failed!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
Serial.println("Wifi Connected!");
|
||||
|
||||
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(".");
|
||||
@ -78,7 +58,114 @@ void setup()
|
||||
Serial.println(mac[0],16);
|
||||
}
|
||||
|
||||
void loop()
|
||||
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()
|
||||
{
|
||||
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; i<numSsid; ++i)
|
||||
{
|
||||
Serial.println(WiFi.SSID(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int startWiFi()
|
||||
{
|
||||
Serial.println("Setup WiFi...");
|
||||
strcpy(ssid, "Cariddiwep");
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(ssid);
|
||||
int status = WiFi.begin(ssid);
|
||||
if ( status != WL_CONNECTED)
|
||||
{
|
||||
Serial.println("Connection Failed");
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("*** Start WiFi example ***");
|
||||
|
||||
//scanNetworks();
|
||||
delay(3000);
|
||||
|
||||
int _status = startWiFi();
|
||||
|
||||
if ( _status == WL_CONNECTED)
|
||||
{
|
||||
Serial.println("Wifi Connected!");
|
||||
|
||||
printIpData();
|
||||
|
||||
printCurrNet();
|
||||
|
||||
scanNetworks();
|
||||
/*
|
||||
Serial.println("Starting server...");
|
||||
server.begin();
|
||||
delay(1000);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
/*
|
||||
static uint8_t count = 0;
|
||||
Serial.println("Retry connect...");
|
||||
status = WiFi.begin(ssid);
|
||||
if (status == WL_CONNECTED)
|
||||
{
|
||||
byte status = 0;
|
||||
Client client = server.available(&status);
|
||||
if (client) {
|
||||
//Serial.print("Status: ");
|
||||
//Serial.println(status, 16);
|
||||
byte idx = 0;
|
||||
while (client.available())
|
||||
{
|
||||
dataBuf[idx++] = client.read();
|
||||
}
|
||||
|
||||
if (idx>0)
|
||||
{
|
||||
dataBuf[idx]=0;
|
||||
//Serial.println((char*)&dataBuf[0]);
|
||||
server.write((char*)&dataBuf[0]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -13,6 +13,8 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "HardwareSerial.h"
|
||||
|
||||
#define INFO_0 1
|
||||
#define INFO_1 2
|
||||
#define INFO_2 4
|
||||
@ -30,13 +32,13 @@
|
||||
|
||||
#ifdef _DEBUG_
|
||||
|
||||
#define INFO1(x) do { PRINT_FILE_LINE() Serial.print("-W-");\
|
||||
#define INFO1(x) do { PRINT_FILE_LINE() Serial.print("-I-");\
|
||||
Serial.println(x); \
|
||||
}while (0);
|
||||
|
||||
|
||||
#define INFO2(x,y) do { PRINT_FILE_LINE() Serial.print("-I-");\
|
||||
Serial.print(x);Serial.print(",");Serial.println(y); \
|
||||
Serial.print(x,16);Serial.print(",");Serial.println(y,16); \
|
||||
}while (0);
|
||||
|
||||
|
||||
@ -49,7 +51,7 @@
|
||||
Serial.print("-W-"); Serial.println(args); \
|
||||
}while (0);
|
||||
|
||||
#define DBG_PIN2 3
|
||||
#define DBG_PIN2 5
|
||||
#define DBG_PIN 4
|
||||
|
||||
#define START() digitalWrite(DBG_PIN2, HIGH);
|
||||
|
@ -19,7 +19,7 @@ void ServerDrv::StartServer(uint16_t port, uint8_t sock)
|
||||
SpiDrv::sendParam(&sock, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
@ -40,7 +40,7 @@ uint8_t ServerDrv::getState(uint8_t sock)
|
||||
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
@ -64,7 +64,7 @@ uint8_t ServerDrv::availData(uint8_t sock)
|
||||
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
@ -92,7 +92,7 @@ bool ServerDrv::getData(uint8_t sock, uint8_t *data)
|
||||
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
@ -118,7 +118,7 @@ bool ServerDrv::getDataBuf(uint8_t sock, uint8_t *_data, uint16_t *_dataLen)
|
||||
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
if (!SpiDrv::waitResponse(GET_DATABUF_TCP_CMD, _data, _dataLen))
|
||||
@ -143,7 +143,7 @@ bool ServerDrv::sendData(uint8_t sock, const uint8_t *data, uint16_t len)
|
||||
SpiDrv::sendBuffer((uint8_t *)data, len, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
@ -169,7 +169,7 @@ uint8_t ServerDrv::isDataSent(uint8_t sock)
|
||||
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
|
@ -1,7 +1,8 @@
|
||||
|
||||
#include "WProgram.h"
|
||||
#include "spi_drv.h"
|
||||
|
||||
#include "pins_arduino.h"
|
||||
#define _DEBUG_
|
||||
extern "C" {
|
||||
#include "debug.h"
|
||||
}
|
||||
@ -9,31 +10,40 @@ extern "C" {
|
||||
#define DATAOUT 11//MOSI
|
||||
#define DATAIN 12//MISO
|
||||
#define SPICLOCK 13//sck
|
||||
#define SLAVESELECT 10//ss
|
||||
#define SLAVESELECT 2//ss
|
||||
#define SLAVEREADY 3
|
||||
|
||||
|
||||
void SpiDrv::spiSetup()
|
||||
void SpiDrv::begin()
|
||||
{
|
||||
int clr = 0;
|
||||
pinMode(DATAOUT, OUTPUT);
|
||||
pinMode(DATAIN, INPUT);
|
||||
pinMode(SPICLOCK,OUTPUT);
|
||||
pinMode(SLAVESELECT,OUTPUT);
|
||||
digitalWrite(SLAVESELECT,HIGH); //disable device
|
||||
// SPCR = 01010000
|
||||
//interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
|
||||
//sample on leading edge of clk,system clock/4 rate (fastest)
|
||||
SPCR = (1<<SPE)|(1<<MSTR);
|
||||
clr=SPSR;
|
||||
clr=SPDR;
|
||||
// Set direction register for SCK and MOSI pin.
|
||||
// MISO pin automatically overrides to INPUT.
|
||||
// When the SS pin is set as OUTPUT, it can be used as
|
||||
// a general purpose output port (it doesn't influence
|
||||
// SPI operations).
|
||||
|
||||
pinMode(SCK, OUTPUT);
|
||||
pinMode(MOSI, OUTPUT);
|
||||
pinMode(SS, OUTPUT);
|
||||
pinMode(SLAVESELECT, OUTPUT);
|
||||
pinMode(SLAVEREADY, INPUT);
|
||||
|
||||
digitalWrite(SCK, LOW);
|
||||
digitalWrite(MOSI, LOW);
|
||||
digitalWrite(SS, HIGH);
|
||||
digitalWrite(SLAVESELECT, HIGH);
|
||||
|
||||
// Warning: if the SS pin ever becomes a LOW INPUT then SPI
|
||||
// automatically switches to Slave, so the data direction of
|
||||
// the SS pin MUST be kept as OUTPUT.
|
||||
SPCR |= _BV(MSTR);
|
||||
SPCR |= _BV(SPE);
|
||||
}
|
||||
|
||||
void SpiDrv::spiDriverInit()
|
||||
{
|
||||
spiSetup();
|
||||
void SpiDrv::end() {
|
||||
SPCR &= ~_BV(SPE);
|
||||
}
|
||||
|
||||
|
||||
void SpiDrv::spiSlaveSelect()
|
||||
{
|
||||
digitalWrite(SLAVESELECT,LOW);
|
||||
@ -132,9 +142,28 @@ char SpiDrv::readChar()
|
||||
if (!readAndCheckChar(check, &x)) \
|
||||
{ \
|
||||
WARN("Reply error"); \
|
||||
INFO2(check, (uint8_t)x); \
|
||||
return 0; \
|
||||
}else \
|
||||
|
||||
bool SpiDrv::waitSlaveReady()
|
||||
{
|
||||
return (digitalRead(SLAVEREADY) == LOW);
|
||||
}
|
||||
|
||||
void SpiDrv::waitForSlaveReady()
|
||||
{
|
||||
#if 0
|
||||
int count = 0;
|
||||
while (!waitSlaveReady() && (++count<TIMEOUT_READY_SLAVE))
|
||||
{
|
||||
delayMicroseconds(1);
|
||||
}
|
||||
#else
|
||||
while (!waitSlaveReady());
|
||||
#endif
|
||||
}
|
||||
|
||||
int SpiDrv::waitResponse(uint8_t cmd, uint8_t numParam, uint8_t* param, uint8_t* param_len)
|
||||
{
|
||||
char _data = 0;
|
||||
@ -318,6 +347,53 @@ int SpiDrv::waitResponse(uint8_t cmd, tParam* params, uint8_t* numParamRead, uin
|
||||
return 1;
|
||||
}
|
||||
|
||||
int SpiDrv::waitResponse(uint8_t cmd, uint8_t* numParamRead, uint8_t** params, uint8_t maxNumParams)
|
||||
{
|
||||
char _data = 0;
|
||||
int i =0, ii = 0;
|
||||
|
||||
char *index[WL_SSID_MAX_LENGTH];
|
||||
|
||||
for (i = 0 ; i < WL_NETWORKS_LIST_MAXNUM ; i++)
|
||||
index[i] = (char *)params + WL_SSID_MAX_LENGTH*i;
|
||||
|
||||
IF_CHECK_START_CMD(_data)
|
||||
{
|
||||
CHECK_DATA(cmd | REPLY_FLAG, _data){};
|
||||
|
||||
uint8_t numParam = readChar();
|
||||
|
||||
if (numParam > maxNumParams)
|
||||
{
|
||||
numParam = maxNumParams;
|
||||
}
|
||||
*numParamRead = numParam;
|
||||
if (numParam != 0)
|
||||
{
|
||||
for (i=0; i<numParam; ++i)
|
||||
{
|
||||
uint8_t paramLen = readParamLen8();
|
||||
for (ii=0; ii<paramLen; ++ii)
|
||||
{
|
||||
//ssid[ii] = spiTransfer(DUMMY_DATA);
|
||||
// Get Params data
|
||||
index[i][ii] = (uint8_t)spiTransfer(DUMMY_DATA);
|
||||
|
||||
}
|
||||
index[i][ii]=0;
|
||||
}
|
||||
} else
|
||||
{
|
||||
WARN("Error numParams == 0");
|
||||
Serial.println(cmd, 16);
|
||||
return 0;
|
||||
}
|
||||
readAndCheckChar(END_CMD, &_data);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void SpiDrv::sendParam(uint8_t* param, uint8_t param_len, uint8_t lastParam)
|
||||
{
|
||||
int i = 0;
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#define WAIT_CHAR_DELAY 100
|
||||
#define TIMEOUT_CHAR_DELAY 10
|
||||
#define TIMEOUT_READY_SLAVE 1000
|
||||
#define SPI_TX_DELAY 2
|
||||
|
||||
#define NO_LAST_PARAM 0
|
||||
@ -16,9 +17,13 @@
|
||||
|
||||
class SpiDrv
|
||||
{
|
||||
private:
|
||||
static bool waitSlaveReady();
|
||||
public:
|
||||
|
||||
static void spiSetup();
|
||||
static void begin();
|
||||
|
||||
static void end();
|
||||
|
||||
static void spiDriverInit();
|
||||
|
||||
@ -28,6 +33,8 @@ public:
|
||||
|
||||
static char spiTransfer(volatile char data);
|
||||
|
||||
static void waitForSlaveReady();
|
||||
|
||||
static int waitSpiChar(char waitChar, char* readChar);
|
||||
|
||||
static int waitSpiChar(unsigned char waitChar);
|
||||
@ -48,6 +55,8 @@ public:
|
||||
|
||||
static int waitResponse(uint8_t cmd, uint8_t* param, uint16_t* param_len);
|
||||
|
||||
static int waitResponse(uint8_t cmd, uint8_t* numParamRead, uint8_t** params, uint8_t maxNumParams);
|
||||
|
||||
static void sendParam(uint8_t* param, uint8_t param_len, uint8_t lastParam = NO_LAST_PARAM);
|
||||
|
||||
static void sendParamLen8(uint8_t param_len);
|
||||
|
@ -14,7 +14,7 @@ extern "C" {
|
||||
#include "debug.h"
|
||||
}
|
||||
|
||||
char WiFiDrv::_networkSsid[] = {0};
|
||||
char WiFiDrv::_networkSsid[][WL_SSID_MAX_LENGTH] = {{"1"},{"2"},{"3"},{"4"},{"5"}};
|
||||
char WiFiDrv::_ssid[] = {0};
|
||||
uint8_t WiFiDrv::_bssid[] = {0};
|
||||
uint8_t WiFiDrv::_mac[] = {0};
|
||||
@ -25,12 +25,17 @@ 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}};
|
||||
|
||||
SpiDrv::spiSlaveSelect();
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_IPADDR_CMD, PARAM_NUMS_1);
|
||||
|
||||
@ -38,7 +43,7 @@ void WiFiDrv::getNetworkData(uint8_t *ip, uint8_t *mask, uint8_t *gwip)
|
||||
SpiDrv::sendParam(&_dummy, sizeof(_dummy), LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
@ -53,19 +58,19 @@ void WiFiDrv::getNetworkData(uint8_t *ip, uint8_t *mask, uint8_t *gwip)
|
||||
|
||||
void WiFiDrv::wifiDriverInit()
|
||||
{
|
||||
SpiDrv::spiDriverInit();
|
||||
SpiDrv::begin();
|
||||
}
|
||||
|
||||
// If ssid == NULL execute a wifi scan, otherwise try to connect to the network specified
|
||||
uint8_t WiFiDrv::wifiSetNetwork(char* ssid, uint8_t ssid_len)
|
||||
{
|
||||
SpiDrv::spiSlaveSelect();
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(SET_NET_CMD, PARAM_NUMS_1);
|
||||
SpiDrv::sendParam((uint8_t*)ssid, ssid_len, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
@ -81,14 +86,14 @@ uint8_t WiFiDrv::wifiSetNetwork(char* ssid, uint8_t ssid_len)
|
||||
|
||||
uint8_t WiFiDrv::wifiSetPassphrase(char* ssid, uint8_t ssid_len, const char *passphrase, const uint8_t len)
|
||||
{
|
||||
SpiDrv::spiSlaveSelect();
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(SET_PASSPHRASE_CMD, PARAM_NUMS_2);
|
||||
SpiDrv::sendParam((uint8_t*)ssid, ssid_len, NO_LAST_PARAM);
|
||||
SpiDrv::sendParam((uint8_t*)passphrase, len, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
@ -104,7 +109,7 @@ uint8_t WiFiDrv::wifiSetPassphrase(char* ssid, uint8_t ssid_len, const char *pas
|
||||
|
||||
uint8_t WiFiDrv::wifiSetKey(char* ssid, uint8_t ssid_len, uint8_t key_idx, const void *key, const uint8_t len)
|
||||
{
|
||||
SpiDrv::spiSlaveSelect();
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(SET_KEY_CMD, PARAM_NUMS_3);
|
||||
SpiDrv::sendParam((uint8_t*)ssid, ssid_len, NO_LAST_PARAM);
|
||||
@ -112,7 +117,7 @@ uint8_t WiFiDrv::wifiSetKey(char* ssid, uint8_t ssid_len, uint8_t key_idx, const
|
||||
SpiDrv::sendParam((uint8_t*)key, len, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
@ -127,7 +132,7 @@ uint8_t WiFiDrv::wifiSetKey(char* ssid, uint8_t ssid_len, uint8_t key_idx, const
|
||||
|
||||
uint8_t WiFiDrv::disconnect()
|
||||
{
|
||||
SpiDrv::spiSlaveSelect();
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(DISCONNECT_CMD, PARAM_NUMS_1);
|
||||
|
||||
@ -135,7 +140,7 @@ uint8_t WiFiDrv::disconnect()
|
||||
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
@ -149,16 +154,14 @@ uint8_t WiFiDrv::disconnect()
|
||||
|
||||
uint8_t WiFiDrv::getConnectionStatus()
|
||||
{
|
||||
SpiDrv::spiSlaveSelect();
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_CONN_STATUS_CMD, PARAM_NUMS_1);
|
||||
|
||||
uint8_t _dummy = DUMMY_DATA;
|
||||
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
||||
SpiDrv::sendCmd(GET_CONN_STATUS_CMD, PARAM_NUMS_0);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
//delayMicroseconds(DELAY_RX_TX);
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
@ -172,7 +175,8 @@ uint8_t WiFiDrv::getConnectionStatus()
|
||||
|
||||
uint8_t* WiFiDrv::getMacAddress()
|
||||
{
|
||||
SpiDrv::spiSlaveSelect();
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_MACADDR_CMD, PARAM_NUMS_1);
|
||||
|
||||
@ -180,7 +184,7 @@ uint8_t* WiFiDrv::getMacAddress()
|
||||
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _dataLen = 0;
|
||||
@ -211,7 +215,8 @@ void WiFiDrv::getIpAddress(uint8_t *ip)
|
||||
|
||||
char* WiFiDrv::getCurrentSSID()
|
||||
{
|
||||
SpiDrv::spiSlaveSelect();
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_CURR_SSID_CMD, PARAM_NUMS_1);
|
||||
|
||||
@ -219,7 +224,7 @@ char* WiFiDrv::getCurrentSSID()
|
||||
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _dataLen = 0;
|
||||
@ -232,7 +237,8 @@ char* WiFiDrv::getCurrentSSID()
|
||||
|
||||
uint8_t* WiFiDrv::getCurrentBSSID()
|
||||
{
|
||||
SpiDrv::spiSlaveSelect();
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_CURR_BSSID_CMD, PARAM_NUMS_1);
|
||||
|
||||
@ -240,11 +246,11 @@ uint8_t* WiFiDrv::getCurrentBSSID()
|
||||
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _dataLen = 0;
|
||||
uint8_t result = SpiDrv::waitResponse(GET_CURR_BSSID_CMD, PARAM_NUMS_1, (uint8_t*)_bssid, &_dataLen);
|
||||
uint8_t result = SpiDrv::waitResponse(GET_CURR_BSSID_CMD, PARAM_NUMS_1, _bssid, &_dataLen);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
@ -253,7 +259,8 @@ uint8_t* WiFiDrv::getCurrentBSSID()
|
||||
|
||||
int32_t WiFiDrv::getCurrentRSSI()
|
||||
{
|
||||
SpiDrv::spiSlaveSelect();
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_CURR_RSSI_CMD, PARAM_NUMS_1);
|
||||
|
||||
@ -261,12 +268,12 @@ int32_t WiFiDrv::getCurrentRSSI()
|
||||
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _dataLen = 0;
|
||||
int32_t rssi = 0;
|
||||
uint8_t result = SpiDrv::waitResponse(GET_CURR_RSSI_CMD, PARAM_NUMS_1, (uint8_t*)rssi, &_dataLen);
|
||||
uint8_t result = SpiDrv::waitResponse(GET_CURR_RSSI_CMD, PARAM_NUMS_1, (uint8_t*)&rssi, &_dataLen);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
@ -275,7 +282,8 @@ int32_t WiFiDrv::getCurrentRSSI()
|
||||
|
||||
uint8_t WiFiDrv::getCurrentEncryptionType()
|
||||
{
|
||||
SpiDrv::spiSlaveSelect();
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_CURR_ENCT_CMD, PARAM_NUMS_1);
|
||||
|
||||
@ -283,7 +291,7 @@ uint8_t WiFiDrv::getCurrentEncryptionType()
|
||||
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t dataLen = 0;
|
||||
@ -297,7 +305,8 @@ uint8_t WiFiDrv::getCurrentEncryptionType()
|
||||
|
||||
uint8_t WiFiDrv::scanNetworks()
|
||||
{
|
||||
SpiDrv::spiSlaveSelect();
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(SCAN_NETWORKS, PARAM_NUMS_1);
|
||||
|
||||
@ -305,14 +314,15 @@ uint8_t WiFiDrv::scanNetworks()
|
||||
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
delayMicroseconds(DELAY_RX_TX);
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint16_t _dataLen = 0;
|
||||
|
||||
tParam params[WL_NETWORKS_LIST_MAXNUM];
|
||||
|
||||
uint8_t ssidListNum = 0;
|
||||
uint8_t result = SpiDrv::waitResponse(SCAN_NETWORKS, params, &ssidListNum, WL_NETWORKS_LIST_MAXNUM);
|
||||
uint8_t result = SpiDrv::waitResponse(SCAN_NETWORKS, &ssidListNum, (uint8_t**)_networkSsid, WL_NETWORKS_LIST_MAXNUM);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
@ -325,7 +335,7 @@ char* WiFiDrv::getSSIDNetoworks(uint8_t networkItem)
|
||||
return NULL;
|
||||
|
||||
//TODO make an RPC call to get the ssid associated with networkItem
|
||||
return _networkSsid;
|
||||
return _networkSsid[networkItem];
|
||||
}
|
||||
|
||||
uint8_t WiFiDrv::getEncTypeNetowrks(uint8_t networkItem)
|
||||
|
@ -6,12 +6,13 @@
|
||||
|
||||
#define KEY_IDX_LEN 1
|
||||
#define WL_DELAY_START_CONNECTION 5000
|
||||
#define WL_DELAY_RETRY_START_CONNECTION 1000
|
||||
|
||||
class WiFiDrv
|
||||
{
|
||||
private:
|
||||
// settings of requested network
|
||||
static char _networkSsid[WL_SSID_MAX_LENGTH];
|
||||
static char _networkSsid[WL_NETWORKS_LIST_MAXNUM][WL_SSID_MAX_LENGTH];
|
||||
|
||||
// settings of current selected network
|
||||
static char _ssid[WL_SSID_MAX_LENGTH];
|
||||
|
@ -94,7 +94,7 @@ typedef struct __attribute__((__packed__))
|
||||
{
|
||||
unsigned char cmd;
|
||||
unsigned char tcmd;
|
||||
unsigned char totLen;
|
||||
//unsigned char totLen;
|
||||
unsigned char nParam;
|
||||
}tSpiHdr;
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
// Size of a MAC-address or BSSID
|
||||
#define WL_IPV4_LENGTH 4
|
||||
// Maximum size of a SSID list
|
||||
#define WL_NETWORKS_LIST_MAXNUM 5
|
||||
#define WL_NETWORKS_LIST_MAXNUM 10
|
||||
// Maxmium number of socket
|
||||
#define MAX_SOCK_NUM 4
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user