Skip to main content

Weather Monitoring Station using Java Sockets and Java RMI


Introduction



This system is a weather monitoring system for mobile base-stations around the country. It uses sensors that can measure temperature, air pressure, humidity and rainfall. Sensors are placed in different locations.


It consists of 3 main components namely, the sensors, a remote server and the monitors. The sensors send updates of the weather readings to the server every 5 mins. The server will store these values and update the monitors periodically every 1 hour with the latest readings at each station.


Monitors will show all the latest weather readings at all locations. Additionally, to receiving periodic updates, monitors are able to query for the latest readings of all the stations or of one location at any time if required. Monitors can view the number of sensors and monitors connected to the server at any given time.


The server will alert the monitors if the weather at any location reaches the critical values specified below.


Temperature - If exceeds 350 C or is below 200 C
Rainfall - If exceeds 20mm


Server will also alert the monitors if any sensor stops responding.

Overview of the implementation



The system is implemented in Java, using Java RMI and Sockets.


The sensors establishes a socket connection with the remote server via TCP/IP ports in order to send updates to the remote server. Socket connections are ideal to establish communication between two processes specially in this scenario where sensor and server may run at two different machines. Readings are serialized and encoded using Base64 and passed through socket communication to the server where they are deserialized and decoded.


The monitors use Java RMI connections to communicate with the remote server. This enables the monitors to invoke methods in the server remotely. The server and monitors will need to perform complex operations and this can be difficult through a socket connection. Java RMI is highly optimized and serves this purpose well.


All the readings received by the server from the sensors are written to a text file.


Running the program


1) Running the server

2) Adding sensors


3) Running the monitor

High level Diagram

DS-HLD.png

Sequence Diagrams



Diagram 1 : Addition of a weather sensor and sending periodic updates to the monitor


Assumption : Assumes a monitor is already connected to the system.


Diagram 2 : Add or remove monitors


Diagram 3 : Query readings by the monitor

Diagram 4 : Alert monitors when the weather reaches critical levels or when a sensor is down




Assumptions



  • There is only one sensor at a particular location and all the readings such as temperature, rainfall, air pressure and humidity are measured by the same.
  • Only a person with admin rights (admin credentials can put up a server).
  • There can be only one instance of a particular sensor up and running. If one person is currently logged in to the sensor, another cannot run it since the username for sensor log in is the same unique name of the sensor.
  • Sensor and monitor are both authenticated by credentials in the text files and they should be configured in order to add new credentials.
  • IOT sensor behavior is simulated by simple Java programs.

Comments

Popular posts from this blog

Fixing 'java RMI - ConnectException: Operation timed out' in WSO2 Enterprise Integrator 6.4

If you ever come across the below exception when running WSO2 Enterprise Integrator 6.4, here is the fix. This error occurs when you have multiple IP addresses from different networks configured in your etc/hosts as below. 10.xxx.x.xxx localhost 192.xxx.x.xxx localhost So simply, removing the unnecessary one and leaving the one of the network that you are currently connected to should resolve this issue. 10.xxx.x.xxx localhost

SIMPLE BLACKJACK GAME IN JAVA (CONSOLE)

import java.util.Scanner; class BlackJack{     public static void main(String[] args)      {         int player_random1 = 100;         int player_random2 = 100;         while(player_random1 >= 12 || player_random2 >= 12  || player_random1 < 3 || player_random2 <3)         {             player_random1 = (int)(Math.random()*100);             player_random2 = (int)(Math.random()*100);         }                  int player_total = player_random1 + player_random2;                  System.out.println("You get a "+player_random1+" and a "+player_random2);         System.out.println("Your total is "+player_total); if(player_total==21)         {             System.out.println("Blackjack! Player Wins!");    return;         } System.out.println();                  int dealer_random1 = 100;         int dealer_random2 = 100;                  while(dealer_random1 >= 12 || deale

Calculator using PHP

This Calculator model will take inputs from the Number 1 and Number 2 fields and when the user clicks on the relevant operator the result will be displayed in the Results field. For log10(), to radian, to degree, sin, cos, tan operations only require one input. Hence, the user is instructed to input the values to the 1st field only. First, before proceeding with the calculation, we need to obtain the values from the text boxes. For that we should include all the form elements inside a form. The result is directed to the same page. Therefore we will use the form action as $_SERVER['PHP_SELF'] and the method as post. Next, we can obtain the values in the text boxes.       $_POST[' form_element_name '] will give you the value of the respective element. We can write the php code as follows (in the <head>) to obtain the value from Number 1 and Number 2 fields.       <?php              $num1=$_POST['num1']; //num1 is the name of th