Home

Tx - Faculty Home - Universiti Teknologi Malaysia

image

Contents

1. A Porret T Melly C C Enz E A Vittoz A low power low voltage transceiver architecture suitable for wireless distributed sensors network IEEE International Symposium on Circuits and Systems 00 Geneva Vol 1 2000 pp 56 59 GJ Pottie W J Kaiser Wireless integrated network sensors Communications of the ACM 43 5 2000 551 558 A Perrig R Szewczyk V Wen D Culler J D Tygar SPINS security protocols for sensor networks Proceedings of ACM MobiCom 01 Rome Italy 2001 pp 189 199 S Hollar 2000 COTS Dust Master Thesis University of California Berkeley 64 8 Jones M Tim 2002 TCP IP Application Layer Protocols for Embedded Systems Charles River Media Inc 9 A Dunkels The Contiki Operating System Web page URL http www sics se adam contiki 10 ATMEL corporation Website URL http www Atmel com 11 GNU groups AVR GCC mailing list URL http www avrtreaks com 12 Jin Wook Lee September 2002 Sensor Network and Technologies APPENDIX A TRANSMITTER AND RECEIVER NODE SOURCE CODES 66 TE EE EE E ERE EE E HERE EE E HERE EE E HERE EE E EE EE EE EE EE EE EE E EE EE EE EE EE EE EE EE EE EE E REESE EE EE E E Ht tH HH HH HE HH HEF EE E EE EE EE EE HHH HH HH HF HH HH HF HH HH FE HF HF TRANSMITTER NODE Ht tH HH HEH HH HH HF HH HF HF tH FH HHH HH HH HF HH HH HF HHT HH FH HE HH E TE EE EE tH HF HH HH FEE HH FE HF HH FEF HH FH HF HH HEF HH FE HF E EE EE tH EHF tH EH
2. 1 lt lt URSEL 1l lt lt UCSZ1 l lt lt UCSA0 z to transmit 10 bits void USART Transmit unsigned int x Wait for empty transmit buffer 67 while UCSRA amp 1 lt lt UDRE Start transmission UDR x send significant byte unsigned char USART RX void Wait for data to be received while UCSRA amp 1 lt lt RXC Get and return received data from buffer return UDR int adc USART Init baudrate DDRA 0x00 set PORTA as input PORTA 0X00 Activate ADC with Prescaler 2 ADCSRA 0510000000 ADMUX 0500100100 ADCSRA 0B01000000 while ADCSRA amp _BV ADSC x ADCH return x Ht Ht HHT HE HE HE HE HE HE HE FE EE EE FE EE FE EE EE EE EE OE EE EE EE EE EE EE EE EE EE EE FE FE FE SF EE HF A Very Simple Application from the uIP 0 6 documentation Ht Ht HH HH HE EE HE HE FE FE EE EE FE FE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE FE FE FE FE EE include app nh void examplel init void uip listen 4500 void examplel_app void if uip newdata uip_rexmit uip send okqqqqqaaqqaaqaaaqaaaqgqaNn 24 Ht Ht HE HE HE HE HE HE HE HE EE EE EE EE EE EE EE FE EE EE EE EE EE EE EE EE EE EE EE EE FE FE EE FE SE HF RS232 DEV Ht Ht Ht HE HE HE HE EE HE HE EE EE EE EE EE EE EE EE OE EE EE EE EE EE EE EE EE EE FE EE EE EE FE FE EE EE EHF include lt avr io h gt include lt string h gt tinclude lt stdio h gt include
3. if uip flags amp UIP CLOSE uip add ack nxt 1 uip conn tcpstateflags FIN WAIT 1 UIP OUTSTANDING ip oconn snrtx 0 DUPF rlags TCP FIN TCP_ ACK goto tcp send nodata If uip len 0 the application has data to be sent in which case we set the UIP OUTSTANDING flag in the connection Structure But we cannot send data if the application already has outstanding data if uip len gt 0 amp amp uip conn tcpstateflags amp UIP OUTSTANDING ulp_conn gt tcpstateflags UIP OUTSTANDING ip oconn nrtx 0 uip add ack nxt uip len else uip len 0 j apprexmit If the application has data to be sent or if the incoming packet had new data in it we must send out a packet if uip len gt 0 uip flags amp UIP NEWDATA Add the length of the IP and TCP headers uip len uip len 40 We always set the ACK flag in response packets BUF gt flags TCP_ACK Send the packet goto tcp send noopts jj goto drop case LAST ACK We can close this connection if the peer has acknowledged our FIN This is indicated by the UIP_ACKDATA flag if uip flags UIP ACKDATA 1 ulp_conn gt tcpstateflags CLOSED break case FIN WAIT 1 The application has closed the connection but the remote host 81 hasn t closed its end yet Thus we do nothing but wait for a FIN from the other side if uip len gt O0 uip add rcv nxt uip l
4. endif UIP_BUFSIZE gt 255 Tdulpugds BUP i1Dzxdr0 ipid gt gt BUF 1p5rd l ipid amp Oxfr Calculate IP and TCP checksums BUF ipchksum 0 BUF gt ipchksum uip ipchksum BUF gt tcpchksum 0 BUF gt tcpchksum ulp_tcpchksum UIP STAT TTUID Stat tcop sentb send UIP STAT T TU1D StaLtpssent The data that should be sent is not present in the uip buf and the length of the data is in the variable uip len It is not our responsibility to do the actual sending of the data however That is taken care of by the wrapper code and only if uip len gt 0 return drop uip len 0 return itt HHH HH HH ERE HERE HH HE EO EH EH EEE EO EEE ee EEO EE EEE EEE OE EE j DIPOPT H 7 itt HHH HH HH HE HE EH HEH HE EH EH GE ERR EE EEE EE EEE EO EE EE EE EEE OE EEE Copyright c 2001 Adam Dunkels This file is part of the uIP TCP IP stack Slas nrbpOpLt h v 1 5 2002 01 15 21 12 41 adam Exp S id i ifndef UIPOPT H define UIPOPT H This file is used for tweaking various configuration options for uIP You should make a copy of this file into one of your project s directories instead of editing this example uipopt h file that comes with the uIP distribution First two typedefs that may have to be tweaked for your particular compiler The uX t types are unsigned integer types where the X is the number of bits in the integer type Most compi
5. break else All other options have a length field so that we easily can skip past them GC uip bur 40 UIP LLH LEN 1 ulp_conn gt tcpstateflags ESTABLISHED ulp_conn gt rcv_nxt 0 BUF gt segno 0 ulp_conn gt rcv_nxt 1 BUF gt segno 1 urp conn rov nxclz BUF seqno 2 uip conn rcv nxt 3 BUF seqno 3 uip add rov nxt l uip flags UIP CONNECTED UIP NEWDATA uip len 0 ULP APPCATBELE 3 goto appsend SOLO drop endif UIP ACTIVE OPEN case ESTABLISHED if BUF gt flags amp TCP_FIN 1 uip add rcv nxt 1 uip len uip flags UIP CLOSE uip len 0 ULP APPCALL 3 u uip add ack nxt l uip_conn gt tcpstateflags LAST_ACK UIP OUTSTANDING ip conn nrtx 05 tcp send finack BUP rlags TCP FIN TCP_ACK 80 goto tcp send nodata If uip len 0 we have TCP data in the packet and we flag this by setting the UIP NEWDATA flag and update the sequence number we acknowledge If the application has stopped the dataflow using uip stop we must not accept any data packets from the remote host if uip len gt 0 amp amp uip conn tcpstateflags amp UIP STOPPED uip flags UIP NEWDATA uip add rcv nxt uip len if uip flags amp UIP NEWDATA UIP ACKDATA UIP APPCALLDL appsend if uip flags amp UIP_ABORT uip conn tcpstateflags CLOSED BUF rlags TCP_RST ICE ACK goto tcp send nodata
6. 4 1 4 2 4 3 4 4 4 5 PCB layout for ISP cable ISP cable RS232 DB9 pin out Pin out of MAX232 Schematic circuit for RS232 serial cable PCB layout for RS232 serial cable RS232 serial cable Steps in designing the code programming Flowchart for transmitter node process Flowchart for USART transmitter node process Flowchart for receiver node process Flowchart for USART receiver node process Embedded software development process Main source code for transmitter uIP Main source code for receiver uIP Programmer notepad in WinAVR New project window Visual basic design Menu bars and title bars Microsoft Comm Control 6 0 PonyProg2000 window Observed Data Transmission using USART without uIP wired Observed Data Transmission using USART with uIP wired before uIP process Observed Data Transmission using USART with uIP wired after uIP process Observed Data Transmission using USART with uIP wireless before uIP process Observed Data Transmission using USART with uIP wireless after uIP process 3 32 33 33 34 34 35 36 37 38 39 40 41 42 44 46 47 48 48 49 50 53 54 55 56 57 xli 4 6 4 7 4 8 Received Data Displayed at HyperTerminal USART with uIP wireless before uIP process Received Data Displayed at HyperTerminal USART with uIP wireless after uIP process Graphical User Interface 58 59 60 xiii ADC
7. btr UIP IPADDRO j if i 14 ptr UIP IPADDRI if i 15 otr UIP IPADDRZ if i 16 otr UIP IPADDRS if i 40 ptr u8_t ulp_appdata G DEP PORIC O CH CUCDLIETT SIO SEND c fe ra232d0ev inrti Initializes the RS232 device and sets the parameters of the device 69 void rs232dev init void indataptr indata void SIO_SEND unsigned char c USART Transmit c it tH Ht HHH HH HH HE HH HE HE EH EEE HO EE HO EH EEE EO EH EEE EOE EEE Et EEE EEO EEE HH p UIP STACK 7 itt HH HHH HH HH HEH HH EE HE EH EH EE HE eH EEE OE EH EE EE EE HOE EE EEE OE EE HH include lt avr io h gt include uip h include uipopt h include uip arch h Variable definitions Wo uip OUP LUIP BUFSIZE s The packet buffer that contains incoming packets volatile u8_t uip_appdata The uip_appdata pointer points to application data Tif UIP_BUFSIZE gt 255 volatile ul6_t uip len The uip_len is either 8 or 16 bits depending on the maximum packet size else volatile u8 t uip len tendif UIP_BUFSIZE gt 255 volatile u8_t uip_flags The uip flags variable is used for communication between the TCP IP stack and the application program struct uip conn uip conn uip_conn always points to the current connection BL PHOL ulp conn Tap conns ULE VONNS The uip conns array holds all TCP connections ulg t uxp lristenports UIP
8. lt UIP hISIENPORIS arc 4 uip listenports c 0 j fer ic 07 C UIP CONNSS c 1 uip conns c tcpstateflags CLOSED tif UIP ACTIVE OPEN lastport 1024 endif UIP ACTIVE OPEN tif UIP ACTIVE OPEN struct ulp conn uzp conneoct ulo t ripaddr ulo t rzport i struct ulp conn conn Find an unused local port again TdLcsrtpDOPrt if lastport gt 32000 i1 lastport 40960 Iot c 0r o lt UIP CONNSS c 4 if uip conns c tcpstateflags CLOSED amp amp uip connslc Lport lastport 70 71 goto again foric 0 c lt UIP CONNS Tc if uip conns c tcpstateflags CLOSED goto found unused for c 0r o DUIP CONNS tto 1 if uip conns c tcpstateflags TIME WAIT goto found unused return void 0 found unused conn amp uip conns c conn gt tcpstateflags SYN SENT UIP OUTSTANDING conn snd nxt 0 conn ack nxt 0 iss 0 conn snd nxt 1 conn ack nxt 1 iss 1 conn snd nxt 2 conn ack nxt 2 iss 2 conn snd nxt 3 conn ack nxt 3 xss 3 if conn gt ack_nxt 3 0 if conn gt ack_nxt 2 0 i1f conn gt ack_nxt 1 0 T4conu ack nxt 0 j conn nrtx 0 conn timer 1 Send the SYN next time around conn lport htons lastbDort conn rport htons rport conn cripaddar 0 rzpadadr 90 conn ripaddr l1 rzpaddadr l return conn endif UIP ACTIVE OPEN jc er ee eee ea
9. security monitoring or to minimize power consumption This project was developed because of the awareness to analyze sensor network system Limited size of memory in a small size microcontroller is said to be limited criteria to run TCP IP protocol into sensor nodes thus through this project we tried to embed uIP into AVR microcontroller uIP is a small TCP IP stack The data transmission was observed by using the RF transmitter and also direct wire interface at the physical layer 1 3 Objectives The objectives of this project are 1 To develop wireless sensor network that distribute transfer environmental data eg temperature using TCP IP protocol 2 To embed the uIP a TCP IP stacks protocol into sensor nodes 1 4 Project Scope The scopes of work for this project are to develop sensor node basic of the sensor network that able to do sensing processing and networking using Processor AVR microcontroller Sensor type Temperature sensor Communication link RF transmitter and receiver module Frequency involved 453 MHz TCP IP Protocol uIP stack The microcontroller was programmed using C C and then the source codes were compiled using GNU tools WinAVR AVR GCC The data collected by the analog temperature sensor was converted into digital representation A D Conversion The transmitter and receiver nodes PCB board were built with DXP 2004 software The AVRISP connector was built to program the INTEL hex code into t
10. the content Fi wipt Ut m seu Doe uar inthe memory ah aa E memory filled as s telekom lab Desktop tx uip UIPslip hex ith 008888 ce ASASAZAZA1ABA A 666626 RAZASARA AS f iiid ERAR EIE 3 Oabziz a a and eA ht Ut 858 8 8 AET 00007 0 monje m L 8 000080 1F 92 GF 92 OF B OF 92 11 24 8F 93 80 91 4C O38 0000980 SF SF 86 93 AC 63 8F 91 OF 96 OF BE OF 980 1F 96 NL X C d h b 0088808 a isoip i ojo D i 00090890 08 NND oae nas been 0000 8 EE 0000D 6 8 B NA downloaded into 0000 i JN i e ii SAN on Program succesful i 0000F 0 i AA Oe ee N Controller 000100 UMEN ii amp 8 HpIN N a ee pe e successfully 69120 On DP BA PI Beis BR Rees PonyProg2000 ATmega8535 Size 8704 Bytes CRC A384h Figure 3 35 PonyProg2000 window CHAPTER 4 RESULT The goal of this project is to distribute the basic of wireless sensor network that can measure the temperature in different parts of the office to help in controlling the air flow Finally this project was succeeding to transmit and receive data implementing TCP IP protocol In this section we will discuss the result from experiments in this project The results were measure with an oscilloscope and were displayed at hyper terminal and Visual Basic 6 0 GUI In view of the fact that it is data transmission between two sensor nodes frame formats
11. typedef unsigned int word 1msec UNIT delay function void delay_ms unsigned int i word j while i jJE11415 8Mhz Exteranl Crystal CKSEL3 0 1 1 1 1 while j j Ht H HH HHH HH HE HF E EE SF HH HF HH EH SF EE EH FHF tH FEF tH EF HH FEF HH HF tH aaa USART RX Ht H HH HHH HH HE HF HH HF HH HF HH E EE HF tH FF tH FF tH EF tH FEF tH HE SF tH EH SF HE EH SF HE tH FF include lt avr io h gt define FOSC 8000000 Clock Speed define BAUD 1200 define baudrate FOSC 16 BAUD 1 void USART_TX unsigned char x void USART_Init unsigned int UBRR unsigned char USART_RX void void hexASCII unsigned char cr unsigned int X y 1 C0r a datae void usart void USART Init baudrate void USART Init unsigned int UBRR Set baud rate UBRRH unsigned char UBRR gt gt 8 UBRRL unsigned char UBRR Enable receiver and transmitter UCSRB 1 lt lt RXEN 1 lt lt TXEN Set frame format 8data no parity 1 stop bit UCSRC 1 URSEL 1 lt lt UCSZ1 1 UCSZ0 void USART_TX unsigned char x 86 Wait for empty transmit buffer while UCSRA amp 1 lt lt UDRE Start transmission UDR x send least significant byte unsigned char USART_RX void Wait for data to be received while UCSRA amp 1 lt lt RXC Get and return received data from buffer return UDR Ht Ht HHT HE HE HE HE
12. AM ARP AVR GCC AVR RISC DHCP DNS DTN EEPROM FTP GPRS HTTP ICMP ISP KB LWIP LSB MHz MSB OS PPP RAM X1V LIST OF ABBREVIATIONS Analog to Digital Conversion Amplitude Modulation Address Resolution Protocol AVR GNU Compiler Collection AVR Reduced Instruction Set Computer Dynamic Host Configuration Protocol Domain Name System Delay Tolerant Network Electrically Erasable Programmable Read Only Memory File Transfer Protocol Global Packet Radio Service HyperText Transfer Protoco Internet Control Message Protocol In Circuit Serial Programmable Kilo Byte Light Weight Internet Protocol Least Significant Bit Megahertz Most Significant Bit Operating System Point to Point Protocol Random Access Memory RF Rx SLIP SMTP SN SRAM TCP IP Tx UDP USART XV Radio Frequency Receiver Serial Line Interface Protocol Simple Mail Transport Protocol Sensor Network Static Random Access Memory Transmission Control Protocol Internet Protocol Transmitter User Datagram Protocol Universal Synchronous Asynchronous Receiver Transmitter XVI LIST OF APPENDICES APPENDIX A Transmitter And Receiver Node Source Codes 65 APPENDIX B Malefile Source Codes 88 APPENDIX C WinAVR Manual 94 CHAPTER 1 INTRODUCTION 1 1 Overview A communication between wireless sensor networks is an information gathering paradigm based on the collective effort of many small wireless sensor nodes The sensor n
13. Hone Format C Check Parity O ascii HEX O DEC Data bits Eight Dj Ur i Commands iwed Received data m zas iss doe Received Ox0E In h ex 5 of e Off Recereed OE i Em On Received x E after uip process Received Ox0E Received Ox0E At 27 celsius Received OKOE Received Ox0E Status Received Ox0E Send X Recewe CTS DSR Received x E Hecereed Ox0E e e e e Received x E Hecereed Ox0E Log Files y Received Ox0E Read from Hecereed Ox0E Received 0x0E Wnet l Wlisconmected fof COM Append to file Create file automatically Figure 4 6 Received Data Displayed at HyperTerminal USART with uIP wireless after uIP process 4 3 Result at Visual Basic 6 0 GUI The transmitter node gets data from environment and sends the frame after processing While at the receiver the received frame was processed to retrieve the data After that the extracted data was transmitted to the computer through the RS232 serial cable in order to display the temperature value at the computer So the Graphical User Interface GUI was developed for this purpose using Visual Basic 6 0 60 Figure 4 7 shows the GUI that developed to display the received temperature value The background wills change depends on the temperature value If the temperature is below than 30 C the background is green which is in normal condition When the temperature is in range 31 C to 40 C the backgr
14. I CFLAGS ALL_ASFLAGS mmcu MCU I x assembler with cpp ASFLAGS Default target all begin gccversion sizebefore TARGET elf TARGET hex TARGET eep S TARGET Iss TARGET sym sizeafter finished end Eye candy AVR Studio 3 x does not check make s exit code but relies on the following magic strings to be generated by the compile job begin echo echo MSG_BEGIN finished echo MSG_ERRORS_NONE end 91 02 echo 0MSG END echo Display size of file sizebefore if f S TARGET elf then echo echo MSG SIZE BEFORE ELFSIZE echo fi sizeafter if f TARGET elf then echo echo MSG_SIZE_ AFTER ELFSIZE echo fi Display compiler version information gccversion CC version Convert ELF to COFF for use in debugging simulating in AVR Studio or VMLAB COFFCONVERT OBJCOPY debugging change section address data 0x800000 V change section address bss 0x800000 change section address noinit 0x800000 V change section address eeprom 0x8 10000 coff TARGET elf echo echo MSG_COFF TARGET cof COFFCONVERT O coff avr lt TARGET cof extcoff TARGET elf echo echo MSG_EXTENDED_COFF TARGET cof COFFCONVERT O coff ext avr lt TARGET cof Program the device program TARGET hex TARGET eep A VRDUDE AVRDUDE_FLAGS AVRDUDE WRITE FLASH AVRDUDE_WRITE_EEPROM Create final output files he
15. capacitors for stability Voltage regulator is used to regulate the 9V input voltage to 5V as the microcontroller circuit is powered by 5V The circuit cannot directly powered by 5V without using the voltage regulator it 1s because the circuit will not stable The analog temperature sensor is connected to PORTA pin 5 and the transmitter module is attached to TXD pin at PORTD The program is uploaded into the microcontroller through these pins MISO MOSI SCK and RESET 22 TETTETETT YT F Figure 3 6 Transmitter Node Circuit Figure 3 7 shows the PCB layout for transmitter node Double layer PCB circuit was implemented for this node because of the complexity i 4 a FR pann 4 r8 a i 2 19 Figure 3 7 PCB Circuit Layout for Transmitter Node 26 Figure 3 8 shows the transmitter node that was built in this project This board attached by transmitter module to communicate with receiver 7 LL B E r LI D t t b B LL 4 V temperature sensor Figure 3 8 PCB Circuit for Transmitter Node 3 2 4 Receiver Node Figure 3 9 shows the circuit constructed for the receiver node that consists a microcontroller eight LEDs to show the output a voltage regulator and other passive equipment The basic equipments for this microcontroller are totally same to the transmitter The output LEDs are connected to PORTC The 220 Ohm resisters that connected series to the LEDs are used to reduce some vol
16. components of a sensor node Though the higher computational powers are being made available in smaller and smaller processors processing and memory units of sensor nodes are still scarce resources For instance the processing unit of a smart dust mote prototype is a 4 MHz Atmel AVR8535 micro controller with 8 KB instruction flash memory 512 bytes RAM and 512 bytes EEPROM 66 TinyOS operating system is used on this processor which has 3500 bytes OS code space and 4500 bytes available code space 2 3 5 Sensor network topology Sheer numbers of inaccessible and unattended sensor nodes which are prone to frequent failures make topology maintenance a challenging task Hundreds to several thousands of nodes are deployed throughout the sensor field They are deployed within tens of feet of each other The node densities may be as high as 20 nodes m Deploying high number of nodes densely requires careful handling of topology maintenance 10 2 3 6 Environment Sensor nodes are densely deployed either very close or directly inside the phenomenon to be observed Therefore they usually work unattended in remote geographic areas They may be working in busy intersections in the interior of a large machinery at the bottom of an ocean inside a twister on the surface of an ocean during a tornado in a biologically or chemically contaminated field in a battlefield beyond the enemy lines in a home or a large building in a large warehouse a
17. conn snd nxt uip add ack nxt 1 xcv nxt should be UIP RTO Us SYN RCVD 1 2 3 ip conni ov nxt lp conn rov nxt rp conn gt rcCv nxt cip add rov nxt l Parse the TCP MSS option 1f BUF tcpoffset amp Oxf0 gt 0x50 BUFE secdgno O np NN BUF gt seqno uip_conn gt ack_nxt uip conn ack nxt uip_conn gt ack_nxt uip conn ack nxt the seqno from the BUF seqno 3 2 BUF gt seqno 1 O if present t BUF 7sroripaddrlol BUF sSrcocipaddrlils UIP OUTSTANDING iss 0 iss iss iss 1 2 2 5 O 1 2 S su incoming packet 1 l7 uri TI lorie 0 c lt BUE 2LODOLISGOGt gt gt 4 5 lt lt Z2 7 1 opt uxp buf 40 DIP LLH LEN Gl if opt 0x00 j End of options J break else if opt 0x01 c 7 NOP option else if opt 0x02 amp amp ulp_buf 40 UIP_LLH_LEN c 1 0x04 An MSS option with the right option length tmpport uip buf 40 UIP LLH LEN c 2 lt lt 8 tip burl4Z0 UIP LLH LEN G 3 Urip conn mss tmpporuL gt UIP TCP MSS UIP TCP _MSS tmpport And we are done processing options break else All other options have a length field so that we easily cal Skip past them G uip buf 40 UIP LLH LEN c 1 Our response will be a SYNAC
18. executing in one clock cycle In this project the AVR ATmega8535 was used to take analog data from temperature sensor and convert them into digital representation The Universal Synchronous and Asynchronous serial Receiver and Transmitter USART is used in this project as it is a highly flexible serial communication device The data frame format that used is 1 start bit 8 data bits 1 stop bit The Transmitter consists of a single write buffer and a serial Shift Register The write buffer allows a continuous transfer of data without any delay between frames The Receiver is more complex than the Transmitter The Receiver consists a Shift Register and a two level receive buffer UDR 3 2 2 Analog Temperature sensor The LM35 is an integrated circuit sensor that can be used to measure temperature with an electrical output proportional to the temperature in C It has an output voltage that is proportional to the Celsius temperature The scale factor is 01V C The LM35 does not require any external calibration or trimming and maintains an accuracy of 0 4 C at room temperature and 0 8 C over a range of 0 C to 100 C Another important characteristic of the LM35DZ is that it draws only 60 micro amps from its supply and possesses a low self heating capability The sensor self heating causes less than 0 1 C temperature rise in still air The LM35 comes in many different packages including the following TO 92 plastic transis
19. goco drop 74 Check if the packet is destined for our IP address if BUF gt destipaddr 0 htons ul6 t UIP IPADDRO lt lt 8 UIP_IPADDR1 UIP STAT frp Stal ipsdrop UIP LOG ip packet not for us goto drop if BUF gt destipaddr 1 htons ul6_t UIP_IPADDR2 lt lt 8 UIP TPADDR3 4 UIP SIAT TTUID SLdL i1p QOTOD UIP_LOG ip packet not ror us goto drop if uip_ipchksum Oxffff Compute and check the IP header checksum UEP STAT Pru stdat ip drop UIP STAT TTUlDp SLaL lDp Ohkerr UIP LOG ip bad checksum qoro drop if BUF gt proto IP PROTO TCP Check for TCP packet If so jump to the tcp_input label goto tcp input if BUF gt proto IP PROTO ICMP We only allow ICMP packets from here ULE STAT ttuip BSLQaL i1DpsQFOD s UIP STAT tt U ulp Stat ip protoerr UIP LOG ip neither tcp nor icmp goto drop UIP STAT T T lp Stat ricomp recocv ICMP echo i e ping processing This is simple we only change the ICMP type from ECHO to ECHO REPLY and adjust the ICMP checksum before we return the packet if ICMPBUF gt type ICMP ECHO UIP_STAT uU1Lp Stat tcCmpywdrop UTE STAT uip_stat icmp typeerr UIP LOG icmp not icmp echo gore drop ICMPBUF type ICMEP ECHO REPLY af ICMPBUP gt icmpchksum gt htons O0xfrrr ICMP ECHO lt lt 8 1 LCMPBUF 1cmpohksum hrons ICMP ECHO l
20. hyper terminal a signal 1s sent down the line to the RIIN pin where the 12V signal coming from the computer is converted to a 0 5V signal coming out of RIOUT a signal that the ATMEL understands Figure 3 18 shows pin out of MA X232 C1 1 16 Voc Vs 2 151 GND c1 13 14 TTOUT C24 14 13 R1IN c2 15 12 R10UT Vs 6 11 T1IN T20UT ll 7 104 T2IN R2IN 8 9 R2OUT Figure 3 18 Pin out of MAX232 34 Figure 3 19 shows the schematic for the RS232 serial cable The components that needed to build the cable are MAX232 chip DB9 connector and four capacitors n o 8 00 2 ifto o o Figure 3 19 Schematic Circuit for RS232 serial Cable Figure 3 20 shows the PCB layout for the cable A single layer PCB circuit also used for this simple circuit C N tu m z3 p 8 RS232 interface using MAX232 Figure 3 20 PCB Layout for RS232 Serial Cable 35 Figure 3 21 shows the complete RS232 that used in this project Figure 3 21 RS232 Serial Cable 3 3 Software Development In this project the code programming was written in C language First we had to configure which registers will be used and setup specific pins for transmitting and receiving the data Then we drew the flowcharts for sensor nodes architecture as a guide to write the program code In this project the code of temperature sensing data transmit and receive and also the main loop in which we have to define
21. in a lowercase s will not be considered source files but generated files assembler output from the compiler and will be deleted upon make clean Even though the DOS Win filesystem matches both s and S the same it will preserve the spelling of the filenames and gcc itself does care about how the name is spelled on its command line ASRC List any extra directories to look for include files here ach directory must be seperated by a space EXTRAINCDIRS Optional compiler flags g generate debugging information for GDB or for COFF conversion O optimization level f tuning see gcc manual and avr libc documentation Wall warning level CE ck Gk Gk 90 Wa tell GCC to pass this to the assembler ahlms create assembler listing CFLAGS g O OPT funsigned char funsigned bitfields fpack struct fshort enums Wall Wstrict prototypes V Wa adhlns c lst patsubst I1 EXTRAINCDIRS Set a language standard compiler flag Unremark just one line below to set the language standard to use gnu99 C99 GNU extensions See GCC manual for more information CFLAGS std c89 CFLAGS std gnu89 CFLAGS std c99 CFLAGS std gnu99 Optional assembler flags Wa tell GCC to pass this to the assembler ahlms create listing gstabs have the assembler create line number information note that for use in COFF files
22. layer In the internet layer IP performs the basic task of getting packet of data from source to destination Transport layer This layer is used in exchanging data and ensures that data arrives in the correct destination In TCP IP protocol suite transport layer also determine which application any give data is intended for This layer is especially needed when the system is planned to be accessed through Internet or other external networks Application layer The application layer is the most common network aware programs interface use in order to communicate across a network with other programs Designing an application layer management protocol has several advantages Sensor networks have many different application areas and accessing them through networks such as Internet is aimed in some current projects 69 An application layer management protocol makes the hardware and software of the lower layers transparent to the sensor network management applications 15 2 5 TCP IP Stack Nowadays the TCP IP protocol suite has become a global standard for communication TCP IP is the underlying protocol used for web page transfers e mail transmissions file transfers and peer to peer networking over the Internet For embedded systems being able to run native TCP IP makes it possible to connect the system directly to an intranet or even the global Internet Embedded devices with full TCP IP support will be first class network citiz
23. locally carry out simple computations and transmit only the required and partially processed data Since large numbers of sensor nodes are densely deployed neighbor nodes may be very close to each other Furthermore the transmission power levels can be kept low which is highly desired in covert operations 2 2 Sensor Networks Applications Sensor networks may consist of many different types of sensors such as seismic low sampling rate magnetic thermal visual infrared acoustic and radar which are able to monitor a wide variety of ambient conditions that include the temperature humidity vehicular movement lightning condition pressure soil makeup noise levels the presence or absence of certain kinds of objects mechanical stress levels on attached objects and the current characteristics such as speed direction and size of an object Sensor nodes can be used for continuous sensing event detection event ID location sensing and local control of actuators The concept of micro sensing and wireless connection of these nodes promises many new application areas The applications were categorized into military environment health home and other commercial areas It is possible to expand this classification with more categories such as space exploration chemical processing and disaster relief 2 3 Factors Influencing Sensor Network Design L F Akyildiz 2001 had discussed that a sensor network design is influenced by man
24. lt stdlib h gt include lt ctype h gt include rs232dev h include uip h char indata char indataptr void delay l1ms unsigned int 1 anar j while i jJ 11415 4i Sing BExteranl Crystal CKSEL 0 1 1 1 1 while j u8 t getchar hextty findnext void Ug Cc char x while indataptr amp amp fisalnum int indataptr Indatepocerq Ts if r1indataptr i1 v indataptrt t else exit 0 if v gt O0 amp amp v lt 9 cae ye TOT 68 else G Toupper vy A 10 return c u8 t getchar_hextty void Uo ce c getchar_hextty_findnext c c lt lt 4 getchar hextty findnext return c define SIO RECV c c getchar_hextty Tdefine SIO POLL ce c getchar_hextty define MAX SIZE UIP BUFSIZE statio ust Slip Dur MAX SIZE s Tif MAX SIZE gt 255 Static ul6 t len tmplen else static us Lt len cumplen endif MAX SIZE gt 255 Ja rs232dev send Sends the packet in the uip buf and uip appdata buffers The first 40 bytes of the packet the IP and TCP headers are read from the uip buf buffer and the following bytes the application data are read from the uip appdata buffer X void rs232dev_send void Tif MAX SIZE gt 255 Ulo t 1j telse Uo 1 tendit MAX SIZE gt 255 7 Uc L tpr Uo T lt gt SIO SEND r STO SEND 2 3 por Turp Dur for i 0 1i lt 4l uip len i 4 if i 13
25. rcov nxt 0 1 BUF seqno uip conn snd nxt ip conn gt snd nxt l3 BUF gt seqno 82 BUF gt seqno 2 ucp conn snd nxtIlz ls BUF gt segno 3 uxp conn sndo nxt Ss BUF gt Sreport uripoconn lport BUF gt destport uip_conn gt rport i BYTE ORDER BIG ENDIAN BUF gt srcipaddr 0 1002 UIP_IPADDRO lt lt 8 UIP IPADDR1 BUF gt srcipaddr 1 0010 UIP_IPADDR2 lt lt 8 UIP IPADDR3 else BUF gt srcipaddr 0 UIP_IPADDR1 lt lt 8 UIP IPADDRO BUF sroipaddr 1 UIP IPADDR3 8 UIP IPADDR2 endif BYTE ORDER BIG ENDIAN BUF destipaddr 0 uip conn ripaddr 0 BUF destipaddr 1 uip conn ripaddr 1 if uip conn tcpstateflags amp UIP STOPPED If the connection has issued uip stop we advertise a zero window so that the remote host will stop sending data BUF wnd 0 BUF gt wnd 1 0 else fit ULE TCP MSS gt 255 BUF gt wnd 0 uip_conn gt mss gt gt 8 else BUF wnda O 0 andit UIP MSS BUF wnd 1 uip_conn gt mss amp Oxff tcp send noconn BUF gt vhl 0x45 BUF gt tos 0 BUF gt ipoffset 0 BUF gt ipoffset 1 0 BUF gt ttl UIP TIL BUF gt protCo IP _PROTO_TCP if UIP BUFSIZE gt 255 BUF len 0 uip len gt gt 8 BUF gt len 1 uip len amp Oxff else BUF gt len 0 0 BUF gt len 1 uip len
26. standards by the Internet Architecture Board IAB The protocol stack used by the sink and all sensor nodes is given in Fig 3 This protocol stack combines power and routing awareness integrates data with networking protocols communicates power efficiently through the wireless medium and promotes cooperative efforts of sensor nodes TCP IP has 5 layers Physical layer Network Access layer Internet layer Host to host layer known as transport layer and Application layer that shown in Figure 2 3 Each layer has its own function on transmitting data 13 TCP IP Layers TCP IP Protocol Suite Figure 2 2 TCP IP Protocol Suite Physical Layer It covers the physical interface between data transmission device and a transmission medium or network The internet protocol suite does not cover the physical layer of any network The physical layer 1s responsible for frequency selection carrier frequency generation signal detection modulation and data encryption Network Access layer Network access layer solved the problem of getting packet across a single network Examples of such protocol are X 25 and Arpanet s Host IMP Protocol The network access layer is responsible for the multiplexing of data streams data frame detection medium access and error control It ensures reliable point to point and point to multipoint connections in a communication network In this project the non standard format is used 14 Internet
27. which does all the work such as to add the TCP IP header and so on Whereas uip appdata acd is a pointer points to the application data when the application from ADC conversion is called If the application wishes to send data this is where the application should write it The rs232dev send are functions to sends the packet in the uip buf and uip appdata buffers The first 40 bytes of the packet the IP and TCP headers are read from the uip buf buffer and the following bytes the application data are read from the uip appdata buffer After sending one packet the delay 1ms 1000 was called to make delay one second before transmitting next frame Lastly is return 0 means the end of the program 44 3 3 3 1 2 Receiver Part Figure 3 29 shows the main source code for uIP stack for receiver node Hinclude lt avr io h gt Hinclude lt stdia h gt define TIMER PRESCALE 1024 define F CPU SOOO0000 i Co ot i AREA TATA AEA HS int main 1 LH d DDEC UZXFF PORTC UZ LD while lif C USART RAl processi i return Figure 3 29 The Main Source Code for uIP for Receiver This programming functions to control all of the receiving tasks In this part the programming code description in main c will be described As in the transmitter part int main void means the beginning of the program execution DDRC is a PORTC Data Direction Register DDRC OXFF means the PORTC Data Direction Register was set to
28. 3 Software Development 3 3 1 Transmitter Node 3 3 2 Receiver Node 3 3 3 uIP 3 3 4 Code Compiler WinAVR 3 3 5 Visual Basic 6 0 RESULT 4 1 Result from Oscilloscope 4 2 Results at Hyper Terminal 4 3 Results at Visual Basic 6 0 GUI CONCLUSION AND RECOMMENDATION 5 1 Discussion 5 2 Recommendation 15 15 18 19 21 27 24 26 28 30 32 35 36 39 4 45 47 52 58 59 61 62 Vill REFERENCES APPENDIX A APPENDIX B APPEBDIX C 63 65 88 94 1X LIST OF TABLES NO TITLE PAGE 2 1 Frequency bands available for ISM applications 11 NO 1 1 2al ZZ 2 9 2 4 3 3 2 3 3 3 4 3 5 3 6 3 3 8 3 9 3 10 3 11 3 12 3 13 3 14 LIST OF FIGURES TITLE Basic communication link of wireless sensor network The components of sensor nodes TCP IP protocol suite TCP IP input processing TCP IP output processing Methodologies diagram Sensor node proposed designed Pin out of ATmega8535 LM35 TO 202 package Common used circuit for LM35 DZ Transmitter node circuit PCB circuit layout for transmitter node PCB circuit for transmitter node Receiver node circuit PCB circuit layout for receiver node PCB circuit for receiver node Transmitter module Receiver module ISP cable circuit design PAGE 13 16 17 19 20 21 23 23 23 25 26 27 27 28 29 30 30 Xl 3 15 3 16 3 17 3 18 3 19 3 20 3 2 9 22 3 23 3 24 3 23 3 26 3 27 3 28 3 29 3 30 3 3 23 92 3 33 3 34 3 35
29. 47 4 wip conn Pur Ls 4 oe Wp COnn snrr x Ok so we need to retransmit We do this differently depending on which state we are in In ESTABLISHED we call upon the application so that it may prepare the data for the retransmit In SYN RCVD we resend the SYNACK that we sent earlier and in LAST ACK we have to retransmit our FINACK UIP STAT Prulp SLat tcocp rexmit Switch uip_conn gt tcpstateflags amp TS MASK case SYN_RCVD In the SYN RCVD state we should retransmit our SYNACK goto tcp_send_synack if UIP ACTIVE OPEN case SYN SENTI In the SYN SENT state we retransmit out SYN BUF gt f lags 0 goto tcp send syn endif UIP ACTIVE OPEN Case ESTABLISHED In the ESTABLISHED state we call upon the application to do the actual retransmit after which we jump into the code for sending out the packet the apprexmit label 7 uip len 0 xp flags UIP_REXMIT UIP_APPCALL goto apprexmit case FIN WAIT 1 case CLOSING case LAST ACK 73 In all these states we should retransmit a FINACK goto tcp send finack j j else if uip conn tcpstateflags amp TS MASK ESTABLISHED If there was no need for a retransmission we poll the application for new data uip len 0 uip flags UIP POLL UTIP APPCALL goto appsend l j SOLO drop This is where the input processing starts UIP STAT 7U2p_Stal ip recv Check validi
30. GET Ink REMOVE TARGET Iss REMOVE OBJ REMOVE LST REMOVE SRC c s REMOVE SRC c d Automatically generate C source code dependencies Code originally taken from the GNU make user manual and modified See README txt Credits Note that this will work with sh bash and sed that is shipped with WinAVR see the SHELL variable defined above This may not work with other shells or other seds d 96 c set e CC MM ALL_CFLAGS lt sed s 0 1 0 M d g gt s llrm f Remove the if you want to see the dependency files generated include SRC c d Listing of phony targets PHONY all begin finish end sizebefore sizeafter gccversion coff extcoff clean clean_list program 93 APPENDIX C WinAVR MANUAL 95 How to use WinAVR for the Microrobot AVR Products Rev 0 1 Contents What is WinAVR How to Install How to Use WinAVR How the Sample Source Code Works Useful Tips What is WinAVR WinAVR pronounced whenever is a suite of executable open source software development tools for the Atmel AVR series of RISC microprocessors hosted on the Windows platform It includes the GNU GCC compiler for C and C How to Install Go to http sourceforge net projects winavr and download the latest version of WinAVR Run the file you ve downloaded Warning There are many different versions of AVR GCC Installing more than one versi
31. HE EE FE EE EE EE EE EE EE EE EE EE EE EH EE EE EE EE EE FE FE EE EE FE FE EE SE EE HF PROCESS RX Ht Ht HE HH HE EE FE HE HE FE HE EE FE HE EE EE FE EE EE EE EE EE EE EE EE EE EE EE EE EE FE EE EE SF EE HF include lt avr io h gt finclude lt stdio h gt int xXxX a Cnt j YIP THIS FRAME NOT FOR US void drop Oi PORTC 0 XEF USART TX NO 5 f KK KK KK kk kc kk KKK main KK KK KK KKK ck ck ck kk kk kx void process unsigned char datal data2 c d e f g h 0 y 1 k unsigned char data 41 hdr 2 rz unsigned char ctr input ir c r 1 C USART_RX ioter rtor j 0 J lt 41 7 ip len i1 C USART RX read incoming data from usart buffer LL 2 S6 else if j 13 d c else if j 14 e c else if j 15 f c else if j 16 g c else if j 25 kc else if j 40 h 2c else c c if d 0x0A check ip address if e 0x02 if f 0X00 if g O0X0A if j 40 PORTC h y 2 h 10 9 USART TX y j else drop else drop else drop else drop else drop else drop 87 APPENDIX B MALEFILE SOURCE CODES 89 THHHHBHHHHHHHBHHHHHBHBHHHHHBHHHHHHBHHHHHHBHHHHHHBHHHHHHBHHHHHHHHHHHHHHHHHHHHHHHHHIE MAKEFILE THHHHBHHHHHHHBHHHHHHBHHHHHBHHHHHHBHHHHHHBHHHHHHBHHHHHHBHHHHHHHHHHHHHHHHHHHHHHHHHE WinAVR Sample makefile written by Eric B Weddington J rg Wunsch et al Released to the Public Domain Please r
32. If no acknowledgment is received within a specific time the data Is retransmitted Web server application Application arta Web server application Cutgorng ooo Web server application Mail sender application Data logger application Figure 2 4 TCP IP output processing Data arrives asynchronously from both the network and the application and the TCP IP stack maintains queues in which packets are kept waiting for service Because packets might be dropped or reordered by the network incoming packets may arrive out of order Such packets have to be queued by the TCP IP stack until a packet that fills the gap arrives Furthermore because TCP limits the rate at which data that can be transmitted over each TCP connection application data might not be immediately sent out onto the network CHAPTER 3 METHODOLOGIES 3 1 Introduction This chapter describes methodology of developing the sensor nodes and in this project it were divided into two sections hardware design and software development The discussion 1s started with hardware design and software development Figure 3 1 1s shown the diagram of the methodologies The sensor nodes were simply designed to able provide sensing and networking As was explained in previous chapter a sensor network normally consist a large number of sensors However for this project the sensor network development was carried out for only two nodes Thus the data transmission will be v
33. K if UIP ACTIVE OPEN tcp send synack 7 BUF gt flags TCP_ACK tcp send syn BUF gt flags TCP SYN else UIP ACTIVE OPEN tcp send synack BUP gt flags ICP SYN ICP ACK endif UIP ACTIVE OPEN We send out the TCP Maximum Segment Size option with our SYNACK BUF optdata 0 23 BUF gt optdata 1 4 BUF gt 0ptdatal2 UIP TCP MSs L xs BUF optdata 5 ULP TCP MSS amp 255 uip len 44 BUF gt tcpoffset goto tcp send This label will be jumped to if we found an active connection found uip flags 0 We do a very naive form of TCP reset processing we just accept any RST and kill our connection We should in fact check if the sequence number of this reset is wihtin our advertised window before we accept the reset if BUF gt flags amp TCP RST ulp_conn gt tcpstateflags UIP_LOG tcp got reset uip flags UIP_ABORT UIP_APPCALL goto drop All segments that are come thus far should have the ACK flag set a CLOSED aborting connection 78 otherwise we drop the packet if BUF gt flags amp TCP_ACK UIP STAT TTUID sStat top sdrop UIP STAT TTUID Stab tCD ackerr UIP LOG tcp dropped non ack segment gorto crop Calculated the length of the data if the application has sent any data to us 7 c BUF gt tcpoffset gt gt 4 lt lt 2 uip_len will contain the length of the actual TCP data This is calculated by s
34. LISTENPORIS The uip listenports list all currently listning ports static uio t ipid The ipid variable is an increasing number that is used for the IP ID field static u8 t iss 4 The 188 variable is used ior the TCP initial sequence number if UIP ACTIVE OPEN Plante uli t last orr Keeps track of the last port used for a new connection endif UIP ACTIVE OPEN Temporary variables statio US C Opt GrLaLtiec l t tmpport Structures and definitions typedef struct IP header ug ct vil tos lenz ipid 2 ipoffset 2 EE proto ulo t uzpcohksum lo t Srcrpaddri2 destipaddr 2 ICMP echo u8 t type header LCOOS ul6 t icmpchksum id segno p prcmphdadrs ul o t define define fdefine define define define ICE BIN ICP SYN ICE ISI TCP PSH ICP ACK ICP URG Ox 01 0x02 0x04 0x08 0x10 0x20 ag define IP PROTO ICMP il define IP PROTO TCP 6 define ICMP ECHO REPLY O define ICMP ECHO 8 Macros define BUF uip tcpip hdr amp uip buf UIP LLH LEN define ICMPBUF ipicmphdr amp uip buf UIP LLH LEN fif UIP STATISTICS struct uip stats uip stat define UIP STAT s s telse define UIP STAT s tendit UIP STATISTIUS ee 1 dif UIP LOGGING define UIP LOG m printf s n m else define UIP LOG m endif UIP LOGGING 1 vold uip init void for c 0
35. PCB layouts were printed and pasted it on the PCB boards using photo paper The PCB boards were put in the laminate machine to make sure the circuit drew on the board The board that drew with the 21 schematic was put in the itching machine After that the boards were cleaned with thinner Lastly the boards were drilled and the devices were completed by soldering the equipment on the boards 3 2 1 AVR Microcontroller An 8 bit AVR RISC micro controller was used as the brain of the sensor node as referred in S Hollar 2000 ATMEL ATmega8535 had 8K bytes of In System Programmable Flash with Read While Write capabilities 512 bytes EEPROM 512 bytes SRAM 32 I O lines execution rate of one instruction per clock and can be attached to a PC ISA bus network Figure 3 3 shows Pin out of ATmega8535 XCK TC PBO PAD ADCO TH PEI PAT ADC INTZIAINE PEZ PAZ ADC CNAIN PER PAZ ADC3 EB Pee PA4 ADCS MOS PBE PAS ADCS MISO PEE PAE ADCS SCH PET PAT ADCT TESTS AREF voc GND GND AVCC XTAL2 POT TOSCI XTAL POE TOSC RMD FD PoE TXD PD Pod INTO POZ PEI IINT POS PEJ OCIB POA PC BDA OTIA FOS POO BEL ICP1 POE POT OC Figure 3 3 Pin out of ATmega8535 27 ATmega8535 supports ADC conversion start on auto triggering on interrupt sources All of the registers are directly connected to the Arithmetic Logic Unit ALU allowing two independent registers to be accessed in one single instruction
36. PSZ 19 16 Pind 1 97 UNIVERSITI TEKNOLOGI MALAYSIA BORANG PENGESAHAN STATUS TESIS JUDUL A COMMUNICATION BETWEEN EMBEDDED TCP IP SENSOR NODES SESI PENGAJIAN 2006 2007 Saya RUZAINI BINTI ABD RAZAK HURUF BESAR mengaku membenarkan tesis PSM Sarjana Dekter Ealsafah3 ini disimpan di Perpustakaan Universiti Teknologi Malaysia dengan syarat syarat kegunaan seperti berikut Hakmilik tesis adalah di bawah nama penulis melainkan penulisan sebagai projek bersama dan dibiayai oleh UTM hakmiliknya adalah kepunyaan UTM Perpustakaan Universiti Teknologi Malaysia dibenarkan membuat salinan untuk tujuan pengajian sahaja Perpustakaan dibenarkan membuat salinan tesis ini sebagai bahan pertukaran di antara institusi pengajian tinggi Sila tandakan V SULIT Mengandungi maklumat yang berdarjah keselamatan atau kepentingan Malaysia seperti yang termaktub didalam AKTA RAHSIA RASMI 1972 TERHAD Mengandungi maklumat TERHAD yang telah ditentukan oleh organisasi badan di mana penyelidikan dijalankan TIDAK TERHAD Disahkan oleh UP ME AT T C TA TANGAN PENULIS TANDATANGAN PENYELIA Alamat Tetap 118 ALOR LINTAH Nama Penyelia PROF DR NORSHEILA 22000 JERTEH BINTI FISAL TERENGGANU Tarikh 22 NOVEMBER 2006 Tarikh 22 NOVEMBER 2006 Catatan Potong yang tidak berkenaan Jika tesis ini SULIT atau TERHAD sila lampirkan surat daripada pihak berkuasa organisasi berkenaan dengan menyatakan sekali tempoh t
37. S V Increase verbosity level Please use this when submitting bug reports about avrdude See lt http savannah nongnu org projects avrdude gt to submit bug reports AVRDUDE_FLAGS v v Define directories if needed DIRAVR c winavr DIRAVRBIN DIRAVR bin DIRAVRUTILS DIRAVR utils bin DIRINC DIRLIB DIRAVR avr lib Define programs and commands SHELL sh CC avr gcc OBJCOPY avr objcopy OBJDUMP avr objdump SIZE avr size Programming support using avrdude AVRDUDE avrdude REMOVE rm f COPY cp HEXSIZE SIZE target FORMAT TARGET hex ELFSIZE SIZE A TARGET elf Define Messages English MSG ERRORS NONE Errors none MSG BEGIN begin MSG END end 2222252 MSG SIZE BEFORE Size before MSG SIZE AFTER Size after MSG COFF z Converting to AVR COFF MSG EXTENDED COFF Converting to AVR Extended COFF MSG FLASH Creating load file for Flash MSG EEPROM Creating load file for EEPROM MSG EXTENDED LISTING Creating Extended Listing MSG SYMBOL TABLE Creating Symbol Table MSG LINKING Linking MSG COMPILING Compiling MSG_ASSEMBLING Assembling MSG_CLEANING Cleaning project Define all object files OBJ SRC c 0 ASRC S 0 Define all listing files LST ASRC S Ist SRC c Ist Combine all necessary flags and optional flags Add target processor to flags ALL_CFLAGS mmcu MCU
38. SF tH tH SF Et SF HE tH FH include uip h include rs232dev h include app h sinelude lt stdio h gt include compiler h Finelude lt avr ic h gt include uip_arch h define TIMER PRESCALE 1024 define F_CPU 8000000 define TIMERCOUNTER PERIODIC TIMEOUT F_CPU TIMER PRESCALE 2 256 static unsigned char timerCounter void initTimer void TCCRO 0x07 TIMSK _BV TOIEO timerCounter 0 SIGNAL SIG OVERFLOWO trimercounterterj f KK kk kk KKK KK KK main OK OK KK KK KK KK KK kk kk xj int main void THE 3 rsz3zdev 1nit i zp initi examplel init while l uip process UIP DATA uip appdata adc rs232dev send delay 1ms 1000 return 0 TE EE EE EHE RE EE E HERE EE E HERE EE E EE EE EE E EE EE EE EE EE EE EE E EE E EE HERE RE EE HERE EE EE RE ERE HH HF EE USART TX TE EE EE E HERE EE E HERE EE E EE EE EE E EE EE EE EE EE EE EE E EE EE E EE E EE HERE EE EHE EF EE FE SF tH HF EE include avr io h define FOSC 8000000 Clock Speed define BAUD 1200 define baudrate FOSC 16 BAUD 1 unsigned int x unsigned int ADCL_data ADCH_data subrutin void USART_Init unsigned int UBRR Set baud rate UCSRA amp Oxfd UBRRH unsigned char UBRR gt gt 8 UBRRL unsigned char UBRR Enable receiver and transmitter UCSRB 1 lt lt RXEN 1 lt lt TXEN Set frame format 8data no parity 1 stop bit UCSRC
39. additional information about filenames and function names needs to be present in the assembler source files see avr libc docs FIXME not yet described there ASFLAGS Wa adhIns lt S Ist gstabs Optional linker flags WI tell GCC to pass this to linker Map create map file cref addcross reference to map file LDFLAGS W1 Map TARGET map cref Additional libraries Minimalistic printf version LDFLAGS Wl u vfprintf Iprintf min Floating point printf version requires Im below LDFLAGS Wl u vfprintf Iprintf flt Im math library LDFLAGS Im Programming support using avrdude Settings and variables Programming hardware alf avr910 avrisp bascom bsd dt006 pavr picoweb pony stk200 sp12 stk200 stk500 Type avrdude c to get a full listing AVRDUDE_PROGRAMMER stk500 AVRDUDE_PORT coml programmer connected to serial device A VRDUDE_PORT Iptl programmer connected to parallel port AVRDUDE WRITE FLASH U flash w TARGET hex AVRDUDE WRITE EEPROM U eeprom w TARGET eep AVRDUDE FLAGS p MCU P AVRDUDE PORT c AVRDUDE PROGRAMMER Uncomment the following if you want avrdude s erase cycle counter Note that this counter needs to be initialized first using Yn see avrdude manual AVRDUDE_ERASE y Uncomment the following if you do not wish a verification to be performed after programming the device AVRDUDE_FLAG
40. and data rate is important In this project it was defined that data transmission using USART with baud rate of 4800 bps 8 bit frame format and Big Endian byte order of the data The data rate was described by the number of bits transmitted each second measured in bit per second bps Each frame contents 44 bytes data 2 bytes header link layer Ibyte checksum link layer 20 bytes TCP header 20 bytes IP header and 1 byte data 52 4 1 Result from Oscilloscope The result will be elaborated in this section which are analog data that has been converted into the digital form In this section the result during transmission was captured with oscilloscope to identify every bit in the frame 4 1 1 USART without uIP Wired Figure 4 1 shows the result collected at the TXD pin and RXD pin during wired transmission The data transmitted is only 1 byte without uIP and USART transmission format that have start bit star bit 0 8 bit data and 1 stop bit stop bit 1 was used The data is OXOE in hexadecimal at temperature 23 C We have defined Big Endian byte order and 8 bit data each time the transmission here we can see from the figure that the data transmit 1s 001 1100001 0101111000011 we WN XE Start bit 0 0X0 Stop bit The actual data is OXOE which 1s 00000111 53 Figure 4 1 Observed Data Transmission using USART without uIP wired 4 1 2 USART with uIP Wired Figure 4 2 shows the result collected at the TXD p
41. ansmission between the sensor nodes operated correctly as developed in the programming sections 5 2 Recommendation The work carried out in this project were focused on the development of a sensor node which constraint on sensing the temperature data embedding the uIP stack into the sensor node and testing the data transmission as well But during the testing no further measurement was done to configure the delay routing protocol and medium access The suggestions for the future works are the following 1 This project should be developed with smaller size lower cost but can be used in wider application and functions since the development is carried out without much constraint on the physical size and cost 2 In addition more sensor nodes should be further developed to represent a real sensor and several sensor types can be combined to sense the data from surroundings depends on the sensor network application 3 More analysis should be done in many angles such as in circuit design antenna design measurement methodologies and result representation REFERENCES William Stallings 2004 Data and Computer Communications International Edition Seventh Edition Upper Saddle River NJ07458 Pearson Prentice Hall A Dunkels May 2003 Full TCP IP for 8 bit architectures In MOBISYS 03 San Francisco California URL http dunkels com adam uip A Dunkels May 2003 uIP A Free Small TCP IP Stack Technical paper
42. ansmission using USART with uIP wireless before uIP process Figure 4 5 shows the result collected at the TXD pin and RXD pin during wired transmission The data transmitted are 44 bytes with uIP and USART transmission format that have 1 start bit star bit 0 8 bit data and 1 stop bit stop bit 1 was also used At the receiver the received frame will be processed to extract the data After processing extracted data is OXOF in hexadecimal at temperature 29 C We have defined Big Endian byte order and 8 bit data each time the transmission the extracted data is 0111100001 0111111000011 lt A NN Start bit OXF 0X0 Stop bit 57 The actual data 1s OXOF which 1s 00001111 a seeeeeurene IEEE NEM TT ata OxOF 29 Celsius li RR Start bit 0 B a iu au P ap U PI wea CR dr EJ LJ OOO Stop bit 1 CF EN RE NC Figure 4 5 Observed Data Transmission using USART with uIP wireless after uIP process 58 4 2 Result at Hyper Terminal Figure 4 6 shows the received data measured at RXD pin at 27 C Those data were not extracted There are 44 bytes data in a frame 2 bytes header link layer 1 byte checksum link layer 20 bytes TCP header 20 bytes IP header and 1 bite data The data were displayed in hexadecimal tn Communication Terminal IE Settings Communication Data in a frame Com Port COM Baud 1200 v Append C CR Send as ty
43. as included with all header file that used to call all functions for uIP programming In this part we will discuss the code line by line in main c 3 3 3 1 1 Transmitter Part Figure 3 28 shows the main source code for uIP stack for transmitter node include uip h Hinclude rsz3zdev hn include app h H include zstdio h include compiler h include sawr io h gt include uip arch h define TIMER PRESCALE 1024 Sdefine F CPU gangaaag Xd ocho cA ce cc x main Wh A c Ac e e e n e og int mainivoid i ua t I int z rsZ3zZzdev initi uip initi examplel initi whilerilt uip process UIP DATA uip appdata adci l rs232dev send delay imsii 0n return OU Figure 3 28 The Main Source Code for uIP for Transmitter 43 This programming functions to control all of the transmitter tasks In this part the programming code description in main c will be described Firstly int main void means the beginning of the program execution While rs232dev init used to initialize the rs232 device and set the parameter of the device which is in source code rs232 tty The uip_init functions call the subroutine to check available ports and connection configure the uIP data structures and examplel init functions call the function to defined port number for the application node Both transmitter and receiver should have the same port number Besides uip process UIP DATA means the actual uIP function
44. c lt x DIE LISTENPORIS amp amp wip liscenports coc 0 o 4 if tmpport uip listenports c goto found listen No matching connection found so we send a RST packet UIP STAT 7Ui 9 sStadt tcD Synrst resect We do not send resets in response to resets if BUF gt flags amp TCP_RST gOLO drop UIP STAT FuLp Stal tco rse BUP gt Eilage ICP RSE ICE ACK uip len 40 BUF tcpoffset 5 lt lt 4 Flip the seqno and ackno fields in the TCP header c BUF gt segno 3 BUF gt seqno 3 BUF gt ackno 3 BUF gt ackno 3 c c BUF gt seqno 2 BUF gt seqno0 2 BUF ackno 2 BUF ackno Z2 c c BUF segnoll l BUF seqno 1 BUF gt ackno 1 BUF ackno l 6 c BUF seqno 0 BUF seqno 0 BUF agcknol9o s BUF ackno O c We also have to increase the sequence number we are acknowledging If the least significant byte overflowed we need to propagate the carry to the other bytes as well if BUF gt ackno 3 0 if BUF gt ackno 2 0 if BUF gt ackno 1 0 r BUE Seckno U0 F i BURP SSrcoore BUF 5sSrcport BUF destport BUF gt destport tmpport Swap IP addresses tmpport BUF gt destipaddr 0 BUF destipaddr 0 BUF gt srcipaddr 0 tmpport tmpport BUF gt destipaddr 1 BUF gt destipaddr 1 BUF gt srcipaddr 1 tmpport And send out the RST packet goto tcp_s
45. croprocessor hosted on the Windows platform It includes the GNU GCC compiler for C and C So far Win AVR supports only the DOS command line platform The user should familiar with DOS commands before using it The user needs to study the Makefile and AVR GCC program WinAVR development tools includes Compilers Assembler Linker 46 Librarian File converter Other file utilities C Library Programmer software Debugger In Circuit Emulator software Editor IDE and many other support utilities The compiler in WinAVR is the GNU Compiler Collection or GCC This compiler was incredibly flexible and can be hosted on many platforms it can target many different processors operating systems back ends and can be configured for multiple different languages front ends This is ideal for calling the make utility which executes user s Makefile which in turn calls the compiler linker and other utilities used to build your software d Programmers Notepad 2 File Edit view Tools DAHA ie x Am Make main c Makefile Si ma In t Window Help iw include uip h include rs232dev h include app h f include txadc22 h include stt include co include av include ui define TIME define F CPI define TIME static unsi u8 t uip_ void initTi f outp C 7 TCCROZOxQ7 Makefile MCU atmegas8535 Output format can be srec i
46. d in Europe and the 915 MHz ISM band in North America Frequency band 6765 6795 KHz 13 553 13 567 KHz 26 95 727 283 KHz 4 06 40 70 MHz Center frequency 6780 kHz 13 5600 KHz 27 120 KHz 40 G MHz 902 928 MHz 2400 2500 MHz 5725 5875 MHz 4 24 75 GHz 61 61 5 GHz 122 123 GHz 144 246 GHz 915 MHz 2450 MHz S800 MHz 24 125 GHz 61 25 GHz 122 5 GHz 245 GHz Table 2 1 Frequency bands available for ISM applications 2 3 8 Power consumption The wireless sensor node being a micro electronic device can only be equipped with a limited power source In some application scenarios replenishment of power 12 resources might be impossible Sensor node lifetime therefore shows a strong dependence on battery lifetime In a ad hoc sensor network each node plays the dual role of data originator and data router The disfunctioning of few nodes can cause significant topological changes and might require re routing of packets and re organization of the network Hence power conservation and power management take on additional importance It is for these reasons that researchers are currently focusing on the design of power aware protocols and algorithms for sensor networks 2 4 TCP IP Protocol Suites TCP IP is a Transmission Control Protocol Internet Protocol It is the most popular network protocol and the basis for the internet TCP IP protocol suite consists of a large collection of protocols that have been issued as Internet
47. e eee eae ema as eo eee ee ae Se eee J v id uip_listen ul6_t port tor c 0 c ULP_LISTENPORTS 4 0 4 if uip listenports c 0 uip listenports c htons port break void uip process u8 t flag uip appdata amp uip buf 40 UIP LLH LEN Check if we were invoked because of the perodic timer fireing if flag UIP TIMER Increase the initial sequence number if iss 3 0 if t tiss 2 0 if t iss 1l1 0 4 iss 0 uip len 0 if uip conn tcpstateflags TIME WAIT uip conn tcpstateflags FIN WAIT 2 uip conn timer 22 if uip conn timer UIP TIME WAIT TIMEOUT uip conn tcpstateflags CLOSED else if uip_conn gt tcpstateflags CLOSED If the connection has outstanding data we increase the connection s timer and see if it has reached the RTO value in which case we retransmit if uip_conn gt tcpstateflags amp UIP OUTSTANDING 4 U1 COnn Camer 7 lf uip cont timer 0 if uip conn nrtx UIP MAXRIX ip conn tcopsLateflags CLOSED We call UIP APPCALL with uip flags set to UIP TIMEDOUT to inform the application that the connection has timed out uip flags UIP TIMEDOUT UIP APPCALL We also send a reset packet to the remote host BUF flags ICP RSI ICP ACK goto tcp send nodata Exponential backofr urzp conn timer UIP RTO lt lt uxp conn nrtx gt
48. e temperature The sensors nodes are embedded with TCP IP stack and able to forward and receive data The programming was developed with WinAVR development tools using C language The hex code will be ported using AVRISP connector Finally the transmission of data between sensor nodes are measured and displayed on computer using hyper terminal mikroBASIC and Visual Basic 6 0 interfacing Each frame that transmitted contents 44 bytes data 2 bytes header link layer Ibyte checksum link layer 20 bytes TCP header 20 bytes IP header and 1 byte data All of those header were removed away to get the actual data The result during transmission was captured with oscilloscope to identify every bit in the frame vi ABSTRAK Rangkaian pengesan adalah sekumpulan nod nod pengesan yang saling berkomunikasi antara satu sama lain Setiap nod pengesan dilengkapi dengan mikropengawal yang kecil modul perhubungan RF pengesan dan satu sumber tenaga Nod nod pengesan ini terikat dari segi ingatan dan kuasa pemprosesan disebabkan oleh kos dan saiz fizikal yang terhad Ciri ciri ini telah dipertimbangkan amat terhad bagi saiz fizikal nod pengesan untuk berupaya menggunakan protokol TCP IP Nod pengesan mempunyai kebolehan untuk mengesan data daripada persekitaran seperti kelembapan cahaya berat dan suhu dan juga dolengkapi dengan protokol TCP IP terbenam untuk perangkaian Projek ini telah untuk dijalankan untuk membangunkan dua modul nod pengesan yang beru
49. ead the make user manual Additional material for this makefile was submitted by Tim Henigan Peter Fleury Reiner Patommel Sander Pool Frederik Rouleau Markus Pfaff On command line make all Make software make clean Clean out built project files make coff Convert ELF to AVR COFF for use with AVR Studio 3 x or VMLAB make extcoff Convert ELF to AVR Extended COFF for use with AVR Studio 4 07 or greater make program Download the hex file to the device using avrdude Please customize the avrdude settings below first make filename s Just compile filename c into the assembler code only To rebuild project do make clean then make all MCU name MCU atmega8535 Output format can be srec ihex binary FORMAT ihex Target file name without extension TARGET UIPslip Optimization level can be 0 1 2 3 s O turns off optimization Note 3 is not always the best optimization level See avr libc FAQ OPT s List C source files here C dependencies are automatically generated SRC main c app c uip arch c uip c rs232_tty c usart_tx c If there is more than one source file append them above or modify and uncomment the following SRC foo c bar c You can also wrap lines by appending a backslash to the end of the line SRC baz c XYZZY C List Assembler source files here Make them always end in a capital S Files ending
50. eiver Node Process 40 3 3 2 1 USART for Transmitter Node Figure 3 26 shows flowchart to receive data using USART First all parameters used in the program such as baud rate and frequency oscillator were defined Then we initialize USART where we set the frame format for data transmission start bit 8 data bits and 1 stop bit as at the transmitter and activate the receiver RXD pin Then if there were data received the data could be read from the USART buffer USART initialization Read data from USART buffer Figure 3 26 Flowchart for USART Receiver Node Process 4 3 3 3 uIP The C source code programming development process is shown in Figure 3 27 This is more details as it lists all the process from creating the code using high level language C language the cross compiler and finally uploading the executable file into the target system For this purposes the setup of Makefile of every source file is important because it determines the types of Linker Loader and the object files to be produced Create a new project Configure to sut the target system Create C source prog ram Compile with chosen memo ry model Link with linker command file Transfer to debugger emulator or emulator Errors Edt C source prog ram OK Put code into flash Figure 3 27 Embedded Software Development Process 42 3 3 3 1 uIP Program Explanation The main program for uIP is main c where this program w
51. em and see the contents MCU name MCU at90s8515 MCU at90s8535 MCU at90s4433 MCU at90s2313 MCU atmegai63 Output format can be srec ihex binary FORMAT ihex Target file name without extension TARGET MR2313 Optimization level can be 0 1 2 3 s O turns off optimization Note 3 is not always the best optimization level See avr libc FAQ OPT 1 OPT s The portion of code above is a sample from a makefile This is the only area you might consider modifying MCU Your CPU Name FORMAT ihex Do not change TARGET Your source code name without extension If you create new source code and want to compile it you have to change this entry to your source file name OPT 1 Change at your own risk In certain cases this optimization option may cause unpredictable results In that case try other options File MR2313 C Description Turns on and off all the ports every 0 5 sec X tal frequency 8 MHz MICROROBOT NA Inc www microrobotna com Free Open Source Free as in Free beer You can do whatever you want with this stuff Don t even worry about buying a beer ha ha James Jeong include avr io h define LED1 PB5 typedef unsigned char byte typedef unsigned int word 1msec UNIT delay function void delay 1ms unsigned int i word j while i j 14268 10Mhz Exteranl Crystal while j 977 void ports init
52. en if BUF 5flags amp ICP FIN ir uip flags amp UIP ACKDATA uip conn tcpstateflags TIME WAIT ulp_conn gt timer 0 else ulp_conn gt tcpstateflags CLOSING UIP OUTSTANDING UTD add TOV nkt 1 goto tcp send ack else if uip flags amp UIP ACKDATA ulp_conn gt tcpstateflags FIN WAIT 2 goto OSOD if uip len gt O0 goto tcp send ack gorco drop case FIN_WAIT_2 if uip len gt 0 uip add rcv nxt uip len Ii BUFE flags amp ICP FIN 4 ulp_conn gt tcpstateflags TIME WAIT rxp conn taimer 0 ip add rcv nxt 1 goto tcp send ack if uip len gt 0 goto tcp send ack coro drop case TIME WAIT goto tcp send ack case CLOSING if uip flags amp UIP ACKDATA ulp_conn gt tcpstateflags TIME WAIT urxp conn gt timer 0 ij goto drop We jump here when we are ready to send the packet and just want to set the appropriate TCP sequence numbers in the TCP header tcp send ack BUF gt flags TCP_ACK tcp_send_nodata uip len 40 tcp send noopts BUF tcpoffset 5 lt lt 4 tcp_send We re done with the input processing We are now ready to send a reply Our job is to fill in all the fields of the TCP and IP headers before calculating the checksum and finally send the packet BUP Scknolu uxpoconn xov nxt BUE acknoll uripoconn rov nxtl BUF acknolz2 urp conn rev nxt BUF S3ckno 5 uip conn
53. end_noconn This label will be jumped to with a connection in LISTEN connection and send a SYNACK found_listen First we check if there are any Swap port numbers LIPO ae f In XL connections are kept in the same table as used connections unused ones have the tcpstate set to CLOSED for c 0 c lt ULP CONNS c if uip conns cl tepsteteflags goto found unused connection for c 0 c DLP CONNS 4c 1 if uip conns c tcpstateflags goto found unused connection All connections are used already 76 BUPF 2srorpaddr ro s BUF sSrcipaddadrl l s we matched the incoming packet that case we should create a new return Unused but connections avaliable J CLOSED TIME_WAIT we drop packet and hope that the remote end will retransmit the packet at a time when we have more spare connections UIP STAT t uip stat tcp syndrop UIP LOG Tep HOLD drop found no unused connections This label will be jumped to if we have found an unused connection that we can use J found_unused_connection uip conn amp uip conns c Fill in the necessary fields for the new connection ulp_conn gt timer ip conn nrtx ulp_conn gt lport BUF gt destport uip conn rport BUE SECDOIU ip conn ripasddero urpeconn cO ripaddrli ulp_conn gt tcpstateflags uxp conn sne nxtro uip conn sud nxt urp conmn snd Nxt urp
54. ens thus being able to fully communicate with other hosts in the network Traditional TCP IP implementations have required far too much resource both in terms of code size and memory usage to be useful in small 8 or 16 bit systems Code size of a few hundred kilobytes and RAM requirements of several hundreds of kilobytes have made it impossible to fit the full TCP IP stack into systems with a few tens of kilobytes of RAM and room for less than 100 kilobytes of code TCP is both the most complex and the most widely used of the transport protocols in the TCP IP stack TCP provides reliable full duplex byte stream transmission on top of the best effort IP layer Because IP may reorder or drop packets between the sender and the receiver TCP has to implement sequence numbering and retransmissions in order to achieve reliable ordered data transfer A Dunkles 2004 had discussed that there are two small generic and portable TCP IP implementations w P lightweight IP and u P micro IP with slightly different design goals The w P implementation is a full scale but simplified TCP IP implementation that includes implementations of IP ICMP UDP and TCP and is modular enough to be easily extended with additional protocols w P has support for multiple local network interfaces and has a flexible configuration option which makes it suitable for a wide variety of devices The u P implementation is designed to have only 16 the absolute minimal se
55. erified between these sensor nodes 19 Temperature Sensor Hardware Software Design Processing Development Communication RF Module Figure 3 1 Methodologies Diagram 3 2 Hardware Design Figure 3 2 shows a diagram of the proposed design architecture for a sensor node Temperature sensor were used to capture data from surroundings and interfaced to the processor An AVR microcontroller ATmega8535 served as the brain of the system and the communications between these nodes were done through RF transmitter and receiver module Each of sensor nodes used a 9V battery as an energy source ATMEL AVR ISP Connector was built to upload the programming of AVR microcontroller chip through to the PC parallel port and RS232 serial cable also was built to connect the node to the computer 20 TEMPERATURE SENSOR SENSE CAPTURE DATA AVR MICROCONTROLER DATA PROCESSING RF TRANSCEIVER COMMUNICATION Figure 3 2 Sensor Node Proposed Design The components in sensor node development are as follow AVR microcontroller ATmega 535 Analog Temperature sensor LM35 DZ Transmitter and Receiver RF Module optimal range 100m 453 92M Hz version Data rates up to 4800 bps A TCP IP Protocol uIP stack 1n each sensor nodes To build the PCB hardware firstly designed the schematic circuits using the DXP2004 software Instruction to use this software will be discussed in Appendix The schematics were converted into the PCB layouts The
56. esis ini perlu dikelaskan sebagai SULIT atau TERHAD Tesis dimaksudkan sebagai tesis bagi Ijazah Doktor Falsafah dan Sarjana secara penyelidikan atas disertasi bagi pengajian secara kerja kursus dan penyelidikan atau Laporan Projek Sarjana Muda PSM I declared that I had read this thesis and in my opinions the thesis had fulfill all of the requirements for obtaining a Bachelors Degree in Electrical Engineering Telecommunication Pes e Signature M Supervisor PROF DR NORSHEILA BINTI FISAL Date 22 NOVEMBER 2006 A COMMUNICATION BETWEEN EMBEDDED TCP IP SENSOR NODES RUZAINI BINTI ABD RAZAK Submitted to the Faculty of Electrical Engineering in partial fulfillment of the requirements for the award of a degree in Bachelor of Electrical Engineering Telecommunication Faculty of Electrical Engineering Universiti Teknologi Malaysia NOVEMBER 2006 I declare that this thesis entitled A COMMUNICATION BETWEEN EMBEDDED TCP IP SENSOR NODES is the result of my own research except as cited in the references The thesis has not been accepted for any degree and is not concurrently submitted in candidature of any other degree o Signature dcin Name RUZAINI BINTI ABD RAZAK Date f 22 NOVEMBER 2006 To my beloved mother father and family for their encouragement and blessing To my dearest friends for his support and understanding Thanks for all 111 1V ACKNOWLEDGEMENT First of all I am greatly indeb
57. ex Addin Data Project Manager Document Dll Gocument Exe Fea i Fea i Fea s Dont show this dialog in the Future Figure 3 31 The New Project Window The codes provides in this software is user friendly and not complicated as the other software because it use the Basic Language Figure 3 32 shows the Menu Bars and figure 3 33 shows the Title Bars provide information similar to most windows programs coding i HE m i 9B s B mas 622 D p B 5 wae L ki HI LL Hle LA dee beet fps Dass Bon uer Dum H n mal Sees 48 EFi u F IT Fhia b prj Bh I ee ee n Frivets Sub Form Telos Can ie nteger TE Ae Peri open Trium Tete oe Ferien Feiss i im Te BTL Fri Ies Hn cho SS mncom ng dis his ihe Hagn Peels T Eton towne s ocomPuybacaisa Then If comdu aralva Eyam ti T Form properties Figure 3 32 Visual Basic design Project Microsoft Visual Basic design File Edit View Project Format Debug Run Query Diagram Tools Add Ins Window Help B h BSE amp By KA d c Cu Figure 3 33 Menu Bars and Title Bars Microsoft Comm Control 6 0 needs to be added in to Toolbox as illustrates in figure 3 34 This tool is important in order to communicate with serial port 49 Components Controls Designers Insertable Objects Microsoft Actives Plugin Microsoft 400 Data Cont
58. he AVR microcontroller Then wrote a device driver for target s network device in uIP serial and configured the uIP codes to be used in the sensor device After that the uIP a TCP IP functions was embedded into the sensor nodes This is done to perform a networking between sensor nodes Then the corresponding between sensor and transmitter that transfer data trough TCP IP were done The temperature result was displayed at the computer using Visual Basic 6 0 interfacing CHAPTER 2 BACKGROUND LITERATURE 2 1 Wireless Sensor Network Wireless sensor network are self organizing wireless networks where all nodes take part in the process of forwarding packets These tiny sensor nodes which consist of sensing data processing and communicating components leverage the idea of sensor networks based on collaborative effort of a large number of nodes Sensor networks represent a significant improvement over traditional sensors A sensor network is composed of a large number of sensor nodes which are densely deployed either inside the phenomenon or very close to it On the other hand this also means that sensor network protocols and algorithms must possess self organizing capabilities Another unique feature of sensor networks 1s the cooperative effort of sensor nodes Sensor nodes are fitted with an on board processor Instead of sending the raw data to the nodes responsible for the fusion sensor nodes use their processing abilities to
59. header TCP header header amp cksum for link layer Transmit using USART Figure 3 23 Flowchart for Transmitter Node Process 38 3 3 1 1 USART for Transmitter Node Figure 3 24 shows flowchart to transmit data using USART program First all parameters used in the program such as baud rate and frequency oscillator were defined Then we initialize USART where we set the frame format for data transmission start bit 6 data bits and I stop bit and activate the transmitter TXD pin Then after getting the data we had to make sure that the transmitter buffer was empty to allow the transmitting START USART initialization E Conversion Complete Wait for empty tx buffer Transmit data From USART buffer Figure 3 24 Flowchart for USART Transmitter Node Process 39 3 3 20 Receiver Node Figure 3 25 shows the flowchart for the overall receiver node process Firstly the frame received was read from USART buffer UDR After that the frame was processed to extract the data In the processing part the header TCP 20 bytes IP 20 bytes non standard link layer header 3 bytes were separated from the data Lastly the complete frame were transmitted using USART and this flow will be repeated for the next data NO Data receive YES Read incoming data In USART buffer Checksum header UIP process P header TCP header Display data Figure 3 25 Flowchart for Rec
60. hex binary FORMAT ihex Target file name without extension TARGET UIPslip optimization level can be 0 1 2 3 s Note 3 is not always the best optimizat ORT 5 List C source files here cC dependencies ll iv 5 Find YD Output UIPslip elf section size text 4550 data 24 bss 663 noinit 0 eeprom o stab 9504 stabstr 4891 Total 19632 Errors none addr o 8388704 8388728 8389391 8454144 o gt Process Exit Code O SRC main c app c uip_arch c uip c rs232 tty c usart tr c If there is more than one source file append them above or modify and uncomment the following 4 lili Figure 3 30 Programmer Notepad in WinAVR 47 3 3 5 Visual Basic 6 0 Visual Basic 6 0 is used to design graphical user interface GUI This software is ease to use and implement as it provides functional ability in the software The Visual Basic Integrated Development Environment IDE provides everything that is needed to develop applications in an easy to use and learn GUI This 1s the example of opening screen that will appear in Visual Basic 6 0 software Figure 3 31 shows the New Project Window is displayed when Visual Basic is started New Project E 5 a PON s qu e I 4 Mew Existing Recent n Da b PN Standard EXE Activex EXE Activex DLL Activer vB Application Control Wizard S fe fe fe 2X De VB Wizard Ackivex Activ
61. high to active the register Besides PORTC 0X00 means PORTC was set to low as 45 an output to display the received data After that c USART RX function called to read the incoming packet from USART buffer Whereas process calls the subroutine to process the incoming packet This function will extract the 8 bits data from the whole frame Lastly is return 0 means the end of the program 3 3 4 Code Compiler WinAVR In developing and compiling the source code several software that available for free download from the net can be used The source code was written 1n C thus Visual C or any other C programmer could be used But in compiling the code another compiler that is more convenient for AVR microcontroller was used to compile the code The selection of software in compiling the code developed depends on the easiest way and without the need of circuit emulator from the vendor To program the code into the chip an alternative way such as an ISP connector can be implemented The followings are the software that might be use as the code compiler as well Figure 3 30 shows the Programmer Notepad window in WinAVR In Figure 3 30 the source code is displayed at the back while the front window shows the makefile setup for the source code After that the source code will be executed by hitting Make All command in the Tool menu WinAVR is a suite of executable open source software development tools for the ATMEL series of RISC mi
62. in and RXD pin during wired transmission The data transmitted are 44 bytes with uIP 54 Start bit 0 bit Stop bit 1 OXFC 1 1 byte of 44 e ir I Figure 4 2 Observed Data Transmission using USART with uIP wired before uIP process Figure 4 3 shows the result collected at the TXD pin and RXD pin during wired transmission The data transmitted are 44 bytes with uIP and USART transmission format that have 1 start bit star bit 0 8 bit data and 1 stop bit stop bit 1 was also used The data is OXOF in hexadecimal at temperature 29 C We have defined Big Endian byte order and 8 bit data each time the transmission the extracted data is 0111100001 0111111000011 lt A NN Start bit OXF 0X0 Stop bit The actual data is OXOF which is 00001111 55 a P ia Ee ee ELT LL L d ry af a a ff AEMEMEMENMEE 4 LI Data 0x0F 29 Celsius TETT T TT T i TIT di did AAA 54 155 d it Stop bit 1 Start bit 0 a 4o an ua us ooa P pm MA am Pu meu eir E A a a s Figure 4 3 Observed Data Transmission using USART with uIP wired after uIP process 4 1 3 USART with uIP Wireless Figure 4 4 shows the result collected at the TXD pin and RXD pin during wired transmission The data transmitted are 44 bytes with uIP The figure shows several bytes of the frame 56 Weinen Figure 4 4 Observed Data Tr
63. inks in place the dongle is identified as a Value Added Pack Dongle Figure 3 15 shows the PCB layout for the cable The simple circuit like this only needs a single layer PCB circuit u t M ne a ue an Fi Bow a a MF X ES UE c N uU iud m fmt LEDI ISP CABLE Figure 3 15 PCB Layout for ISP Cable 32 Figure 3 16 shows the ISP Cable that built in this project The cable is in small size and robust when built it as PCB circuit Figure 3 16 ISP Cable 3 2 7 RS232 Serial Cable In this project the DB9 version is used Figure 3 17 shows the signals common for DB9 version Note that the protective ground is assigned to a pin at the large connector where the connector outside is used for that purpose with the DB9 connector version 33 Data carrier detect Data set ready Receive data Request to send Transmit data Clear ta send Data terminal read Ring indicator Signal ground Protective ground Figure 3 17 RS232 DB9 Pin Out The MAX232 is the industrial standard IC for converting TTL CMOS level signals to RS232 level signals RS232 Is and Os are at 12 and 12V Well the ATMEL only outputs 0 5V signals so if we want to speak true RS232 we need to convert the 0 SV signal pulses to their equivalent 12V RS232 pulses The MAX232 does exactly that If we put 5V on the TIIN pin we will see 12V on the TIOUT pin This is how we pass data out to the computer If we press a key in
64. lers use unsigned char and unsigned short for those two respectively typedef unsigned char u8 t typedef unsigned short ul6 t The configuration options for a specific node This includes IP address netmask and default router as well as the Ethernet address The netmask default router and Ethernet address are appliciable only if uIP should be run over Ethernet All of these should be changed to suit your project ii UIP IPADDR The IP address of this uIP node define UIP IPADDRO OxOA 10 define UIP_IPADDR1 0x02 772 define UIP IPADDR2 Ox00 0 define UIP IPADDR3 OXOA 10 men Nc cre tn ncn NO NER UR include app h UIP ACTIVE OPEN Determines if support for opening connections from uIP should be compiled in If this isn t needed for your application don t turn it on A web server doesn t need this for instance define UIP ACTIVE OPEN 1 UIP CONNS The maximum number of simultaneously active connections 7 define UIP CONNS 10 UIP LISTENPORTS The maximum number of simultaneously listening TCP ports For a web server 1 is enough here define UIP LISTENPORTS 10 UIP BUFSIZE The size of the buffer that holds incoming and outgoing packets td UIP STATISTICS Determines if statistics support should be compiled in The statistics is useful for debugging and to show the user define UIP STATISTICS 0 UIP LOGGING Determines if logging of cer
65. ne UIP TTL 2990 UIP TIME WAIT TIMEOUT How long a connection should stay in the TIME WAIT state Has no real implication so it should be left untouched define UIP TIME WAIT TIMEOUT 120 ifndef LITTLE ENDIAN define LITTLE ENDIAN 3412 endif LITTLE ENDIAN ifndef BIG ENDIAN define BIG ENDIAN 1234 endif BIGE ENDIAN SPARC IS BIG ENDIAN INTEL IS LITTLE ENDIAN ifndef BYTE ORDER define BYTE ORDER BIG ENDIAN endif BYTE ORDER lendif UIPOPT H HH EE E EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE ERE ERE ERE ERE E EE EE HE HE EE HE HE HE HE HE EE EE E HH tH tH tH HH HH HH HE HH HH HE HH EE Ht Ht Ht Ht HH HH HH HH HH FH Ht EHF RECEIVER NODE HH HH tH tH tH HH oH tH tH HH oH tH tH Ht Ht Ht Ht HH HH HH EH HH EH EH EHH HH tt it H tH tH oH oH oH tH tH tH tH tH EE HE tH HE HE HE HE HE HE HE HE HE HE HE HE HE HE HE HE HE HE HEH include avr io h Tineclude lt stdio h gt define TIMER PRESCALE 1024 define F CPU 8000000 We we wd wem See see ae eae 1 WA cw uxEgdwWXuXueXxXXJXW 4 main TJ 85 int main ii Cc DDRC OXFF PORTC 0X00 while 1 C USART RX processi return 0 TE EE EE tH HF HH HH FE HE HH FEF HH FH HF HH EF E EE EE HH FEF tH HF HH EH SF HH HF HH EH Ft Et SF HE tH FF DELAY TE EE EE tH HHH HH FEE HH FEF HH FEF HH EF tH EF HH FEF tH HE SF HH HF tH EH SF HH EH SF HF tH FE HH FH include lt avr io h gt typedef unsigned char byte
66. o understand them thoroughly the first time Take your time you will learn the process gradually e lfit seems that your AVR CPU is kind of slow check the bit configuration Refer to Security Bit Settings for ATMega Family pdf for details e Read make txt which comes with WinAVR e http www gnu org manual manual html Compiler and make manuals e Refer to your AVR gcc manual C WinAVR doc avr libc avr lioc usermanual index html This file comes with WinAVR Use the Programmers Notepad that comes with WinAVR It is quite a cool editor
67. odes which are intended to be physically small and inexpensive are equipped with one or more sensor a short range radio transceiver a small microcontroller and s power supply in the form of a battery A Dunkles J Alonso T Voigt 2004 Figure 1 1 shows the basic communication link of wireless sensor network where the transmitter node is willing to forward the information to the target destination and the received data will be displayed at the computer A Tx Node 1 Node2 Computer Figure 1 1 Basic communication link of wireless sensor network A wireless sensor network usually cannot operate in complete 1solation but must be connected to an external network through which monitoring and controlling entities can reach the sensornet As TCP IP the Internet Protocol suite has become the de facto standard for large scale networking it 1s interesting to be able to connect sensornet to TCP IP networks A Dunkles 2004 had discussed three different ways to connect sensor network with TCP IP networks proxy architectures DTN overlays and TCP IP for sensor networks They conclude that the methods are in some sense orthogonal and that combinations are possible but that TCP IP for sensor networks currently has a number of issues that require further research before TCP IP can be viable protocol family for sensor networking 1 2 Problem Statement Nowadays sensor network becomes more important to human life whether for
68. on of AVR GCC including Maro GCC causes a problem Uninstall any existing version of AVR GCC before installing a new version How to Use WinAVR So far WinAVR supports only the DOS command line platform The user should be familiar with DOS commands before using it During the WinAVR installation the program installer changes and or adds some settings in your PC You can see the added options using the set DOS command Once WinAVR is installed the user can call the installed programs from any folders It is recommended to create a new folder for each source code for the purpose of simplicity 1 Download sample source codes at http www microrobotna com download AVR Source Codes zip and copy the file to the WinAVR folder and unzip it 2 The following folders are created in the CAWinAVRMAVR Source Codes The folders are named after the CPU boards Inchworm AT90S4433 Inchworm Maro_GCC Inchworm mega MR8 MR16 MR161 MR162 MR163 MR2313 MR4433 MR8515 MR8535 AT90S MR8535 mega MR Servo8 Owl Robot AT9084433 Owl Robot Maro GCC Owl Robot mega Note In the future there might be some more folders 96 Refer to Owl Robot mega or Inchworm mega source for the MR SERVO8 board Each folder contains three or more files The following is the MR2313 folder s contents Makefile MR2313 c MR2313 hex Note The name MR2313 above varies in each folder All three files are text format files You can open th
69. ound is yellow shows that now are hot condition If the temperature is above 40 C the background is red meaning very hot condition x 30 degree normal 30 x 41 degree hot TEMPERATURE TEMPERATURE 10 15 2006 11 41 PM 10 17 2006 3 00 AM TEMPERATURE DER 10 17 2006 3 01 AM x gt 40 degree very hot Figure 4 7 Graphical User Interface CHAPTER 5 CONCLUSION AND RECOMMENDATION 5 1 Discussion Due to many constraints and limited resources such as power consumption energy efficiency available memory and buffering in the system that need to be considered implementing a TCP IP protocol into the small architecture of an embedded system seems to be a hard task The source code that used to do the whole operations was written in C language and were complied using WinAVR The IP address and the application port for transmitter node were configured to match with the receiver node A non standard format was used to handle the data at the Link Layer The verification of data transmission was carried out for both wired and wireless communication In this thesis the development of sensor nodes for both transmitter and receiver part has been presented Although the development of sensor nodes was done using a small memory size of 8KB the sensor nodes that can do sensing processing and networking using TCP IP protocol have been successfully developed As elaborated in 62 the previous chapter the data tr
70. paya untuk mengesan nilai suhu untuk memprogramkan tindanan TCP IP ke dalam nod pengesan dan berupaya untuk menghantar data kepada nod yang seterusnya Pengaturcaraan dibangunkan dengan sebuah perkakasan pembangunan WinAVR Kod perenambelasan diprogramkan melalui penghubung AVRISP Akhir sekali penghantaran data di antara nod nod pengesan ditentukan dan keputusan dipaparkan di skrin komputer menggunakan perisian hyper terminal mikroBASIC dan pengantaramuka Visual Basic 6 0 Setiap paket data uang dihantar nengandungi 2 bait kepala 2 bait checksum 20 bait kepala TCP 20 bait kepala IP dan I bait data Semua kepala ini ditapis untuk mendapatkan data Data semasa penghantaran diukur menggunakan osiloskop Vil TABLE OF CONTENTS CHAPTER TITLE PAGE TITLE i DECLARATION ii DEDICATION iii ACKNOWLEDGEMENT iv ABSTRACK V TABLE OF CONTENTS vii LIST OF TABLE X LIST OF FIGURE xi LIST OF ABBREVIATIONS xiv LIST OF APPENDICES xvi 1 INTRODUCTION 1 1 Overview 1 2 Problem Statement 1 3 Objectives KR UU Q 1 4 Project Scope 2 BACKGROUND LITERATURE 2 1 Wireless Sensor Network 5 2 2 Sensor Networks Applications 2 9 Factors Influencing Sensor Network Design 2 4 TCP IP Protocol Suites 2 5 TCP IP Stack METHODOLOGIES 3 Introduction 3 2 Hardware Design 3 2 1 AVR Microcontroller 3 2 2 Analog Temperature sensor 3 2 3 Transmitter Node 3 2 4 Receiver Node 3 2 5 RF Communication 3 2 6 AVR ISP Cable 3 2 7 RS232 Serial Cable 3
71. ping 44 bytes B 2 hdr Stop Bits One Stop Bit w C LF C Send as number Ciearhistoy F LOT 1 cksm Party None Format TUE O ASCII HEX C DEC 20 TCP header LE V Received i i 20 IP header ed to COMT Receiwed 0x72 0x74 0x00 Ox00 0x01 0x29 0x60 0x28 1 data Received EX 0uB5 0162 0462 0400 0A OvOC ODA M Beeefied s d 0x85 Oxo ny JUU Us Us MC 0x06 O2 0x00 0 04 0x11 Ox7A 02 94 Orii Recemed 002 Ox 0x04 0218 0x11 0x03 0x10 0x00 Ox Ox02 0x00 FE OxFE OxFF 0x00 OnE Recened 0490 0x24 0x20 ODE Data OxOE Te Received 0x72 Ox74 0x00 0x00 0x01 0x29 0x60 0428 Recemed A4 0x85 0x82 0x62 OxDO 0x04 0x00 Ox At 2 7 Celsi us Read from Recemed 0402 0000 0004 0x11 0x74 O02 0654 0211 Ox02 CC 0604 Oxi 0x17 0x03 0210 0x00 Write ta 3 Receved 0x74 0x02 0x00 O FS OFE OxFF 0x00 0208 O90 024 0x20 ODE Create file Disconnected from COM append to file automatically v Figure 4 6 Received Data Displayed at HyperTerminal USART with uIP wireless before uIP process Figure 4 7 shows the extracted data at HyperTerminal measured at TXD pin at receiver node All of those header were removed away to get the actual data This data was measured at temperature 27 C 59 a r Communication Terminal Sethings Communication Com Port v Baud 1200 Append CR C Send as typing Stop Bits Une Stop Bit LI LF L Send as number Party
72. pplications where low cost and longer range are required The receiver module requires no external RF components except for the antenna The super heterodyne design exhibits exceptional sensitivity and selectivity A SAW filter can beaded to the antenna input to improve selectivity for applications that require robust performance Figure 3 13 shows the receiver module 30 Figure 3 13 Receiver Module 3 2 6 AVR ISP Cable AVR ISP in System Programmable Cable is used for uploading the hex into the microcontroller directly The circuit diagram of ISP Cable is shown in figure 3 14 that can be built easily The equipment that needed to built the cable are connector 4LS245 chip DB25 and other passive equipment AMRA s my A t h oco c ie s m E ni i D ide Me D Corrector 25 Figure 3 14 ISP Cable Circuit Design 31 The ISP has only four signals to be implemented which are MOSI MISO SCK and RESET LED1 is as a indicator to detect the programmer either on or off The LED turned on when PC started up and during the uploading Otherwise there might be some error occurred The 74L S245 an octal tri state buffer was used as the main component makes the operation 1s extremely simple It was used to provide the float state after the hex code has been written into the AVR chip The two loop back connections pin 2 to 12 and 3 and 11 is used to identify the ISP cable or so called as dongle With both l
73. rol 6 0 OLEDB E Microsoft Agent Control 2 0 Microsoft Calendar Control 11 0 Microsoft Chart Control 6 0 OLEDB v Microsoft Comm Control 6 0 Microsoft Common Dialog Control 6 0 Microsoft Data Bound List Controls 6 0 Microsoft DataGrid Control 6 0 OLEDB Microsoft DakaList Controls 6 0 OLEDE Microsoft DataRepeater Control 6 0 OLEDE Microsoft DDS Microsoft DirecEAnimation Media Controls w Browse s gt Selected Items Only 1 VideaSofE vsFlex3 Controls Location CAWINDOW S systems WSFLEXS OCX Cancel Figure 3 34 Microsoft Comm Control 6 0 3 3 6 Serial Device Programmer To program the AVR microcontroller a serial device programmer was used PonyProg2000 Before programming the chip we had to setup the interface whether to use serial or parallel connector Then calibrate the bus timing choose the device to be used and setup the configuration and security bits After all calibration and setting were done the chosen hex file could be uploaded into the microcontroller Before that we had to ensure that we had chosen the right memory location for the programming which is flash memory Figure 3 35 illustrates PonyProg2000 window It shows the hex file which tells us the size of the program and the last memory that the program use When the program 50 is successfully uploaded into microcontroller it will show a notice that the program is successful U PenyProg2000 Serial Device
74. sends a FIN hence the application goes directly from ESTABLISHED to LAST ACK case SYN RCVD In SYN RCVD we have sent out a SYNACK in response to a SYN and we are waiting for an ACK that acknowledges the data we sent out the last time Therefore we want to have the UIP ACKDATA flag set If so we enter the ESTABLISHED state ir uip flags amp UIP ACKDATA Uurp oconn toostaterlags ESTABLISHED uip flags UIP CONNECTED uip len 0 UIP APPCALL goto appsend 79 goto drop if UIP ACTIVE OPEN case SYN SENTIT In SYN SENT we wait for a SYNACK that is sent in response to our SYN The rcv nxt is set to sequence number in the SYNACK plus one and we send an ACK We move into the ESTABLISHED state if uip flags amp UIP ACKDATA amp amp BUF gt flags ICP SYN TCP_ACK Parse the TCP MSS option if present 1f BUF gt tcpoffset amp Oxf0 gt 0x50 lori o 05 UOBUBP CDODOLLSet gt gt d 3 2 j 4 Opt urxp buf 40 UIP LLH LEN Gl if opt 0x00 End of options break else if opt 0x01 c 7 NOP option 7 else if opt 0x02 amp amp ulp_buf 40 UIP LLH LEN c 1 0x04 An MSS option with the right option length tmpport uip bur 40 UIP LLA LEN c Z lt lt 9 aip bur 40 UIP BLI LEN cow 3 Uip conn mss tmpport gt UIP ICP MSS UIF ICP MSS tmpport And we are done processing options
75. t lt 6 13 else ICMPBUF 212cmpcohksum NLons rcMP ECHO lt lt 91 Swap IP addresses tmpport BUF destipaddr 0 BUF 5destipaddr 0 BUF 5srcipaddr 0 BUF 5srcipaddr 0 tmpport tmpport BUF gt destipaddr 1 BUF destzazpaddr l BUFP gt Ssreipaddr 1 BUF gt srcipaddr 1 tmpport ULP STAT Tulip SLdL lompssenbs goto send l TCR input processing y tcp input UIP STAT tu uip StattOp recv s if uip tcpchksum Oxffff Compute and check the TCP 75 checksum UIP STAT ttu uip Stdt teporop UIP _ STAT TTUID SLtadt top chkerr UIP LOG tcp bad checksum goto drop Demultiplex this segment First check any active connections for rp conn amp uip conns 0 uip conn lt amp uip conns UIP CONNS FULD conn 1f uip_conn gt tcpstateflags CLOSED amp amp BUF gt srcipaddr 0 uip_conn gt ripaddr 0 amp amp BUF 5srcripaddr l uip connu rripaddr l1 amp amp BUF destport uip conn lport amp amp BUF gt srCcport uip conn rport gore round If we didn t find and active connection that expected the packet either this packet is an old duplicate or this is a SYN packet destined for a connection in LISTEN If the SYN flag isn t set it is an old packet and we send a RST if BUF gt flags TCP SYN goto reset tmpport BUF gt destport Next check listening connections toric 0
76. t of features needed for a full TCP IP stack It can only handle a single network interface and does not implement UDP but focuses on the IP ICMP and TCP protocols From a high level viewpoint the TCP IP stack can be seen as a black box that takes incoming packets and demultiplexes them between the currently active connections Before the data 1s delivered to the application TCP sorts the packets so that they appear in the order they were sent The TCP IP stack will also send acknowledgments for the received packets Figure 2 4 shows how packets come from the network device pass through the TCP IP stack and are delivered to the actual applications In this example there are five active connections three that are handled by a web server application one that is handled by the e mail sender application and one that is handled by a data logger application Nenyvork interface e al Mail sender application oO Data lozger application Figure 2 3 TCP IP input processing A high level view of the output processing can be seen in Figure 2 5 The TCP IP stack collects the data sent by the applications before it 1s actually sent onto the network 17 TCP has mechanisms for limiting the amount of data that 1s sent over the network and each connection has a queue on which the data is held while waiting to be transmitted The data is not removed from the queue until the receiver has acknowledged the reception of the data
77. tage before going through the LEDs 27 n LE LE Ei s a LECE Lac i i LECE Figure 3 9 Receiver Node Circuit Figure 3 10 shows the PCB layout for receiver node Double layer PCB circuit also was implemented for this node because of the complexity Li a Atmega 3535 RECEIVER NODE Figure 3 10 PCB Circuit Layout for Receiver Node 28 Figure 3 11 shows the transmitter node that was built in this project This board attached by receiver module to communicate with receiver Received data PORT C Data OE hex At temperature 27 C Figure 3 11 PCB Circuit for Receiver Node 3 2 5 RF Communication The wireless sensor network needs transmitter and receiver module to communicate between nodes So in this project the transmitter and receiver module from RADIOTRONIX are used to the purpose 20 3 2 5 1 Transmitter Module The RCT 433 AS is ideal for sensor network applications where low cost and longer range is required The transmitter operates from a 1 5 12V supply making it ideal for battery powered applications The transmitter employs a Surface Acoustic Wave SAW stabilized oscillator ensuring accurate frequency control for best range performance Output power and harmonic emissions are easy to control Figure 3 12 shows the transmitter module Figure 3 12 Transmitter Module 3 2 5 2 Receiver Module The RCR 433 HP is ideal for sensor network a
78. tain events should be 84 compiled in Useful mostly for debugging The function uip log char msg must be implemented to suit your architecture if logging is turned on define UIP LOGGING 0 UIP LLH LEN The link level header length this is the offset into the uip buf where the IP header can be found For Ethernet this should be set to 12 For SLIP this should be set to 0 define UIP LLH LEN 0 The following configuration options can be tweaked for your project but you are probably safe to use the default values The options are listed in order of tweakability ui UIP ARPTAB SIZE The size of the ARP table use a larger value if this uIP node will have many connections from the local network define UIP ARPTAB SIZE 8 The maxium age of ARP table entries measured in 10ths of seconds An UIP ARP MAXAGE of 120 corresponds to 20 minutes BSD default define UIP ARP MAXAGE 120 UIP RTO The retransmission timeout counted in timer pulses i e the speed of the periodic timer usually one second define UIP RTO 3 UIP MAXRTX The maximum number of times a segment should be retransmitted before the connection should be aborted define UIP MAXRTX 8 UIP TCP MSS The TCP maximum segment size This should be set to at most UIP BUFSIZE UIP LLH LEN 40 define UIP TCP MSS UIP BUFSIZE UIP LLH LEN 40 UIP TTL The IP TTL time to live of IP packets sent by uIP defi
79. ted to ALLAH SWT on His blessing to make this project began successfully I would like to take this opportunity to express my deepest gratitude to my beloved supervisor of this project Prof Dr Norsheila Bt Fisal who has relentlessly and tirelessly assisted me in completing this project She has given me support and insight in doing this project and has patiently listened and guided My utmost thanks also go to my family who has given me support throughout my academic years I also would like to express my gratitude to Mr Adel Mr Ariff Adib Aziz and my friends for the co operation during doing this project I also very big thank you to Hamka Mohd Harith who give support direct or indirectly to the project Once again thank you very much ABSTRACK A sensor network is a group of sensor nodes which are communicate among each other Sensors are constrained in terms of memory and processing power because of their limited physical size and cost These constraints have been considered too limiting for physical size sensor to be able to use the TCP IP protocols The purposed sensor node has ability to sense environmental data such as humidity light weight and temperature and has been ported with embedded TCP IP protocol to perform the networking The sensor node is equipped with a small microcontroller a RF communication module a sensor and an energy source This project was carried out to develop two nodes that also able to sense th
80. the sensor networks 2 3 3 Production costs Since the sensor networks consist of a large number of sensor nodes the cost of a single node is very important to justify the overall cost of the networks If the cost of the network is more expensive than deploying traditional sensors then the sensor network is not cost justified As a result the cost of each sensor node has to be kept low 2 3 4 Hardware constraints A sensor node is made up of four basic components as shown in Fig 2 1 a sensing unit a processing unit a transceiver unit and a power unit They may also have application dependent additional components such as a location finding system a power generator and a mobilizer Sensing units are usually composed of two subunits sensors and analog to digital converters ADCs The analog signals produced by the sensors based on the observed phenomenon are converted to digital signals by the ADC and then fed into the processing unit The processing unit which is generally associated with a small storage unit manages the procedures that make the sensor node collaborate with the other nodes to carry out the assigned sensing tasks A transceiver unit connects the node to the network One of the most important components of a sensor node is the power unit Power units may be supported by a power scavenging unit such as solar cells Sensing Unu Processing DN Processor Sensor ADC Transceiver Power Unit Figure 2 1 The
81. the timer driver and the device driver were developed After that those codes need to be compiled using a window platform of AVRGCC WinAVR as it can handled the compiling debugging and created the hex code as well Figure 3 10 shows the steps in designing the code programming After 36 compiling the hex file that produced was uploaded into the chip using PonyProg2000 The analog temperature that measured by the sensor firstly converted into digital value before transmitting and the received data were displayed at computer using Visual Basic interfacing Figure 3 22 shows the flow in designing the code programming TEES Programming Application s Flowchart Code using Setup Makefile Upload Code C ompile usin To target Device i ne g PonyProg2000 CAP errr rere Pee eer en LEKELERE IILIIIIITITPITITIPTTTTTTITT Figure 3 22 Steps in designing the code programming 3 3 1 Transmitter Node Figure 3 23 shows the flowchart for the overall transmitter node process Firstly the analogue value from the temperature sensor was measured and the value was 27 converted into digital value before processing In the processing part the data was added with the header TCP 20 bytes IP 20 bytes non standard link layer header 3 bytes After that the complete frame were transmitted using USART and this flow will be repeated for the next data NO Get input sensor UIP process IP
82. tor like package TO 46 metal can 23 transistor like package 8 lead surface mount SO 8 small outline package and TO 202 package Shown in the figure 3 4 Figure 3 4 LM335 TO 202 package Figure 3 5 shows the common used circuit for the sensor In this circuit parameter values commonly used are V 4 to 30v But 5v or 12 v are typical values used and Ra V 10 Actually it can range from 80 KW to 600 KW but most just use 80 KW Ve Figure 3 5 Common Used Circuit for LM35 DZ 24 The output voltage 1s converted to temperature by a simple conversion factor The sensor has a sensitivity of 10mV C Use a conversion factor that is the reciprocal that is 100V C The general equation used to convert output voltage to temperature is Temperature C Vout 100 C V So if Vout is 1V then Temperature 100 C The output voltage varies linearly with temperature 3 2 3 Transmitter Node Figure 3 6 shows the circuit constructed for the transmitter node that consists a microcontroller a temperature sensor a voltage regulator and other passive equipment The basic equipments for this microcontroller are the reset button and the oscillator circuit The purpose of the reset button is to reset the program that embedded in the microcontroller and it consists of a reset button a resistor and a capacitor Besides 8 MHz crystal oscillator is used to generate clocking for the microcontroller and it consists two
83. ttached to animals attached to fast moving vehicles and in a drain or river moving with current This list gives us an idea about under which conditions sensor nodes are expected to work They work under high pressure in the bottom of an ocean in harsh environments such as debris or a battlefield under extreme heat and cold such as in the nozzle of an aircraft engine or in arctic regions and in an extremely noisy environment such as under intentional jamming 2 3 7 Transmission media In a sensor network communicating nodes are linked by a wireless medium These links can be formed by radio infrared or optical media To enable global operation of these networks the chosen transmission medium must be available worldwide One option for radio links is the use of industrial scientific and medical ISM bands which offer license free communication in most countries The International Table of Frequency Allocations contained in Article S5 of the Radio 11 Regulations Volume 1 species some frequency bands that may be made available for ISM applications They are listed in Table 2 2 For sensor networks a small sized low cost ultra low power transceiver is required According to 68 certain hardware constraints and the trade off between antenna efficiency and power consumption limit the choice of a carrier frequency for such transceivers to the ultrahigh frequency range They also propose the use of the 433 MHz ISM ban
84. ty of the IP header if BUF gt vhl 0x45 IP version and header length JIP STAT 7ulp Sstatlsap cdrop UIP STAT TTULlD StadL lpvhlerr s UIP LOG ip invalid version or header length goto drop Check the size of the packet If the size reported to us in uip_len doesn t match the size reported in the IP header there has been a transmission error and we drop the packet rif UIP BUFSIZE gt 255 if BUF len 0 uip len UIP LLH LEN gt gt 8 UIP STAT 7U1pStatsap arop UIP STAT tTulD Stat ip hblenerr UIP LOG ip invalid length high byte IP length high byte HOLO drop 1f BUF gt len 1 uip len UIP LLH LEN amp Oxff WIP STAT p StdL tp dPop UIP_STAT uip_stat ip lblenerr UIP LOG ip invalid length low byte IP length low byte goto drop j else if BUF gt len 0 0 IP length high byte UIP STAT tuUi Stattpdrop UIP STAT ttuip StaLt ip hblenerr UIP_LOG ip invalid length high byte gore drop if BUF gt len 1 uip len UIP LLH LEN IP length low byte may UIP STAT TTUID SLabL ip drop UIP STAT t uip stat ip lblenerr UIP LOG ip invalid length low byte gOLO drop endif UIP BUFSIZE gt 255 if BUF gt ipoffset 0 amp Ox3f We don t allow IP fragments ae UIP STAT 7U10_Stat ip drop UIP STAT tt ip Stat ip rragerr UIP LOG ip fragment dropped
85. ubtracing the length of the TCP header in c and the length of the IP header 20 bytes uip len uip len c 20 First check if the sequence number of the incoming packet is what we re expecting next If not we send out an ACK with the correct numbers in if uip len gt 0 amp amp BUF 5seqno 0 uip conn rcv nxt 0 BUF 2segno l 1 wip conn rcev nxt ll BUF sSeqno 2 l9 uuip conn rcv nxt 2 BUF seqno 3 1s uip conn 5rcv nxt 3 9 4 goto tcp send ack Next check if the incoming segment acknowledges any outstanding date If 850 we also reset the retransmission timer if BUF gt ackno 0 uip_conn gt ack_nxt 0 amp amp BUF ackno 1 uip_conn gt ack_nxt 1 amp amp BUF gt ackno 2 uip_conn gt ack_nxt 2 amp amp BUF gt ackno 3 uip_conn gt ack_nxt 3 uip conn snd nxt 0 uip conn sck nxt 0 uip conn snd nxt l uip conn ack nxt 1 uip conn snd nxt 2 uxp conn ack nxcI 2 Urpeon5n sHnd nxt 15 uip conn ack mx cls if uip_conn gt tcpstateflags amp UIP OUTSTANDING uip flags UIP_ACKDATA ulp_conn gt tcpstateflags amp UIP OUTSTANDING rxp conn timer UIP RIO l Do different things depending on in what state the connection is a Switch uip_conn gt tcpstateflags amp TS MASK CLOSED and LISTEN Aare uot handled here CLOSE WAIT is not implemented since we force the application to close when the peer
86. void DDRB Oxff Configures PORTB as an output port DDRD Oxff Configures PORTD as an output port void ports set void PORTB Oxff Outputs Oxff to PORTB PORTD Oxff Outputs Oxff to PORTD void ports_clear void PORTB 0 Outputs 0 to PORTB PORTD 0 Outputs 0 to PORTD void start_signal void byte c for c 5 c gt 0 c PORTB amp _BV LED1 Bit clear Turn On LED1 delay_1ms 20 0 2 sec delay PORTB BV LED1 Bit set Turn Off LED1 delay_1ms 20 0 2 sec delay int main void ports_init Ports Initialization start signal Toggle LED1 five times while 1 Keeps toggling all ports every 0 5 sec ports set delay 1ms 50 ports clear delay 1ms 50 The above is example source code 3 Launch the DOS command line platform 4 Go to your WinAVR directory and select the folder which is the same as your board name 5 Type the command below and press Enter to compile the source code make all 6 Launch the PonyProg2000 program and download the generated hex file to your board Refer to How to use PonyProg for Microrobot AVR Products Eng pdf for details 7 To erase the files generated by the compiler use the following command make clean Useful Tips Just follow the above instructions first before studying the makefile make and avr gcc program These are quite complicated You don t have t
87. x eep from ELF output file hex elf echo echo MSG_FLASH OBJCOPY O FORMAT R eeprom lt eep elf echo echo MSG_EEPROM OBJCOPY j eeprom set section flags eeprom alloc load V change section Ima eeprom 0 O FORMAT lt Create extended listing file from ELF output file ss elf echo echo MSG_EXTENDED_LISTING OBJDUMP h S lt gt Create a symbol table from ELF output file sym elf echo echo MSG_SYMBOL_TABLE avr nm n lt gt Link create ELF output file from object files SECONDARY TARGET elf PRECIOUS OBJ elf OBJ echo echo MSG_LINKING CC ALL_CFLAGS OBJ output LDFLAGS Compile create object files from C source files 06 0 F c echo echo MSG_COMPILING lt CC c ALL_CFLAGS lt o Compile create assembler files from C source files s 96 c CC S ALL_CFLAGS lt o Assemble create object files from assembler source files 0 P S echo echo MSG_ASSEMBLING lt CC c ALL_ASFLAGS lt o Target clean project clean begin clean_list finished end clean_list echo echo MSG_CLEANING REMOVE TARGET hex REMOVE TARGET eep REMOVE TARGET obj REMOVE TARGET cof REMOVE TARGET elf REMOVE TARGET map REMOVE TARGET obj REMOVE TARGET a90 REMOVE TARGET sym REMOVE S TAR
88. y factors which include fault tolerance scalability production costs operating environment sensor network topology hardware constraints transmission media and power consumption These factors are addressed by many researchers as surveyed in the paper However none of these studies has a full integrated view of all factors that are driving the design of sensor networks and sensor nodes These factors are important because they serve as a guideline to design a protocol or an algorithm for sensor networks In addition these influencing factors can be used to compare different schemes 2 3 1 Fault tolerance Fault tolerance is the ability to sustain sensor network functionalities without any interruption due to sensor node failures Some sensor nodes may fail or be blocked due to lack of power have physical damage or environmental interference The failure of sensor nodes should not affect the overall task of the sensor network This is the reliability or fault tolerance issue As a result the fault tolerance level depends on the application of the sensor networks and the schemes must be developed with this in mind 2 3 2 Scalability The number of sensor nodes deployed in studying a phenomenon may be in the order of hundreds or thousands Depending on the application the number may reach an extreme value of millions The new schemes must be able to work with this number of nodes They must also utilize the high density nature of

Download Pdf Manuals

image

Related Search

Related Contents

  La Lettre électronique de Réseau  PDF, 2,50 MB - Cour des comptes  Samsung DB-P70 User Manual  Motorola D501 telephone  EH2426  KIT DE MARCHA EN PARALELO  Novosoft Mobile Instant Messenger  instalar sobre la estufa  Série ZD/ ZA/ ZR 330 – 644  

Copyright © All rights reserved.
Failed to retrieve file