DIY Home Automation - AVS Forum
Forum Jump: 
 1Likes
Reply
 
Thread Tools
post #1 of 68 Old 02-08-2013, 03:59 PM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
After evaluating the cost of several Home Automation products, I came to the conclusion that I could make my own for a mere fraction of the price.
$60 low-level hardware vs $3000 (or more) big-box stuff.

I was thinking of coding my own software for a DIY Home Automation based off of relays, such as this, for my new home theater.
https://www.sparkfun.com/products/9669

These are 5V relays that are USB controllable.

These would control larger relays up to whatever value... say 30amps.

I'm a professional programmer, so coding interactive webpages and serial-controllers DLL's are no problem for me.

The only challenaging part would be finding a corresponding USB device for digital-varisting capable of 120v support up to say 5 or 15amps.

My Automation system would lack all the fancy RF-wave and video switching stuff, which I don't care about.

I should be able to do remote IR controlling as well, I'm almost 100% sure of that.

Thoughts?

"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
Sponsored Links
Advertisement
 
post #2 of 68 Old 02-08-2013, 04:14 PM
AVS Special Member
 
Mr.Tim's Avatar
 
Join Date: Jul 2004
Location: SC
Posts: 2,081
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 11 Post(s)
Liked: 56
It depends on what you intend to do with relays. I have built many 120v dimming relays (well, triacs) using DMX and RS-485, which will support much longer runs than USB.

However, all it does is give you dimming. I use them outside for Christmas lights. I wouldn't be keen on installing DIY 120v stuff inside my home.

I suppose you could use the USB relay to power the coil on a 120v ice cube relay, at which point you would at least have a UL listing on the 120v portion. THere are plenty of communities out there for this kind of thing.

Tim

ICC Certified.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
||
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
||
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
||
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

Mr.Tim is online now  
post #3 of 68 Old 02-08-2013, 05:06 PM
AVS Special Member
 
lilmike's Avatar
 
Join Date: Dec 2009
Location: Pacific Northwest
Posts: 2,193
Mentioned: 0 Post(s)
Tagged: 1 Thread(s)
Quoted: 18 Post(s)
Liked: 86
Cool idea, and that is a cool little toy!

I'm looking into the Z-wave based options for my upcoming renovation. There look to be a lot of control options for that, some are actually FOSS.

Since this is appliance-level hardware (in other words - it should just work), I'm willing to spend a bit more and get something that I don't have to mess with or code a whole backend for.

Hornresp Tutorials (By amateurs, for amateurs!)


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
lilmike is offline  
post #4 of 68 Old 02-09-2013, 01:09 PM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
I'd want security, lighting control and power management all from a single interface on a touchscreen tablet.
For now, it will be limited to my theater. With the possibility of an intercom system between that and the kitchen (which could be a stand-alone system).

For the app interface, I was thinking of a floor-plan overlay design for device selection, and/or a text drilldown tree-list by category.

1) Lighting control: Support for up to 8 light-zones, with at least on/off capability for all 8, but preferably including 4 dimmer zones with support of up to 400watts on each.
2) Power management: Being able to cycle 16 power devices with variable delay and with timer options, all independently and/or in various clusters of user-defined modes. Supporting both 120v and 240v up to 30amps.
3) Security management:
a) Keyless entry, with network lock/unlock. Preferably Biometric or maybe a combination, RFID proximity and/or key code.
b) Support for 3 IP camera HUD. Preferably with tilt/zoom and night-vision.
c) Motion Sensor Alerting

Future Capabilities:
4) Media controller (audio at least)
5) VOIP or Skype/Facetime etc

So I need 24 high-powered relays, 4 fuses and high-powered triacs, one heck of a PC breakout box, and probably a 10 channel gigabit/11g/n router.
All of this for as cheap as possible of course...
(damn, I might as well go with a full Crestron system or something frown.gif)

The problem isn't the software for me, it is in finding good controller-hardware, either wired/wireless for cheap. Preferably USB, Eithernet or 11g.
I wonder if something like the X10 breakout controller drivers are proprietary closed-source or open or well documented at least? confused.gif

"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #5 of 68 Old 02-09-2013, 04:28 PM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
For $140, I found a 24 channel RS485-over-USB controlled relay system. The cheapest I've found yet...

