Hello,
I am trying to run a web server onto an arduinoUno that when polled performs simple ascii STRING reading from a serial device.
It is basically the ethernet webserver example with some minor changes.
Here Is the code I wrote
#include <Ethernet.h>
#include <SPI.h>//needed for ethernet shield
char incomingByte=-1; // for incoming serial data
char data[30];
int ledr=0;
boolean led=true;
//setup ethernet
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);// (port 80 is default for HTTP):
EthernetServer server(80);//setup serial port
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
Ethernet.begin(mac, ip);
server.begin();
}void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (c == '\n' && currentLineIsBlank) {
Serial.print("s");//put here command to send to the device
int i=0;
while (Serial.available() > 0) {
if(i<30){
data*=(char)Serial.read();*
- i++;*
_ data*='\0';_
_ }_
_ }_
_ // send a standard http response header*_
* client.println("HTTP/1.1 200 OK");*
* client.println("Content-Type: text/html");*
* client.println("Connnection: close");*
* client.println();*
* client.println("");*
* client.println("");*
* // add a meta refresh tag, so the browser pulls again every 5 seconds:*
* client.println("<meta http-equiv="refresh" content="5">");*
* client.println("data_Received");
_ client.println(data);_
_ client.println("_
_");_
_ //end if \n e current line blank. _
_ client.println("");_
_ ledr=~ledr;_
_ break; _
_ }_
_ if (c == '\n') {_
_ // you're starting a new line*_
* currentLineIsBlank = true;*
* }*
* else if (c != '\r') {*
* / you've gotten a character on the current line*
* currentLineIsBlank = false;*
* }*
* }*
* }*
* // give the web browser time to receive the data*
* delay(1);*
* // close the connection:*
* client.stop();*
* Serial.println("client disonnected");*
* }*
}
[/quote]
Now, the respone I Should have is exactly the string ""done \n", and with pc-serial port it works fine.
Anyway, the running web server response is "ÿßßþÿÙÖü", that's quite different from what was expecting.
I suppose there should be logical errors in my routine, but I can't figure out where.
Any hint would be appreciated.