Step by step on doing serial UART to WiFi Server using Arduino
1. Hardware need
A. Netgear WiFi Router
B. Arduino USB board
can be ordered from http://www.cutedigi.com/product_info.php?cPath=277&products_id=4221.
C. Arduino WiFi Shield
can be ordered from http://www.cutedigi.com/product_info.php?cPath=284&products_id=4237.
2. Software
Download WiShield library from
http://www.cutedigi.com/pub/Arduino/WiFi_project/WiShield.zip
and placed under
arduino-0017\hardware\libraries\WiShield.
3. CuteDigi's Serial (UART) to WiFi Sketch
/*
http://www.cutedigi.com
GNU license
*/
#include <WiShield.h>
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
// Wireless configuration parameters ----------------------------------------
byte local_ip[] = {10,0,0,3}; // IP address of WiShield
byte gateway_ip[] = {10,0,0,1}; // router or gateway IP address
byte subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
prog_char ssid[] PROGMEM = {"cutedigi"}; // 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 = {"big_secret"}; // max 64 characters
// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // 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
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------
Server server(5000);
Client client;
unsigned long last_serial;
void setup()
{
Serial.begin(9600);
WiFi.begin(local_ip, gateway_ip, subnet_mask);
server.begin();
Serial.begin(9600);
}
void loop()
{
if(!client.connected()) {
server.available(&client);
} else {
if (Serial.available() > 0)
{
client.print((char)Serial.read());
last_serial=millis();
}
else
{
if ( millis()-last_serial > 10 )
client.sendnow();
}
while(client.available()) {
char c = (char)client.read();
Serial.print(c);
}
}
}
Quick Test:
We will download a serial port monitor from: http://www.linksprite.com/pub/software/LinkSprite-NEC-serial-v1.0.rar
The TCP/IP debugger from: http://www.simplecomtools.com/tcptesttool.html