With my own software this would solve all of 1 & 2, except for the computer-controlled dimming part of the lighting.

I'd still need to connect these low-ish powered relays to high-powered relays as these aren't designed for Lab clones and multi-hundred-watt lights,
which is no big deal. I'd slap that into a DIY box with NEMA inputs and outputs to make it all clean of course (no exposed high-voltage wiring LOL).

The cool thing with this solution is that it isn't wireless, thus it remains absolutely secure; teenaged hackers can't turn my gear off via RF signals from their mom's basement LOL. (Unlike X10 etc...)

I'm not even going to worry about features 3 through 5 until the first two are fully solved. That's why I went down this rabbit hole to start with after all...

http://www.ebay.com/itm/USB-RS485-24-Channel-Relay-Board-controller-/280583706515?pt=LH_DefaultDomain_0&hash=item4154179793

"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #6 of 68 Old 02-09-2013, 09:54 PM
AVS Special Member
 
A9X-308's Avatar
 
Join Date: Mar 2008
Location: Australia; now run by adults.
Posts: 5,270
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 86 Post(s)
Liked: 70
I'm doing my apartment/HT automation with a set of networked Arduino Mega2560 and have just received a Raspberry Pi which I'm planning to use as a display interface. Arduinos come with all sorts of shield modules so you can wifi or Xbee somewhere you can't get wiring directly.

Search ebay under 'relay boards' or 'relay modules' and you'll see plenty of them that will handle 10A at 120V. Above that you're going to need to find something else. I use MCP23S17 port expanders driving ULN2803 octal darlington drivers and Omron G4a relays because they meet my specs (20A at 240V, 80A surge) and I got a tray of 50 for under a $1ea new.

I set it up this way because I don't want a PC on all the time. And because it was a fun project and got me back into embedded design after a long hiatus. Much as I loathe C, it makes life a lot easier than assembly, but it still sucks compared to Forth.
A9X-308 is offline  
post #7 of 68 Old 02-10-2013, 05:31 AM
AVS Special Member
 
Martycool007's Avatar
 
Join Date: Jun 2011
Posts: 3,536
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 184 Post(s)
Liked: 153
I am sooo green when it comes to the home automation stuff that is out now as it seems to get more complicated by each passing year. So let me get this straigt, you are using relays, (which are basically just switches that turn some on & off, right?) to control when the lights come on, accompanied by some dimmer switches for the level of light. Then you are also going to be using relays for turning on your equipment, something like 16 different components, right?

I have absolutely no idea what you will be doing for security management, but I am guessing that you will have hi tech cameras that will monitor everything....not sure how you are going to operate those? Also what kind of devise, or software will the security cameras feed the video into, and how do you propose to monitor this video? Also with regards to the security system, are you going to have window breakage detectors and motion sensors, and if so, how do you plan to operate and manage those with regards to how all of this fits together?

Are you writing the software for a DIY home automation controller, similar to a Creston? If so, how and what are you going to use for the hardware? If not, are you going to buy a controller like the Crestons that so many folks use?

What is a high powered Triac and what is its purpose? What is a PC breakout box and what is a 10 channel 11gig router? Sorry for all of the dumb questions but I will be remodeling a house soon and would like to have some sort of home automation like you described, and like I said, I am totally green on this!
Martycool007 is online now  
post #8 of 68 Old 02-10-2013, 02:01 PM
AVS Special Member
 
A9X-308's Avatar
 
Join Date: Mar 2008
Location: Australia; now run by adults.
Posts: 5,270
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 86 Post(s)
Liked: 70
I'm not sure who you are asking these questions, so I'll assume me in part and reply.
Quote:
Originally Posted by Martycool007 View Post

I am sooo green when it comes to the home automation stuff that is out now as it seems to get more complicated by each passing year. So let me get this straigt, you are using relays, (which are basically just switches that turn some on & off, right?) to control when the lights come on, accompanied by some dimmer switches for the level of light. Then you are also going to be using relays for turning on your equipment, something like 16 different components, right?
I am using relays, both for power selection and control in the HT and some house functions, such as lighting in the theatre room. For example it is programmed so that when you press Play on a selection that uses video, the room lights will dim, and will ramp up when you press Pause or Stop. If I selected TT as source, none of the amps etc that run the surrounds (tri-amped) will be powered up. All power switching is done close to zero cross accounting for relay delay.

