share software

Pop your questions regarding Home automation Domotica hardware here.....
Edwin2008
Advanced Member
Advanced Member
Posts: 721
Joined: Fri Nov 28, 2008 4:14 pm
Location: Netherlands

Re: share software

Post by Edwin2008 »

where was it ment for?
** edwin **
korsteed
Starting Member
Starting Member
Posts: 29
Joined: Sun Jan 31, 2010 9:19 pm
Location: Vleuten

Re: share software

Post by korsteed »

I have written software in Java that makes a socket-connection to a RFX-com reciever and
filters out events from devices I have in my house. The events I want to keep, are stored in an Oracle database (using JDBC).
I can share this software, but it was created quickly for my own devices, not a generic solution for all devices.
So if you have different devices or want to use a different database, you probably have to modify some code.
Tiz
Member
Member
Posts: 146
Joined: Tue May 19, 2009 12:21 pm
Location: Netherlands

Re: share software

Post by Tiz »

@korsteed. I am also developing in java but I do not have much experience with exception handling. I am particularly interested in the way you programmed your socket connection. For my own project I am communicating through rs232 using the rxtx classes, but I think it would help a lot to see how other people deal with communication, possible buffers of messages, exception handling etcetera.
Mathijs
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: share software

Post by Digit »

Edwin2008 wrote:where was it ment for?
Storing RFXMeter counter values in a MS SQL database.
koenbelgium
Starting Member
Starting Member
Posts: 11
Joined: Thu Apr 30, 2009 12:26 pm
Location: Belgium

Re: share software

Post by koenbelgium »

@Tiz, I developed a solution in Java as well and decoupled the interfaces (rs232, email, ...) from the server application.
The communication between de interfaces (clients) and the server happens via JMS. JMS is a good way to buffer messages and handling exceptions because crashes of an interface do not destroy the server.
When the server is not reachable, the messages are stored at client side or in the JMS broker (if available). Once the server is restarted, it receives the events that were generated during his absence.
The server is connected to a database using jdbc which makes it database independent, for the moment I am using SQL Server and Derby.

For the moment I have following interfaces:
* RS232 to my home automation system
* RS232 to send and receive SMS via GSM
* IP to send and receive emails (JavaMail)
* IP GUI to administrate system (Swing)
* IP GUI to control system on touch screen (Swing)
* IP GUI to control temperature zones (Swing)
* IP to my Squeezebox (prove of concept via xAP)
* RS232 to my Yamaha audio systems (under development)

Lots of other plans unfortunately time restrictions limits my progress :-(
Tiz
Member
Member
Posts: 146
Joined: Tue May 19, 2009 12:21 pm
Location: Netherlands

Re: share software

Post by Tiz »

Wow, sounds a lot like what I am trying to do, but I am only at the beginning. I have also decoupled the interfaces, but only in the class structure and am using the observer pattern to have the interfaces "talk" to the listeners. Those are both what I cal the scenariomanager (that determines whether an action needs to be performed) or the loggingmanagaer that takes care of logging events in the right way and the right spot.
But I am finishing my part time study this year, so the project is a little bit delayed :-)
Mathijs
korsteed
Starting Member
Starting Member
Posts: 29
Joined: Sun Jan 31, 2010 9:19 pm
Location: Vleuten

Re: share software

Post by korsteed »

I created a very lightweight/simple program. I haven't put a lot of effort (yet) into logging, error handling and/or making it generic.
The main goal was to get up and running quickly and make the program better when/if I have time.

It's a single threaded program that keeps on running in a dedicated JVM.
It makes a socket-connection to the RFX-com receiver, parses the received bytestream to a RfxSignal object and stores the data in the RfxSignal
to a database and continue receiving a new bytestream.
If an unexpected event takes place, the program will stop running, but I haven't seen that happen yet (running 24x7 for 5 months now).

The main method looks like this:

Code: Select all

	void run(String ipAddress) {
		try {
			// creating a socket to connect to the server
			requestSocket = new Socket(ipAddress, 10001);

			System.out.println("Connected to rfxcom");
			in = requestSocket.getInputStream();

			int count;
			byte[] previous = null;
			byte[] buffer = new byte[16384]; 

			while ((count = in.read(buffer)) > 0) {

				if (ByteUtil.equalBuffer(buffer, previous, count)) {
					// skip this record. It's the same as previous
				} else {
					previous = ByteUtil.copyByteBuffer(buffer, count);
					RfxSignal thisSignal = RfxParser.getRfxSignal(buffer,count);
					if (thisSignal!=null){						
						try {
							RfxDAO.getInstance().store(thisSignal);
						} catch (SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
					
				}
			}
		} catch (UnknownHostException unknownHost) {
			System.err.println("You are trying to connect to an unknown host: "+ipAddress);
		} catch (IOException ioException) {
			ioException.printStackTrace();
		} finally {
			// Closing connection
			try {
				in.close();
				requestSocket.close();
			} catch (IOException ioException) {
				ioException.printStackTrace();
			}
		}
	}

Post Reply

Return to “Questions & Discussions Forum”