lvtn [english]

Upload: dang-anh-tuan

Post on 08-Apr-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 LVTN [english]

    1/35

    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

  • 8/7/2019 LVTN [english]

    2/35

    2

    Abstract

    This thesis consists of five parts. In the first part, we present block diagram of controlcircuits 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]MicrocontrollerPIC16F877A

    [7]RS232

    [2] LCDDisplay

    [8] Power

    [5] Relay block

    [3] ReceiveRF block

    [4]Sensors block(thermal, pH..)

    [6] Switchblock

    [9] PC

    [10] Extension circuit

    Main circuit

    [11]Phone

  • 8/7/2019 LVTN [english]

    3/35

    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

    MicrocontrollerPIC16F877

    RS232

    LCD display

    Power

    Relay block

    [3] Receive RF block

    PC/Main

    circuit

    (*) Sensor block(thermal, pH)

    Extension

    circuit

    Phone

  • 8/7/2019 LVTN [english]

    4/35

    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 HomeMobile

    RemoteMobile

    Sensor

    Cell phone network

  • 8/7/2019 LVTN [english]

    5/35

    5

    1.3 The model connection with extended circuit using transmitter and receiver RFmodules 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 CenterSensor [1]

    Extended

    RemoteSensor1 [3]

    PC

    Remote mobile

    Home Mobile

    Extended Remotesensor2 [2]

    RF

    RS232

  • 8/7/2019 LVTN [english]

    6/35

    6

    1.4Model 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 dont have internet, but covered bymobile network

    HomePC

    Internet

    Remote PC

    RemoteCenterSensor

    ExtendedRemoteSensor1

    ExtendedRemoteSensor2

    Mobile

    GPRS

    HomePC

    Internet

    Remote PC RemoteCenterSensor

    ExtendedRemoteSensor1

    Extended

    RemoteSensor2

    RS232

    RS232

    RS232

  • 8/7/2019 LVTN [english]

    7/35

    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 RFsignal?

    Save receivedcharacters to

    RF buffer

    Process UARTbuffer [a], anddelete it

    RF frame is

    completed?

    -Process RFbuffer[b]And delete it

    No

    No

    Yes

    Yes

  • 8/7/2019 LVTN [english]

    8/35

    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 datafrom sensors andsave to buffer

    Havetrigger

    event?

    Send data in buffer toBoard center (center circuit)

    Start

    Yes

    No

  • 8/7/2019 LVTN [english]

    9/35

    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 devices 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 nhanOK

    - 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

  • 8/7/2019 LVTN [english]

    10/35

    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 bpsBits: 8

    Parity: None

    Stop Bits: 1

    3.2.2 General structure of a command in FBUS

    1e: cable

  • 8/7/2019 LVTN [english]

    11/35

    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, iflen 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

  • 8/7/2019 LVTN [english]

    12/35

    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

    UARTUART

    UART

  • 8/7/2019 LVTN [english]

    13/35

    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

  • 8/7/2019 LVTN [english]

    14/35

    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

    Receivecharacter C

    C=#

    Start=1Len=0

    C=*=

    -Buffer[len]=C-Len=len+1

    -Output to lcd display-Process command inbuffer-Len=0

    Yes No

    NoYes

    Have characterscome to COMport?

    Yes

    No

    Start

  • 8/7/2019 LVTN [english]

    15/35

    15

    Figure 2 Transmitter RF module

    Circuit for connecting to these modules

    Figure 3 Connect to receiver module

    Figure 1 Receiver RF module

  • 8/7/2019 LVTN [english]

    16/35

    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

    Synchronize string

    Start byte Bit1

    Bit2

    Bit3

    Bit4

    Bit5

    Bit6

    Bit7

    Bit8

    Time

    Amplitude

  • 8/7/2019 LVTN [english]

    17/35

    17

    ProgrammingTransmitter

    - Transmit a byte

    void truyen1(unsigned int8 x)

    {

    int i=0;

    for(i=0;i

  • 8/7/2019 LVTN [english]

    18/35

    18

    for(i=0;i

  • 8/7/2019 LVTN [english]

    19/35

    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

    SocketIntroduction

    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

  • 8/7/2019 LVTN [english]

    20/35

    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.

  • 8/7/2019 LVTN [english]

    21/35

    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,

  • 8/7/2019 LVTN [english]

    22/35

    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 Serverlike 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 ByteDim str As String

  • 8/7/2019 LVTN [english]

    23/35

    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

  • 8/7/2019 LVTN [english]

    24/35

    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 connectedwith 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.

  • 8/7/2019 LVTN [english]

    25/35

    25

    V. RESULT & DISCUSS

    5.1 Some image of Data management and processing program

    Figure 5 Management software system

  • 8/7/2019 LVTN [english]

    26/35

    26

    Figure 6 Management with Yahoo

    Figure 7 Data collection and control devices through the Yahoo

  • 8/7/2019 LVTN [english]

    27/35

    27

    Figure 8 Management with SMS

    .

    Figure 9 Collect data by SMS

  • 8/7/2019 LVTN [english]

    28/35

    28

    Figure 10 Some functions of the software

    Figure 11 Observed data as graphs

  • 8/7/2019 LVTN [english]

    29/35

    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

  • 8/7/2019 LVTN [english]

    30/35

    30

    Figure 14 Control equipment

    Figure 15 Monitoring of environmental parameters

    5.3 Some images of prototype board

  • 8/7/2019 LVTN [english]

    31/35

    31

    Figure 16 The board connections and mobile devices

    Figure 17 Terminal Board 1

  • 8/7/2019 LVTN [english]

    32/35

    32

    Figure 18 Terminal Board 2

    Figure 19 Center Board

    5.4 Some images of debugging software

  • 8/7/2019 LVTN [english]

    33/35

    33

    Figure 20 Control interface FBUS connection

    Figure 21 Control interface COM connection

  • 8/7/2019 LVTN [english]

    34/35

    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 :

    http://www.embedtronics.com/nokia/fbus.html

    http://www.edaboard.com/ftopic264676.html

    http://discussion.forum.nokia.com/forum/showthread.php?t=72056

    http://www.8051projects.net/microcontroller-tutorials/

    http://www.panuworld.net/nuukiaworld/hardware/cables/fbus.htm

    http://www.picvietnam.com/forum/showthread.php?t=2234

    http://www.serasidis.gr/circuits/smscontrol/smscontroller.htm

    http://www.developershome.com/sms/

    http://www.edaboard.com/ftopic70001.htmlhttp://www.activexperts.com/xmstoolkit/atcommands/dtmf/

    http://www.edaboard.com/topic293431.html

  • 8/7/2019 LVTN [english]

    35/35

    Table of content

    Abstract ............................................................................................................................... 2I .Circuit block and model connection................................................................................ 2

    1.1 Main circuit block diagram........................................................................................ 2

    1.2 The most simple connection model ........................................................................... 31.3 The model connection with extended circuit using transmitter and receiverRF modules or RS232...................................................................................................... 51.4 Model connection for collecting data from remote sensor using internet ................. 61.5 Replaced model for remote region while dont have internet, but covered by

    mobile network ................................................................................................................ 6II. Algorithms for programming microcontroller in the board (center board andextension board) .................................................................................................................. 7

    2.1 Center Board .............................................................................................................. 72.2 Extended circuit for main circuit ............................................................................... 8

    III. Protocols for connecting cell phone to PC or microcontroller ..................................... 8

    3.1 AT command ............................................................................................................. 93.2 FBUS protocol ......................................................................................................... 10

    IV. Details of the links in the system................................................................................ 114.1 UART connection .................................................................................................... 114.2 RF connectton ......................................................................................................... 144.3 Internet connection................................................................................................... 19

    V. RESULT & DISCUSS ................................................................................................ 255.1 Some image of Data management and processing program.................................... 255.2 Some image of website for Control and monitor devices........................................ 295.3 Some images of prototype board ............................................................................. 305.4 Some images of debugging software ...................................................................... 32

    REFERENCE.................................................................................................................... 34