Ethermega with D-link router & Prepaid wireless

Combining the power of the ATmega2560 MCU with onboard Ethernet, a microSD card slot, an efficient switchmode power supply, and a small prototyping area. [Product page]
Post Reply
vero96
Posts: 25
Joined: Sat Jun 01, 2013 10:08 pm

Ethermega with D-link router & Prepaid wireless

Post by vero96 » Mon Jul 08, 2013 12:46 am

Hi, I am using a Ethermega with an SD card to read whats on the SD card in the Browser (Mozilla) I have used "Geany" as the text editor and everything works fine I am able to read the HTML script on the card when I enter the IP address into the address bar, here is the code I have used with the mega -

Code: Select all




/*--------------------------------------------------------------
  Program:      eth_websrv_SD

  Description:  Arduino web server that serves up a basic web
                page. The web page is stored on the SD card.
  
  Hardware:     Arduino Uno and official Arduino Ethernet
                shield. Should work with other Arduinos and
                compatible Ethernet shields.
                2Gb micro SD card formatted FAT16
                
  Software:     Developed using Arduino 1.0.3 software
                Should be compatible with Arduino 1.0 +
                SD card contains web page called index.htm
  
  References:   - WebServer example by David A. Mellis and 
                  modified by Tom Igoe
                - SD card examples by David A. Mellis and
                  Tom Igoe
                - Ethernet library documentation:
                  http://arduino.cc/en/Reference/Ethernet
                - SD Card library documentation:
                  http://arduino.cc/en/Reference/SD

  Date:         10 January 2013
 
  Author:       W.A. Smith, http://startingelectronics.com
--------------------------------------------------------------*/

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

// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip( 169,x,x,x); // IP address, may need to change depending on network
EthernetServer server(80);  // create a server at port 80

File webFile;

void setup()
{
    Ethernet.begin(mac, ip);  // initialize Ethernet device
    server.begin();           // start to listen for clients
    Serial.begin(9600);       // for debugging
    
    // initialize SD card
    Serial.println("Initializing SD card...");
    if (!SD.begin(4)) {
        Serial.println("ERROR - SD card initialization failed!");
        return;    // init failed
    }
    Serial.println("SUCCESS - SD card initialized.");
    // check for index.htm file
    if (!SD.exists("index.htm")) {
        Serial.println("ERROR - Can't find index.htm file!");
        return;  // can't find index file
    }
    Serial.println("SUCCESS - Found index.htm file.");
}

void loop()
{
    EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                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("Connection: close");
                    client.println();
                    // send web page
                    webFile = SD.open("index.htm");        // open web page file
                    if (webFile) {
                        while(webFile.available()) {
                            client.write(webFile.read()); // send web page to client
                        }
                        webFile.close();
                    }
                    break;
                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                } 
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)
}



The configuration from above is as follows - Ethermega plugged into PC, PC wifi card picks up signal from a wifi hotspot and I can communicate with the outside world. Enter the IP of the mega into the address bar and I am connected to the script on then SD card in the browser.

I have also used a phone connected to the same hotspot as the PC the mega is plugged into and attempted to connect to the IP address of the mega unsuccessfully.


However when I attempt to connect to the mega's IP address from another PC using a different IP address ie. a dongle plugged into a d-link router on the other side of the room I am unable to connect?

I have gone into the admin section for the d-link router and entered the IP address for the mega on port 80 in the use as server section, then going back to the PC with the Hotspot ( different IP ) from the dongle router combo and attempted to connect to the mega the connection times out or I get the message server may be too busy or may have moved permanently to a new address.


I emailed a fellow Arduino enthusiast the IP address he was unable to connect, so he pinged the IP of the mega while it was "online" and had no contact/could not connect.

I have also spoken to my ISP one tech told me I was using DHCPIP addresses and and needed a static IP another tech told me I had a static IP and needed a DHCPIP addresses. I spent 8 hours ( Yes 8 hours many calls I'm not kidding! ) on the phone just trying to get an straight answer they said they would ring back ha.

So my problem is this, I don't use an ADSL cable connection to the house ( it's very old ) and I travel often so WiFi is my only option. I had a preconceived idea that the mega would act as the "Server" the "router WiFi dongle combo" would act like a "tower" and I would be able to pick up the signal and connect that way.


Perhaps I have some misconceptions about how these things work ( Arduino/TCP-IP ), however I am trying to learn and would like to get this working. I believe in the learning by doing philosophy, seems all I'm doing is making mistakes, so I'm learning from this all is not lost ;)

Any advice would be greatly appreciated
Thanks in advance,

vero

vero96
Posts: 25
Joined: Sat Jun 01, 2013 10:08 pm

Re: Ethermega with D-link router & Prepaid wireless

Post by vero96 » Mon Jul 08, 2013 9:24 am

Hi, Thanks for the prompt reply, I should have mentioned in the OP the router I am using is the d-link dwr-161 here's a link to the product page http://www.dlink.com.au/products/?pid=952


Also on the point of Telstra they did say they could assign me a static IP however just to clarify, that static IP would be for the pre-paid dongle that the router uses to connect to the internet I assume?

So from what I have read on the product page and info I have the router makes the cut, A call to Telstra should see me with a static IP for the dongle ( has sim card ) should see me into a setup that is viable to use with the ethermega.

As previously stated I want to be able to see it on another network (and for others to see it, corney but true) so if there is anything I have missed.

Assuming I have this right I set up the dongle with the Static IP > its connected to the Router > the Ethermega is connected to the Wan/Lan port > Ethermega has its own unique IP and MAC addresses. On another PC with a different modem and IP as a client I enter the IP of the Ethermega and all going well should be connected to the mega and able to read in the Browser the info written to the SD card.

If I have anything wrong anyone feel free to jump in and correct me, any suggestions or feed back would be welcome

Cheers, vero

vero96
Posts: 25
Joined: Sat Jun 01, 2013 10:08 pm

Re: Ethermega with D-link router & Prepaid wireless

Post by vero96 » Fri Jul 12, 2013 2:03 am

Hi, Well they say if sounds too good to be true it probably is, after another 1/2 dozen or more phone calls ( easy 4+ hours ) :evil: to Telstra no they will not assign me a static IP on a wireless network. Just to clarify as it is associated with the thread, I was told by several "techs" many time's it could be done hence the confusion. Long story short the only way too have one assigned on last count is to have ADSL + a Business account for which your'll be needing an ABN........ring tomorrow who knows their stories change like the wind.

So, I picked up a D-link dgs-1005d switch & Freetronics mid-span injector, found this thread http://forum.arduino.cc/index.php?PHPSE ... c=112955.0 which was very helpful, and have been at it trying to get this set-up configured, as to access/see whats on the SD on another network.


However no Cigar, I configured the dwr-161 for virtual server setting IP xxx.xxx.x.xx:80 (port 80), having enabled the source & destination ports in the "virtual server rules list" and similarly in the "inbound filtering" and "outbound filtering" using the same IP and Port 80 (tried 81/443/8080) none of them worked with the code only 80. changed some of the firewall setting on the win8 pro machine, and spoke to D-link about my router settings ie. router admin.

D-link weren't helpful either ( as they are totally unaware of Arduino ) I explained my situation not being able to see my other network - their reply was take it up with your ISP!!! it seems as long as your "plug and play" device works ie. can connect to the internet they are not interested! So no help from them configuring a device I have only had for a month and never owned before.

I've tried everything except the things that go together to make this set-up work, seriously if anyone can point me in the right direction that would be a massive help. I've spent day's + the last 12 hours straight attempting to get this going, I'm not looking for some else to do the hard work for me. I know I'm missing something but what?

Any questions I'd be happy to answer, they may provide answers, if anyone has any thoughts or ideas feel free to share, they would be greatly appreciated! Thanks in advance

vero

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Ethermega with D-link router & Prepaid wireless

Post by angusgr » Tue Jul 16, 2013 11:06 pm

vero96 wrote: However no Cigar, I configured the dwr-161 for virtual server setting IP xxx.xxx.x.xx:80 (port 80), having enabled the source & destination ports in the "virtual server rules list" and similarly in the "inbound filtering" and "outbound filtering" using the same IP and Port 80 (tried 81/443/8080) none of them worked with the code only 80.
Hi vero,

I've tried to use consumer routers for this kind of thing before and run into similar problems, I know how frustrating it is!

I'm not sure exactly what you mean by "none of them worked with the code only 80". If I were you I'd try chosing a totally different port to anything to the router might use, something like 5555, and use that everywhere (so you connect from your browser to xxx.xxx.xxx.xxx:5555), just to bypass any conflicts that might exist on the other ports. Consumer routers can be a bit recalcitrant about forwarding ports they are using for other functions (even if it "should" work.)

If you connect your full-size computer to the local side of the D-Link router (ie on the ethernet side, not via the 3G dongle) then are you able to connect to the local IP of the EtherMega and see the web page?

Good luck!

- Angus

vero96
Posts: 25
Joined: Sat Jun 01, 2013 10:08 pm

Re: Ethermega with D-link router & Prepaid wireless

Post by vero96 » Thu Jul 18, 2013 8:53 pm

Hi, Angus Thanks for your response,

I'm still at it I think I'm getting somewhere but no luck as yet...
I'm not sure exactly what you mean by "none of them worked with the code only 80". If I were you I'd try chosing a totally different port to anything to the router might use, something like 5555, and use that everywhere (so you connect from your browser to xxx.xxx.xxx.xxx:5555), just to bypass any conflicts that might exist on the other ports
sorry what was trying to convey was that the script/code used from the web server in the IDE will only complile & upload if 80 is assigned as the port to use.

Code: Select all

EthernetServer server(80);  // create a server at port 80


I have gone into the router's inbound filtering/outbound filtering /mac address filtering /virtual server setting and attempted to configure everything as described by the manual (and in a related Arduino Forum post mentioned previously ) But when I try to access the mega's network remotely I am unable. That was also using port no's. in the 5000 - 6000 range whilst keeping the server at port 80

I was able to find the routers external IP using ipchicken.com and used that in the routers settings with ( example port 5535 ) and the server's IP 192.168.x.xx:80 however no remote access as yet. Also if the external IP is entered with either eg. port 5535 or 80 no connection.
Similarly if I enter the servers Ip and eg. Port 5535 or 80 no connection?
If you connect your full-size computer to the local side of the D-Link router (ie on the ethernet side, not via the 3G dongle) then are you able to connect to the local IP of the EtherMega and see the web page?
Well the answer to that is yes and no, the d-link has only one ethernet port so If I plug the router into the PC's only ethernet port with the dongle removed from the router no I can not connect ( I'm not trying to be rude just answering the question )

However with the the dongle still removed and the PC connected to the other network's wireless, when the router was plugged into the switch and the PC into the switch that the mega was also plugged into yeah I could just enter the IP and port no. ie. http://192.168.x.xx:80 and yep info on the SD card was there.

As for "seeing" what on the mega remotely nope! hope this sheds some light on the situation I know I'm doing something wrong, and as I've only ever used wireless haven't needed a router until now so lacking those basics, Google, Forums & Youtube and the manual obviously have been my only outlet for info.

As always any thoughts would be greatly appreciated, thanks in advance,

vero

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Ethermega with D-link router & Prepaid wireless

Post by angusgr » Fri Jul 19, 2013 1:32 am

Hi vero,

Thanks for the reply and the explanation. Not rude at all, it makes it very clear what you're seeing.

The only last thing I can think of is to check the local IP of the D-Link router is on the same subnet as the EtherMega, ie if the router is 192.168.X.Y then the EtherMega could be 192.168.X.Z (only the last segment can be different.)

vero96 wrote: sorry what was trying to convey was that the script/code used from the web server in the IDE will only complile & upload if 80 is assigned as the port to use.

Code: Select all

EthernetServer server(80);  // create a server at port 80
That's weird!

The approach you're using (forwarding a different external port to internal port 80) should still work, but this seems unusual to me that the sketch won't work on a different port. In the WebServer example I can set this port number to any valid value and it compiles fine for me. What errors do you see?

It might be worth investigating this issue further, just in case the D-Link has a bug when port 80 is involved in any port forwarding.
vero96 wrote: However with the the dongle still removed and the PC connected to the other network's wireless, when the router was plugged into the switch and the PC into the switch that the mega was also plugged into yeah I could just enter the IP and port no. ie. http://192.168.x.xx:80 and yep info on the SD card was there.
If you disable wireless on the PC, connect the PC and the EtherMega to the switch, connect the switch to the D-Link router and attach the Dongle then do most things work? Specifically:
- Accessing the internet from the PC via the dongle?
- Accessing the EtherMega using local IP http://192.168.x.xx:80 ?

- Angus

jebz
Posts: 33
Joined: Sun Feb 12, 2012 10:58 pm

Re: Ethermega with D-link router & Prepaid wireless

Post by jebz » Mon Jul 22, 2013 11:15 pm

See if you can get hold of Silicon Chip December 2009 - http://www.siliconchip.com.au/Issue/200 ... ox%2C+Pt.2 The internet setup for the WIB is identical to your etherMega requirement. The issue with wireless internet service providers is that not many give you a routable address (eg 203.11.23.45) mostly you get private addresses like 10.90.1.23 . This means that the ethernet packets won't be passed over the internet if you try to access a web device using one of these addresses.

vero96
Posts: 25
Joined: Sat Jun 01, 2013 10:08 pm

Re: Ethermega with D-link router & Prepaid wireless

Post by vero96 » Sat Nov 16, 2013 11:42 pm

Hi Jebz

I was able to pick up a WIB and the rest of the required/relevant information is on the Silicon Chip website still :D I built it got it working at home at least ( intranet ) then spent weeks trying to figure out what was wrong.

Well nothing was wrong other than that Telstra cannot tell the same story twice, after hours spent on the phone and a lot of research on my behalf I discovered that on the pre-paid service I had been using I was NEVER going to be able to connect remotely or log on to any server running at home via a 3G Dongle modem or any configuration mentioned in this thread.

If anyone wants to know more PM me but the long and short of it is no one in the call centers knows what they are on about it's the usual turn the device on turn it off, remove sim for ten seconds, reboot your PC ect. the list goes on.

The bottom line is it is NOT possible to do what I was doing/attempting on pre-paid full stop not only that but they block ALL incoming ports making the task impossible some post paid accounts can have certain codes added to them but then again call on another day and you may well get a different story.

Thanks to everyone who contributed here trying to help, I was misinformed time and time again by Telstra will need a different provider or plan to get the EtherMega or WIB running.

Cheers Vero

johnmina
Posts: 1
Joined: Wed Apr 17, 2019 1:47 pm

Re: Ethermega with D-link router & Prepaid wireless

Post by johnmina » Wed Apr 17, 2019 2:09 pm

I was facing some issue in configuring my D-Link wireless Router with Ethermega and got resolved now. My issue was different but after reading and implementing all provided solutions I got solutions.

Post Reply