The plan is later to add mains outlet control and lighting through the rest of the apartment as I find time and need to do so. I have a friend who has build a similar system in his home, and when he's not there, lights and other devices such as radios turn on/off in a correct sequence to simulate people being there, and I'd like to add this later.
Quote:
Originally Posted by Martycool007 View Post

I have absolutely no idea what you will be doing for security management, but I am guessing that you will have hi tech cameras that will monitor everything....not sure how you are going to operate those? Also what kind of devise, or software will the security cameras feed the video into, and how do you propose to monitor this video? Also with regards to the security system, are you going to have window breakage detectors and motion sensors, and if so, how do you plan to operate and manage those with regards to how all of this fits together?
I'm doing PIR and window break, and am looking at some inexpensive commercial systems to do video. My own stand alone system will call (and later ) email if it detects. Not sure if I'll be able to integrate the two bet they might not be necessary. We'll see.
Quote:
Originally Posted by Martycool007 View Post

Are you writing the software for a DIY home automation controller, similar to a Creston? If so, how and what are you going to use for the hardware? If not, are you going to buy a controller like the Crestons that so many folks use?
Can't afford a Crestron, so I'm basically making a DIY on that does what I want, some of which is highly specific to my my particular set up and equipment, some of which is modified to suit my needs. Total cost for everything should be under $500, plus a lot of coding and soldering, but I enjoy that anyway.
Quote:
Originally Posted by Martycool007 View Post

What is a high powered Triac and what is its purpose?
A triac is a solid state switch which can handle alternating currents, making it suitable for controlling the mains on many devices. They are also sued in some dimmers for lighting. High powered would mean one that can handle mains voltage as well as the current that the load you wish to control will draw, say 5 or 10A. Some can handle considerably more current.
Quote:
Originally Posted by Martycool007 View Post

What is a PC breakout box and what is a 10 channel 11gig router?
PC aren't natively suitable for controlling ancillary devices such as relays, so that need some sort of interface to connect to the PC via USB or RS232. These usually then let you control say 24 relays or other devices. These are used in many industrial applications worldwide.

I've never heard of a '10 channel 11gig router'. 10 channel I assume means 10 RJ45 ports but this is an uncommon configuration. Routes/switchers etc are usually in a multiple of 8 ports, 8/16/24/48 and small home/SOHO versions have 5. 11gig might refer to one of the common networking protocols 802.11g. There are faster variants such as 802.11n. Go with the fastest you can afford in a new installation to allow for longest life.
Quote:
Originally Posted by Martycool007 View Post

Sorry for all of the dumb questions but I will be remodeling a house soon and would like to have some sort of home automation like you described, and like I said, I am totally green on this!
If I was with you in person and had the floorplans and could ask questions about what you want to control and how, whether you want to use a single server and route all TV/video through the network etc it would be easier to make suggestions. FWIW I'm licensed to do this sort of work in my country.

My basic plan is to add at least one Cat6 cable and port to each room, and depending upon the room and it's use and possible uses later, I'd likely add more. You could always bring say 4 cables from each room to a central point with the switch(es) placed there and connect up the outlets you are using now. Rearrange the living room in 5 years might mean a point on the opposite wall is more convenient (no exposed cables), so all you'd need to do then is go to the 'network cupboard' and change to the correct wire. Trust me, you will regret not putting them in now when the cost will be minimal as it's easy and cheap to do before the drywall/gyprock goes up, and much more expensive later. In some cases due to the construction of the house it may be very difficult and expensive or impossible to add later without something you may not like, such as an external visible conduit.
A9X-308 is offline  
post #9 of 68 Old 02-12-2013, 12:47 PM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
Quote:
Originally Posted by Martycool007 View Post

I am sooo green when it comes to the home automation stuff that is out now as it seems to get more complicated by each passing year. So let me get this straigt, you are using relays, (which are basically just switches that turn some on & off, right?) to control when the lights come on, accompanied by some dimmer switches for the level of light. Then you are also going to be using relays for turning on your equipment, something like 16 different components, right?

Correct.
Quote:
Originally Posted by Martycool007 View Post

