|
|
@ -37,7 +37,7 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <WIZ810MJ.h>
|
|
|
|
#include <WIZ810MJ.h>
|
|
|
|
|
|
|
|
#include <SPrint/staticPrint.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Define SPI-related pins
|
|
|
|
// Define SPI-related pins
|
|
|
@ -131,41 +131,41 @@ void initModule() {
|
|
|
|
#define PIN_LED 2
|
|
|
|
#define PIN_LED 2
|
|
|
|
|
|
|
|
|
|
|
|
void setup () {
|
|
|
|
void setup () {
|
|
|
|
Serial.begin(9600);
|
|
|
|
Serial.begin(19200);
|
|
|
|
Serial.println("Setup enter...");
|
|
|
|
SPrintln("Setup enter...");
|
|
|
|
|
|
|
|
|
|
|
|
configureSPI();
|
|
|
|
configureSPI();
|
|
|
|
|
|
|
|
|
|
|
|
initModule();
|
|
|
|
initModule();
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println("Test W5100 configuration...");
|
|
|
|
SPrintln("Test W5100 configuration...");
|
|
|
|
|
|
|
|
|
|
|
|
byte config_gateway[] = {192,168,2,101};
|
|
|
|
byte config_gateway[] = {192,168,0.1};
|
|
|
|
byte config_subnet_mask[] = {255,255,255,0};
|
|
|
|
byte config_subnet_mask[] = {255,255,0,0};
|
|
|
|
byte config_mac_address[] = {0x02,0xDE,0xAD,0xBE,0xEF,0x00};
|
|
|
|
byte config_mac_address[] = {0x02,0xDE,0xAD,0xBE,0xEF,0x00};
|
|
|
|
byte config_ip_address[] = {192,168,2,105};
|
|
|
|
byte config_ip_address[] = {192,168,0,69};
|
|
|
|
|
|
|
|
|
|
|
|
setGAR(config_gateway);
|
|
|
|
setGAR(config_gateway);
|
|
|
|
setSUBR(config_subnet_mask);
|
|
|
|
setSUBR(config_subnet_mask);
|
|
|
|
setSHAR(config_mac_address);
|
|
|
|
setSHAR(config_mac_address);
|
|
|
|
setSIPR(config_ip_address);
|
|
|
|
setSIPR(config_ip_address);
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println("End test W5100 configuration...");
|
|
|
|
SPrintln("End test W5100 configuration...");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println("Test W5100 driver code...");
|
|
|
|
SPrintln("Test W5100 driver code...");
|
|
|
|
|
|
|
|
|
|
|
|
getGAR(ip);
|
|
|
|
getGAR(ip);
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print("Gateway IP read (first digit): ");
|
|
|
|
SPrint("Gateway IP read (first digit): ");
|
|
|
|
Serial.println(ip[0], DEC);
|
|
|
|
Serial.println(ip[0], DEC);
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println("End test W5100 driver code...");
|
|
|
|
SPrintln("End test W5100 driver code...");
|
|
|
|
|
|
|
|
|
|
|
|
pinMode(PIN_LED, OUTPUT);
|
|
|
|
pinMode(PIN_LED, OUTPUT);
|
|
|
|
digitalWrite(PIN_LED, HIGH);
|
|
|
|
digitalWrite(PIN_LED, HIGH);
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println("Setup exit...");
|
|
|
|
SPrintln("Setup exit...");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -173,7 +173,7 @@ void sendPrompt(uint8_t *buffer) { // {Socket targetSocket, ) {
|
|
|
|
|
|
|
|
|
|
|
|
strcpy((char *) buffer, "w00t!> ");
|
|
|
|
strcpy((char *) buffer, "w00t!> ");
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print("send result: ");
|
|
|
|
SPrint("send result: ");
|
|
|
|
//Serial.println(send(testSocket, buffer, 6), DEC);
|
|
|
|
//Serial.println(send(testSocket, buffer, 6), DEC);
|
|
|
|
Serial.println(send(testSocket, buffer, strlen((char *)buffer)), DEC);
|
|
|
|
Serial.println(send(testSocket, buffer, strlen((char *)buffer)), DEC);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -181,38 +181,39 @@ void sendPrompt(uint8_t *buffer) { // {Socket targetSocket, ) {
|
|
|
|
void sendBanner(uint8_t *buffer, int ledState) { // {Socket targetSocket, ) {
|
|
|
|
void sendBanner(uint8_t *buffer, int ledState) { // {Socket targetSocket, ) {
|
|
|
|
|
|
|
|
|
|
|
|
//strcpy((char *) buffer, "Content-Type: text/plain\n\nfoo!\n");
|
|
|
|
//strcpy((char *) buffer, "Content-Type: text/plain\n\nfoo!\n");
|
|
|
|
strcpy((char *) buffer, "HTTP/1.1 200 OK\n\rContent-Type: text/html\n\r\n\r<html><body bgcolor='#000000'>foo!</body></html>\n\r");
|
|
|
|
|
|
|
|
if (ledState) {
|
|
|
|
if (ledState) {
|
|
|
|
|
|
|
|
strcpy((char *) buffer, "HTTP/1.1 200 OK\n\rContent-Type: text/html\n\r\n\r<html><body bgcolor='#000000'>foo!</body></html>\n\r");
|
|
|
|
buffer[66] = 'F';
|
|
|
|
buffer[66] = 'F';
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
strcpy((char *) buffer, "HTTP/1.1 200 OK\n\rContent-Type: text/html\n\r\n\r<html><body bgcolor='#000000'>bar!</body></html>\n\r");
|
|
|
|
buffer[68] = 'F';
|
|
|
|
buffer[68] = 'F';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print("send result: ");
|
|
|
|
SPrint("send result: ");
|
|
|
|
Serial.println(send(testSocket, buffer, strlen((char *)buffer)), DEC);
|
|
|
|
Serial.println(send(testSocket, buffer, strlen((char *)buffer)), DEC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
void loop() {
|
|
|
|
Serial.println("Test W5100 socket...");
|
|
|
|
SPrintln("Test W5100 socket...");
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print("Create socket result: ");
|
|
|
|
SPrint("Create socket result: ");
|
|
|
|
Serial.println(socket(testSocket, Sn_MR_TCP, 80, 0), DEC);
|
|
|
|
Serial.println(socket(testSocket, Sn_MR_TCP, 80, 0), DEC);
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print("Socket status: ");
|
|
|
|
SPrint("Socket status: ");
|
|
|
|
Serial.println(IINCHIP_READ(Sn_SR(testSocket)), HEX);
|
|
|
|
Serial.println(IINCHIP_READ(Sn_SR(testSocket)), HEX);
|
|
|
|
|
|
|
|
|
|
|
|
if (IINCHIP_READ(Sn_SR(testSocket)) == SOCK_CLOSED) {
|
|
|
|
if (IINCHIP_READ(Sn_SR(testSocket)) == SOCK_CLOSED) {
|
|
|
|
Serial.println("Socket still closed, waiting...");
|
|
|
|
SPrintln("Socket still closed, waiting...");
|
|
|
|
while (IINCHIP_READ(Sn_SR(testSocket)) == SOCK_CLOSED) {
|
|
|
|
while (IINCHIP_READ(Sn_SR(testSocket)) == SOCK_CLOSED) {
|
|
|
|
//pass
|
|
|
|
//pass
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print("Listen on socket result: ");
|
|
|
|
SPrint("Listen on socket result: ");
|
|
|
|
Serial.println(listen(testSocket), DEC);
|
|
|
|
Serial.println(listen(testSocket), DEC);
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println("Waiting for connection...");
|
|
|
|
SPrintln("Waiting for connection...");
|
|
|
|
|
|
|
|
|
|
|
|
while (getSn_SR(testSocket) == SOCK_LISTEN) {
|
|
|
|
while (getSn_SR(testSocket) == SOCK_LISTEN) {
|
|
|
|
delay(500);
|
|
|
|
delay(500);
|
|
|
@ -222,7 +223,7 @@ void loop() {
|
|
|
|
|
|
|
|
|
|
|
|
getSn_DIPR(testSocket, ip);
|
|
|
|
getSn_DIPR(testSocket, ip);
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print("Destination IP read (last digit): ");
|
|
|
|
SPrint("Destination IP read (last digit): ");
|
|
|
|
Serial.println(ip[3], DEC);
|
|
|
|
Serial.println(ip[3], DEC);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -288,7 +289,7 @@ void loop() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ((state == STATE_ERR) || (state == STATE_END)) {
|
|
|
|
if ((state == STATE_ERR) || (state == STATE_END)) {
|
|
|
|
Serial.println("");
|
|
|
|
SPrintln("");
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -298,14 +299,14 @@ void loop() {
|
|
|
|
if (dataLength >= MAX_RX_BUFFER_SIZE) { // TODO: blah, blah...
|
|
|
|
if (dataLength >= MAX_RX_BUFFER_SIZE) { // TODO: blah, blah...
|
|
|
|
dataLength = MAX_RX_BUFFER_SIZE-1;
|
|
|
|
dataLength = MAX_RX_BUFFER_SIZE-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Serial.print("dataLength: "); Serial.println(dataLength, HEX);
|
|
|
|
// SPrint("dataLength: "); Serial.println(dataLength, HEX);
|
|
|
|
//Serial.print("recv result: ");
|
|
|
|
//SPrint("recv result: ");
|
|
|
|
//Serial.println(recv(testSocket, bytesReceived, dataLength), DEC); // NOTE: Throws away unread portion? No?
|
|
|
|
//Serial.println(recv(testSocket, bytesReceived, dataLength), DEC); // NOTE: Throws away unread portion? No?
|
|
|
|
recv(testSocket, bytesReceived, dataLength); // TODO: Return length?
|
|
|
|
recv(testSocket, bytesReceived, dataLength); // TODO: Return length?
|
|
|
|
bytesReceived[dataLength]=0x00;
|
|
|
|
bytesReceived[dataLength]=0x00;
|
|
|
|
Serial.print((char *)bytesReceived);
|
|
|
|
Serial.print((char *)bytesReceived);
|
|
|
|
|
|
|
|
|
|
|
|
//Serial.print("send result: ");
|
|
|
|
//SPrint("send result: ");
|
|
|
|
//Serial.println(send(testSocket, bytesReceived, dataLength), DEC);
|
|
|
|
//Serial.println(send(testSocket, bytesReceived, dataLength), DEC);
|
|
|
|
|
|
|
|
|
|
|
|
//sendPrompt(bytesReceived);
|
|
|
|
//sendPrompt(bytesReceived);
|
|
|
@ -317,10 +318,10 @@ void loop() {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
disconnect(testSocket);
|
|
|
|
|
|
|
|
close(testSocket);
|
|
|
|
close(testSocket);
|
|
|
|
|
|
|
|
disconnect(testSocket);
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println("End test W5100 socket...");
|
|
|
|
SPrintln("End test W5100 socket...");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|