1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-03 14:24:15 +01:00

Changes to integrate latest core updates to WiFly branch

This commit is contained in:
mlafauci 2011-08-31 10:34:51 +02:00
parent 9785b99cba
commit 00b945d869
23 changed files with 136 additions and 251 deletions

View File

@ -1,37 +0,0 @@
#ifndef client_h
#define client_h
#include "Arduino.h"
#include "Print.h"
class Client : public Stream {
public:
Client();
Client(uint8_t sock);
uint8_t status();
int connect(IPAddress ip, uint16_t port);
int connect(const char *host, uint16_t port);
virtual void write(uint8_t);
virtual void write(const char *str);
virtual void write(const uint8_t *buf, size_t size);
virtual int available();
virtual int read();
virtual int read(uint8_t *buf, size_t size);
virtual int peek();
virtual void flush();
void stop();
uint8_t connected();
operator bool();
friend class Server;
private:
static uint16_t _srcport;
uint8_t _sock; //not used
uint16_t _socket;
uint8_t getFirstSocket();
};
#endif

View File

@ -1,44 +0,0 @@
#include <Arduino.h>
#include <IPAddress.h>
IPAddress::IPAddress()
{
memset(_address, 0, sizeof(_address));
}
IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet)
{
_address[0] = first_octet;
_address[1] = second_octet;
_address[2] = third_octet;
_address[3] = fourth_octet;
}
IPAddress::IPAddress(uint32_t address)
{
memcpy(_address, &address, sizeof(_address));
}
IPAddress::IPAddress(const uint8_t *address)
{
memcpy(_address, address, sizeof(_address));
}
IPAddress& IPAddress::operator=(const uint8_t *address)
{
memcpy(_address, address, sizeof(_address));
return *this;
}
IPAddress& IPAddress::operator=(uint32_t address)
{
memcpy(_address, (const uint8_t *)&address, sizeof(_address));
return *this;
}
bool IPAddress::operator==(const uint8_t* addr)
{
return memcmp(addr, _address, sizeof(_address)) == 0;
}

View File

@ -1,72 +0,0 @@
/*
*
* MIT License:
* Copyright (c) 2011 Adrian McEwen
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* adrianm@mcqn.com 1/1/2011
*/
#ifndef IPAddress_h
#define IPAddress_h
// A class to make it easier to handle and pass around IP addresses
class IPAddress {
private:
uint8_t _address[4]; // IPv4 address
// Access the raw byte array containing the address. Because this returns a pointer
// to the internal structure rather than a copy of the address this function should only
// be used when you know that the usage of the returned uint8_t* will be transient and not
// stored.
uint8_t* raw_address() { return _address; };
public:
// Constructors
IPAddress();
IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
IPAddress(uint32_t address);
IPAddress(const uint8_t *address);
// Overloaded cast operator to allow IPAddress objects to be used where a pointer
// to a four-byte uint8_t array is expected
operator uint32_t() { return *((uint32_t*)_address); };
bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };
bool operator==(const uint8_t* addr);
// Overloaded index operator to allow getting and setting individual octets of the address
uint8_t operator[](int index) const { return _address[index]; };
uint8_t& operator[](int index) { return _address[index]; };
// Overloaded copy operators to allow initialisation of IPAddress objects from other types
IPAddress& operator=(const uint8_t *address);
IPAddress& operator=(uint32_t address);
friend class EthernetClass;
friend class UDP;
friend class Client;
friend class Server;
friend class DhcpClass;
friend class DNSClient;
};
const IPAddress INADDR_NONE(0,0,0,0);
#endif

View File

@ -8,8 +8,8 @@ extern "C" {
}
#include "IPAddress.h"
#include "Client.h"
#include "Server.h"
#include "WiFiClient.h"
#include "WiFiServer.h"
class WiFiClass
{
@ -89,8 +89,8 @@ public:
// function used for test
uint8_t test();
friend class Client;
friend class Server;
friend class WiFiClient;
friend class WiFiServer;
};
extern WiFiClass WiFi;

View File

