Friday, December 16, 2011

Mineserv: Automatic Start/Stop Perl Init Script

I was getting tired of having to manually start and stop my Minecraft server whenever the server rebooted and I couldn't make backups without manually disabling level saving first. I wasn't too happy with the shell script alternatives so I wrote my own version with Perl.


Because the Minecraft server does not support daemon processes you need a program called "GNU Screen" which creates a virtual terminal that can run in the background and be re-attached when needed.

To install screen, in Debian based operating systems, run:
`sudo apt-get install screen`
For other distributions check your package manager.
Source can be found here.

This script should be very easy to modify and add functionality to and would work nicely for other services that require screen to run with a little bit of modification.
Let me know if you add any functionality or re-hash the script for something else and I can post it here. Please share alike.

Download: mineserv

Installing the Script
- Install "screen" if you don't already have it
- Edit the SETTINGS variables to fit your server environment.
- Make a copy of the file in /etc/init.d/
- Make it executable: sudo chmod a+x /etc/init.d/mineserv
- Add it to the init list: sudo update-rc.d mineserv defaults

Uninstalling the Script
- Simply delete the file: sudo rm /etc/init.d/mineserv
- Remove from the init list: update-rc.d -f mineserv defaults

Using the Script
- Usage: /etc/init.d/mineserv {start|stop|restart|status|backup|cleanup [days]}
(Backup makes a .tar.gz archive of the world folder in the backup directory
(Cleanup deletes backups older than [days] given in the backup directory)

- To send a command to the server console: /etc/init.d/mineserv command "your command"
- To bring up the server console run: screen -r mineserv (Make sure run as the correct user)
-To give items to players: mineserv give [player] [item id] [amount]
This command will allow you to give more than 64 items at a time so specify any amount!

Monday, February 14, 2011

A Parser for GNUSim8085 Assembler Listings


Update: I am happy to announce that this functionality based off of my code will be added to GNUSim8085 in version 1.3.8.

I've been building an 8 bit microcomputer (still a work in progress) around the classic Intel 8085 processor. I found this excellent open source program, GNUSim8085, a "graphical simulator, assembler and debugger for the Intel 8085 microprocessor in Linux and Windows."

This program was extremely useful for writing and debugging my operating system. Unfortunately it had no ability to assemble the program to a binary in order to burn it to ROM, forcing me to hand assemble my programs in a hex editor.

To fix this, I wrote a parsing tool in C, it takes a GNUSim8085 assembler listing and strips out the hex data and OP codes to a binary file.

Download: gnuasm85.c


Update: I was able to get it to compile in GCC for windows, you can grab the compiled .exe here.

Instructions: Open up your assembly program in GNUSim85, make sure it runs. Set the "Load me at" value to the proper address offset. Then hit Ctrl + L to generate an assembler listing of your program and save it. Then run that assembler listing through gnuasm85 like so, "gnuasm85 foo.asm -o foo.bin".

Sunday, May 9, 2010

Simple AM Transmitter and Receiver

Update: I actually made a math error as I did not know
what I was doing at the time.

I actually inadvertently made a 7 MHz circuit instead of a
50 MHz circuit so I have changed the title but kept the component
values and fixed the equations so that they are now correct.

Sorry if I threw anyone off. I am still learning myself.



My fist adventure in radio! I started off by building a Hartley oscillator with one transistor and then amplitude modulated a signal with a second transistor. I then built an AM receiver schematic I found and calculated the tank circuit for 7 MHz.

Understand that this transmitter is extremely simple and haphazardly thrown together, it does not transmit any further than across the room but it is useful for understanding the basic concept of a transmitter.

AM Transmitter Schematic
(Q1 makes the Hartley oscillator, Q2 amplitude modula
tes the signal by attenuating the signal rather than multiplying it with the carrier (this makes it a very weak transmitter!). It will only broadcast across a room. To increase power you would need to add some amplification and use a better modulation method. You may find this helpful for calculating the resistance values needed)

AM Receiver Schematic

(I recommend replacing the 120k
regenerative feedback resistor with a variable resistor. I used 2N3904 transistors in my build)

The Tank Circuit

The operating frequency of the Hartley oscillator and the frequency tuned in by the receiver is determined by the inductor (L) and the capacitance (C) values in the tank circuit.

Explanation of a "tank circuit".

In my circuit the variable
capacitor's max capacitance is at 290 pF and the coils are roughly 1.746 uH (Micro Henrys). Turning the variable capacitor lowers it's capacitance and thus increases the resonant frequency.

I made the air-core inductor out of a .25 inch diameter soda straw.

Specs:
Diameter: .25 inches
Length: .75 inches

Turns: 31


This equation can be used for calculating the dimensions of an air-core inductor,



Where,
  • L is inductance in uH
  • d is coil diameter in inches
  • l is coil length in inches
  • n is number of turns.

I found this air-core inductor calculator to be a very handy tool for designing coils.


Calculating Inductance Needed

To calculate the inductance L (in mico Henrys) needed you will need to know 2 things.
What frequency you want to operate in and your maximum variable capacitance
(290 pF according to my multimeter).

The formula for resonant frequency is,



Which can be rearranged to find the proper inductance value needed,



The easy way to calculate this is using realistic component values is,



So using my values as an example we take the minimum
frequency we want to tune and the maximum capacitance
my variable capacitor can reach,



Which comes out to,



Because of the previous errors I made (explained above) the actual
inductance I used was 1.746 uH which is still in the ball park for 7 MHz.

Thursday, April 1, 2010

Digital Clock - 7490 Decade Counters and a Hacked Quartz Clock



No microcontrollers needed here! I started playing with some 7490 decade counters and decided to build a digital clock. The first trick was getting an accurate 1 second time base. There are a few options here, you can divide the 60 Hz AC line frequency (in the US) down to 1 Hz or you can build a crystal oscillator and divide that frequency down with decade counters.

I decided to take a more hacky approach and took a 1 Hz oscillator circuit out of an analog Micky Mouse clock. There are a few different ways you can wire these up explained very nicely here. With my clock I didn't have to run the outputs through diodes or transistors (each output is 1/2 Hz), connecting them directly together worked just fine. I also powered it off the 5 volt supply by using a current limiting LED across its power input, the alternative is to have a separate battery for the clock. Every quartz clock circuit is different so its something you have to experiment with on the breadboard before building!


digital_clock_schematic.pdf

The time is kept by six 7490 decade counters. The 1 Hz clock is pulsed into a 7490 wired up as a mod 10 counter (for seconds 0-9). The output of the mod 10 counter is pulsed into a 7490 wired as a mod 6 counter (for seconds 0-5). That circuit is then duplicated for the minutes (0-59). The hours are then counted by two 7490s wired up as a mod 24 counter. (0-23).

The tens of seconds are displayed by 3 LEDs in binary. The 7 segment displays are driven by four 4511 BCD-to-7 segment decoders. I needed thirty-three 100 Ohm resistors in total for all the displays and LEDs. Good luck!

Saturday, January 30, 2010

Time Delayed Door Alarm


My cat likes to open the front door if we don't latch it properly, which is often. Waking up to a cold house sucks! I designed a time delayed alarm with a couple of 555 timers, if the door is open for roughly 30 seconds it sounds off a piezoelectric speaker until the door is closed again.

Here is the circuit.
(Printer Friendly PDF)



Parts Needed:

- 555 Timer (x2)
- 100k Resistor (x2)
- 10k Resistor (x3)
- 1 Meg-ohm Resistor
- 33uF Electrolytic Capacitor
- 2.2 nF Ceramic Capacitor
- NPN Transistor
- Diode
- Piezoelectric Speaker
- 16 Pin Socket
- 9 Volt Battery Clip
- 9 Volt Battery Holder
- 9 Volt Battery
- Magnetic Contact Switch (found much cheaper at Radio Shack)
- Radio Shack General-Purpose Circuit Board (46.8 x 72.2 mm)

If you don't have any of the resistors it would be cheaper to get a grab bag rather than buy individual resistances in bulk.

Also this circuit is not picky about voltages, you could probably use anywhere from 3 to 16 volts, anything that the 555 will handle.

How it works:

When the door is closed the diode keeps the capacitor (C1) discharged to ground.

When the door opens and the magnetic switch is disconnected the pull up resistor (R2) sets the trigger, on the first 555, high and allows the 33uF capacitor (C1) to charge through the 1 meg-ohm resistor (R1). When the charge reaches 2/3 of the supply voltage the output pin on the 555 is set low. The time it takes for the capacitor (C1) to reach 2/3 of the supply voltage is found by this equation,

Time(sec) = (1.1) x (Resistance) x (Capacitance)

For example if we take the values used in my circuit,

Time = (1.1) x (1,000,000) x (.000033)

The time delay comes out to about 36 seconds. Depending on the quality of the capacitor its not going to be totally precise for such a long delay but its close enough for our purposes. For more precise timing you would want to use a decade counter clocked with a 555.

Anyway, the output on the first 555 is inverted by the transistor, so when the output goes low after 36 seconds R4 pulls the output high, its basically a logic NOT gate. The second 555 is a simple multivibrator circuit which generates a square wave used to drive the Piezoelectric Speaker. The alarm will keep sounding until the door is closed thus resetting the circuit.

If you wanted to cheat you could do away with the second 555 timer and get a Piezoelectric Buzzer which will generate a tone on its own when a DC voltage is applied to it.

Let me know if you bother building one.


Tuesday, November 24, 2009

Tunnel Firefox through SSH with a SOCKS Proxy

You should always be careful when connecting to a public WiFi connection, you don't want to end up like these poor saps at the Defcon convention.

I'm sure you have found yourself in a situation where you had an overzealous network filter block websites on a public connection (like at a library, work, or school). Or perhaps you don't quite trust the connection you are on?

If you have a Linux box at home that you can SSH into, you can set up a socks proxy to tunnel firefox over an SSH connection. To anyone else it will appear as if you were surfing from your servers connection.

The command is:

ssh -D 8080 user@host -N

(This will work with putty on windows too)

Leave that terminal running in the background then in firefox go to...

Tools > Options (Edit > Prefrences in Linux) > Advanced > Network > Connection Settings

And set up a manual proxy configuration under the SOCKS Host to connect to localhost (IP: 127.0.0.1) and port 8080.

You can also set up Pidgin to use a SOCKS proxy in the same way for more secure IM conversations.

Cheers.

Sunday, November 8, 2009

Set up a free Dynamic DNS for your home Ubuntu server.

This tutorial assumes you are using Debian based linux, such as ubuntu, and you have a server set up with root privileges on a home connection.

Update: Your router might already have Dynamic DNS functionality built it, specifically for the DynDNS service. If you can use that instead it will save yourself a lot of trouble! If not, read on and good luck :-)

DNS stands for Domain Name System, it is the service that allows you to go to google.com instead of having to remember google's IP address. A Dynamic DNS service will accept a change in IP address for a domain name. So instead of remembering your latest IP address assigned from your ISP to connect to your home server we will only have to remember one name, for example myhomeserver.dyndns.org. The server will then report any IP changes to the Dynamic DNS service.

There are a number of free Dynamic DNS services out there, for this tutorial we will be using DynDNS.

Head over to http://www.dyndns.com/ and enter in a name for your server.



You will then need to make an account with Dynamic DNS. Once you are finished it should set an IP address from where you logged in from by default. Now we are going to get your Ubuntu server to check if there is a change in IP address and if so log into your DynDNS account and report the change.

To accomplish this we are going to use the ddclient program.

First lets get ddclient from synaptic; execute this command:
sudo apt-get install ddclient

It will then run through a command line based installer and ask you a few questions to set up a basic config file. Answer all the questions it asks you, the DynDNS hostname you set, your DynDNS username and password, etc.

The tricky part is when it asks, "Enter the interface which is used for using dynamic DNS service."

If you are not behind a router or a firewall you can simply enter: eth0

But in my case I am behind a router so I cannot see what my global IP is, so I am going to use another server that will check the IP for me.

So if you are behind a router just skip this question and we will fix it manually in the config file later.

After synaptic is done installing ddclient we are going to have to manually edit the config file and add a few things. For this tutorial I am going to use emacs to edit the files.

Run the command: sudo emacs /etc/ddclient.conf

Your config file should look something like this:


# Configuration file for ddclient generated by debconf
#
# /etc/ddclient.conf

pid=/var/run/ddclient.pid
protocol=dyndns2
use=if, if=
server=members.dyndns.org
login=[your dyndns username]
password=[your dyndns password]
yoursite.dyndns.org


If your server is not behind a router then the use line should be set to "use=if, if=eth0".

However if your server is behind a router change this line,

use=if, if=

to this,

use=web, web=checkip.dyndns.com/, web-skip='IP Address'

And lastly put a new line that says,

daemon=600

This will tell the script to check your IP address every 10 minutes (600 seconds) using checkip.dyndns.com as a reference. If the IP has changed it will send an update to DynDNS else it will wait another 10 min and check again. The smallest value you are allowed to set for the update interval is every 60 seconds.

If you are using the emacs editor hold down the CTRL key and hit "X", then "S" to save your file. Then hold down CTRL again and hit "Z" to get back to the command line.


So your final configuration file should look something like this,


# Configuration file for ddclient generated by debconf
#
# /etc/ddclient.conf

daemon=600 #reports IP every 600 seconds

pid=/var/run/ddclient.pid
protocol=dyndns2
use=web, web=checkip.dyndns.com/, web-skip='IP Address'
server=members.dyndns.org
login=[your dyndns username]
password=[your dyndns password]
yoursite.dyndns.org



Now that we are all configured it is time to restart the ddclient program.

Cross your fingers and execute this command,

sudo /etc/init.d/ddclient restart

Assuming everything is set up properly ddclient should report any IP address changes. Now there is still one problem, DynDNS expects an update at LEAST once a month or else it will set your account as inactive. This is an issue if you keep the same IP for more than a month.

To avoid this we are going to make a cron job that will force ddclient to update every month.

Execute the command "crontab -e". You will be greeted with a simple editor. Add this on a new line,


00 00 28 * * ddclient -host yoursite.dyndns.org -force


Then hold down CTRL and hit X, it will ask you if you want to save, type "y" to say yes and hit enter.

Everything should work beautifully now!

Cheers.