I have absolutely no idea what you will be doing for security management, but I am guessing that you will have hi tech cameras that will monitor everything....not sure how you are going to operate those? Also what kind of devise, or software will the security cameras feed the video into, and how do you propose to monitor this video? Also with regards to the security system, are you going to have window breakage detectors and motion sensors, and if so, how do you plan to operate and manage those with regards to how all of this fits together?

I don't have any glass in my theater, only doors. Motion activated sensors for video recording and alerts, should be doable, not sure about a single integrated DIY solution for that though (depends on the camera vendor).
My UPS probably has email alerts for power loss, which may also be handy (not that there is anything I could do about it though).
Quote:
Originally Posted by Martycool007 View Post

Are you writing the software for a DIY home automation controller, similar to a Creston? If so, how and what are you going to use for the hardware?
Yes. My HTPC, which is on 24/7 already.

I was thinking of getting a RAID-5 NAS in time for my HTPC as well.

"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #10 of 68 Old 02-12-2013, 02:54 PM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
Quote:
Originally Posted by A9X-308 View Post

It is programmed so that when you press Play on a selection that uses video, the room lights will dim, and will ramp up when you press Pause or Stop. If I selected TT as source, none of the amps etc that run the surrounds (tri-amped) will be powered up. All power switching is done close to zero cross accounting for relay delay.

Dude that is insane, how did you detect zero-crossing. Diagram?
I've never really dipped into the hardware-aspect of automation control before.
You must have used the Arduino chip for the relay delay, calculating the next half-wave 8ms delay or 16ms full-cycle (substracting the relay activation time of course).

Also, what media player are you using for those control hooks?

"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #11 of 68 Old 02-12-2013, 09:16 PM
AVS Special Member
 
A9X-308's Avatar
 
Join Date: Mar 2008
Location: Australia; now run by adults.
Posts: 5,270
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 86 Post(s)
Liked: 70
Quote:
Originally Posted by BassThatHz View Post

Dude that is insane, how did you detect zero-crossing. Diagram?
I'm not at home at the moment, but I'll post it when I get a chance.
Quote:
Originally Posted by BassThatHz View Post

I've never really dipped into the hardware-aspect of automation control before.
My background is electronics, so I approach design of a system as 'how is this easiest (for me) to do' and use a lot of electronic sub systems to augment processors. For me, that is implement anything in software that I can't do easily in hardware.
Quote:
Originally Posted by BassThatHz View Post

You must have used the Arduino chip for the relay delay, calculating the next half-wave 8ms delay or 16ms full-cycle (substracting the relay activation time of course).
That's pretty much it. The zero cross detector goes to a spare input pin on the Mega, so when it's about to open/close a relay, it constantly loops looking for that pin to change state and adds a delay to get relay operating delay plus software delay to equal 20mS (50Hz here). I tested all the relays I used for many operational cycles and averaged the delay to use for that type of relay.
Quote:
Originally Posted by BassThatHz View Post

Also, what media player are you using for those control hooks?
I'm not using a media player to implement this - it operates with no PC running.
I have XBMC but I find it easier most of the time to simply access a file and play it rather than use media players. When I wish to play something that's on a PC, I select that as a 'Source' via IR remote, which brings the PC out of sleep mode (and sets up the rest of the system) and I use a keyboard/trackball combo to control the PC.
A9X-308 is offline  
post #12 of 68 Old 02-14-2013, 09:54 AM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
Quote:
Originally Posted by A9X-308 View Post

I'm not using a media player to implement this - it operates with no PC running.
I find it easier most of the time to simply access a file and play it rather than use media players. When I wish to play something that's on a PC, I select that as a 'Source' via IR remote, which brings the PC out of sleep mode (and sets up the rest of the system) and I use a keyboard/trackball combo to control the PC.

A9X you don't use a computer? How then are you accessing the file-system on the drive? (AVR with network file streaming or ?)
How do you pass the h264 into an HDMI AV connection?
How does your Arduino know that the movie is playing or paused/stopped?

"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #13 of 68 Old 02-14-2013, 06:46 PM
AVS Special Member
 
A9X-308's Avatar
 
