Converting Int Values from Anlogue inputs to Text for output on webpage.

Hi All,

I'm using a slightly modified version of the Web server example to try and remotely monitor one of our transmitter sites from the analogue inputs via closing relay contacts, as far as hardware is concerned i'm all set and have it working fine.
However i'm having trouble getting my head around the programming code.

At the moment it's displaying each of the outputs as the int range 0-1024.

What i want it do:
For example, if Analog 3 input value is above 500 i need it to display "OK" on the webpage
If the value is below 500 need it to display "Fail".
and the same for the Transmitter Temperature need a certain input voltage to have a correct temperature scale.

I've have been looking on Google for hours for conversion of int to words and so on... But can't find anything that relates to this..

Here is the Code:

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup()
{
// start the Ethernet connection and the server:
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 you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println(""); //refresh page every 1 second to update with new data values.

// output the value of analog input pin 0
for (int analogChannel = 0; analogChannel < 1; analogChannel++) {
client.print("TRANSMITTER TEMP : ");
client.print(analogRead(analogChannel));
client.println("

");
}

// output the value of analog input pin 1
for (int analogChannel = 1; analogChannel < 2; analogChannel++) {
client.print("ROOM TEMPERATURE : ");
client.print(analogChannel);
client.print(analogRead(analogChannel));
client.println("

");
}

// output the value of analog input pin 2
for (int analogChannel = 2; analogChannel < 3; analogChannel++) {
client.print("TRANSMITTER STATUS : ");
client.print(analogChannel);
client.print(analogRead(analogChannel));
client.println("

");
}
// output the value of analog input pin 3
for (int analogChannel = 3; analogChannel < 4; analogChannel++) {
client.print("EMERGENCY PLAYER STATUS : ");
client.print(analogChannel);
client.print(analogRead(analogChannel));
client.println("

");
}
// output the value of analog input pin 4
for (int analogChannel = 4; analogChannel < 5; analogChannel++) {
client.print("POWER STATUS : ");
client.print(analogChannel);
client.print(analogRead(analogChannel));
client.println("

");
}
// output the value of analog input pin 5
for (int analogChannel = 5; analogChannel < 6; analogChannel++) {
client.print("ENTRY WARNING: ");
client.print(analogChannel);
client.print(analogRead(analogChannel));
client.println("

");
}
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();
}
}

Also, as you can probably tell i'm relatively new to this, so if anyone could help me with the code and explain to me how it fits in with: "for (int analogChannel = 5; analogChannel < 6; analogChannel++)"

It would be greatly appreciated!

Thanks in advance.

Those for statements are doing nothing; I assume they were lifted from an example where several similar analog reads were being performed. You can get rid of all of them. The translation of numbers into words just needs an if. So this:

          for (int analogChannel = 0; analogChannel < 1; analogChannel++) {
            client.print("TRANSMITTER TEMP : ");
            client.print(analogRead(analogChannel));
            client.println("<p />");
             }

Can be replaced by:

            client.print("TRANSMITTER TEMP : ");
            if(analogRead(analogChannel) < 500)
              {
              client.print("FAIL");
              }
            else
              {
              client.print("OK");
              }
            client.println("<p />");

Thankyou Very much for your Help!

Worked Great!..

Its so simple, can't believe i couldn't put that together :blush:

Thanks Again!