share software

Pop your questions regarding Home automation Domotica hardware here.....

Re: share software

Postby Edwin2008 » Sun Mar 13, 2011 2:18 pm

where was it ment for?
** edwin **
Edwin2008
Advanced Member
Advanced Member
 
Posts: 720
Joined: November 2008
Location: Netherlands

Re: share software

Postby korsteed » Sun Mar 13, 2011 11:16 pm

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.
korsteed
Starting Member
Starting Member
 
Posts: 29
Joined: January 2010
Location: Vleuten

Re: share software

Postby Tiz » Sun Mar 13, 2011 11:25 pm

@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
Tiz
Member
Member
 
Posts: 146
Joined: May 2009
Location: Netherlands

Re: share software

Postby Digit » Sun Mar 13, 2011 11:50 pm

Edwin2008 wrote:where was it ment for?


Storing RFXMeter counter values in a MS SQL database.
User avatar
Digit
Global Moderator
Global Moderator
 
Posts: 3388
Joined: March 2006
Location: Netherlands

Re: share software

Postby koenbelgium » Mon Mar 14, 2011 2:18 pm

@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 :-(
koenbelgium
Starting Member
Starting Member
 
Posts: 11
Joined: April 2009
Location: Belgium

Re: share software

Postby Tiz » Mon Mar 14, 2011 5:06 pm

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
Tiz
Member
Member
 
Posts: 146
Joined: May 2009
Location: Netherlands

Re: share software

Postby korsteed » Mon Mar 14, 2011 7:55 pm

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();
         }
      }
   }

korsteed
Starting Member
Starting Member
 
Posts: 29
Joined: January 2010
Location: Vleuten

Previous

Return to Questions & Discussions Forum

Who is online

Users browsing this forum: No registered users and 1 guest

cron