Automatically blocking spam bots

December 12th, 2013

I installed a forum on my website, but there was no way to force manage the addition of new users.  I then got busy and ignored it till my amazon EC2 bill came in and it was 10x normal.  Seems that the site was being inundated with spam of some sort (not sure the nature of it, I took it down before spending too much time on it).  However, after a couple weeks, the traffic did not stop and I got sick of it.  So I threw together a quick script to pull the IP address from anyone trying to look at the (now removed) forum and add it to my list of blocked IP addresses.  It seems fairly useful so I thought I would share..

 

use strict;
use File::Tail;

my %ips = ();
my $ref = tie *FH,"File::Tail",(name=>”<YOUR APACHE LOG FILE>");
while (<FH>) {
        if (m/<URL TO LOOK FOR>/) {
                my @list = split(‘ ‘, $_);
                my $ip = $list[0];
                if ($ips{$ip} != 1) {
                        $ips{$ip} = 1;
                        print "iptables -I INPUT -s $ip -j DROP\n";
                        system("iptables -I INPUT -s $ip -j DROP");
                }
        }
}

 

You’ll need to install File::Tail and Time::HiRes to get it to work.

Electronics

Internet Down From Bad Cap

September 3rd, 2013

I noticed some websites loading way slow, and I used speedtest to find out that I was getting 2mbits instead of my usual 15.  I called up support and they said everything was fine, and it looked my router was problematic.  After I hung up, nothing worked and bypassing the router didn’t help.  I called back and another 45 minutes of debugging later, the support guy said he had no clue. 

I suspected the modem at this point, got off the phone, but couldn’t get online to order a replacement.  So I cracked it open, and instantly saw a swollen cap next to a big inductor.  In my experience, power supply electrolytic caps are the biggest point of failure.

2013-09-03 15.27.21

I found a replacement quickly in my caps drawer and 5 minutes later..

 

2013-09-03 15.30.54

It was a bit tall for the space so I had to mount it sideways.  Plugged it back in and everything is humming along just fine.  Annoying how quickly a single point of failure will make a bunch of electronics obsolete, ending up in the waste dump.  But it would cost $1 more if they used parts that were less-prone to failure, and we are so driven by the cost of goods…

In my polymers class I learned that it would cost $0.03 more to make diapers biodegradable, but that’s too much for the market to bear.  So rather we have to deal with giant mounds of shitty diapers. 

Electronics

Boat camping in Lake Sonoma

July 18th, 2013

This post is a big departure from my usual discussion on food and electronics, but I did a lot of searching online before camping at Lake Sonoma (CA) last weekend, and I never found this information till I was onsite – and it would have really helped me out.  So I requested a copy of the information and I’m posting it here to help future campers pick a better spot to camp at.

This is a conversion of the document they give you when you go to check into a primitive campsite.

We had a great time camping there, but when we left, we forgot to pack up my hammock which was a gift from a dear friend from when I was in Thailand. 

Primitive Boat-in and Hike-in Campsites at Lake Sonoma on Warm Springs Arm

Eight out of the fifteen primitive campgrounds at Lake Sonoma lie along the seven-mile long Warm Springs arm of the lake. These eight campgrounds are also accessible by trail for the enjoyment of our equestrians and hikers. Please note that Bummer Peak is a trail camp only – Bummer Peak does NOT have boat access. Campers should use caution around campgrounds, as much of Lake Sonoma’s terrain is steep.

NO BOAT ACCESS!

Two sites available for hike-in, bicycle, or horseback campers. Round trip from No Name Flat is about 5 miles. Offers great views.

clip_image002[4]

Seven spacious sites in a ski zone. Sites 1 & 4 are close to the water. Sites 2 & 3 are close together. Camp is susceptible to choppy wake.

clip_image004[4]

One of two group campgrounds, Island View has four sites available to accommodate groups as large as 30-50. Accessible by boat or hike-in. Decent for boating access, ample shade and in a no-wake zone.

clip_image006[4]

13 large sites with plenty of play space for children. Buck Pasture has quiet boat traffic, good fishing and swimming. Sites 1, 2, 3, 4, 6, 12 & 13 are on shoreline. Site 6 is very small.

clip_image008[4]

This campground is located in a no-wake zone. Sites 3, 4 & 5 are close to the water. The hike from Skaggs Springs Vista is 1.1 miles.

clip_image002[6]

These six sites are in a ski zone and have the shortest walk-in distance. Sites 1, 2 & 3 are close to the water but have no shade. Sites 4, 5 & 6 are set back from the shoreline.

clip_image004[6]

An ideal campground for fishing and swimming activities. Five sites on moderate terrain and varied shade coverage. Sites 1 & 3 are on the shoreline, 2 & 4 on the hills and site 5 on a peninsula. All sites are in a no-wake. no-ski zone.

clip_image006[6]

Old Sawmill has nine sites isolated far up this arm of the Lake. Site 1 has a natural spring and horse corral. Campground has fig trees, old foundations and more. All sites are located up from the shore.

clip_image008[6]

Primitive Boat-in and Hike-in Campsites at Lake Sonoma on Dry Creek Arm

Lake Sonoma’s Dry Creek arm extends twelve miles and has seven campgrounds accessible by boat only. The terrain is steep and hazardous, so campers should exercise caution around campgrounds and when exiting your boat. The Yorty Creek day use area is also located on this arm and has a small boat ramp suitable for car top launching (NO TRAILERS). Campers who wish to park overnight at Yorty Creek should check in at the visitor center for a parking pass. Failure to obtain a pass can result in a citation.

Group camping with six sites. Beautifully shaded by redwood trees and situated in a ski zone.

clip_image002[8]

Eight sites nestled on densely wooded terrain with a steep shoreline. Excellent shade coverage and situated off a “no ski” zone, this camp is an ideal location for fisherman.

clip_image004[8]

Eight sites on a steep hillside. Rustlers is the closest camp-ground to Yorty Creek. Sites 1 & 2 are close together, sites 4 & 5 have a steep shoreline and moderate shade.

clip_image006[8]

All seven sites are within 150 feet of shore and have at least partial shade. Sites 1 & 2 are furthest from shore, 3 & 4 are close together, 5 & 7 are near shore.

clip_image002[10]

All ten sites are evenly spread out and within 150 feet of shore. Sites 5 and 10 nearest the water. Site 6 is on a little peninsula. Sites 3 & 4, 11 & 12 have shade and privacy and site 7.has full sun

clip_image004[10]

Twelve sites in a “no wake” zone with lots of sun. Sites 1-4 near the water. Sites 1-5 with moderate shade, the other sites have full sun.

Sites 11 & 12 are on separate peninsula.

clip_image006[10]

The 10 sites offer a combination of shade, gentle slope and a great beach. Located in a “no wake” zone so boat noise is minimal. Sites 4 & 5 are close together sites. Sites 7-10 are about 100 feet from shore.

clip_image002[12]

Electronics

Adding heating bed to Ultimaker

June 23rd, 2013

I am just wrapping up adding a heatbed to my ultimaker and I wanted to do a quick write up to help others.

I ordered the following:

I also used a thermistor that I had on hand (Vishay NTCLG100XX203JB – 20Kohm NTC). 

The power supply mounted nicely underneath the ultimaker.  I cut out the center part of the polycarbonate sheet and drilled holes to mount the PCB heater to it.  I cut a sheet of kapton and taped it to the PCB using kapton tape. 

image

 

The negative side of the power was connected to the ultimaker pcb ground (bottom circle).  The positive side was connected to the heating PCB.  The other terminal of the heating PCB was connected to the screw terminal marked with an arrow.  Diode D3 needs (top circle) to be removed for this configuration to work.  I just cut it with wire cutters.  All you will lose is the status LED with this mod, and I don’t ever see a reason to want to add it back in as you can’t even see the status LED. 

image

A thermistor is a resistor which varies its resistance as a function of the temperature.  The typical specification is the resistance of the thermistor at 25deg C (mine was 20k).  To get the best sensitivity, you need to determine the resistance of the thermistor at the operating temperature (in my case, it is 70C for PLA).  By looking at the datasheet, we see that it is 3.5kOhms. 

image

This means that you want to populate resistor R4 with something close to 3.5kOhms (I had a 3.3k resistor that I used). 

image

By doing this, you will maximize the change in the output around 70deg – in other words, you will have the most sensitivity at that point.  For a voltage divider in the configuration used by the ultimaker, the output voltage (sensed by the analog-digital converter) is equal to .  If we plot the change in output voltage as a function of temperature, I get a plot like this.  Notice the peak is around 70C.  image

In order to configure the firmware, you need to change configuration.h to set TEMP_SENSOR_BED to some number (I used 10).  I then edited thermistortables.h to modify entry 10 to correspond to values relevant to me.

There is a script that computes this stuff for you based on a curve fit, but as I had the datasheet with the specific resistances, I just used that data.  I populated a spreadsheet table to have the temperature in on column, the resistance in another, and I computed the ADC value as gif where was computed above, and is the oversampling number and seems to be fixed at 16.  I then generated a list the corresponded to the ADC value vs. the temperature. 

image

I took the output and copied it over entry 10 in the thermistortables.h file.

image

I then compiled and uploaded the code.  I used my IR temperature probe to verify that the temperature readings were correct.  Win.

Electronics

uCurrent (from EEVblog) current upgrade

April 4th, 2013

2013-04-04 18.11.33I  have been having a lot of issues as of late using my HP 34401A DMM to measure current.  The DMM measures current by passing the current through a resistor to rectify the current into a voltage based on the relationship V=IR.  It then measures the voltage across the resistor to determine the current.  I used a secondary DMM to measure the resistance to 5.5Ohms

This is quite typical.  However, the size of the resistor is somewhat large (5.5Ohms), and causes a drop in voltage across that resistor (also based on V=IR).  The more current you measure, the larger the drop in voltage.  A 1A current will cause a 5.5V drop!

As my WiFi module was powering up, it would require a larger draw of current due to large inrush, this would cause a sudden spike in current which would cause the a drop in voltage across the current sense resistor which would cause things to break.  Took me a full day to figure out that this was the culprit to my problems.  Very annoying. 

So I ordered a precision current measurement device by the EEVblog author (http://www.adafruit.com/products/882) which works in the exact same way as my DMM, but it passes the current through a much smaller resistor (in the mA setting, it passes the current through a 0.01 Ohm .5% resistor – R1 in http://alternatezone.com/electronics/ucurrent/uCurrent%20Schematic.png).  Thus, for a 1A current, we expect only a voltage drop of .01 * 1 = 10mV!  Much better. 

2013-04-04 15.51.14However, I want to measure at least up to 1A, and the documentation states it only works up to 300mA.  If you look at the circuit, it sets up a virtual ground at 1.5V (given a 3V supply), take the voltage difference across the current sense resistor and amplifies it 100x using U1.  Thus a 1A current should result in 10mV * 100 = 1V.  This should easily be within the output capability of U1.  So I posted to the authors forum, and asked.  It seems the 300mA limit is because of the switch SW1’s limit.  Doh.  So I added some solder blobs to force it into mA mode and capable of supporting much higher currents (see photo – 2 solder blobs directly below the LED (D1). 

So it works fine, but I am getting an unusual amount of noise out of the system given the precision components and the quality opamp.  In looking at the circuit, I would wager that it’s from R2.  It is always in there, parallel with either R8 or R1.  It’s so much larger than R1 or R8, that it doesn’t really alter the measurement, however, it does add Johnson noise  which is amplified as well.  The amplifier has a GBW of 6.5Mhz, and no additional filtering is provided, so we can approximate the bandwidth as 6.5Mhz/100=65kHz (not exactly, but close enough).  We can use this to calculate the noise from R2 to be 3.2uV (from http://www.sengpielaudio.com/calculator-noise.htm) * 100 = 320uV noise.  At 1mA/mV (the output of the device), that’s equal to 320uA of background noise.  I’ll take out the resistor at some point to see how it improves the signal, but it’s a bit annoying that it’s there.  He could have easily hooked R2 to the 1st terminal of SW1 to avoid this source of error..

image

Electronics

How to handle JSON data using the electric imp.

January 7th, 2013

I’ve had more requests for examples of accessing JSON data using an electric imp.  I use it to collect weather information from weather underground. Here’s some skeleton code to highlight what you need..

 

local astronomy = OutputPort("Astronomy","number");
function getAstronomyData() {
    astronomy.set(1); //initiates outbound connection to retreive astronomy data
}

function dumptable(p, t) {
    foreach(key, value in t) {
        if (typeof value == "table") {
            dumptable(p+"."+key, value);
        }
        else server.log(p+"."+key + " = " + value);
    }
}

//this class receives the json data
class Astronomy extends InputPort {
    function set(payload) {
        //to figure out json structure uncomment the following and check the log output
        //dumptable("",payload);
       
        //all the data is considered a string, so convert to integer or whatever as necessary 
        local variable = payload.moon_phase.sunset.hour.tointeger(); 
        doSomethingWith(variable);
       
        //schedule another update in 1 minute
        imp.wakeup(60, getAstronomyData);
    }
}

function boot() {
    //invoke a call to get the astronomy data here
    getAstronomyData(); // or use imp.wakeup() to specify a time to invoke
}

imp.configure("Outdoor Automation", [Astronomy("astronomy","string") ], [astronomy]);

 

In the planner, setup an HTTP request which sends the request in the form of a GET request specifying the url (which, in the case of weather underground, includes the api key).  Set the content type to json.

 

image

 

Connected an arrow from your application to the HTTP request and one from the HTTP request back to the application.

 

The way it works is that when you write to the HTTP request, the URL is called.  When data is returned, it will invoke Astronomy.set() (defined in imp.configure(), which you need to provide) which then parses the data. 

A dumptable function is provided in order to help you figure out the structure of the json data the first time to know how to extract it.

Hope this helps.

Electronics

Electric Imp & SHTxx sensors

December 17th, 2012

There have been a couple people requesting the code to drive an SHT temp/humidity sensor from an electric imp, so I’ll post it below.  No warrantee implied..  Also, it’s ugly as someone else wrote it for some other microprocessor and I just tweaked it; I would never write such aesthetically displeasing code.    Obviously, I’m big banging pins 8 and 9; adjust to suite your needs.  Don’t forget the pullup resistor on one of those lines.  This is also written for the SHT71, tweak for whichever unit you are using.

 

class SHT {
       
    function delay_us(x) {imp.sleep(0.000001 * x);}

     noACK =0;
     ACK=1;
                                //adr  command  r/w
     STATUS_REG_W =0×06;   //000   0011    0
     STATUS_REG_R =0×07;   //000   0011    1
     MEASURE_TEMP =0×03;   //000   0001    1
     MEASURE_HUMI =0×05;   //000   0010    1
     RESET        =0x1e;   //000   1111    0
    
    data_output = true;
   
    function constructor() {
        hardware.pin8.configure(DIGITAL_OUT);
        hardware.pin9.configure(DIGITAL_OUT);
        s_softreset( );
    }
   
   
   
    function sck_set(x) {
        hardware.pin8.write(x);
       
    }
    function data_set(x) {
        if (!data_output) {
            hardware.pin9.configure(DIGITAL_OUT); 
            data_output = true;
        }
        hardware.pin9.write(x);
       
    }
   
    function data_get() {
        if (data_output) {
            hardware.pin9.configure(DIGITAL_IN);
            data_output = false;
            }
        return hardware.pin9.read();
    }
   
   
    function SCK( val) {
        if (val) {
            sck_set(1);
        } else {
            sck_set(0);
        }
    }
   
    function DATA( val) {
        if (val) {
            //input w/ pullup resistor
            data_get();
        } else  {
            //output – gnd
            data_set(0);
        }
    }           
   
   
    function sht_init() {
        s_write_statusreg(0, 0×00); //8/12 bit resolution
    }
   
   
       
   
   
    //———————————————————————————-
    function s_write_byte( value) {
    //———————————————————————————-
    // writes a byte on the Sensibus and checks the acknowledge
      local error=0; 
   
      for (local i=0×80; i>0; i=i/2)             //shift bit for masking
      {
          if (i & value) DATA( 1);          //masking value with i , write to SENSI-BUS
          else DATA(0);                       
            delay_us(5);
          SCK( 1);                          //clk for SENSI-BUS
          delay_us(5);        //pulswith approx. 5 us     
          SCK( 0);
      }
      delay_us(5);
      DATA( 1);                           //release DATA-line
      SCK( 1);                            //clk #9 for ack
    
      error=data_get();                       //check ack (DATA will be pulled down by SHT11)
      SCK( 0);  
      return error;                     //error=1 in case of no acknowledge
    }
   
    //———————————————————————————-
    function s_read_byte( ack)
    //———————————————————————————-
    // reads a byte form the Sensibus and gives an acknowledge in case of "ack=1"
    {
      local val=0;
      DATA( 1);                     //release DATA-line
      for (local i=0×80; i>0 ; i = i>>1)  {           //shift bit for masking
       SCK( 1);                    //clk for SENSI-BUS
        if (data_get()) val=(val | i);        //read bit 
        SCK( 0);                      
      }
      if (ack) {
          DATA(0);
      } else {
          DATA(1);
      }
     
      SCK( 1);                      //clk #9 for ack
      delay_us(5);          //pulswith approx. 5 us
      SCK( 0);                           
      DATA( 1);                     //release DATA-line
      return val;
    }
   
    //———————————————————————————-
    function s_transstart( )
    //———————————————————————————-
    // generates a transmission start
    //       _____         ________
    // DATA:      |_______|
    //           ___     ___
    // SCK : ___|   |___|   |______
    { 
       DATA( 1);
       SCK( 0);//Initial state
       delay_us(2);
       SCK( 1);
       delay_us(2);
       DATA( 0);
       delay_us(2);
       SCK( 0); 
       delay_us(6);
       SCK( 1);
       delay_us(2);
       DATA( 1);          
       delay_us(2);
       SCK( 0);          
    }
   
    //———————————————————————————-
    function s_connectionreset( )
    //———————————————————————————-
    // communication reset: DATA-line=1 and at least 9 SCK cycles followed by transstart
    //       _____________________________________________________         ________
    // DATA:                                                      |_______|
    //          _    _    _    _    _    _    _    _    _        ___     ___
    // SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______|   |___|   |______
    { 
      server.log("connectionreset()");
      DATA( 1);
      SCK( 0);                    //Initial state
      for(local i=0;i<9;i++)                  //9 SCK cycle
      {
          SCK( 1); delay_us(1);
        SCK( 0); delay_us(1);
      }
      s_transstart();                   //transmission start
    }
   
    //———————————————————————————-
    function s_softreset( )
    //———————————————————————————-
    // resets the sensor by a softreset
    {
      local error=0; 
      s_connectionreset();              //reset communication
      error = s_write_byte( RESET);       //send RESET-command to sensor
      return error;                     //error=1 in case of no response form the sensor
    }
   
    //———————————————————————————-
    function  s_read_statusreg() {
    //———————————————————————————-
    // reads the status register with checksum (8-bit)
      local error=0;
      local ret = {};
      s_transstart();                   //transmission start
      error=s_write_byte(STATUS_REG_R); //send command to sensor
      ret.value <- s_read_byte(ACK);
      ret.checksum <- s_read_byte(noACK);
      ret.error <- error;
     
      return ret;                     //error=1 in case of no response form the sensor
    }
   
    //———————————————————————————-
    function s_write_statusreg( p_value)
    //———————————————————————————-
    // writes the status register with checksum (8-bit)
    {
      local error=0;
      s_transstart();                   //transmission start
      error= error+s_write_byte( STATUS_REG_W);//send command to sensor
      error= error+s_write_byte( p_value);    //send value of status register
      return error;                     //error>=1 in case of no response form the sensor
    }
                                   
   
    function s_getHumidity( ) {
        local timer=0.0;
        local data=0.0;
        local a;
        local b;
        local crc;
        local result=0;
        local errorString="";
   
        s_transstart();
        if (s_write_byte( MEASURE_HUMI)) {
            server.log("s_getHumidity:writing data error");
            return 0;
        }
       
        // wait up until 2 seconds for DATA to go low
        while (timer < 2 && data_get()) {
            imp.sleep(0.01);
            timer = timer + 0.01;
        }
        // see if an error occured (data_get is still high) 
        if (data_get()) {
            server.log("s_getHumidity:no response");
            return 0;
        }
       
   
        a = s_read_byte( ACK); //MSB
        b = s_read_byte( ACK); //LSB
     
        crc = s_read_byte( noACK); //checksum
        result = a<<8 | b;
       
    //    data = -4.0 + (result * 0.0405) – (0.0000028 *result * result); 
   
        return result;
    //    return data;
    }
   
    function s_getTemperature( ) {
        local timer=0.0;
        local data=0.0;
        local a;
        local b;
        local crc;
        local result=0;
        local errorString="";
   
        s_transstart();
        if (s_write_byte( MEASURE_TEMP)) {
            server.log("s_getTemperature:writing data error");
            return 0;
        }
       
        // wait up until 2 seconds for DATA to go low
        while (timer < 2) {
            if (data_get() == 0) break;
            imp.sleep(0.01);
            timer = timer + 0.01;
        }
        // see if an error occured (data_get is still high) 
        if (data_get()) {
            server.log("s_getTemperature:no response");
            return 0;
        }
   
        a = s_read_byte( ACK); //MSB
        b = s_read_byte( ACK); //LSB
        crc = s_read_byte( noACK); //checksum
        result = a<<8 | b;
   
    //    data = -40.2 + ( .018 * result );
    //    return data;
        return result;
    }
   
    //—————————————————————————————-
    function get()
    //—————————————————————————————-
    // calculates temperature [°C] and humidity [%RH]
    // input :  humi [Ticks] (12 bit)
    //          temp [Ticks] (14 bit)
    // output:  humi [%RH]
    //          temp [°C]
    { local C1=-4.0;              // for 12 Bit
      local C2=0.0405;           // for 12 Bit
      local C3=-0.0000028;        // for 12 Bit
      local T1=0.01;             // for 14 Bit @ 5V
      local T2=0.00008;           // for 14 Bit @ 5V   
      local rh_lin;                     // rh_lin:  Humidity linear
      local rh_true;                    // rh_true: Temperature compensated humidity
      local t_C;                        // t_C   :  Temperature [°C]
   
    //  s_connectionreset();
    // imp.sleep(1);
         
      local hum_data=s_getHumidity();             // rh:      Humidity [Ticks] 12 Bit
      local temp_data=s_getTemperature();           // t:       Temperature [Ticks] 14 Bit
   
   
      t_C=temp_data*0.01 – 40;                  //calc. temperature from ticks to [°C]
      rh_lin=C3*hum_data*hum_data + C2*hum_data + C1;     //calc. humidity from ticks to [%RH]
      rh_true=(t_C-25)*(T1+T2*hum_data)+rh_lin;   //calc. temperature compensated humidity [%RH]
      if(rh_true>100)rh_true=100;       //cut if the value is outside of
      if(rh_true<0.1)rh_true=0.1;       //the physical possible range
     
      local t_F = t_C * 9 / 5 + 32;
     
      local ret = {};
      ret.temp <- t_F;
      ret.humidity <- rh_true;
     
      return ret;
    }
}

 

sht <- SHT(); //instantiate class only once

local tempHum = sht.get(); //call as often as you want
server.log("temp="+tempHum.temp+" hum="+tempHum.humidity);

Electronics ,

Outdoor Automation Controller Installed

November 18th, 2012

2012-11-18 20.55.08I ordered an enclosure from Amazon, but in the meantime, I gutted my sprinkler control box and stuck my control module in there.  It’s connected to the two sprinkler zones, and the 120V side of my low-voltage outdoor light system (less current on the 120V side). 

2012-11-17 21.02.50In the process, I must have shorted the output of the 24VAC power supply for my irrigation system, as it stopped working.  Using a hack saw, chisel and mallet, I managed to open the power supply and only found a large transformer.  The photo is of the primary windings.  You’ll notice three wires sticking up, the black wires (120VAC) connect to two of them.  On the right, it connects to the primary winding.  On the left, it connects to a silver wire that goes into the coil and out again in the middle, which also connects to the winding.  It seems as if they decided to a fuse in the middle of the toroid to make it impossible to access.   And given the multimeter shows a short between the left and middle terminal, the fuse must be blown.   Talk about designing in obsolescence. 

I could short out these terminals or put a fuse inline to make the transformer work, but I was able to find a 16VAC (measured @ 19VAC with the multimeter) rated at like 1/3rd the current but it is still capable of powering the sprinkler solenoids so I decided to just use that. 

2012-11-18 20.55.42In any case, the device is collecting data just fine and posting it to COSM here.  The rain sensor is attached and is configured to trigger when it gets 1/8” of rain.  I’m not sure how long it will stay activated after triggered.  I also forgot to order a phototransistor to use as my light intensity sensor.  I’ll order one and add it at some time in the future.

I’m trying to figure out how squirrel parses json data (I’m just seeing it as a table blob and not sure how to access it) so I can get sunrise/sunset info to control the lights.  I’m also not sure how best to control the sprinklers given the rain data, but that shouldn’t be too bad.

I threw together a really really quick web interface to be imageable to manually turn the lights/spinklers on/off. It works fine as is very responsive, and will be made to look nice and I’ll probably add a configuration page for my sprinkler control. 

So far, I’ve been pleased with the outcome of this project.  Next up, I need to write some android widgets to display data and do some home automation, and add some business logic. 

I’ve got another Electric Imp module, not sure where it will end up.  I’m thinking monitoring power consumption for each circuit in my house, or modifying my dryer to allow me to turn it on/off and get an SMS notification when it is done with the cycle rather than buzzing loudly and repeatedly.  It might also be interesting to track the temperature and humidity of the out-gas, though I’m concerned with fouling my gas sensor with lint..

Electronics

Taking a break from the EEG work.. Outdoor Automation

November 9th, 2012

2012-11-09 18.00.05I’ve always wanted to implement some home automation system.  My first attempt at implementing an X10 based system worked for a time, then it failed.  Lights would turn on randomly, switches stopped working.  Ultimately, the lesson I learned was that you get what you pay for.  With the X10 system: cheap shit.

I’ve since implemented a couple systems, they work for a time, but nothing robust.  I was happy to find the Electric Imp which is an inexpensive WiFi module with a cloud based backend.  I wanted to test it out, and thought automating my backyard low voltage lights and sprinkler system would be a good first application.  Luckily, most of the work was initially done by their developers in their implementation of the ‘Jane’ platform.  I asked, and was given access to their source files (since posted on their site).  I modified it to my liking:

  • Only 3 relays, not 4 to reduce PCB size cost
  • Swapped their temp sensor for an SHT71 temp/humidity sensor.  Overkill, for this application, but I have a number of extra ones from a previous project
  • Replaced their shift register with an I2C I/O expander (I need more I/O pins)
  • Used a full bridge rectifier to allow more power to supply the caps.  I also like the way full bridge rectifiers look. 
  • Added support for an external NPN based light sensor.
  • Added support for an external rain sensor.

I need to test/debug the hardware, write code in some language named after a rodent, get a box to mount the electronics – and then I’ll be all set. 

 

For the UI, I will be putting a framed Nexus 7 permanently in the wall.  It will serve as a frontend to a number of applications I want to make.

I think I’m going to make a number of visualization widgets to plot things like power consumption, temp, etc, and have a webserver running on the hardware that will serve html pages to do the configuration (when the sprinklers work, etc).  I plan on using it to control music in the house.  Let see how far I get along this project before being sidetracked.

Electronics

Website Migration from 1and1.com to Amazon’s EC2

October 31st, 2012

It was a bit of work to get everything setup, but I finally migrated my websites from 1and1.com (horrible horrible company) to amazon’s EC2 service.  Wow, performance is great, I pay for what I use only  (way cheaper) – and the first year is pretty much free for you to try out.  If you know anything about setting up a linux box with apache and mysql – it’s trivial. 

The EC2 management console took a bit of playing with to figure it out.  You can add disks, make backup snapshots, configure the firewall, increate the ram, add CPUs, etc.. Very slick.

In any case, the migration is still in progress and I need to fix a few more things.  But after the migration, I hope to be updating this site more frequently.

Electronics