Pages: [1]   Go Down
Author Topic: unable to log on to arduino from phone  (Read 647 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 1
Posts: 252
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was testing my arduino ethernet sketch and I can log on to it from my computer (on the same network) but when I try with my android phone (off network obviously) it does not find the site. What am I missing?

Here is the code for reference (IDE 1.0 and the hardware is a Arduino Ethernet).

Code:
//byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xE3, 0xCA };
//byte ip[] = { 192, 168, 1, 3 };
//byte gateway[] = { 192, 168, 1, 1 };

/*
* Web Server
*
* A simple web server that shows the value of the analog input pins.
*/
#if ARDUINO > 18
#include <SPI.h> // needed for Arduino versions later than 0018
#endif
#include <Ethernet.h>
#include "PCD8544.h"
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xE3, 0xCA };
byte ip[] = { 192, 168, 1, 10 };
byte gateway[] = { 192, 168, 1, 1 };
EthernetServer server(80);

int tempPin = A2;
int humidPin = A1;
int temp2Pin = A0;
float TempVAL;
float TempVAL2;
float TempC;
float Temp2C;
float RH;

// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
PCD8544 nokia = PCD8544(7, 6, 5, 8, 3);

void setup()
{
    Serial.begin(9600);
  Serial.println();
  nokia.init();
  nokia.setContrast(50);
  delay(500);
  
Ethernet.begin(mac, ip, gateway);
server.begin();

Serial.println(Ethernet.localIP());

  pinMode(humidPin, INPUT);
  pinMode(temp2Pin, INPUT);
  pinMode(tempPin, INPUT);

}
void loop()
{
  
    analogRead(humidPin);
  delay(10);
  int humid = analogRead(humidPin);
  delay(50);
  
  analogRead(tempPin);
  delay(10);
  TempVAL = analogRead(tempPin);
  delay(50);
  
  analogRead(temp2Pin);
  delay(10);
  TempVAL2 = analogRead(temp2Pin);
  delay(50);
  
  //TEMP
TempVAL = (((TempVAL / 1024) * 5) * 100); // convert value to kelvin
TempVAL = (TempVAL - 273); // convert value to celsius
TempC = TempVAL;
TempVAL = (TempVAL * 1.8 + 32); // convert value to farenheit

//TEMP2
TempVAL2 = (TempVAL2 / 1024) * 5;
Temp2C = (TempVAL2 - 0.5) * 100;
float temperatureF = (Temp2C * 9.0 / 5.0) + 32.0;

RH = (0.1577*humid - 25.868);

  nokia.setCursor(0, 0);
  nokia.print("Temp1= ");
  nokia.print(temperatureF);
  nokia.print("*F");
  nokia.print("Temp2= ");
  nokia.print(TempVAL);
  nokia.print("*F");
  nokia.print("Humid= ");
  nokia.print(RH);
  nokia.print("%");
  nokia.display();
  delay(2000);
  nokia.clear();
  
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (c == '\n' && current_line_is_blank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// output the value of each analog input pin
//for (int i = 0; i < 6; i++) {
client.print("Temperture 1 = ");
client.print(TempVAL);
client.print("F, ");
client.print("Temperature 2 = ");
client.print(temperatureF);
client.print("F, ");
client.print("Humidity = ");
client.print(RH);
client.print("%");
//client.print(analogRead(i));
client.println("<br />");



//}
break;
}
if (c == '\n') {
// we're starting a new line
current_line_is_blank = true;
} else if (c != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
client.stop();
}
}


  void setCursor(uint8_t x, uint8_t y);
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 150
Posts: 6130
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The 192.168.1.10 ip is only valid on your localnet (connected to your router). If you are trying to access the shield from the internet, you will need to put that ip in the "DMZ" (ip/port forwarding) on your router, then access it using the public ip on your router.

So I don't have to cover everything twice, take a look at this post starting at reply #10.
http://arduino.cc/forum/index.php/topic,88173.0.html
Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 252
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Perfect.... Thanks Tim, I knew it was something simple... I should have remembered my great half life server port-forwarding debacle of 2001... lol.
Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 252
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If your curious what the temp and humidity in my living room is....

*edit* link removed
« Last Edit: January 23, 2012, 11:34:04 am by RobDrizzle » Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 150
Posts: 6130
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice! Worked good here. That didn't take you long at all!
Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 252
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

All work well, except randomly (ever few calls) each temp sensor has a low reading. You can see in on the Nokia display here pretty often and every now and again on the web if you refresh quickly.

I have been running these sensors and basic temp code for months and they have never acted like that...
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 150
Posts: 6130
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I presume the Nokia is your display? If so, you really need to drop this delay in nokia.print() stuff.
Quote
  delay(2000);
That slows your ability to service clients to one every 2.2 seconds with the analog read delays added in. I would come up with a different way to add that delay so you can service the waiting clients faster than that.
Logged

Pages: [1]   Go Up
Jump to: