Dangerous Prototypes

Other projects => Past projects => Web platform => Topic started by: ezflyr on December 18, 2009, 05:47:51 pm

Title: Making a web platform accessible to the outside world....???
Post by: ezflyr on December 18, 2009, 05:47:51 pm
Hi all,

I've got my web platform on order, and I'm already formulating some ideas for putting it to work! First and foremost, I'm going to 'web enable' my home-brew home automation system. How cool would it be to check the hot tub temperature via the web (this is a measurement I'm already making and displaying locally at home)???

Anyway, is there a good primer available for making a device like the web platform accessible to the outside world? I assume that a service like Dynamic DNS (or equivalent) is required for those of us with non-static IP's? How about router setups, port selection, etc., etc.?

Thanks,

John
Title: Re: Making a web platform accessible to the outside world....???
Post by: ian on December 18, 2009, 05:51:57 pm
Hi John,

The Microchip TCPIP stack has a Dynamic DNS client. The source is pretty well documented, but I think they actually have a comprehensive help document too. That might be what you're looking for.

What I like to do though, as with the Twitter controlled Christmas tree, is keep the web platform as the client because it's not very powerful (compared to a server). Use a web server to store settings and configurations, let the web platform contact it to submit data and read the feeds. I did something similar with Google Apps and my Daft Punk table.
Title: Re: Making a web platform accessible to the outside world....???
Post by: ezflyr on December 19, 2009, 04:10:38 am
Hi Ian,

Ideally, I'd like to make the web platform not dependent on a separate web server. I spent a bit of time looking at DynDNS today, and the service does support certain hardware devices, although I couldn't find any detail about protocols, etc. if one wanted to 'roll their own'....... In concept it would appear to be pretty staight-forward - periodically the web platform would send it's current IP address to the DynDNS server so that the external 'hostname' would always point to the correct IP. I've got an email in to their support folks, so hopefully I can report back with some positive info later on?

I haven't checked the Microchip TCP/IP stack yet, but I wonder if there is some sort of a 'standard' mechanism for this sort of thing?

Thanks,

John
Title: Re: Making a web platform accessible to the outside world....???
Post by: brett on December 19, 2009, 09:35:44 pm
It's a great idea, but sometimes it (Dynamic DNS) might be a bit hard to achieve on only the device - I'd suspect you might need to do "Stuff" on your modem/router too.  [I hope this isn’t too basic for you – I just want to make sure you have a way forward]

Here's how I use Dynamic DNS :

I have an ADSL modem/router.  It's connected to an ISP, who gives me an "external" IP address.  I have my modem setup to register this external address in a Dynamic DNS provider.  Now, if I want to get to a device that's inside my network, I just need to use my Dynamic DNS address (yournamehere.dyndns.com for instance).

So that gets you an externally accessable address (the external IP on my router) in a DNS that is reachable from elsewhere in the world.

Next, is making sure I can get HTTP packets to my device.  This is the bit that gets interesting (ie it's hard, and depends on your modem/router, and it’s time to pull out the manual most likely).  

First, I want my device to always get the same internal IP address, so I make sure my device is on and connected to the network, and then I go and make a DHCP reservation on the router for the address that it was just assigned.  In my router’s menu, this is in the “fixed hosts” section of the DHCP server setup.  You will have to use the MAC address (usually shown in the “DHCP active leases”) to make sure the DHCP server recognises the device based on the MAC.

If I have only one device on my internal network that I want to be accessible, I can just use port 80 (the default HTTP port).  If I have more than one device that I want to be able to access, then I need my router to do some "port forwarding" for me, and in that case I need to pick a second port, say port 8080, to use.

The next configuration step I will take is on my router's "port forwarding" settings. In my modem this is under "virtual server" menu and then "port forwarding".  For my chosen port, 80 or 8080, I would define an inbound port forward rule to forward TCP traffic on the chosen port, and then have it forward to (always) port 80 on the device.  In my router config screen, I define the protocol as TCP, the “external port” start and finish port as 8080 (or just 80) and the “redirect port” start and finish to 80, and finally I define the internal IP address I made the reservation for above.

Then, as the last step, I can access my device from a different network using the DynDNS entry myname.dyndns.com by going to http://myname.dyndns.com:8080 (http://myname.dyndns.com:8080) in a browser (if I was going to port 80 I could leave off the :8080 part, or substitute a different port if I had lots of devices).  In my router’s case, I can’t test that from inside my network, so I’d do that from a mobile phone browser or when I was on a network at work or get a friend to test for me. 

That should get you working, I hope !

The one thing that none of this setup addresses is security.  That’s one of the big reasons why it’s often better to “proxy” this through a server as Ian suggests, as that can be set up to do the security/access control, and the internal communication from the server to the device is all unencrypted.  Or, it might be possible to put a security challenge/response in the web platform (I dunno if it has one now? Ian?? Mmmm, might have to get my order underway soon and check for myself ! :) )  Then again, if you’re only showing temperatures around your house or something like that, the value of that data isn’t very high so you may chose to simply accept that there’s no security – and certainly it’d be good enough to test the whole thing works!
Title: Re: Making a web platform accessible to the outside world....???
Post by: ezflyr on December 20, 2009, 02:47:18 pm
Brett,

Duh! Of course! My web platform will be on my home network behind a router, so the router itself will do the 'heavy lifting' associated with using the DynDNS service, not the web platform. It looks like my router is capable of working with the DynDNS service, although I'll have to update the firmware to do it.  As you mention, I'll have to set things up so that the web platform always gets the same local IP. I don't know what I was thinking previously - thanks for pointing out the router option!

John
Title: Re: Making a web platform accessible to the outside world....???
Post by: ian on December 20, 2009, 02:59:30 pm
Great suggestion. I didn't think about that either, my WRT has that feature too.

If you go this route I'd like to hear about your experience, it sounds like a really easy solution for a lot of people.

It's easy to make the web server IP static, just disable DHCP at compile and set the IP in TCPIPConfig.h.
Title: Re: Making a web platform accessible to the outside world....???
Post by: bluesign2k on December 21, 2009, 12:12:09 pm
You shouldn't need to edit the code/disable the DHCP on the webserver to do this, just assign a static IP to your webserver's MAC on the router... this is exactly what I do on the business card webserver and it works great :)
Title: Re: Making a web platform accessible to the outside world....???
Post by: brett on December 23, 2009, 12:28:17 am
i agree, leaving a device with DHCP enabled and making a permanent reservation is simpler, in case you ever needed to relocate it to a new network that had a different IP address range for instance.  (in general, hardcoding things like this is a bad concept, I'm sure we'd all agree, and DHCP makes it easy not to block yourself)
Title: Re: Making a web platform accessible to the outside world....???
Post by: Scorpia on December 24, 2009, 03:33:29 am
I think i would like to see the ability to set a static IP address by creating a .txt file on the SD card with the details in it.

this way if you wanted a static address you simply create the file and when you want to go back to dhcp just delete / rename it.

it would be the easiest way to do it I think without having to recompile.

( ! ) Fatal error: Uncaught exception 'Elk_Exception' with message 'Please try again. If you come back to this error screen, report the error to an administrator.' in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
( ! ) Elk_Exception: Please try again. If you come back to this error screen, report the error to an administrator. in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
Call Stack
#TimeMemoryFunctionLocation
10.00932081936session_write_close ( )...(null):0
20.00962213528ElkArte\sources\subs\SessionHandler\DatabaseHandler->write( )...(null):0
30.00962214304Database_MySQL->query( ).../DatabaseHandler.php:119
40.05252353032Database_MySQL->error( ).../Db-mysql.class.php:273