Join Date: Mar 2008
Location: Australia; now run by adults.
Posts: 5,270
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 86 Post(s)
Liked: 70
Quote:
Originally Posted by BassThatHz View Post

A9X you don't use a computer? How then are you accessing the file-system on the drive? (AVR with network file streaming or ?)
How do you pass the h264 into an HDMI AV connection?
How does your Arduino know that the movie is playing or paused/stopped?
There is some misunderstanding. The 'control' system of Arduinos, does not need a PC to be running. I can put a disc in the BRP and select 'Play CD' via IR RC and control the system from the RC (stop, play, change sources etc). The Arduino receives the IR codes and acts according to what it receives.

The Arduinos do not need to know whether a source is playing or not. They set up the conditions to allow it to happen and control some of the functions of the devices. If I was watching a movie from the BRP, after initial system set up, and pressing play, they are idle until the next control is pressed.

If I wish to play a file stored on computer selecting 'PC Music' / 'PC Movie' sets up the system by turning on/off power amps, projector, AVR etc and by applying the settings for that source if needed, and then I control the movie/music being played from the PC via a combo keyboard and trackball.

On the PC where I have a lot of movies and music stored, I have XBMC but it is sort of annoying, and I have no problem just opening MPC and selecting a DVD file to play for instance. I might get J River later, when I build a dedicated HTPC. Movie files from the PC are played out to the AVR via HDMI. The PC is connected to a network that runs throughout the apartment (not the garage yet though) so I can access and play files from any computer connected to the network.
A9X-308 is offline  
post #14 of 68 Old 02-15-2013, 01:39 PM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
Ah IR input. Gotcha!
Good idea, Why didn't I think of that? tongue.gif

"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #15 of 68 Old 11-03-2013, 03:49 AM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
Here is the KMTronic based Relay Controller code I wrote yesterday.

It's an Alpha-version since I don't have the hardware yet to prove that it is totally bug free.

[Alpha version delete, contained errors in the relay code. Beta 0.9 is now available as of Nov 23, 2013 which is error-free.]

I wrote it in C# .Net 4.5 (Visual Studio 2012)

It runs as a Window Service.
The Windows Service hosts my own custom-coded WebHost controller (aka webserver) that I wrote.
The web server hosts the content of the web page that I intend to use from my tablet via wi-fi to control the USB attached relay circuits (as I explained in previous posts),
the KMTronic relay controller logic is embedded into the webserver's server-side code interacting with the webpage (of course).

I coded my own WebHost because I didn't want to have to install Microsoft IIS and the baggage that comes with that. (and just for the sake of the programming-challenge I suppose wink.gif ).


The code is a bit ugly ATM because I threw it together very quickly, but it all works up to the KMTronic stuff; this I know.
It's a good starting foundation, at least...

"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #16 of 68 Old 11-03-2013, 11:48 AM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
Here's an explanation of each part of the app.

It is composed of 6 parts.

