Hi,
I have an Arduino project using an ethernet shield and I wanted to be able to access it remotely, so I set up a dynamic DNS service with www.no-ip.com. It works fine when I access it through my local network but if I try from an outside network it gives me the following error:
"Response Error.
Technical Description:
502 Bad Gateway - Response Error, a bad response was received from another proxy server or the destination origin server"
From what I understand, this means that www.no-ip.com has sent the request to the correct IP address but there was no server there?
Here's my Arduino code (not sure if this would be part of the problem though):
#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal.h>
#include <Time.h>
#include <TimeAlarms.h>
// General
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x98, 0x26 };
IPAddress ip(192,168,1,134);
EthernetServer server(80);
int pin[8] = {2,3,4,5,6,7,8,9};
static char readString[30];
static char *state[8] = {"OFF","OFF","OFF","OFF","OFF","OFF","OFF","OFF"};
char trueFalse;
int val;
int cursorPin;
//LCD
LiquidCrystal lcd(14,15,16,17,18,19);
int backLight = 1;
void setup()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
//Sets the LEDpin as an output
for(int i = 0; i < 8; i++){
pinMode(pin[i],OUTPUT);
digitalWrite(pin[i],HIGH);
}
//LCD Setup
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH);
lcd.begin(20,4);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("SprinkDuino");
lcd.setCursor(0,1);
lcd.print("Version 1.0");
delay(5000);
lcd.clear();
}
void loop()
{
EthernetClient client = server.available();
if (client)
{
boolean currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
int pos = strlen(readString);
if(pos < 30){
readString[pos++] = c;
readString[pos] = '\0';
}
if (c == '\n' && currentLineIsBlank)
{
char *response = strtok(readString, "?");
response = strtok(NULL, "=");
if(strcmp (response, "A") == 0){
val = 1;
}
else {
val = atoi(response);
}
response = strtok(NULL, ";");
if(strcmp (response, "T") == 0){
trueFalse = 'T';
}
else {
trueFalse = 'F';
}
client.println("<html>");
//Refresh page every 5 seconds to keep page live
client.print("<meta http-equiv=\"refresh\" content=\"5\">");
client.println("<h1>SprinkDuino</h1>");
client.println("
");
client.print("<table border=1><tr>");
client.print("<td><a href=\"./?A=T;\"><button>Turn All On</button></a>");
client.print("<a href=\"./?A=F;\"><button>Turn All Off</button></a>
");
//Individual pin control
for(int i = 0; i < 8; i++){
if ((val == (i + 2)) && (trueFalse == 'T')) {
digitalWrite(pin[i],LOW);
}
else if ((val == (i + 2)) && (trueFalse == 'F')) {
digitalWrite(pin[i],HIGH);
}
//Turn all on or off
else if ((val == 1) && (trueFalse == 'T')) {
for(int i = 0; i < 8; i++){
digitalWrite(pin[i],LOW);
}
}
else if ((val == 1) && (trueFalse == 'F')) {
for(int i = 0; i < 8; i++){
digitalWrite(pin[i],HIGH);
}
}
//Changes state[] depending on pin status
for(int h = 0; h < 8; h++){
if(digitalRead(pin[h]) == LOW){
state[h] = "ON";
}
else{
state[h] = "OFF";
}
}
client.print("Sprinkler ");
client.print(pin[i]);
client.print(" is ");
client.print(state[i]);
if (state[i] == "ON") {
client.print("<a href=\"./?");
client.print(pin[i]);
client.print("=F;\"><button>Turn Off</button><a>");
}
else {
client.print("<a href=\"./?");
client.print(pin[i]);
client.print("=T;\"><button>Turn On</button><a>");
}
client.print("
");
}
client.print("</td><td>");
client.print("<h1>Schedule</h1>");
client.print("</td></tr>");
client.print("</table>");
client.println("</html>");
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);
readString[0] = '\0';
// close the connection:
client.stop();
}
}
void digitalClockDisplay(){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Time: ");
lcd.print(hour());
printDigits(minute());
printDigits(second());
lcd.setCursor(0,2);
lcd.print("1|2|3|4|5|6|7");
}
void printDigits(int digits){
lcd.print(":");
if(digits < 10)
lcd.print('0');
lcd.print(digits);
}
Another quick question...If I change the port to anything but 80 like 8080, it still works but only prints the output text from the Arduino. I tried changing my firewall settings and even turning it off, but it still didn't interpret the code as html. This isn't too big of a problem for me since port 80 seems to be doing the trick, but just thought I'd ask.
Thanks!