Remote control and monitoring system via sms and internet

However, this software not only be used to send/ receive data, but it is also

improved to process command and connect to the board. The synchronous speed is

115200 bps. In addition, we only setup this programon remote PC, then we can use

Yahoo Messenger program on some PC to connect to remote PC and send device

control command. To do that, we open a chat window from YM and send a message

which contains standard control commands (ex: D01: ON#, Reload#.) to Yahoo id

signed in to program put in remote PC.

pdf35 trang | Chia sẻ: lethao | Lượt xem: 2329 | Lượt tải: 1download
Bạn đang xem trước 20 trang tài liệu Remote control and monitoring system via sms and internet, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
1 HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY FACULTY OF ELECTICAL – ELECTRONICS ENGINEERING DEPARTMENT OF TELECOMMUNICATION PFIEV PROGRAM ---------------o0o--------------- GRADUATION THESIS REMOTE CONTROL AND MONITORING SYSTEM VIA SMS AND INTERNET Instructor: PhD. Hoang Dinh Chien Student: Le Phuc Hoang Student: Phan Tuan Duong HCM, July 2009 2 Abstract This thesis consists of five parts. In the first part, we present block diagram of control circuits and models connection to connect these circuits with computer at the processing center through infrastructure mobile network or internet network. Programming algorithms for the microcontrollers in these circuits will be presented in Part II. The most important part, communicating with the phone (PC vs. Phone, Microcontroller vs. Phone), to access reality through infrastructure telecommunications network is presented in part III. Part IV will present more details about connection in the system as in UART connection, RF connection, internet connection (using Yahoo server or TCP socket). Chapter five will present results and discussion. I .Circuit block and model connection 1.1 Main circuit block diagram [1]Microcontroller PIC16F877A [7] RS232 [2] LCD Display [8] Power [5] Relay block [3] Receive RF block [4]Sensors block (thermal, pH..) [6] Switch block [9] PC [10] Extension circuit Main circuit [11] Phone 3 - The most important block in this circuit is [1] Microcontroller PIC16F877A (PIC), coordinating activities of the remaining (control display ASCII characters on the LCD display [1], the control switch (relay) [5], control serial communication via RS232[7], process signals from the sensor block [4], and encode and decode for the RF link [3] This block is similarly to the block of the main circuit, but there is no switch block circuit. We can use this circuit independently with the main circuit, and the structure of the sensor block (*) may be changed to connect with different sensors 1.2 The most simple connection model Microcontroller PIC16F877 RS23 2 LCD display Power Relay block [3] Receive RF block PC/ Main circuit (*) Sensor block (thermal, pH…) Extension circuit Phone 4 Center PC connects with a cell phone (Home Mobile). Home Mobile will send message containing commands (SMS) to Remote Mobile. Remote Mobile is a cell phone connected with the board having sensors. This board collects parameters from sensor, then transfers to Remote Mobile and Remote Mobile sends SMS containing these parameters to Home Mobile. At home, Center PC reads SMS from Home Mobile and processes data. Center PC Home Mobile Remote Mobile Sensor Cell phone network 5 1.3 The model connection with extended circuit using transmitter and receiver RF modules or RS232 The blocks “Extended Remote Sensor1” and “Extended Remote Sensor2” are extended blocks to enlarge the system. The details of RF link and RS232 link (UART link) will be presented in Part IV. Data from sensors in the block [1], [2], [3] will be send to center by remote mobile. The SMS message received at Home Mobile will be processed by PC (storage and graph) Remote Center Sensor [1] Extended Remote Sensor1 [3] PC Remote mobile Home Mobile Extended Remote sensor2 [2] RF RS232 6 1.4 Model connection for collecting data from remote sensor using internet Target of this model: Saving cost for region which have internet 1.5 Replaced model for remote region while don’t have internet, but covered by mobile network Home PC Internet Remote PC Remote Center Sensor Extended Remote Sensor1 Extended Remote Sensor2 Mobile GPRS Home PC Internet Remote PC Remote Center Sensor Extended Remote Sensor1 Extended Remote Sensor2 RS232 RS232 RS232 7 This model using GPRS (2G) network for connection sensors from remote area to center II. Algorithms for programming microcontroller in the board (center board and extension board) 2.1 Center Board We use model connection in section 1.4 for programming microcontroller in center board (Because this is the most complicated model connection) Start Have RF signal? Save received characters to RF buffer Process UART buffer [a], and delete it RF frame is completed? -Process RF buffer[b] And delete it No No Yes Yes 8 Processing data in buffer RF (block [b]), buffer UART (block [a]).It means detach data bytes in them, and save to third Buffer. After that waiting for certain time, or trigger event caused by center (such as calling signal or arrival message signal from center), to transmit data in that buffer to center by SMS 2.2 Extended circuit for main circuit III. Protocols for connecting cell phone to PC or microcontroller We use two types of protocol in this thesis, AT command and FBUS protocol Collecting data from sensors and save to buffer Have trigger event? Send data in buffer to Board center (center circuit) Start Yes No 9 3.1 AT command 3.1.1 Some single AT commands used in communication with the cell phone at+cbc? Get information about the pin status, to know when to cover the pin at+gmm? Get information about your phone model, to select the appropriate AT command set at+cgmi? Get information about device‘s manufacturer at+csq? Get information about the strength interference at+cusd=1,"*101#" Get information about the amount in the account of SIM, for the should recharge the SIM at+csca? Retrieved number message center, used to sending message process at+cpbr=1,25 Used to read the telephone directory from 1 to position 25 3.1.2 The combination of AT commands - Combination of AT commands to read the last message in the device at+cpms=”me” After this command we know the number of messages (X) have in the phone at+cmgf=1 Specify the message read in text format ( at+cmgf=0, PDU format) at+cmgr=X After this command we have the last message in the device Sample at+cpms="me" +CPMS: 18,70,7,30,18,70 OK at+cmgf=1 OK at+cmgr=18 +CMGR: "REC READ","+84936975464","MrChick","09/05/01,10:13:13+28" Test doc noi dung tin nhan OK - Combination of commands to help read all messages at+cpms="me” show out memory to read data is the device memory (at+cpms="sm” show out memory to read data is the SIM memory) at+cmgf=1 Specify the message read in text format at+cmgl="all” Read all messages in the memory - Combination of command to help read the message received from device 10 at+cnmi=2,1,0,0,0 Setting up the report when the message send to device When a message come to device, the phone will output to COM port the following text string +CMTI: "ME",60 This string show that the message is saved in the position 60 in the phone (ME) Similarly, if messages stored in SIM in position 60, the string returns form +CMTI: "SM",60 Then we need to output the combination of the following to read the message in text format at+cpms=”me” at+cmgf=1 at+cmgr=60 - Combination of command to delete message in the phone Command delete messages in the position X in the device memory or SIM memory at+cpms=”me” (SIM memory: at+cpms=”sm”) at+cmgd=X 3.2 FBUS protocol 3.2.1 General about FBUS protocol The FBUS protocol is used in communication between phone and PC. We can also use FBUS for communication between phone and microcontroller. FBUS bases in packets for error control and management. FBUS parameters Speed: 115,200 bps Bits: 8 Parity: None Stop Bits: 1 3.2.2 General structure of a command in FBUS 1e: cable 11 S: source address D: destination address 00: pc/ microcontroller address 0c: phone address type: command type len: number of octet from len to sq body: content of command sq: sequence packet number 0? Padding, if len is odd, octet 00 is added to frame chk: checksum,, for checking error, 2 byte 3.2.3 Command from PC to phone, request send an SMS message to 3.2.4 Structure of ACK command from phone to PC Type: type command of command needed to ack IV. Details of the links in the system 4.1 UART connection Circuit of conversion voltage level for connecting PC & Microcontroller 12 Programming to establish communication between the controller and the computer is important. The purpose is to transmit and receive command strings from PC to microcontroller or from microcontroller to microcontroller We use the following diagram for establish protocol communication Detail of UART communication Text string is transmitted to ASCII characters. Start a chain of characters ‘#‘, and ended the series as characters ‘*’ To ease the process of communication between the computer-PIC, and PIC-PIC, we defined a set of commands PIC is always in the status of pending orders from the PC. When it receives the string text from PC, it will split the command based on the characters ' # 'and' * '. After separating out each command, PIC will in turn implement the commands #ping* Use ping to check connection between circuits PC CENTER TERMINAL1 TERMINAL2 UART UART UART 13 #1r1n* Use 1r1n to enable relay1 in TERMINAL1 #1r2n* Use 1r1n to enable relay2 in TERMINAL1 #1r1f* Use 1r1f to disable relay1 in TERMINAL1 #1r2f* Use 1r2f to disable relay2 in TERMINAL1 #1the* Request terminal1 send data about temperature to CENTER #1r1s* Request TERMINAL1 send status of relay1 to CENTER #1r2s* Request TERMINAL1 send status of relay2 to CENTER #2r1n* Use 2r1n to enable relay1 in TERMINAL2 #2r2n* Use 2r1n to enable relay2 in TERMINAL2 #2r1f* Use 2r1f to disable relay1 in TERMINAL2 #2r2f* Use 2r2f to disable relay2 in TERMINAL2 #2the* Request terminal1 send data about temperature to CENTER #2r1s* Request TERMINAL2 send status of relay1 to CENTER #2r2s* Request TERMINAL2 send status of relay2 to CENTER Algorithm for processing string in center board, and terminal board 14 Len: length of buffer Start=1: allowed to save characters to receive buffer Start=0: not allowed to save characters to receive buffer 4.2 RF connectton 4.2.1 Using transmitter and receiver RF module to make RF connection Receive character C C=’#’ Start=1 Len=0 C=’*’ Start=0 -Buffer[len]=C -Len=len+1 -Output to lcd display -Process command in buffer -Len=0 Yes No No Yes Have characters come to COM port? Yes No Start 15 Figure 2 Transmitter RF module Circuit for connecting to these modules Figure 3 Connect to receiver module Figure 1 Receiver RF module 16 Figure 4 Connect to transmitter module 4.2.2 Programming to communicate in RF link Two important parts in this session are: -Transmit one byte (8 bits) -Transmit many bytes (Frame) Structure of one byte Structure of one frame Synchroniz e string Start byte Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 Bit 8 Time Amplitude 17 Programming Transmitter - Transmit a byte void truyen1(unsigned int8 x) { int i=0; for(i=0;i<100;i++) { tx=0;delay_us(20); tx=1;delay_us(20); } //byte start tx=0;delay_ms(1); tx=0;delay_ms(1); tx=1;delay_ms(1); tx=1;delay_ms(1); tx=0;delay_ms(1); tx=0;delay_ms(1); tx=1;delay_ms(1); tx=1;delay_ms(1); //data 18 for(i=0;i>i;delay_ms(1);} } - Transmit a frame Sample: string need to be transmitted is “1r1n”, programming code is: Truyen1(‘#’); Truyen1(‘1’);Truyen1(‘r’); Truyen1(‘1’); Truyen1(‘n’); Truyen1(‘*’); - Decoding in Receiver To separate one byte data, circuit need to find the start byte. The following code for the start byte (0b11001100) of the circuit while(timnext0<8){ delay_us(150); //vong1 if((rxrf==0)&&(timnext0==0)) {timnext0++;} //vongtieptheo if((timnext0>0) &&(timnext0<2)) { delay_ms(1);if(rxrf==0) {timnext0++;} else {timnext0=0;}} if((timnext0>=2) &&(timnext0<4)){ delay_ms(1);if(rxrf==1) {timnext0++;} else {timnext0=0;}} if((timnext0>=4) &&(timnext0<6)){ delay_ms(1);if(rxrf==0) {timnext0++;} else {timnext0=0;}} if((timnext0>=6) &&(timnext0<8)){ delay_ms(1);if(rxrf==1) {timnext0++;} else {timnext0=0;}} } After finding the start byte , separating data byte is very easily tong=0 for (i=0;i<=7;i++){ delay_ms(1); if(rxrf==1) { if(i==0) tong=tong+1; if(i==1 )tong=tong+2; if(i==2 )tong=tong+4; if(i==3 )tong=tong+8; 19 if(i==4) tong=tong+16; if(i==5) tong=tong+32; if(i==6) tong=tong+64; if(i==7) tong=tong+128; } } The varible tong content data byte Algorithm helps decoding a frame (a frame consists of many of byte data) if(tong=='#') {luu_buffer=1;vi_tri_buffer=0;do_dai_buffer=0;} if(tong=='*') luu_buffer=0; if((luu_buffer==1) && (tong!='#')){ buffer_rf[vi_tri_buffer]=tong; vi_tri_buffer++; do_dai_buffer++; } else{ if(tong!='#'){ break; } } 4.3 Internet connection Socket  Introduction Socket interface is a programming application (API-Application Programming Interface). It introduced the first edition of UNIX - BSD 4.2. as the system function syntax language C (socket (), bind (), connect (), send (), receive (), read (), write (), close () ,..). Today, Socket supported in most operating systems such as MS Windows, Linux and used in many programming languages different as C, C + +, Java, Visual Basic, Visual C 20 Socket set allows the communication channel that two channels are marked by two ports (port). Through this process one can receive and send data to the other.  Port number To be able to make the communication, one process must declare number of socket you use. Each port can communicate at an address specified in the system. When the process is assigned a port number, it can receive data sent to this port from the other. Process the remaining is also required to create a socket. Besides the port number, the two sides must also communicate the IP address of each other. IP Address distinction between this computer with other computers on the network TCP / IP. In the port number used to distinguish the different processes on the same computer. 21  Realization We designed software to connect Center PC to Remote PC. This software is written from Visual Basic (VB) and used socket to build a client – server system. VB provide us a component, which has function as socket, is Winsock (mswinsck.ocx). After we have setup this program on 2 PC (1 center PC and 1 remote PC), we must put in program one port number (here is 1221) and IP for each PC. The program on center PC is designed to send control commands (messages) to remote PC after connecting successfully. The program on remote PC will receive commands and transfer it to COM port (RS232). The board connects to remote PC through COM port will receive and perform these commands. The data from sensor or device will be transmitted to the board, then is sent to remote PC. Remote PC continues to send this data to center PC processing. Yahoo Messenger  Introduction Yahoo Messenger (YM) is an application connection to exchange data between two PC through Internet. This is software widely used in Vietnam. Although not an open source software entirely but Yahoo Server allows you to connect directly with it to transmit information, the data to a YM any use Port 5050 and the Host Server (cs101.msg. yahoo.com, scs.msg.yahoo.com ,...) that always guarantee the stability, 22 Center PC Remote PC Board Yahoo Server security, and especially the speed of transfers is very high, almost real. So we can completely write an application based Yahoo Server to create a connection between PC and controls, control devices remotely. We use Yahoo server to connect Center PC to Remote PC. Center PC send commands to Remote PC via Yahoo Messenger. After receiving command of Center PC, Remote PC (has a program, written by VB, control and manage device directly) send those commands to board connected to PC and transfer data to Center PC. Protocol : 0-sckTCPProtocol Remote Host : scs.msg.yahoo.com Remote Port : 5050  Realization Yahoo Messenger (YM) provides open sources to connect with Yahoo Server like YSMG versions (8 to 16). When using this program, we can transmit data between 2 PC easily. We designed a software using open source of YM put in each PC (center PC and remote PC). This is important code used to connect Yahoo Server: Private Sub sckMain_Connect() Dim ByteArray1() As Byte Dim ByteArray2() As Byte Dim str As String 23 On Error GoTo ErrorRaised FunctionMadeError = "sckMain_Connect" SentPacket.Service(1) = 0 SentPacket.Service(2) = Asc("L") '=&H4C SentPacket.Status(1) = 0 SentPacket.Status(2) = 0 SentPacket.Status(3) = 0 SentPacket.Status(4) = 0 SentPacket.SessionID(1) = 0 SentPacket.SessionID(2) = 0 SentPacket.SessionID(3) = 0 SentPacket.SessionID(4) = 0 SentPacket.Data = "" ConvertYmsgType2ByteArray SentPacket, ByteArray1 sckMain.SendData ByteArray1 '----------------------Next--------------- DoEvents 'This line is realy important due to some mswinsock bug! SentPacket.Service(1) = 0 SentPacket.Service(2) = YAHOO_SERVICE_AUTH SentPacket.Status(1) = 0 SentPacket.Status(2) = 0 SentPacket.Status(3) = 0 SentPacket.Status(4) = YAHOO_STATUS_AVAILABLE SentPacket.SessionID(1) = 0 SentPacket.SessionID(2) = 0 SentPacket.SessionID(3) = 0 SentPacket.SessionID(4) = 0 SentPacket.Data = "1" + Separator + txtUser.Text + Separator ConvertYmsgType2ByteArray SentPacket, ByteArray2 sckMain.SendData ByteArray2 Exit Sub ErrorRaised: ErrorHandler End Sub 24 However, this software not only be used to send/ receive data, but it is also improved to process command and connect to the board. The synchronous speed is 115200 bps. In addition, we only setup this program on remote PC, then we can use Yahoo Messenger program on some PC to connect to remote PC and send device control command. To do that, we open a chat window from YM and send a message which contains standard control commands (ex: D01: ON#, Reload#...) to Yahoo id signed in to program put in remote PC. Website We can use website from some PC everywhere to control devices connected with remote fix PC. To realize this idea, we designed a website which is written by PHP language. In addition, PHP language provides us a function to connect PC to Board though RS232. So we can send control commands directly from website to board. This is important code to connect to board. <?php include "php_serial.class.php"; // Let's start the class $serial = new phpSerial; // First we must specify the device. This works on both linux and windows (if $serial->deviceSet("COM1"); // Then we need to open it $serial->deviceOpen(); // To write into //$serial->sendMessage("Hello Mr Chick!"); // Or to read from $read = $serial->readPort(); ?> All of PHP files is put on remote PC which is responsible as Server. Then we can use browser (ex: firebox, internet explorer,…) from some PC (as client) to use interface of website to control remote devices. So we can control and collect remote data easily and use this data every time, everywhere. 25 V. RESULT & DISCUSS 5.1 Some image of Data management and processing program Figure 5 Management software system 26 Figure 6 Management with Yahoo Figure 7 Data collection and control devices through the Yahoo 27 Figure 8 Management with SMS . Figure 9 Collect data by SMS 28 Figure 10 Some functions of the software Figure 11 Observed data as graphs 29 Figure 12 Installation parameters for software 5.2 Some image of website for Control and monitor devices Figure 13 Log in using the web interface 30 Figure 14 Control equipment Figure 15 Monitoring of environmental parameters 5.3 Some images of prototype board 31 Figure 16 The board connections and mobile devices Figure 17 Terminal Board 1 32 Figure 18 Terminal Board 2 Figure 19 Center Board 5.4 Some images of debugging software 33 Figure 20 Control interface FBUS connection Figure 21 Control interface COM connection 34 REFERENCE [1] RAHUL P. et al (2007). A Novel Approach to Remote Sensing and Control. The 6th WSEAS Int. Conf. on Electronics, Hardware and Optical communication, Corfu Island, Greece [2] Sony Ericsson. (2003). AT Commands Online Reference T68, T68i, T300, T310, T610, Z600, T230, T238, T226, T630 Website : 35 Table of content Abstract ............................................................................................................................... 2 I .Circuit block and model connection ................................................................................ 2 1.1 Main circuit block diagram........................................................................................ 2 1.2 The most simple connection model ........................................................................... 3 1.3 The model connection with extended circuit using transmitter and receiver RF modules or RS232...................................................................................................... 5 1.4 Model connection for collecting data from remote sensor using internet ................. 6 1.5 Replaced model for remote region while don’t have internet, but covered by mobile network ................................................................................................................ 6 II. Algorithms for programming microcontroller in the board (center board and extension board).................................................................................................................. 7 2.1 Center Board .............................................................................................................. 7 2.2 Extended circuit for main circuit ............................................................................... 8 III. Protocols for connecting cell phone to PC or microcontroller ..................................... 8 3.1 AT command ............................................................................................................. 9 3.2 FBUS protocol ......................................................................................................... 10 IV. Details of the links in the system................................................................................ 11 4.1 UART connection .................................................................................................... 11 4.2 RF connectton ......................................................................................................... 14 4.3 Internet connection................................................................................................... 19 V. RESULT & DISCUSS................................................................................................ 25 5.1 Some image of Data management and processing program.................................... 25 5.2 Some image of website for Control and monitor devices........................................ 29 5.3 Some images of prototype board ............................................................................. 30 5.4 Some images of debugging software ...................................................................... 32 REFERENCE.................................................................................................................... 34

Các file đính kèm theo tài liệu này:

  • pdfRemote control and monitoring system via sms and internet.pdf