1) The TestConsole project: is a command-line interface to host the WebHost. (I use this for fast debugging).
2) The WebContent project: has the webpage stuff in it and bridges the gap between the webhost layer and the RelayConfigurator. (aka code-behind page).
3) The WebHost project: that hosts the WebContent stuff. (This emulates IIS, or Apache for the Java folks)
4) The RelayLib project: that talks with the KMTronic hardware. (Untested)
5) The RelayConfig project: this stores the Relay Configuration stuff, and right now it bridges the gap between the WebContent and the RelayLib. (aka business-logic layer)
6) The BassThatHzRelay project: that hosts the Window Service stuff (when we are running it for real, and aren't debugging stuff via the command line hoster), this hosts the WebHost.


The two important pieces are as follows....




#4 The RelayLib:

Pretty straight forward, based on the examples that KMTronic has posted on their website. This is where the rubber meets the road.
Since the web host is multithreaded I dropped down into single-threading mode so as not to have issues with the controller.

I see a code bug there with the State flags, they are being ignored, no big deal I'll fix it when I get the hardware.
Code:
    public class Relay
    {
        public byte ID;
        public bool State;
        public string Name;
    }

     public class RelayController
    {
        private static Mutex mut = new Mutex();

        public void ToggleRelays(List<Relay> RelaysToStart, List<Relay> RelaysToStop)
        {
            ToggleListOfRelayBoxes(true, RelaysToStart);
            ToggleListOfRelayBoxes(false, RelaysToStop);
        }

        private void ToggleListOfRelayBoxes(bool State, List<Relay> Relays)
        {
            if (Relays != null)
            {
                foreach (var relay in Relays)
                {
                    relay.State = State;
                    ToggleRelay(relay.ID, relay.State);
                }
            }
        }

        private void ToggleRelay(byte ChannelID, bool State)
        {
            byte StateByte = 0x00;
            if (State)
                StateByte = 0xFF;

            mut.WaitOne();          
            var coms = System.IO.Ports.SerialPort.GetPortNames();
            var serialPort1 = new System.IO.Ports.SerialPort(coms[0]);
            serialPort1.Open();
            serialPort1.Write(new byte[] { 0xFF, ChannelID, StateByte }, 0, 3);
            serialPort1.Close();
            mut.ReleaseMutex();
        }
    }



#3 The WebHost:
This is my favorite part, I always wanted to write my own HTTP handler.

This code is gonna need more work if I want things to look they weren't built in 1995 (resource locator/handler) wink.gif

I have it hardcoded to localhost domain name resolution and port 8080 with no security layer yet. (good enough for now....)

I process the HTML requests Asynchronously, assuming EndGetContext is multi-threaded and thread-safe. wink.gif

I put in some default HTML return code just to help with debugging stuff, just in-case I mess something up (unlikely).
Code:
public class WebHost
    {
        private HttpListener listener = new HttpListener();

        private Func<HttpListenerRequest, string> _HttpResponseHandler;
        Thread ListenerThread;
        bool IsRunning = true;

        public void Start(string uri, Func<HttpListenerRequest, string> httpResponseHandler)
        {
            //example: "http://localhost:8080/"
            listener.Prefixes.Add(uri);
            listener.AuthenticationSchemes = AuthenticationSchemes.Anonymous;

            _HttpResponseHandler = httpResponseHandler;
            
            Stop();
            listener.Start();
            IsRunning = true;

            ListenerThread = new Thread(new ThreadStart(ProcessRequestsAsync));
            ListenerThread.Start();
       }

        private void ProcessRequestsAsync()
        {
            while (IsRunning && listener.IsListening)
            {
                IAsyncResult result = listener.BeginGetContext(new AsyncCallback(HttpRequestHandler), listener);
                result.AsyncWaitHandle.WaitOne();
            }
        }

        public void Stop()
        {
            IsRunning = false;
            if (ListenerThread != null)
            {
                try
                {
                    ListenerThread.Abort();
                }
                catch { }
            }

            if (listener.IsListening)
            {
                listener.Stop();
            }
        }

        private void HttpRequestHandler(IAsyncResult result)
        {
            HttpListenerContext Context = listener.EndGetContext(result);

            HttpListenerRequest Request = Context.Request;
            HttpListenerResponse Response = Context.Response;

            if (Request.RawUrl != "/" && Request.RawUrl != "/Default.html")
            {
                return;
            }

            string ResponseString  = String.Empty;

            Response.StatusCode = 200;
            Response.StatusDescription = "OK";
            Response.ContentType = "text/html";

            if (_HttpResponseHandler != null)
            {
                ResponseString = _HttpResponseHandler.Invoke(Request);
            }

            if (String.IsNullOrEmpty(ResponseString))
            {
                ResponseString = "<HTML><BODY>Default Content</BODY></HTML>";
            }

            byte[] Buffer = System.Text.Encoding.UTF8.GetBytes(ResponseString);
            Response.ContentLength64 = Buffer.Length;
            System.IO.Stream OutputStream = Response.OutputStream;
            OutputStream.Write(Buffer, 0, Buffer.Length);
            OutputStream.Close();
            Response.Close();
            
        }
    }

Here is the actual webpage that gets send to the bowser, kept it pretty simple (for now...)
Code:
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <form name='input' action='/Default.html' method='post'>
            <input name ='btnMusic' type='submit' value='Music Mode' />
            <input name ='btnMovies' type='submit' value='Movie Mode' />
            <input name ='btnOff' type='submit' value='All Off' />
        </form>
    </body>
</html>


Should run lightning-fast, and all of this fits within just 30kb of harddrive space and RAM. (winning batman, WINNING! biggrin.gif )
Much better than the jigobytes of RAM, diskspace, and zillions of CPU cores needed to run the more traditional bloatware of today (Norton AV and Vista both come to mind biggrin.gif).

"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #17 of 68 Old 11-08-2013, 09:11 PM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
Just purchased the hardware. 16 channels. It's coming from Bulgaria so it's gonna take a while to get here. I paid the extra for a tracking number though.


It will be cool to see my software in action.

Now, I wonder if I even have a free USB port left? I might have to get a usb hub too! eek.gif

"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #18 of 68 Old 11-17-2013, 12:33 AM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
Hardware will be here on the 22nd according to the tracking number.
It's on the east coast right now and it has to go to the west coast yet, so 1900 more miles to go.



It's traveled 5200miles so far, hopefully it's still in one piece. rolleyes.gif

"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #19 of 68 Old 11-23-2013, 04:06 PM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
The hardware has arrived.

I'll be cannibalizing this LiteOn power supply as a power source for it.



Now, time to see if this thing works... or if it catches on fire. haha wink.gif

Looks like I have some work to do...

"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #20 of 68 Old 11-23-2013, 04:24 PM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
I've powered one board up, it didn't explode or make weird noises... So far so good.


"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #21 of 68 Old 11-23-2013, 04:34 PM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
I installed the 64bit driver and plugged it in to my $3000 HTPC, and flames didn't come out. So good so far...





Now I'll have to load my code and see if I can make it all work together! wink.gif

"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #22 of 68 Old 11-23-2013, 06:03 PM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
The RS485 is wired. No smoke yet.


"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #23 of 68 Old 11-23-2013, 07:56 PM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
Here's Beta-Version: 0.9 of my app.

I've corrected some minor errors in the alpha version of my code that prevented the relay from operating correctly, as I speculated.

This code works:

BassThatHzRelayBeta0.9.zip 24k .zip file



You can see the changes I had to make to fix it compared to the previous blurb.

I also now keep the controller connection open until all devices have finished switching states, it makes them switch faster (more on this below...)
Code:
public class RelayController
    {
        private static Mutex mut = new Mutex();
        private System.IO.Ports.SerialPort serialPort1;

        public RelayController()
        {
            mut.WaitOne();
            var coms = System.IO.Ports.SerialPort.GetPortNames();
            serialPort1 = new System.IO.Ports.SerialPort(coms[1]);
            mut.ReleaseMutex();
        }

        public void ToggleRelays(List<Relay> RelaysToStart, List<Relay> RelaysToStop)
        {
            mut.WaitOne();
            serialPort1.Open();

            ToggleListOfRelayBoxes(true, RelaysToStart);
            ToggleListOfRelayBoxes(false, RelaysToStop);

            serialPort1.Close();
            mut.ReleaseMutex();
        }

        private void ToggleListOfRelayBoxes(bool State, List<Relay> Relays)
        {
            if (Relays != null)
            {
                foreach (var relay in Relays)
                {
                    ToggleRelay(relay.ID, State);
                }
            }
        }

        private void ToggleRelay(byte ChannelID, bool State)
        {
            byte StateByte = 0x00;
            if (State)
                StateByte = 0x01;
        
            serialPort1.Write(new byte[] { 0xFF, ChannelID, StateByte }, 0, 3);
        }
    }

The non-beta version will include a relay delayer and have configurable relay settings / com channel.
Basically better control over the activities going on, right now everything is still hard-coded to my theater's specifications, which you are welcome to customize yourself. wink.gif

"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #24 of 68 Old 11-23-2013, 08:43 PM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
That's all folks... for now. wink.gif

"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #25 of 68 Old 11-24-2013, 10:20 AM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
I've coded the delay-er logic and made the com channel configurable.

I have at least three more things I want to do to it yet:
1) Browser image hosting (to make the browser page look fancier).
2) Configuration-driven relays (to make it not specific to just my theater, and not needing recompiles).
3) SSL and Password Authentication (to have security control).
Code:
namespace RelayLib
{
    public class Relay
    {
        public byte ID = 0x01;
        public string Name = string.Empty;
        public TimeSpan? StartDelay = null;
    }

