Take the 2-minute tour ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

Few days back I started a project to interface ardunio with the ENC28J60 Ethernet shield. I am totally new to the world of electronics and i got the code for controlling an LED and reading an analog input from a website. And everything wen't well and now I'm able to control the led through a webpage and the webpage is showing the analog reading on the webpage beautifully. But as you might have guessed, I'm able to control the arduino board and the associated sensors though the cross-over Ethernet cable. Now I wanna extend this project and control the LEDs through internet, so that I can access it from anywhere with a valid internet connection. Now coming to the ACTUAL DOUBT, here it does. 1. I need an Internet source to connect to my ENC28J60 board. Can I provide this source using the following setup? I'll connect a USB dongle to my laptop and I'll share the internet connection from my laptop to the LAN. And if I can do that what should be the IP address to enter into the browser to access the webpage written in my arduino board? If this does not work in what way can I provide my internet source to my ENC28J60 so that I'll be able to access it globally through browsers?

// A simple web server that always just says "Hello World"

#include "etherShield.h"
#include "ETHER_28J60.h"

int outputPin = 6;

static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24};  
  // so unless you have more    than one of these boards
  // connected, you should be fine with this value.

static uint8_t ip[4] = {169, 254, 2, 233};     // the IP address for your board. Check your home hub
 // to find an IP address not in use and pick that
 // this or 10.0.0.15 are likely formats for an address
 // that will work.

 static uint16_t port = 80;                                      // Use port 80 - the standard for HTTP

 ETHER_28J60 e;

 void setup()
 { 
  e.setup(mac, ip, port);
  pinMode(outputPin, OUTPUT);
 }

 void loop()
 {
  char* params;



  if (params = e.serviceRequest())
  {
   e.print("<H1>Web Remote</H1>");
   e.print("<A HREF='?cmd=off'>Turn off</A>");
   e.print("<H1>          </H1>");
   e.print("<A HREF='?cmd=on'>Turn on</A>");
   if (strcmp(params, "?cmd=on") == 0)
   {
    digitalWrite(outputPin, HIGH);

   }
   else if (strcmp(params, "?cmd=off") == 0) // Modified -- 2011 12 15 # Ben Schueler
   {
    digitalWrite(outputPin, LOW);

   }
    e.print("<H1>Analog Value</H1><br/><table>");
    e.print("<tr><th>Inputpin</th><td><td><td><td><th>Value</th></tr>");
    e.print("<tr><td>"); e.print(0); e.print("</td><td><td><td><td><td>");  e.print(analogRead(0)); e.print("</td></tr>");

e.respond();
 }
 delay(100);
}
share|improve this question

migrated from electronics.stackexchange.com Apr 10 at 16:03

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

1  
Accessing it globally is a tricky problem of overcoming firewalls and NAT. It's the same problem as accessing a server on your laptop globally would be. Nearly all consumer IoT devices go the other way: the device polls a server to find out what to do. –  pjc50 Apr 10 at 15:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.