@ -7,19 +7,19 @@ extern "C" {
}
#include "WiFi.h"
#include "Client.h"
#include "Server.h"
#include "WiFiClient.h"
#include "WiFiServer.h"
#include "server_drv.h"
uint16_t Client::_srcport = 1024;
uint16_t WiFiClient::_srcport = 1024;
Client::Client() : _sock(MAX_SOCK_NUM) {
WiFiClient::WiFiClient() : _sock(MAX_SOCK_NUM) {
}
Client::Client(uint8_t sock) : _sock(sock) {
WiFiClient::WiFiClient(uint8_t sock) : _sock(sock) {
}
int Client::connect(const char* host, uint16_t port) {
int WiFiClient::connect(const char* host, uint16_t port) {
/* TODO Add DNS wifi spi function to resolve DNS */
#if 0
// Look up the host first
@ -37,7 +37,7 @@ int Client::connect(const char* host, uint16_t port) {
#endif
}
int Client::connect(IPAddress ip, uint16_t port) {
int WiFiClient::connect(IPAddress ip, uint16_t port) {
_sock = getFirstSocket();
if (_sock != NO_SOCKET_AVAIL)
{
@ -49,36 +49,40 @@ int Client::connect(IPAddress ip, uint16_t port) {
return 1;
}
void Client::write(uint8_t b) {
size_t WiFiClient::write(uint8_t b) {
if (_sock != 255)
{
START();
ServerDrv::sendData(_sock, &b, 1);
while (!ServerDrv::isDataSent(_sock));
END();
return 1;
}
return 0;
}
void Client::write(const char *str) {
size_t WiFiClient::write(const char *str) {
if (_sock != 255)
{
unsigned int len = strlen(str);
ServerDrv::sendData(_sock, (const uint8_t *)str, len);
while (!ServerDrv::isDataSent(_sock));
return len;
}
return 0;
}
void Client::write(const uint8_t *buf, size_t size) {
size_t WiFiClient::write(const uint8_t *buf, size_t size) {
if (_sock != 255)
{
ServerDrv::sendData(_sock, buf, size);
while (!ServerDrv::isDataSent(_sock));
return size;
}
return 0;
}
}
int Client::available() {
int WiFiClient::available() {
if (_sock != 255)
{
return ServerDrv::availData(_sock);
@ -87,7 +91,7 @@ int Client::available() {
return 0;
}
int Client::read() {
int WiFiClient::read() {
uint8_t b;
if (!available())
return -1;
@ -96,23 +100,23 @@ int Client::read() {
}
int Client::read(uint8_t* buf, size_t size) {
int WiFiClient::read(uint8_t* buf, size_t size) {
if (!ServerDrv::getDataBuf(_sock, buf, &size))
return -1;
return 0;
}
int Client::peek() {
int WiFiClient::peek() {
//TODO to be implemented
return 0;
}
void Client::flush() {
void WiFiClient::flush() {
while (available())
read();
}
void Client::stop() {
void WiFiClient::stop() {
if (_sock == 255)
return;
@ -132,7 +136,7 @@ void Client::stop() {
_sock = 255;
}
uint8_t Client::connected() {
uint8_t WiFiClient::connected() {
if (_sock == 255) {
return 0;
} else {
@ -142,7 +146,7 @@ uint8_t Client::connected() {
}
}
uint8_t Client::status() {
uint8_t WiFiClient::status() {
if (_sock == 255) {
return CLOSED;
} else {
@ -150,12 +154,12 @@ uint8_t Client::status() {
}
}
Client::operator bool() {
WiFiClient::operator bool() {
return _sock != 255;
}
// Private Methods
uint8_t Client::getFirstSocket()
uint8_t WiFiClient::getFirstSocket()
{
for (int i = 0; i < MAX_SOCK_NUM; i++) {
if (WiFiClass::_state[i] == 0)

39
WiFi/WiFiClient.h Executable file
View File

@ -0,0 +1,39 @@
#ifndef wificlient_h
#define wificlient_h
#include "Arduino.h"
#include "Print.h"
#include "Client.h"
#include "IPAddress.h"
class WiFiClient : public Client {
public:
WiFiClient();
WiFiClient(uint8_t sock);
uint8_t status();
virtual int connect(IPAddress ip, uint16_t port);
virtual int connect(const char *host, uint16_t port);
virtual size_t write(uint8_t);
virtual size_t write(const char *str);
virtual size_t write(const uint8_t *buf, size_t size);
virtual int available();
virtual int read();
virtual int read(uint8_t *buf, size_t size);
virtual int peek();
virtual void flush();
virtual void stop();
virtual uint8_t connected();
virtual operator bool();
friend class WiFiServer;
private:
static uint16_t _srcport;
uint8_t _sock; //not used
uint16_t _socket;
uint8_t getFirstSocket();
};
#endif

View File

@ -2,17 +2,17 @@
#include "server_drv.h"
#include "WiFi.h"
#include "Client.h"
#include "Server.h"
#include "WiFiClient.h"
#include "WiFiServer.h"
Server::Server(uint16_t port)
WiFiServer::WiFiServer(uint16_t port)
{
_port = port;
}
void Server::begin()
void WiFiServer::begin()
{
uint8_t _sock = WiFiClass::getSocket();
if (_sock != NO_SOCKET_AVAIL)
@ -22,7 +22,7 @@ void Server::begin()
}
}
Client Server::available(byte* status)
WiFiClient WiFiServer::available(byte* status)
{
//accept();
@ -30,7 +30,7 @@ Client Server::available(byte* status)
{
if (WiFiClass::_server_port[sock] != 0)
{
Client client(sock);
WiFiClient client(sock);
int _status = client.status();
if (status != NULL)
*status = _status;
@ -43,26 +43,26 @@ Client Server::available(byte* status)
}
}
return Client(255);
return WiFiClient(255);
}
void Server::write(uint8_t b)
void WiFiServer::write(uint8_t b)
{
write(&b, 1);
}
void Server::write(const char *str)
void WiFiServer::write(const char *str)
{
write((const uint8_t *)str, strlen(str));
}
void Server::write(const uint8_t *buffer, size_t size)
void WiFiServer::write(const uint8_t *buffer, size_t size)
{
for (int sock = 0; sock < MAX_SOCK_NUM; sock++)
{
if (WiFiClass::_server_port[sock] != 0)
{
Client client(sock);
WiFiClient client(sock);
if (WiFiClass::_server_port[sock] == _port &&
client.status() == ESTABLISHED)

View File

@ -1,21 +1,21 @@
#ifndef server_h
#define server_h
#ifndef wifiserver_h
#define wifiserver_h
extern "C" {
#include "utility/wl_definitions.h"
}
#include "Print.h"
#include "Server.h"
class Client;
class WiFiClient;
class Server : public Print {
class WiFiServer : public Server {
private:
uint16_t _port;
void* pcb;
public:
Server(uint16_t);
Client available(uint8_t* status = NULL);
WiFiServer(uint16_t);
WiFiClient available(uint8_t* status = NULL);
void begin();
virtual void write(uint8_t);
virtual void write(const char *str);

View File

@ -22,16 +22,16 @@
*/
#include <WiFi.h>
#include <IPAddress.h>
char ssid[32] = { 0 };
char ssid[] = "yourNetwork";
char pass[] = "secretPassword";
int status = WL_IDLE_STATUS;
// The address of the server you want to connect to (pachube.com):
IPAddress server(173,203,98,29);
// initialize the library instance:
Client client(server, 80);
WiFiClient client;
long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop
@ -40,11 +40,10 @@ const int postingInterval = 10000; //delay between updates to Pachube.com
int startWiFiWpa()
{
Serial.println("\nSetup WiFi Wpa...");
//strcpy(ssid, "AndroidAP9647");
strcpy(ssid, "Cariddi");
strcpy(ssid, "tigoenet");
Serial.print("SSID: ");
Serial.println(ssid);
const char *pass = "1234567890";
const char *pass = "m30w-m30w";
status = WiFi.begin(ssid, pass);
if ( status != WL_CONNECTED)
{
@ -110,11 +109,11 @@ void loop() {
// this method makes a HTTP connection to the server:
void sendData(String thisData) {
// if there's a successful connection:
if (client.connect()) {
if (client.connect(server, 80)) {
Serial.println("connecting...");
// send the HTTP PUT request.
// fill in your feed address here:
client.print("PUT /api/http://api.pachube.com/v2/feeds/24196.csv HTTP/1.1\n");
client.print("PUT /api/24196.csv HTTP/1.1\n");
client.print("Host: www.pachube.com\n");
// fill in your Pachube API key here:
client.print("X-PachubeApiKey: gw0L2A-J5ACRGQccX59tCYt0IEzyecr-SoiuC47U1-8\n");

View File

@ -7,7 +7,7 @@
* WiFi shield attached
created 13 July 2010
by Domenico La Fauci
by dlf (Metodo2 srl)
modified 5 June 2011
by Tom Igoe
*/

View File

@ -7,7 +7,7 @@
* WiFi shield attached
created 13 July 2010
by Domenico La Fauci
by dlf (Metodo2 srl)
modified 5 June 2011
by Tom Igoe
*/
@ -61,7 +61,7 @@ void loop() {
void printIpData() {
// print your WiFi shield's IP address:
ip = WiFi.localIp();
ip = WiFi.localIP();
Serial.print("IP: ");
Serial.print(ip[3]);
Serial.print(".");

View File

@ -25,7 +25,7 @@ char pass[] = "secretPassword"; // the WPA2 password for your network
int status = WL_IDLE_STATUS; // the Wifi radio's status
// telnet defaults to port 23
Server server(23);
WiFiServer server(23);
boolean gotAMessage = false; // whether or not you got a message from the client yet
@ -56,7 +56,7 @@ void setup() {
void loop() {
// wait for a new client:
Client client = server.available();
WiFiClient client = server.available();
// when the client sends the first byte, say hello:
if (client) {

View File

@ -31,7 +31,7 @@ int status = WL_IDLE_STATUS;
IPAddress server(173,203,98,29);
// initialize the library instance:
Client client;
WiFiClient client;
long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop

View File

@ -7,7 +7,7 @@
* WiFi shield attached
created 13 July 2010
by Domenico La Fauci
by dlf (Metodo2 srl)
modified 5 June 2011
by Tom Igoe
*/
@ -16,9 +16,8 @@
#include <SPI.h>
#include <WiFi.h>
char ssid[] = "yourNetwork"; // the name of your network
char pass[] = "secretPassword"; // the WPA2 password for your network
char ssid[] = "yourNetwork";
char pass[] = "secretpassword";
int status = WL_IDLE_STATUS; // the Wifi radio's status
byte mac[6]; // the MAC address of your Wifi shield
@ -29,6 +28,10 @@ IPAddress subnet; // the subnet mask
void setup() {
// initialize serial:
Serial.begin(9600);
// scan for existing networks:
Serial.println("Scanning available networks...");
//WiFi.begin();
scanNetworks();
// attempt to connect using WEP encryption:
// Serial.println("Attempting to connect to WEP-128 network...");

View File

@ -24,7 +24,7 @@ char pass[] = "secretpassword";
int status = WL_IDLE_STATUS;
// initialize the library instance:
Client client;
WiFiClient client;
const int requestInterval = 30*1000; // delay between requests; 30 seconds

View File

@ -9,7 +9,7 @@
* WiFi shield attached
created 13 July 2010
by Domenico La Fauci
by dlf (Metodo2 srl)
modified 21 May 2011
by Tom Igoe
*/
@ -17,7 +17,6 @@
#include <SPI.h>
#include <WiFi.h>
#include <IPAddress.h>
char ssid[] = "yourNetwork";
char pass[] = "secretPassword";
@ -27,7 +26,7 @@ IPAddress server(74,125,115,105); // Google
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
Client client;
WiFiClient client;
void setup() {
Serial.begin(9600);

View File

@ -9,7 +9,7 @@
* Analog inputs attached to pins A0 through A5 (optional)
created 13 July 2010
by Domenico La Fauci
by dlf (Metodo2 srl)
modified 5 June 2011
by Tom Igoe
*/
@ -22,7 +22,7 @@ char ssid[] = "yourNetwork";
char pass[] = "secretpassword";
int status = WL_IDLE_STATUS;
Server server(80);
WiFiServer server(80);
void setup() {
// initialize serial:
@ -39,7 +39,7 @@ void setup() {
else {
server.begin();
Serial.print("Connected to wifi. My address:");
IPAddress myAddress = WiFi.localIp();
IPAddress myAddress = WiFi.localIP();
Serial.print(myAddress[0]);
Serial.print(".");
Serial.print(myAddress[1]);
@ -53,7 +53,7 @@ void setup() {
void loop() {
// listen for incoming clients
Client client = server.available();
WiFiClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;

View File

@ -6,10 +6,9 @@
A simple server is setup to exchange data.
created 13 July 2010
by Domenico La Fauci
by dlf (Metodo2 srl)
*/
#include <WiFi.h>
#include <IPAddress.h>
byte mac[6] = { 0 };
IPAddress ip;
@ -19,11 +18,11 @@ byte dataBuf[80] = { 0 };
char ssid[32] = { 0 };
int status = WL_IDLE_STATUS;
Server server(23);
WiFiServer server(23);
void printIpData()
{
ip = WiFi.localIp();
ip = WiFi.localIP();
Serial.print("IP: ");
Serial.print(ip[3],10);Serial.print(".");
@ -136,7 +135,7 @@ void loop()
if (status == WL_CONNECTED)
{
byte status = 0;
Client client = server.available(&status);
WiFiClient client = server.available(&status);
if (client) {
//Serial.print("Status: ");
//Serial.println(status, 16);

View File

@ -6,10 +6,9 @@
A simple server is setup to exchange data.
created 13 July 2010
by Domenico La Fauci
by dlf (Metodo2 srl)
*/
#include <WiFi.h>
#include <IPAddress.h>
byte mac[6] = { 0 };
IPAddress ip;
@ -21,12 +20,11 @@ int status = WL_IDLE_STATUS;
#define MAX_NUM_SSID 10
char ssidList[MAX_NUM_SSID][32] = { {0} };
Server server(23);
WiFiServer server(23);
void printIpData()
{
ip = WiFi.localIp();
ip = WiFi.localIP();
Serial.print("IP: ");
Serial.print(ip[3],10);Serial.print(".");
@ -147,7 +145,7 @@ void loop()
if (status == WL_CONNECTED)
{
byte _status = 0;
Client client = server.available(&_status);
WiFiClient client = server.available(&_status);
if (client) {
Serial.print("Status: ");
Serial.println(status, 16);

View File

@ -6,10 +6,10 @@
A simple server is setup to exchange data.
created 13 July 2010
by Domenico La Fauci
by dlf (Metodo2 srl)
*/
#include <WiFi.h>
#include <IPAddress.h>
#define _PRINT_
byte mac[6] = { 0 };
@ -23,12 +23,12 @@ int status = WL_IDLE_STATUS;
char ssidList[MAX_NUM_SSID][32] = { {0} };
Server server(23);
WiFiServer server(23);
boolean gotAMessage = false; // whether or not you got a message from the client yet
void printIpData()
{
ip = WiFi.localIp();
ip = WiFi.localIP();
Serial.print("\nIP: ");
Serial.print(ip[3],10);Serial.print(".");
@ -153,8 +153,7 @@ void execCmd(char* buf)
Serial.print("\nExecuting command: ");
Serial.println(buf);
#endif
//server.write(buf);
server.print(buf);
server.write(buf);
}
@ -163,7 +162,7 @@ void loop()
if (status == WL_CONNECTED)
{
byte _status = 0;
Client client = server.available(&_status);
WiFiClient client = server.available(&_status);
if (client) {
if (!gotAMessage) {
Serial.println("\nWe have a new client\n");

View File

@ -6,10 +6,9 @@
A simple server is setup to exchange data.
created 13 July 2010
by Domenico La Fauci
by dlf (Metodo2 srl)
*/
#include <WiFi.h>
#include <IPAddress.h>
byte mac[6] = { 0 };
IPAddress ip;
@ -22,11 +21,11 @@ int status = WL_IDLE_STATUS;
char ssidList[MAX_NUM_SSID][32] = { {0} };
Server server(23);
WiFiServer server(23);
void printIpData()
{
ip = WiFi.localIp();
ip = WiFi.localIP();
Serial.print("IP: ");
Serial.print(ip[3],10);Serial.print(".");

View File

@ -6,10 +6,9 @@
A simple server is setup to exchange data.
created 13 July 2010
by Domenico La Fauci
by dlf (Metodo2 srl)
*/
#include <WiFi.h>
#include <IPAddress.h>
byte mac[6] = { 0 };
IPAddress ip;
@ -22,11 +21,11 @@ int status = WL_IDLE_STATUS;
char ssidList[MAX_NUM_SSID][32] = { {0} };
Server server(23);
WiFiServer server(23);
void printIpData()
{
ip = WiFi.localIp();
ip = WiFi.localIP();
Serial.print("IP: ");
Serial.print(ip[3],10);Serial.print(".");

View File

@ -2,7 +2,7 @@
//
// File: debug.h
//
// Author: Domenico La Fauci
// Author: dlf (Metodo2 srl)
//
//********************************************/