    public class RelayController
    {
        private static Mutex mut = new Mutex();
        private System.IO.Ports.SerialPort serialPort1;

        public RelayController()
        {
            mut.WaitOne();

            string com_channel = ConfigurationManager.AppSettings.Get("com_channel");
            if (String.IsNullOrEmpty(com_channel))
            {
                var coms = System.IO.Ports.SerialPort.GetPortNames();
                com_channel = coms[0];
            }
            serialPort1 = new System.IO.Ports.SerialPort(com_channel);

            mut.ReleaseMutex();
        }

        public void ToggleRelays(List<Relay> RelaysToStart, List<Relay> RelaysToStop)
        {
            mut.WaitOne();
            serialPort1.Open();

            ToggleListOfRelayBoxes(true, RelaysToStart);
            ToggleListOfRelayBoxes(false, RelaysToStop);

            serialPort1.Close();
            mut.ReleaseMutex();
        }

        private void ToggleListOfRelayBoxes(bool State, List<Relay> Relays)
        {
            if (Relays != null)
            {
                foreach (var relay in Relays)
                {
                    if (relay.StartDelay.HasValue)
                    {
                        System.Threading.Thread.Sleep((int)relay.StartDelay.Value.TotalMilliseconds);
                    }

                    ToggleRelay(relay.ID, State);
                }
            }
        }

