by GregEigsti » Sun Mar 28, 2010 9:25 pm
Here you go, its the socketapp example all moved into the sketch/pde with unnecessary stuff stripped out. It was tested with WEP 128.
My apps-conf.h has the following standard change
- Code: Select all
//Here we include the header file for the application(s) we use in our project.
//#define APP_WEBSERVER
//#define APP_WEBCLIENT
#define APP_SOCKAPP
//#define APP_UDPAPP
//#define APP_WISERVER
And my uip-conf.h has been changed as follows; UIP_CONF_MAX_CONNECTIONS probably did not need to be changed and I think its probably critical to change UIP_CONF_MAX_LISTENPORTS.
- Code: Select all
/**
* Maximum number of TCP connections.
*
* \hideinitializer
*/
#define UIP_CONF_MAX_CONNECTIONS 2
/**
* Maximum number of listening TCP ports.
*
* \hideinitializer
*/
#define UIP_CONF_MAX_LISTENPORTS 2
And the sketch
- Code: Select all
/*
* Socket App
*
* A simple socket application example using the WiShield 1.0
*/
#include <WiShield.h>
extern "C" {
#include "uip.h"
}
// Wireless configuration parameters ----------------------------------------
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
unsigned char local_ip[] = {192,168,1,10}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"SSID"}; // max 32 bytes
unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters
// WEP 128-bit keys
prog_uchar wep_keys[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Key 3
// setup the wireless mode
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------
void setup()
{
//set up serial communications
Serial.begin(57600);
WiFi.init();
}
void loop()
{
WiFi.run();
}
extern "C" {
/*---------------------------------------------------------------------------*/
/*
* The initialization function. We must explicitly call this function
* from the system initialization code, some time after uip_init() is
* called.
*/
void socket_app_init(void)
{
/* We start to listen for connections on TCP ports 80 and 8080. */
uip_listen(HTONS(80));
uip_listen(HTONS(8080));
}
/*---------------------------------------------------------------------------*/
/*
* In socketapp.h we have defined the UIP_APPCALL macro to
* socket_app_appcall so that this function is uIP's application
* function. This function is called whenever an uIP event occurs
* (e.g. when a new connection is established, new data arrives, sent
* data is acknowledged, data needs to be retransmitted, etc.).
*/
void socket_app_appcall(void)
{
if(uip_connected()) {
Serial.print("Accepted connection on port: ");
Serial.println(ntohs(uip_conn->lport));
uip_close();
}
}
/*---------------------------------------------------------------------------*/
}
Greg