Alan numitron clock
SNES Pi Webserver
USB Volume/USB toys
SNES Arcade cabinet
Game boy projects
Home Presence Detector
Rand Nerd Tut
Carnet du maker (fr)
SNES Pi Webserver
Last update: Mon Oct 15 22:56:20 2018
Need a web server for self hosting, use a Raspberry Pi 2 of course (seeing I expect 200-300 page views a day we're safe). I need a DMZ in my internal network so the old router sleeping in the closet found a new life. I also had those beefy AC/DC modules in my lucky bag in Akihabara years ago, make the 110v a steady 10.5V with a decent amount of amps (measured 4 when short cutting I think). Throw in a couple of step down "buck" converters (no 7805) from eBay to have a decent efficiency and get my 5v for the Raspi as 3.3v for the router. Interresting fact this SoB of router does not work with 3.3v but is fed about 3.5-3.6v otherwise it doesn't start or keep rebooting. Not the fault of the power module, I tested with my beefy DC supply and with a precise 3.3v it keep on rebooting. The original power plug was measured 3.47V (though labelled 3.3v), so, what the hell, it works, maybe not for a century but I'll manage.
The whole thing is stuffed inside a SNES body that was the empty shell of my Arcade cabinet made with a SNES. I had to make fake joypad port, just wood with a few holes and painted/varnished the same as the SNES original grey, ... if you don't pay attention it makes acceptable illusion.
Bill of materials
- Raspberry Pi 2 for the web server: could be any of the Raspi familly in fact if you have a small site, just runs a website in python and maybe nginx
- AC/DC converter from 110V to something like 5~12V. Mine gives 10.5V at 4A when shorted, more than enough
- An old Buffalo router that you bring back from the closet of the dead with DD-WRT a fantastic alternate firmware. Luckily my old router was in the list, installation was a bit tricky but it worked.
- Buck converters (no 7805) to lower the AC/DC converter output DC voltage to the 5V needed by the Raspi and 3.5V needed by the router (it says 3.3V but that doesn't work, it needs a tad bit more to boot).
- A old Super Famicon to host your project with nobility and nostalgy
- I sacrificed a cartridge and stuck a fan inside to suck out the hot air in summer, but it ended up making so much vibrations that I turned it off (not documented)
|1- Raspberry Pi2
2- AC/DC converter (110V AC -> 10.5V DC)
3- Old router
4- Step down buck converters (to 5v and 3.5v)
||Nearly final product. Looks not bad huh?
||Final product: there's a small fan in the cartridge to help with air convection (the router gets quite hot). This website you read now is hosted from my toilets :) my living room (I moved house). But that is cool to say that this website ran for 2-3 years from my toilets.
Now comes the fun. My goals are to:
- Serve static content: html, css, images... I don't care/desire php modules or else, I'm fine editing my site with emacs (yes, I do)
- A little dynamic though: if I could do some page combination on the fly like ASP.Net master page or maybe have a few tags dynamcally parsed, that would be cool but I could live without it.
Option 1 use a home made Python webserver
✗ Which is what I did first, it handled bravely a few attacks until some a$$hole found a breach and killed it with a few commands. Yeah, BaseHTTPServer is not the most robust implementation.
Option 2 a existing Python framework
✔ Flask is the answer. and that's the way to go!
I used the Flask to build a custom single editor multithreaded webservice. I can edit pages on the site live, that works quite fine. It's a work in progress, but if you're interrested do check on github, there's the full site: https://github.com/AlanFromJapan/alanWebSites
Option 3 a fullfledge web server
✗ Not Apache (robust but cabalistic config), but maybe an easier/lighter Nginx? Would have worked but I wanted some flexibility.
I put it here for memory, since when I make update I work on other servers now (all the content is on Github so why not?).
The site executes under Python 2.7+:
sudo apt-get install python-setuptools
sudo easy_install pip
sudo pip install Flask
sudo pip install futures
You need flask as the main engine, and you need futures for multithreading thread-pool for blinking leds. The above commands get you easy_install to get pip to get the before mentionned packages.
Now to get the site source :
git clone https://github.com/AlanFromJapan/alanWebSites.git and go get a small coffee.
Once downloaded, edit the
electrogeek.ini file and run by
python electrogeek_flask.py or use the start script.
Notes regarding the Leds: adding the leds support came with a few tricks (and thanks to this person for sharing):
Need to run a Jessie debian so go for a
sudo rpi-update and the usual apt-get update/upgrade
Does not run as root so the web server user must be in the gpio group
sudo adduser webuser gpio
And in case you still get a no access to /dev/mem, check the permissions and do
sudo chown root.gpio /dev/gpiomem ; sudo chmod g+rw /dev/gpiomem
It's documented on the Raspi GPIO fun page, just check. Now there's a kill button hidden behind the cartridge.
Page served LED
Following the code change in the present project source code, check the
ledz.pi thing and documented here, each time a page is served a small green led blinks. It's next to the red power led.
I won't go into micro details here because it will change between your house and me, and it gets a little too private. I'm no network expert, so forgive if some details I keep before me.
Dashed lines are wifi, plain are wired, red is DMZ (as setup in the main router) and blue is regular intranet
On the main router:
"DMZ router" is the DMZ target for the main router: all incoming extrnal traffic is redirected to that DMZ router
All external incoming traffic to the DMZ router management port is rejected (important)
NATing (port 80 external - port XYZ internal) can happen on that router (not in my case though)
On the DMZ router:
NATing of individual ports to the webserver: port 80 for http, 443 for ssh (not HTTPs, ssh so I can admin from outside and fool my company proxy), 8089 for dev server
Only incoming traffic is allowed on these 3 ports, no outgoing traffic allowed (only RESPONSE traffic)
All traffic from Dev server to Internal NW is rejected (except on the 3 ports as explained above)