        private void ToggleRelay(byte ChannelID, bool State)
        {
            byte StateByte = 0x00;
            if (State)
                StateByte = 0x01;

            serialPort1.Write(new byte[] { 0xFF, ChannelID, StateByte }, 0, 3);
        }
    }
}

"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #26 of 68 Old 11-24-2013, 10:35 AM
AVS Special Member
 
A9X-308's Avatar
 
Join Date: Mar 2008
Location: Australia; now run by adults.
Posts: 5,270
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 86 Post(s)
Liked: 70
Quote:
Originally Posted by BassThatHz View Post

my $3000 HTPC
Three grand? I just built a 3770/7790/8G/120B SSD/1TB HDD HTPC and had change from a grand at Australian prices and can run full SVP/madVR.
A9X-308 is offline  
post #27 of 68 Old 11-24-2013, 12:33 PM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
My computer is 1.5 years old now. The prices have come way down since then (especially SSD's, I paid $400 for one).

Back when this was considered day-0 new/elite (there's better stuff out now, of course):

$600 i7 3820 LGA2011
$600 64GB QC DDR3
$600 GTX 670
$600 3 3TB HDD
$400 Max IOPS 128GB SDD
$300 Asus P9X79
$300 24" LG
$200 Xonar HDAV1.3
$150 Creative Xtreme Music v1
$120 Hi-End Case

Prices are approximate but it was roughly: $3-4k

"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #28 of 68 Old 11-24-2013, 12:48 PM
AVS Special Member
 
A9X-308's Avatar
 
Join Date: Mar 2008
Location: Australia; now run by adults.
Posts: 5,270
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 86 Post(s)
Liked: 70
I'm assuming that this was built for more than just a HTPC (gaming?), otherwise why 64G RAM? A G1610 will play back BR perfectly with the iGPU. I only built mine with a 3770/7790 because I wanted full madVR/SVP and it to be running far from max to keep it quiet.

Just mentioning it in case a reader thinks you need to spend that much for a HTPC.
A9X-308 is offline  
post #29 of 68 Old 11-26-2013, 05:14 PM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
256GB of ram would be ideal for me. I've been experimenting with RAM disks.

That, and I just like overkill.

"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
post #30 of 68 Old 12-01-2013, 03:35 PM - Thread Starter
AVS Special Member
 
BassThatHz's Avatar
 
Join Date: Apr 2008
Location: East side of NW Cascades
Posts: 2,883
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 226 Post(s)
Liked: 353
Does anyone know if the Omega Solids are a good item to buy: SSRL240DC50?

Say's it has: Zero Voltage Switching, which is a feature I desire.

I need 4 of these, and a few of the 15/20's too.

http://www.omega.com/pptst/ssrl240_660.html


"If Bad Sound Were Fatal, Audio Would Be the Leading Cause of Death."


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
BassThatHz is offline  
Reply DIY Speakers and Subs

User Tag List

Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page


Forum Jump: 

Posting Rules  
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off