Jingwei
Published © Apache-2.0

Sensors Management System

Sensors management, data collection, data analysis, privilege distribution.

IntermediateShowcase (no instructions)253
Sensors Management System

Things used in this project

Hardware components

Intel Edison
Intel Edison
×1
Temperature Sensor
Temperature Sensor
×1
air quality sensor
×1
moister sensor
×1
MQ5
×1

Software apps and online services

eclipse

Hand tools and fabrication machines

Eclipse
Java
Tomcat
javaEE
jsp html css jquery ajax
Mysql struts spring hibernate

Code

Get data from sensor

Java
This is a part of code that we can use to collect the data from our sensor to our computer
public int getDataFromSensor(int id) {
		int i = 0;
		System.out.println("This is UserDaoImpl!");
		try {
			int[] dateFormSensor = SocketUtils.getDateFormSensor();
			 i = dateFormSensor[id];
		} catch (Exception e) {
			e.printStackTrace();
		}
		return i;
		
	}

get data from database

Java
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
   static final String DB_URL = "jdbc:mysql://localhost/STUDENTS";

   //  Database credentials
   static final String USER = "username";
   static final String PASS = "password";
   
   public static void main(String[] args) {
   Connection conn = null;
   Statement stmt = null;
   try{
      //STEP 2: Register JDBC driver
      Class.forName("com.mysql.jdbc.Driver");

      //STEP 3: Open a connection
      System.out.println("Connecting to a selected database...");
      conn = DriverManager.getConnection(DB_URL, USER, PASS);
      System.out.println("Connected database successfully...");
      
      //STEP 4: Execute a query
      System.out.println("Creating statement...");
      stmt = conn.createStatement();

      String sql = "SELECT id, first, last, age FROM Registration";
      ResultSet rs = stmt.executeQuery(sql);
      //STEP 5: Extract data from result set
      while(rs.next()){
         //Retrieve by column name
         int id  = rs.getInt("id");
         int age = rs.getInt("age");
         String first = rs.getString("first");
         String last = rs.getString("last");

         //Display values
         System.out.print("ID: " + id);
         System.out.print(", Age: " + age);
         System.out.print(", First: " + first);
         System.out.println(", Last: " + last);
      }
      rs.close();
   }catch(SQLException se){
      //Handle errors for JDBC
      se.printStackTrace();
   }catch(Exception e){
      //Handle errors for Class.forName
      e.printStackTrace();
   }finally{
      //finally block used to close resources
      try{
         if(stmt!=null)
            conn.close();
      }catch(SQLException se){
      }// do nothing
      try{
         if(conn!=null)
            conn.close();
      }catch(SQLException se){
         se.printStackTrace();
      }//end finally try
   }//end try
   System.out.println("Goodbye!");
}//end main
}//end JDBCExample

socket

Java
  public static void main(String[] args) throws IOException {
        ServerSocket listener = new ServerSocket(9090);
        try {
            while (true) {
                Socket socket = listener.accept();
                try {
                    PrintWriter out =
                        new PrintWriter(socket.getOutputStream(), true);
                    out.println(new Date().toString());
                } finally {
                    socket.close();
                }
            }
        }
        finally {
            listener.close();
        }
    }
}

java mail

Java
String host="smtp.gmail.com";   
  final String user = jTextField1.getText();  
  final String password = new String(jPasswordField1.getPassword());
  


   if(!user.equals("") && !password.equals(""))
   {
     String SMTP_PORT = "465";
     String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";    
    
     String to=jTextField3.getText();
  
     //Get the session object  
     Properties props = new Properties();
     props.put("mail.smtp.starttls.enable", "true");
     props.put("mail.smtp.host",host);  
     props.put("mail.smtp.auth", "true");  
     props.put("mail.debug", "true");
     props.put("mail.smtp.port", SMTP_PORT);
     props.put("mail.smtp.socketFactory.port", SMTP_PORT);
     props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
     props.put("mail.smtp.socketFactory.fallback", "false");  
   
     Session session = Session.getDefaultInstance(props,  
     new javax.mail.Authenticator() {
        
       protected PasswordAuthentication getPasswordAuthentication() {  
       return new PasswordAuthentication(user,password);  
       }  
     });    
   
     //Compose the message  
     
     try 
     {  
        MimeMessage message = new MimeMessage(session);  
        
        // creates message part
        MimeBodyPart messageBodyPart = new MimeBodyPart();
        messageBodyPart.setContent(message, "text/html");     
     
        message.setFrom(new InternetAddress(user));  
        message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));        
        
        message.setSubject(jTextField5.getText());
        message.setText(jTextPane1.getText());  
        //send the message  
        Transport.send(message);    
     
        JOptionPane.showMessageDialog(null,"message sent successfully...");
        jLabel7.setVisible(false);
      } 
      catch (MessagingException e) {e.printStackTrace();}  
      }
  
   else 
   {
      JOptionPane.showMessageDialog(null,"Dear User! Please Enter Email or Password");

excel

Java
try
        {
            InputStream file = new File("howtodoinjava_demo.xlsx");
            XSSFSheet sheet = workbook.getSheetAt(0);
 
           
            while (rowIterator.hasNext()) 
            {
                Row row = rowIterator.next();
                //For each row, iterate through all the columns
                Iterator<Cell> cellIterator = row.cellIterator();
                 
                while (cellIterator.hasNext()) 
                {
                            System.out.print(cell.getNumericCellValue() + "t");
                            break;
                        case Cell.CELL_TYPE_STRING:
                            System.out.print(cell.getStringCellValue() + "t");
                            break;
                    }
                
                System.out.println("");
           
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }

xml

XML
<aop:config>
   <aop:aspect id="myAspect" ref="aBean">
      <aop:pointcut id="businessService"
         expression="execution(* com.xyz.myapp.service.*.*(..))"/>

      <!-- a before advice definition -->
      <aop:before pointcut-ref="businessService" 
         method="doRequiredTask"/>

      <!-- an after advice definition -->
      <aop:after pointcut-ref="businessService" 
         method="doRequiredTask"/>

      <!-- an after-returning advice definition -->
      <!--The doRequiredTask method must have parameter named retVal -->
      <aop:after-returning pointcut-ref="businessService"
         returning="retVal"
         method="doRequiredTask"/>

      <!-- an after-throwing advice definition -->
      <!--The doRequiredTask method must have parameter named ex -->
      <aop:after-throwing pointcut-ref="businessService"
         throwing="ex"
         method="doRequiredTask"/>

      <!-- an around advice definition -->
      <aop:around pointcut-ref="businessService" 
         method="doRequiredTask"/>
   ...
   </aop:aspect>
</aop:config>

jquery

JavaScript
$("table").delegate("td", "hover", function(){
	$(this).toggleClass("hover");
});
This is equivalent to the following code written using .live():

$("table").each(function(){
	$("td", this).live("hover", function(){
		$(this).toggleClass("hover");
	});
});
Additionally, .live() is roughly equivalent to the following .delegate() code.

$(document).delegate("td", "hover", function(){
	$(this).toggleClass("hover");
});

Person javabean

Java
public class Person{
  
  private String name;
  private String gender;
  private String email;
  private String privilege;
  
  
}

Credits

Jingwei

Jingwei

1 project • 1 follower
Master Student in Computer Science
Contact

Comments