Using Twitter API with a Proxy in WordPress

1280px-Reverse_proxy_h2g2bob.svg

I was launching a new WordPress website at work that was developed by an outside agency. This site was using twitteroauth built into the theme to access the twitter API. Where I work all the web servers are behind a firewall with a strict whitelist for all incoming and outgoing connections besides the incoming HTTP and HTTPS requests. This makes it difficult to access the twitter API because it could be a different IP address every time. To solve this issues my work provides a proxy server to make requests out to. So my research began.

WordPress began to provide configuration settings in the wp-config.php file for them (http://wpengineer.com/1227/wordpress-proxysupport/):

define('WP_PROXY_HOST', '192.168.84.101');
define('WP_PROXY_PORT', '8080');
define('WP_PROXY_USERNAME', 'my_user_name');
define('WP_PROXY_PASSWORD', 'my_password');
define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com');

Unfortunately, the developers built the twitter api into their theme so I had to manually track down the API calls to modify them to use the WordPress configuration settings. In the twitteroauth.php file in the themes folder I was able to add three lines to the
curl_setopt parameters to function http (http://php.net/manual/en/function.curl-setopt.php):

curl_setopt($ci, CURLOPT_PROXY, '192.168.84.101');
curl_setopt($ci, CURLOPT_PROXYPORT, 8080);
curl_setopt($ci, CURLOPT_HTTPPROXYTUNNEL, 1);

Everything worked once I added those three lines.

MAME Bar Top Aracade Cabinet

Introduction

Update: Check out this Instructable –Legend of Zelda Bartop Arcade Cabinet

In an old episode on Hak5, Wess Tobler (@Dankiswess) did segment on making a MAME bar top arcade cabinet. This segment inspired me to make my own MAME (Multiple Arcade Machine Emulator) arcade cabinet, so I began doing research on different MAME cabinet designs. Bartop Arcade had many different designs and templates for bar top arcades. Below is the design and template that I based my MAME cabinet off of.

Build Phase

Items need for the build phase:

For the build phase I used the template that I found from Bartop Arcade and cut out each piece. I decided against having a slide out drawer, so I had to make some slight modifications. Below is a picture of the cabinet about 90% into the build phase.

After cutting and assembling the exterior of the cabinet, I had to wire all the buttons. Once that was done it was onto the software configuration.

Software Configuration

A lot of research went into deciding exactly how the software side of this project would be configured. I was initially set on using MALA as my front-end, but then I found Hyperspin.

Not only was Hyperspin a superior looking front-end, it would allow me to run many different emulators including a NES and SNES emulator. Hyperspin does most of its configuration through GUIs and XML files. Below is a image of the cabinet 90% complete running PAC-MAN.

Hyperspin also allowed for configuring other applications to open from within it. I configured it to run Aussie Juke as one of the emulators. Also, after reading a comment by Moonlit on episode five of TheNewTech.tv, I decided to modify the registry entry for explorer.exe to boot to Hyperspin.
HKEY_Current_User\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell

Final Thoughts

There are several things I have to do to complete this project. First, I need to finish the marquee. The marquee will end up being a Cylon eye covered by a tinted plexiglass. Second, I need to mount the PC hardware inside the cabinet.

Home Automation Over Wi-Fi

Introduction

On an episode of Hak5 they discussed setting up a garage door to be opened with a mobile device. Unfortunately, the audio was missing on the section where they discussed building/configuring the actual hardware to operate the garage door. This episode inspired me to start working on some home automation that could be accessed with any internet capable device without the need to install any software on the device. I wanted to be able to control several lights throughout my house and my garage.

I decided to use x10 to give me a starting point.

X10 is an international and open industry standard for communication among electronic devices used for home automation, also known as domotics. It primarily uses power line wiring for signaling and control, where the signals involve brief radio frequency bursts representing digital information. A wireless radio based protocol transport is also defined – wikipedia

Hardware

  1. Arduino
  2. 10KΩ Resistor
  3. x10 PSC04
  4. x10 Lamp Module
  5. x10 Universal Relay Module
  6. RJ11 Cable
  7. RJ11 Jack
  8. LAMP server with an open USB port

Step 1: Building and Configuring the Arduino

Follow the wiring schematics below for wiring your Arduino to an RJ11 Jack.

Data Pin = Pin 8

Zero Crossing Pin = Pin 9

X10 - arduino wiring schematic

First, wire the 5v connection on the Arduino to the 10KΩ resistor. This will be wired to the data pin 8. Second wire data pin 8 to the black wire on the RJ 11 surface jack. Wire the green and red wires on the RJ11 surface jack together and wire them to the ground pin on the Arduino. Finally wire the data pin 9 to the yellow wire on the surface jack (sometimes you may have to swap the data pin and the zero crossing pin depending on if the RJ11 cord is a cross over or not)

RJ 11 Jack Wiring
Arduino and RJ11 Jack

Grab the x10 Library from arduino.

Clone my github repository https://github.com/jfurcean/House-Control.git.

Push the arduino/x10House.pde to the arduino. This code reads data in the form of ascii characters over the USB. It converts the characters into x10 byte codes that are used with the x10 Library. It then uses the x10 Library to push x10 commands out to the PSC04 moudle over RJ11.

Step 2: Configuring the Webserver

A webserver running PHP with an open USB port is required. I used a LAMP server running Ubuntu 11.04. Drop the contents of www from my github repository into your active web directory. Inside index.php you must set $serialPath to the path that your arduino is connected to. For example

$serialPath = “/dev/ttyUSB0″;

If your using Apache as your webserver you must allow Apache to write to that path name.

sudo chgrp www-data /dev/ttyUSB0

sudo chmod 775 /dev/ttyUSB0

The web application reads config files to display certain x10 actions. When viewing the web application you need to make sure  userName set. For example:

http://192.168.1.101?userName=john.

This will then use john.xml as the config file. The config file determines what stuff you can control.

<modules>
<module name=’Living Room’ house=’a’ unit=’1′ type=’light’/>
<module name=’Bed Room’ house=’a’ unit=’3′ type=’light’/>
<module name=’Garage’ house=’a’ unit=’2′ type=’button’/>
</modules>

Web Interface

Web Interface - x10 Modules Listing
Web Interface - Light x10 Module Control
Web Interface - x10 Button Module Control

 Step 3: Add/Wire x10 Modules

All that is left is to plug any lamp into a lamp module, an appliance into an appliance module or wire a garage door, sprinkler, etc to the universal relay module.

x10 Lamp Module
x10 Universal Relay Module

Step 4: Enjoy

Enjoy being able to control your house from any internet capable device connected to your network

Light Control via iPod Touch

Garage Door Control via iPod Touch

Questions? Comments? Suggestions?

Please feel free to contact me