eHouse Smart Home – Android Programming

eHouse 4 Android – Sending events and commands to eHouse system by SMS , eMail , WiFi , Internet

eHouse Smart Home communication with Android.
To send one or several events eHouse system was created class ehousecommunication with one command ( one line of source code)
All functions of this class are static ( without creating an instance of the class ) .

class ehousecommunication contains and will be extended by all the methods of sending control commands to the eHouse building automation of devices working on Android .

Currently , these are:

  • SMS
  • eMail
  • TCP/IP ( WiFi , Ethernet , Internet , Intranet , LAN , WAN)

Functions available in the class “ehousecommunication”


public static int AddAsciiEvent(String event)

Adding an event (eHouse command) for drivers in the event queue to send any transmission method
parameter event: the event code ( DirectEvent written in hex code ) according to eHouse standard:
example : ehousecommunication.AddAsciiEvent(“37010101020000000000”); event – toggle ( change ) output 1 for RM 1 (address 55,1 )

ehousecommunication.AddAsciiEvent ( “37010101020000000000” ); // Toggle output 1 of RM1 – hex address ( 37h , 1 )
addrh – 55 ( 37h) ( controller address High)
addrl – 1 ( controller address Low )
command – command = eg. set output
arg 1 – No output (1) – 1 parameter for the command (no output )
arg 2 – set value (2) – Parameter 2 for the command ( switch – change state)
arg 3 – parameter 3 for the command
arg 4 – Parameter 4 for the command
arg 5 – parameter 5 for the command
arg 6 – parameter 6 for the command
arg 7 – parameter 7 for the command

returns the number of bytes in the queue binary – 10 bytes for each added event.

Events are also added to the binary queue : EventToRunByte 10B each event
and the text : EventToRun 20 characters each event ( encoded in the ascii hex – as a function parameter )

If you are sending events via TCP/IP , you can send a maximum of 20 events ( 200B ) ( sent to binary queue ) .
In the case of events sent by SMS , you can send a maximum of seven events ( sent to a queue of text ) .
In the case of events sent by eMail You can send a maximum of seven events ( sent to a queue of text ) .

For compatibility is best to accept the lowest value for all methods (7) to be able to choose any form of transmission events from the queue to drivers


public static void ClearEventQueue()

Clears the contents of both events queues (binary and text) and the length of the queue
Example of use: ehousecommunication.ClearEventQueue() ;


public static void init()

Initializes the communication settings for all modes – reads the configuration files of the application exported with “eHouse.exe /mobile”.
This function must be activated first ( before starting the transmission attempts, data synchronization , etc. )

Current configuration files must be uploaded to the SD card directory ” /ehouse/ ” .
These files should be exported from eHouse application and update if :

  • changes hash – encryption code
  • change the transmission settings for any media
  • change passwords
  • adding / removing devices
  • rename drivers , output , input
  • change image for graphic visualization

Example of use: ehousecommunication.init();


static public String GetLog()

returns the contents of the log
Example of use: String Log = ehousecommunication.GetLog();


public static void ClearLog()

Cleans automatic system log contains important information about the transmission,
Example of use: ehousecommunication.ClearLog();


static public String GetSmtpLog()

returns the contents of the sending emails log through an SMTP server
Example of use: String Log = ehousecommunication.GetSmtpLog();


public static void ClearSmtpLog()

Clears the log automatically sending emails through an SMTP server
Example of use: ehousecommunication.ClearSmtpLog();


public static boolean SendEmail()

Sends an event queue by eMail

returns “true” how about

clears the event queue if transfer was ok
writes the results to a log SMTP

Example of use: ehousecommunication.SendEmail();


public static boolean SendSMS()

Sends an event queue by SMS

returns “true”

clears the event queue if transfer was ok

Example of use: ehousecommunication.SendSMS();


public static boolean SendWiFi( String host , int port )

Sends an event queue via TCP/IP ( WiFi , Ethernet , Internet , LAN , WAN)

host – IP address of the server that receives a local or global events or services or similar ddns
port – No server port receiving data

returns “true”

clears the event queue if transfer was ok

Example of use: locally for CommManager ehousecommunication.SendWiFi ( “192.168.0.254”, 9876 ) ;



The complete code example

/ * EHouse For ANDROID panels , tablets , PDAs , Smartphones template API for communication to the eHouse system
* ONLY FOR REGISTERED USERS , VENDORS , COOPERATIVES Copyright iSys . En All Rights Reserved
*
* Requires classes :
* ehousecommunication . class :
* Sending Events is eHouse system via:
* SMS , eMail , WIFI , INTERNET , ETHERNET , TCPIP

* Application Template Steering (API ) for ANDROID platform to communicate with the system eHouse and Visualization System Status
* ONLY for registered users of the system eHouse , Cooperating Firm All Rights Reserved
*
* Requires class :
*
* ehousecommunication . class :
* Sends system events (commands ) to the system drivers eHouse by :
* SMS , eMail , WIFI , INTERNET , ETHERNET , TCPIP
*
*
* /
package ehouse.android ;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class extends Activity ehouseandroid
{
Override
public void onCreate ( Bundle savedInstanceState )
{ TextView tv = new TextView (this) ;
super.onCreate ( savedInstanceState ) ;
ehousecommunication.init();

/*
* Adding eHouse event to queue
* Adding event ehouse system in the event queue
*
*/
ehousecommunication.AddAsciiEvent( “37010101020000000000” ) ; // Toggle output 1 of RM1 – hex address ( 37h , 1 )
// addrh 55 ( 37h )
// addrl 1
// command 1 – set output
// arg 1 – No output (1 )
// arg 2 – set value ( 2 ) toggle
// Arg 3 . . not used

/* Sending eHouse events from the queue via WiFi , Ethernet or the Internet (TCP/IP ) via PC server or CommManager
*
* Send events from the event queue (TCP / IP) over WiFi , Ethernet or Internet
*/

ehousecommunication.SendWiFi ( “192.168.0.254” ,9876 ) ; // Sending a CommManager via WiFi , Ethernet – local

/* Send Contents of EventQueue via eMail for reception by emailgate.exe
* Sends an event from the event queue by eMail to receive the software emailgate.exe
*/

// ehousecommunication.SendEmail() ;

/*
* Send Contents of EventQueue via SMS for reception by CommManager or SMS – Gate connected to PC
* Sends the contents of the Event queue by SMS for CommManager
* Or Goals SMS / GSM phone connected to the PC received by the application SMSGate.exe
*
*
*/
// SendSMS() ;

/*
* Clear Event Queue to send ( after successful transmission via any method ) performed automatically box
*
* Clears the event queue to be sent ( automatically removes events after sending any method )
*
*/

// ehousecommunication.ClearEventQueue();

/*
* Get recent transmission Log
* Returns the log of the last transmission
*/

tv.setText(ehousecommunication.GetLog());
setContentView(tv);

/*
*
* Clear Log
*
* Clear Log
*
*/
// ClearLog();

}
}