10

Firstly Cheers to all PROGRAMMERS [ Today = Programmers day :) ]

Secondly, I'm working on a project where the specifications require using a server as a front end and an application in the back end. The project is an advanced smart home system. The server will handle commands coming from the client through the internet (let's say like a remote control from outside the house) and send them (through a channel of communication) to the application (planning on using JAVA application) which will handle the main logic like controlling hardware stuff (lights ...) , reading from a microphone (local mic) and accessing a database to act as a speech recognition system (offline).

Now I'm still in the planning phase and I'm not sure which technologies are the best for this project. I'm thinking to use Node.js or Apache as the server and a JAVA application as the back end and any SQL database for the application's SRS.

I hope this illustration demonstrates clearly how the system works:

enter image description here

The main question is:

What is the best way to make the Java application communicate with the server (communication channel [must be bidirectional]) ?

and Do you recommend a specific server other than the mentioned ones for this job ?

What crossed my mind so far:

1- JSP and servlets (making the server is the application too). But I don't want a server to handle the offline stuff and I'm not sure if java servlets can access hardware interface. I also want the server to be separate from making critical decisions (different layer for security reasons and since it won't be used as frequently as the local [offline] system).

2- Communication channel :

A- A shared file, but it's a bad idea since I don't want the application to check if the file contents changed (command received) or not from time to time (excessive operations).

B- A an inter-process-communication through a port (socket communication) seems the best solution but I don't know how that would turn in terms of operation cost and communication errors.

OS used : Linux Raspbian

EDIT:

I'm sure ZMQ+Apache is good enough for this task, but how is it in comparison to WebServices (like SOAP) ? Would WebServices be a better solution in terms of standard implementation and security ?

All related suggestions are welcomed, TQ

CME64
  • 1,673
  • 13
  • 24

1 Answers1

4

ZeroMQ is great for internal communications, or any other similar communication solutions.

For specifically your case, I can see that ZeroMQ would be a best fit.
Reasons:

  • You offline server have to be agnostic to web solution.
  • Communication can be reliable and bi-directional, possibly another patterns like (pub>sub, req<>res, etc).
  • Restarting any of sides would not require to restart the sockets (connection) on other side, as messages are queued.
  • Possibility to scale not just on same hardware, but as well to local area network or even through internet.
  • Big community of support. It might look a bit hard to get into, but in reality it is dead simple, just go to examples and once concept understood - it is very easy and neat to work with.
  • ZeroMQ has lots drivers for most popular languages, that includes Java and Node.js.

Considerations:

  • You need to think over packets and data will be sent. So some popular data protocols like XML or JSON is good way of thinking.
  • Responsibilities over different services - make sure they are not dependant on each other too much. Or if main offline server - is a core of system, make sure it does not depend on web facing service, so that web face can be removed/replaced/improved etc.

Few more points to think about:
Why Java, and what about modular approach? For example if you want to expand and scale - add more sensors into smart home solutions, then having one giant application would require to change it, it is harder to maintain as well as maintain different clients with own needs. Think modular way - some core functionality for offline stuff, but many aggregator processes that would talk to different sensors. This makes easier to support different setups and environments, as well maintain the system as a whole by improving independent components.

moka
  • 22,846
  • 4
  • 51
  • 67
  • A fascinating answer! I just don't know ZeroMQ so I have to test it first to know if it is the solution and it sounds really good according to your description. About having more sensors, actually the system in the illustration is simplified to be more focused on the main point. It is more like a wireless transmitter connected to that USB port and is the port of comm. between all the MCUs around the house using IDs, so multiple sensors will work too. Why java, is because I used it once to communicate with the MCU through a wireless transmitter over the USB and worked successfully + threading. – CME64 Sep 13 '13 at 21:14
  • Hi, I'm back. After a lot of reading and trials, ZeroMQ is just annoying and frustrating to work with in java. I managed to compile it for windows successfully and wasted a lot of time on that, but in the end it didn't work. Also another thing got me thinking about finding another way, is that it uses dlls and windows based files in order to run on windows. I'm developing on windows but I'll run it on a Linux based system.. Apache+PHP and java are cross-platform but this ZMQ does sound like it's going to give me trouble when I deploy it on Linux afterwards. Just feels right to keep you posted. – CME64 Dec 04 '13 at 13:55
  • Hi! Thanks for posting. I use ZeroMQ on windows and linux (ubuntu, centos) and on Mac OS X, and had no troubles compiling on any of those systems. You probably want to follow official documentation for compiling and installing - and it should be just fine. Linux compiling was even easier (but both went just straight forward using official documentation). You've said: "but in the end it didn't work" you mean - you couldn't install it and make it work, or actual ZeroMQ did not match your needs? You probably want to read their introduction guide to be familiar with concepts before hacking.. – moka Dec 13 '13 at 11:52
  • I Actually managed to compile it successfully on windows, but it didn't work (in the application) when I imported the library because I had ZMQ x64 installed and the compiled result was only for x32. I assumed that even if i fixed this problem I still won't be able to see the light in this tunnel. I'll try again and install ZMQ 32 and go beyond the last error and see what happens. from what you wrote, did you mean the libraries that you compiled worked on all OSs or you had to recompile it for each? and did you use it with JAVA or other applications of IPC? .. thank you! – CME64 Dec 17 '13 at 05:58
  • 1
    Compiling libraries like ZMQ is very common need in daily developers life, especially for back-end developers. I've recompiled it once for each platform, and it was straight forward process. I am using ZMQ with: .Net, node.js, C++. – moka Dec 26 '13 at 01:01
  • I never said ZMQ is not easy to build ,,, my trouble is specific to JZMQ and look up the number of ppl over the internet having trouble with it. just to mention, on linux it took me less than 10 mins to compile JZMQ and it works like a charm but on windows .. it's stupid you even have to alter some codes, place some lib files in MS-VS and look up each problem that appears in a long series in order to just compile .. specifically for x64 bit .. never mind that is not important right now, I wanted it on linux anyways – CME64 Jan 31 '14 at 02:46
  • 1
    There was recently forked repo from zmq, which were ok to be compiled on windows, but now looks like it is gone. And officially they do not support windows, there are workarounds - but yes, it is hell now. Same story with npm module for zmq. So probably use linux :) – moka Feb 02 '14 at 15:37