Hi,
I have written a ethernet server based on the code found in net.
Sakura is not responding for the ethernet frames from client. I am using offline compiler
Code ::
#include <rxduino.h>#include <Ethernet.h>#define INTERVAL 100byte mac[] = {0x08, 0x09, 0x3c, 0x12, 0x34, 0x56};byte ip[] = {192,168,0,2};TEthernet Ethernet;EthernetServer server (80);void setup(){ pinMode(PIN_LED0,OUTPUT); pinMode(PIN_LED1,OUTPUT); pinMode(PIN_LED2,OUTPUT); pinMode(PIN_LED3,OUTPUT); Serial.begin(115200,SCI_SCI0P2x); Ethernet.begin(mac,ip); Serial.write("Ethernet done \n");Serial.print("My IP address is: "); Serial.println(Ethernet.localIP()); server.begin(); Serial.write("Server begin done \n"); /*speed: Baud rateThe port: port to be used (if omitted, use the virtual COM port of USB0)I use a virtual COM port USB0: SCI_USB0I use the (TxD) (RxD), pin 30 pin 31 SCI_SCI2AI use the (RxD) (TxD), pin 26 SCI_SCI2B pin 24. Used to access XBeeI use the (RxD) (TxD), Pin 6 Pin 7 SCI_SCI6BI use the (TxD) (RxD), pin 1 SCI_SCI0P2x pin 0Select the one it received for the first time in USB0 or SCI_AUTO pin 0,1*/Serial.write("Setup done \n");}void loop(){EthernetClient client; client = server.available (); if (client) { // got client? boolean currentLineIsBlank = true; digitalWrite(PIN_LED0, 1); delay(INTERVAL); while (client.connected()) { digitalWrite(PIN_LED1, 1); delay(INTERVAL); if (client.available()) { // client data available to read char c = client.read(); // read 1 byte (character) from client // last line of client request is blank and ends with \n // respond to client only after last line received digitalWrite(PIN_LED2, 1); delay(INTERVAL); if (c == '\n' && currentLineIsBlank) { digitalWrite(PIN_LED3, 1); delay(INTERVAL); // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); client.println(); // send web page client.println("<!DOCTYPE html>"); client.println("<html>"); client.println("<head>"); client.println("<title>GK-Sakura Web Page</title>"); client.println("</head>"); client.println("<body>"); client.println("<h1>Hello from GK-Sakura!</h1>"); client.println("<p>A web page from the GK-Sakura server</p>"); client.println("</body>"); client.println("</html>"); break; } // every line of text received from the client ends with \r\n if (c == '\n') { // last character on line of received text // starting new line with next character read currentLineIsBlank = true; } else if (c != '\r') { // a text character was received from client currentLineIsBlank = false; } } // end if (client.available()) } // end while (client.connected()) delay(1); // give the web browser time to receive the data client.stop(); // close the connection } // end if (client)// Serial.write("LOOP\n");}
Hi I cant really help with the software side, but just a few thoughts
It would be useful to explain how you are using the Ethernet interface without having to look through all the code
This would help someone to understand in more detail the problem and for the users who are using the Ethernet interface see if it is similar to your design
Make sure that if you are using the internal hardware Ethernet and PHY that all the connections, jumpers and interfaces etc. are set correctly (especially if you have been using the board for any other functions)
Also that if you are porting code from the web many Arduino Ethernet implementations use an external shield board to provide the MAC and PHY and a serial interface between the MCU and the shield board
(often SPI as this is the fastest). The Ethernet interface on the GR-Sakuara board I am sure you are aware is connected directly to the RX63N MCU
Also there a number of posts in the forum and India design contexts about using Ethernet, which may be of some assistance with your problem
Sorry I can't be of more help
I too tried this out, and it didnt work out at all ... Been on it for a while now. Have you gotten it to work / any progress at all ?
I did try your code out, but didnt debug properly(didnt have time) ... was planning on doing it tomorrow.
I did try out some other codes online and also went through a website which had explanations of each function in Ethrnet library and made my code. That too did not work.
I the latter approach had some issues with the dhcp itself (i think) ... as ...
When i gave it a static IP in the ethernet.begin function, it continued past the Ethernet.begin function, but My laptop could not find the ip in it's local group...
I also answered to another user in another blog that there are many reasons, what could be wrong (e.g. router setup, MAC filtering, wrong IP range, etc.), see: renesasrulz.com/.../3839.aspx
And I also have posted there that I also have difficulties to get the Ethernet web server running with the OFFline compiler. So, please try that first using the ONline web compiler.
Anyway, here's my code, which definitely works. It worked with using the DHCP (without using the ip address) and using the ip setting manually. Honestly speaking, I'm not sure which impact the MAC address has. But mine is different. I think, it shouldn't matter (unless you have a MAC filtering in your router enabled, which might block certain MAC addresses).
Here's my code:
#define RXDUINO
// increase compatibility to test also for Arduino
#ifdef RXDUINO
#include <rxduino.h>
#else
#include <Arduino.h>
#include <SPI.h>
#endif
#include <Ethernet.h>
TEthernet Ethernet;
// MAC-Adresse
byte mac[] = {
0x90, 0xA2, 0xDA, 0x0D, 0x02, 0x8C}; // ensure it's not blocked by router or network
byte ip[] = {
0xC0, 0xA8, 0x02, 0x69}; // not used, but can be used...
EthernetServer server(80);
const int analogPin = A0;
const int inputTestPin = 0;
const int led1 = 1;
const int led2 = 2;
void setup()
{
pinMode(PIN_LED0,OUTPUT); // for debugging
pinMode(PIN_LED3,OUTPUT); // for debugging
pinMode(inputTestPin, INPUT); // for testing
digitalWrite(PIN_LED0, LOW);
digitalWrite(PIN_LED3, LOW);
pinMode(led1,OUTPUT); // for debugging
pinMode(led2,OUTPUT);
digitalWrite(led1,0);
digitalWrite(led2,0);
Serial.begin(9600); // Bit rate don't care if via USB
delay(500);
// use ONLY that statement if ip is fixed:
// Ethernet.begin(mac, ip);
// if DHCP, no further variable necessary, but check for getting IP correctly
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed get address on DHCP");
while(1); // loop forever in case of error = stop
}
Serial.println("Get IP address from DHCP is success.");
server.begin();
Serial.print("Please access by browser at http://");
Serial.println(Ethernet.localIP());
char outStr[80];
void loop()
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
boolean currentLineIsBlank = true;
while (client.connected()) {
Ethernet.processPackets();
if (client.available()) {
digitalWrite(PIN_LED0, HIGH); // Server ist UP!
char c = client.read();
Serial.write(c);
if (c == '\n' && currentLineIsBlank) {
digitalWrite(PIN_LED3, HIGH); // shows: client request is there
// http
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
client.println("<!DOCUTYPE HTML>");
client.println("<html>");
client.println("<h1>Answer from GR-Sakura</h1><p style='color:red; font-weight:bold;'>Hello!</p>");
sprintf( outStr , "Value of Analog Pin A0: %d value of Digital Pin 0: %d LED1 is: %d", analogRead(analogPin), digitalRead(inputTestPin), digitalRead(led1) );
client.println(outStr);
client.println("</html>");
break;
// EOL(\n)
if (c == '\n') {
currentLineIsBlank = true;
//
else if (c != '\r') {
currentLineIsBlank = false;
delay(10);
client.stop();
// digitalWrite(PIN_LED0, LOW); // Server ist DOWN!
Serial.println("client disconnected");
(if it helps, I also could post the sketch.bin file)
I have tried both offline and online compilers, it is not working for me.i will try your code. Are usingUSB as serial connection. I tried to install driver, somehow, devices is not detecting as com port.
seems you have a basic problem.
I'm not sure which OS you are using, but for Windows maybe this thread might help:
renesasrulz.com/.../508.aspx
or that with some additional explanations:
renesasrulz.com/.../3779.aspx
Sometimes, I made the experience that the USB serial port and connection to the USB terminal does not work immediately after uploading the code. So, try to remove the USB connection after uploading the sketch.bin and connect it again and try again then to connect via the USB terminal.
Hi Juergen Zimmer,
With online compiler ethernet is working for first time after reset.
With offline compiler ethernet is not working.
Please see the log connection is not getting closed in the second time and it is hang.
26/09/2013 05:26:29.042 [RX] - Get IP address from DHCP is success.<CR><LF>
Please access by browser at http://192.168.1.105<CR><LF>
new client<CR><LF>
GET / HTTP/1.1<CR><LF>
Host: 192.168.1.105<CR><LF>
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Firefox/24.0<CR><LF>
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8<CR><LF>
Accept-Language: en-US,en;q=0.5<CR><LF>
Accept-Encoding: gzip, deflate<CR><LF>
Connection: keep-alive<CR><LF>
<CR><LF>
client disconnected<CR><LF>
GET /favicon.ico HTTP/1.1<CR><LF>
Accept: image/png,image/*;q=0.8,*/*;q=0.5<CR><LF>
Serial port also works fine now with USB.
Ethernet hang does not happen everytime. tried with iexplore and firefox.
Is there any solution for offline. i might be depended on library we are using in offline compiler. skectch size is different between online and offline compiler for the same code.
Hello,
I have tried so many time in ON line and OFF line complier Ethernet doesn't work.Please tell me any hardware changes is there.
There is no hardware change involved. Whatever code runs on the ON line compiler will also run on the OFF line compiler.
yes Abdeali is correct.......code should run for both Offline and online
I suspect the libraries used will make the difference in case of offline and online compilers.
With offline size of the sketch.bin is 93kb
with online size was 97kb.
Is there any way to update the offline compiler lib to latest?
Please any one give me Ethernet udp code or give me some idea
How to find MAC ID of the module ?
Sorry to delay reply.
GR-SAKURA has no MAC address itself.
So in case of prototyping using them, specify your MAC like sample of Arduino.
www.arduino.cc/.../WebClient
U/L bit in 1st octet should be specified 1.
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
~~~~