Michigan State University ECE 480 Design Team 3 “Connect-on-Demand” Satellite/Radio Link for Tanzanian Schools Sponsored by: George & Vickie Rock & Dow Chemical Company Luis Garcia Eric Hatch Joe Larsen Michael Moulton Rafael Ocampo Rodney Singleton Dr. Selin Aviyente – Facilitator Wednesday, April 28, 2010
82
Embed
“Connect-on-Demand” Satellite/Radio Link for Tanzanian Schools
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Michigan State University
ECE 480
Design Team 3
“Connect-on-Demand” Satellite/Radio Link for Tanzanian Schools
Sponsored by: George & Vickie Rock
& Dow Chemical Company
Luis Garcia Eric Hatch Joe Larsen
Michael Moulton Rafael Ocampo
Rodney Singleton
Dr. Selin Aviyente – Facilitator
Wednesday, April 28, 2010
2
Executive Summary
In rural Africa MSU has a small network of schools sharing an Internet connection. The
Internet networking equipment is centrally located at Baraka Primary School, which subsequently
routes the Internet connection to other schools via WiFi and WiMAX. Unfortunate in terms of
power use, Baraka is solar-powered and this system is operating near capacity. As a result the
power usage of the networking equipment has to be configured to allow the expansion of the
network and allow Internet access in the evening, when the source of solar power (the sun) is no
longer available. Team 3 produced a system that powers on networking equipment when an end
user is attempting to access a website. When the Internet connection is idle, the equipment is turned
off. The networking equipment can be turned on and off from schools up to 5 miles away through
the use of a low power FM radio. This system has been tested to ensure it is power efficient and
requires little to no user interaction. In May 2010 this system will be installed in Tanzania. As a
result, another school can be added to the network without a significant increase of the solar system,
and students will have more access to the Internet, in terms of the time of day.
3
Acknowledgment
We would like to thank our sponsors, George & Vickie Rock as well as Dow Chemical
Company for the opportunity to work on a very challenging yet rewarding group project. Their
generous contributions helped us to acquire the equipment necessary for the development of our
final product.
Also, we would like to thank Professors Erik Goodman and Kurt DeMaadg for the
opportunity to travel to Tanzania where we will actually install and implement our working
prototype.
A special thanks to Eric Tarkleson for being our informant on what equipment in Tanzania
that we will have to interface with, as well as our liaison to suppliers located in Tanzania.
We would especially like to thank Greg Mulder for all his technical advice, and his keen
interest in particular to our project. His knowledge was just what we needed for our continual
progress. Without his expertise in amateur radio, we would not have been going in the direction
that led us to our success.
A very special thank you to the Radisson Hotel in downtown Lansing for supplying us with
a room on the top floor for the half an hour required for the FM radio link testing.
Finally, we would like Design Team 4 for a cooperative approach to solving one another’s design issues as they arise, as well integrating the computing stations to the “Connect-on-Demand” project.
4
Table of Contents Introduction ........................................................................................... 5
Only new hardware would be low power microcontroller, receiver, and relays. Power consumed would be very low. Wireless bridges would be turned off when not in use.
This would require a low power microcontroller, receiver, and router to place software on. The router would be an additional device that would have to be powered. But the wireless bridges could be powered off when not in use.
This would require a low power microcontroller and router to place software on. The router would always be on as would the wireless network bridges
Durability/Robustness Microcontroller, relays, and decoder will be placed inside of a protective case. Transmitter, receiver, and antennas will be exposed to the elements so smaller cases might have to be fabricated.
Microcontroller, relays, and decoder will be placed inside of a protective case. Transmitter, receiver, and antennas will be exposed to the elements so smaller cases might have to be fabricated.
All equipment would be housed inside of a protective case
Low Maintenance There will be an ability to remotely connect to administer software, but hardware will be designed to require as little servicing as possible
As long as there are no hardware failures almost all aspects of this system could be accessed remotely.
All components, other than relays and the microcontroller could be administered remotely as they would be software.
11
In determining the software that can be used to detect user generated requests there are
several options available. These range from developing an application using only modules or
libraries to handle low level details to modifying currently existing software to accommodate the
system requirements. The table below presents three options. Scapy and a shell script would
require the most testing and development time, but would allow for the most control over how the
system works. Tinyproxy is a piece of software which is considered to be very stable and mature.
Time would have to be invested in learning the functionality of existing code.
Networking Software Design Justification Table
Scapy Tinyproxy Shell Script Durability/Robustness Scapy is a powerful
program, but has proven that it can
crash unexpectedly in testing.
This would require a lot of error detection
to prevent the application from malfunctioning.
Tinyproxy has been in use for a very long time and has been
proven to be effective.
The functionality that would be added would
be minimal.
Currently being used in Tanzania.
While this application could be run in a shell script, these scripts are meant for batch jobs,
not demons running in the background.
Reading and writing to a file at the same would most likely make this option
unstable. Low Maintenance Application could be
easily modified without recompiling
the program.
There is an extensive configuration file that could be easily edited. If a program bug has
to be fixed the application will have
to be recompiled.
This would probably have to be restarted multiple times in a day and edited for
efficiency after installation in
Tanzania. Safety This would be
accessible by only those with sudo or
root privileges. But no physical risk would be
associated with this software.
This would be accessible by only those with sudo or
root privileges. But no physical risk would be
associated with this software.
This would be accessible by only those with sudo or
root privileges. But no physical risk would be
associated with this software.
Low Cost Free and open source Free and open source Free and open source
12
Team 3 is also responsible for selecting a device to use for the network bridge between
Baraka Primary School and Rift Valley Primary School. Several devices where considered that
could meet the distance requirements and operate in the unlicensed spectrum. Below are the two
solutions that were considered.
Wireless Data Bridge Justification Table
Ligo Point to Point 5 GHz Motorola Canopy Point to Point 2.4 GHz Low Power Consumption (At Baraka)
Maximum power consumption of 12 W. This will probably be adjusted to something less as the transmission only needs to go 5 to 6 miles while the device has a maximum range of 25 miles.
The maximum power consumption would be 8.2 W. This can be adjusted to a lower amount as the maximum range of the devices is 35 miles.
Durability/Robustness This device is built for rugged outdoor environments. It is able to handle the temperatures of up to 60 degrees Celsius. The average temperature in Tanzania is 27 degrees Celsius.
This device is designed for outdoor use and has an expected mean time between failures of 40 years. The maximum operating temperature is 55 degrees Celsius and can survive wind speeds of up to 190 km/hr.
Low Maintenance This device simply has to be attached to an existing network via Ethernet. Management can be preformed through the browser or via SSH. This will allow for remote maintenance from MSU.
This device simply has to be attached to an existing network via Ethernet. Management can be preformed through the browser or via Telnet or FTP. This will allow for remote maintenance from MSU, the connection may be unsecure. If the device had to be replaced the reflector dish would most likely make removal and installation more cumbersome.
Safety The primary physical safety concern is individuals climbing up on a roof or pole to access the device. Best solution for this is to restrict access to the devices in Tanzania by placing Acacia branches at physical access points.
The primary physical safety concern is individuals climbing up on a roof or pole to access the device. Best solution for this is to restrict access to the devices in Tanzania by placing Acacia branches at physical access points.
Low Cost $1912.00 (2 antennas, power adapters, and mounting brackets)
$2017.60 (2 antennas, power adapters, and mounting brackets)
13
While not part of our design criteria, a consideration must be taken into account is the ease
at which equipment can be transported to Tanzania after testing in the United States. As a result of
being smaller, the Ligo PTP 5-23 is a better option, as it does not have a bulky reflector dish.
The table below shows some of the consideration that went into choosing what type of radio
will be used for the radio link. The FM radio ended up being the best choice overall.
Justification Table for radio link
Design Criteria AM Radio FM Radio no-modulation 'RF tone' Receiver Power Consumption
low higher very low
Robustness -more prone to interference -able to send encoded signal
-more reliable in adverse conditions -able to send encoded signal
-most reliable -only able to send one command (two are needed)
http://tism.msu.edu/favicon.ico HTTP/1.1 5. INFO Apr 25 16:59:01 [23241]: No proxy for tism.msu.edu 6. CONNECT Apr 25 16:59:01 [23241]: Established connection to host
"tism.msu.edu" using file descriptor 7. 7. INFO Apr 25 16:59:01 [23241]: Closed connection between local client
(fd:6) and remote client (fd:7)
In Firefox the webpage loaded as expected. At line 1 of the tinyproxy.log file, it shows the
Python script was executed to check for an IP address. Then at line 2 the log file show an Internet
connection was detected successfully. Tinyproxy finally continues on to send out the user request
and return it to the user when a response from tism.msu.edu is received. Python.log:
2010-04-25 16:59:01 STATUS Internet Connection Confirmed 2010-04-25 16:59:01 STATUS Sending turn on single 2010-04-25 16:59:01 CLOSING
The Python.log file looks as we would expect it to. It shows the script starting and since
there is an active Internet connection, at least one of the sites (google.com, yahoo.com, bbc.com)
can be pinged successfully. A turn on signal is sent and the script exits. It is evident from the time
stamps these log entries occurred at the same time. Under the testing conditions it can be concluded
they refer to the same HTTP requests. The next step is to test the ability to cache a user request.
43
To test this functionality the Ethernet cable was unplugged from the computer and a request
was made from Firefox. This time cnn.com was visited because tism.msu.edu has been cached by
Tinyproxy and the request may not have gone out to the network. Under normal circumstances
Firefox would timeout, but the screen simply appears as though it is loading:
Figure T.9: Normally when an Internet connection is not available Firefox would immediately time-out.
The output form tinyproxy.log is:
1. CONNECT Apr 25 17:18:25 [24211]: Beginning IP test
This output only shows one line. That one line was the python application being executed. The log
does not show successful completion of the script or an error being returned. This means the python
application was running, if we look at the output for python.log this is confirmed: 2. 2010-04-25 17:17:58 STARTING Entering main loop. 3. 2010-04-25 17:17:58 STATUS Sending turn on single 4. 2010-04-25 17:17:58 STATUS Connection invalid, sending Turn on signal 5. 2010-04-25 17:17:58 STATUS turn on signal has been sent 1 times 6. 2010-04-25 17:18:03 STATUS Sending turn on single 7. 2010-04-25 17:18:03 STATUS Connection invalid, sending Turn on signal 8. 2010-04-25 17:18:03 STATUS turn on signal has been sent 2 times 9. 2010-04-25 17:18:08 STATUS Sending turn on single 10. 2010-04-25 17:18:08 STATUS Connection invalid, sending Turn on
signal 11. 2010-04-25 17:18:08 STATUS turn on signal has been sent 3 times
44
It should be noted that the output is truncated as it is rather long. The timestamps can be
compared to from the two log outputs to show the events are related. The python.log file repeatedly
shows no Internet connection being detected. After each failed attempt to detect a connection a turn
on signal is sent and the loop continues. The last set is to plug the Ethernet cable back into the
computer to simulate an Internet connection becoming available.
After a couple of seconds the output from python.log is very similar to when there was an
active Internet connection. This means an Internet connection was successfully detected. The
Python script exited and allowed Tinyproxy to send out the HTTP request. The applicable log
entries are below: 1. 2010-04-25 17:23:38 STATUS Internet Connection Confirmed 2. 2010-04-25 17:23:38 STATUS Sending turn on single 3. 2010-04-25 17:23:38 CLOSING
By looking at the output from tinyproxy.log it is also evident that the Python script
completed successfully (line 2 below). And the request was sent onto cnn.com. A response was then
received from the web server and the connection was closed: 1. CONNECT Apr 25 17:18:25 [24211]: Beginning IP test
Notes:R1: Satellite Router and Satellite AntennaR2: No longer usedR3: Rift Valley Secondary SchoolR4: Manyara Secondary School9 PIN D connector is female
AC Circuit
DC Circuit
Timer
Outlet Box (Baraka)
60
Tinyproxy
Computer
UPS(240 VAC)
Wireless Router
Tone Producer
FM Radio Transmitter
24VDC Power Supply
POEAdapter
UPS(240 VAC)
Wireless Repeater
WiMAX Antenna
24VDC Power Supply
FM Radio Receiver
FM Radio Transmitter
UPS(240 VAC)
24VDC Power Supply
Tinyproxy
Tone Producer
POEAdapter
WiFi Antenna
FM Radio Transmitter
24VDC Photovoltaic
System
12VDC Photovoltaic
System
Tinyproxy
120VAC Inverter
FM Radio Receiver
Microcontroller
240VAC Inverter
Tone Decoder
Outlet Box
POE Adapter
WiFi Antenna
POE Adapter
WiMAX Antenna
Satellite Router
Satellite Antenna
Computer
Computer
To Baraka To Baraka
To Baraka To Baraka
From ManyaraFrom Rift Valley
From Rift Valley From Manyara
Baraka
Rift Valley Manyara
PowerDataRemote ControlWireless DataWireless Remote Control
Overall Schematic in Tanzania
61
5
2.5
2.2k
2.2k1µ
U1: LM324NRelay: EC2-5NJ
24
LM7508AR1
5
from computer
24
R11N4148
TIP31A
+
-
5
2.5
U1b
0.022µ
2.5 2.5
68k
2.2k 2.2k
2.2k
0.022µ 0.022µ
+
-
5
2.5
U1c
0.05µ
2.5 2.5
330k
10k 10k
10k
0.05µ 0.05µ
+
-
5
2.5
U1d
10k
10k
5.6k
5
2.5
-
+U1a
1k
5
9-pin Dpin 4
pin 5
370
600 (3 - 1.8k in parallel)
RF SolutionsRTFQ2
1 2 3 4 5
5VDATA
GND
Audio Cable
Manyara
2.24kHz
234Hz
Tone Generator (Manyara)
62
5
2.5
2.2k
2.2k1µ
U1: LM324NRelay: EC2-5NJ
24
LM7508AR1
5
from computer
24
R11N4148
TIP31A
+
-
5
2.5
U1b
0.01µ
2.5 2.5
82k
2.7k 2.7k
2.7k
0.01µ 0.01µ
+
-
5
2.5
U1c
0.1µ
2.5 2.5
82k
2.7k 2.7k
2.7k
0.1µ 0.1µ
+
-
5
2.5
U1d
10k
10k
5.6k
5
2.5
-
+U1a
1k
5
9-pin Dpin 4
pin 5
370
600 (3 - 1.8k in parallel)
RF SolutionsRTFQ2
1 2 3 4 5
5VDATA
GND
Audio Cable
Rift Valley
1.31kHz
123Hz
Tone Generator (Rift Valley)
63
PIC18F4520 Code #include <p18cxxx.h> #include <ADC.h> #pragma config WDT=OFF //Initialization of parameters long int count, count2, bcd,rcd,mcd, bflag, rflag, mflag, mflash, rflash, bflash, mto, rto, saton, curfew, decrec, reboot;//countdown=1800, count=250000 int adc_result, loop; void main() TRISD = 0xF0; TRISC = 0x00; OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_12_TAD, ADC_CH0 & ADC_INT_OFF, 0); //open adc port for reading ADCON1 =0x10; //set VREF+ to CH3 and VREF- to GND (VSS) //First case is annotated to show what each line of code does //All other cases follow the same logic with few deviation while(1) //**********While no requests are being made. Turns on the decoder if the reboot flag is set**********// while (PORTDbits.RD6==0 & PORTDbits.RD5==0 & PORTDbits.RD4==0) PORTCbits.RC6 = 0; PORTCbits.RC7 = 0; if (reboot==1) PORTCbits.RC7 = 1; for (count = 1; count < 300000; count++); PORTCbits.RC7 = 0; decrec=0; reboot=0; PORTCbits.RC5 = 0; PORTCbits.RC4 = 0; PORTDbits.RD3 = 0; //Case 1: Only Baraka makes a request //Baraka Request if(PORTDbits.RD6==1) for (count = 1; count < 300000; count++); if(PORTDbits.RD6==1) bflash=1;
64
//Pulse code if (bflash==1) PORTCbits.RC5 = 1; for (count = 1; count < 300000; count++); PORTCbits.RC5 = 0; bflash=0; bcd=50; //Starts countdown while(bcd>0) bflash=1; decrec=1; //Battery Check SetChanADC(ADC_CH0); ConvertADC(); //perform ADC conversion while(BusyADC()); //wait for result adc_result = ReadADC(); //get ADC result if (PORTDbits.RD7==0) curfew=1; //Interrupt runs as long as battery is lower than 13.5 Volts or curfew flag is set for 11pm while(adc_result<0x03DC || curfew==1) bcd=0; //Shuts down components that are on at the time if (bflash==1) PORTCbits.RC5 = 1; for (count = 1; count < 300000; count++); PORTCbits.RC5 = 0; if (decrec==1) PORTCbits.RC6 = 1; for (count = 1; count < 300000; count++); PORTCbits.RC6 = 0; decrec=0; reboot=1; bflash=0; //Continues to check battery SetChanADC(ADC_CH0);
65
ConvertADC(); //perform ADC conversion while(BusyADC()); //wait for result adc_result = ReadADC(); //get ADC result //if battery voltage is still lower than desired, sets the reading to 0 to keep it in the loop if(adc_result<0x03F2) adc_result=0x00; //If daytime signal is given, takes the program out of the loop if (PORTDbits.RD7==1) curfew=0; //Timeout Programming for(count = 1; count < 250000; count++); bcd--; //When another Baraka request is made, it resets the timer if(PORTDbits.RD6==1) //safety check to make sure it’s an actual request coming in and not just noise for (count = 1; count < 300000; count++); if(PORTDbits.RD6==1) bcd=50; //Manyara request during Baraka countdown. Breaks program if(PORTDbits.RD5==1) for (count = 1; count < 300000; count++); if(PORTDbits.RD5==1) mflag=1; break; //Rift Valley request during Baraka countdown. Breaks program if(PORTDbits.RD4==1) for (count = 1; count < 300000; count++); if(PORTDbits.RD4==1) rflag=1; break; //Red light flash for timeout if(bcd==0) if (bflash==1) PORTCbits.RC5 = 1;
66
for (count = 1; count < 300000; count++); PORTCbits.RC5 = 0; bflash=0; if(PORTDbits.RD6==1) bcd=50; //**********Individual Manyara Request**********// if(PORTDbits.RD5==1) for (count = 1; count < 300000; count++); if(PORTDbits.RD5==1) saton=1; mflag=1; //**********Individual Rift Valley Request**********// if(PORTDbits.RD4==1) for (count = 1; count < 300000; count++); if(PORTDbits.RD4==1) saton=1; rflag=1; rto=1; //**********Case 2: Rflag bit is set. When the last request made is from Rift Valley**********// if (rflag==1) //Turns on satellite if it isn't already on if (saton==1) if (bflash==0) PORTCbits.RC5 = 1; for (count = 1; count < 300000; count++); PORTCbits.RC5 = 0; saton=0; //turns on WiMAX if it isn't already on if (rto==1) PORTCbits.RC4 = 1; for (count = 1; count < 300000; count++); PORTCbits.RC4 = 0;
67
rto=0; bcd=50; rcd=50; rflag=0; //Runs countdown based off satellite while(bcd>0) bflash=1; decrec=1; //Battery Check SetChanADC(ADC_CH0); ConvertADC(); //perform ADC conversion while(BusyADC()); //wait for result adc_result = ReadADC(); //get ADC result if (PORTDbits.RD7==0) curfew=1; //Program halt while(adc_result<0x03DC || curfew==1) bcd=0; mcd=0; rcd=0; //Shuts down everything that is in use if (mflash==1) PORTDbits.RD3 = 1; for (count = 1; count < 300000; count++); PORTDbits.RD3 = 0; mflash=0; if (rflash==1) PORTCbits.RC4 = 1; for (count = 1; count < 300000; count++); PORTCbits.RC4 = 0; rflash=0; if (bflash==1) PORTCbits.RC5 = 1; for (count = 1; count < 300000; count++); PORTCbits.RC5 = 0; bflash=0; if (decrec==1)
68
PORTCbits.RC6 = 1; for (count = 1; count < 300000; count++); PORTCbits.RC6 = 0; decrec=0; reboot=1; SetChanADC(ADC_CH0); ConvertADC(); //perform ADC conversion while(BusyADC()); //wait for result adc_result = ReadADC(); //get ADC result if(adc_result<0x03F2) adc_result=0x00; if (PORTDbits.RD7==1) curfew=0; //Timeout Programming for(count = 1; count < 40000; count++); if (rcd>0) rflash=1; rcd--; if (mcd>0) mflash=1; mcd--; bcd--; //Checks for new requests and resets respective timers. Also turns on what needs to be used if(PORTDbits.RD6==1) for (count = 1; count < 300000; count++); if(PORTDbits.RD6==1) bcd=50; if(PORTDbits.RD4==1) for (count = 1; count < 300000; count++); if(PORTDbits.RD4==1) if (rto==1) PORTCbits.RC4 = 1; for (count = 1; count < 300000; count++); PORTCbits.RC4 = 0; rto=0; rcd=50;
69
bcd=50; if(PORTDbits.RD5==1) for (count = 1; count < 300000; count++); if(PORTDbits.RD5==1) if (mto==1) PORTDbits.RD3 = 1; for (count = 1; count < 300000; count++); PORTDbits.RD3 = 0; mto=0; bcd=50; mcd=50; //Red light pulse for timeout works individually if(rcd==0) if (rflash==1) PORTCbits.RC4 = 1; for (count = 1; count < 300000; count++); PORTCbits.RC4 = 0; rflash=0; rto=1; if(PORTDbits.RD4==1) bcd=50; rcd=50; if(mcd==0) if (mflash==1) PORTDbits.RD3 = 1; for (count = 1; count < 300000; count++); PORTDbits.RD3 = 0; mflash=0; mto=1; if(PORTDbits.RD5==1) bcd=50; mcd=50; if(bcd==0)
70
if (bflash==1) PORTCbits.RC5 = 1; for (count = 1; count < 300000; count++); PORTCbits.RC5 = 0; bflash=0; mflag=0; rflag=0; //**********Case 3: Rflag bit is set. When the last request made is from Manyara. Follows the same protocol as RFlag**********// if (mflag==1) if (saton==1) if (bflash==0) PORTCbits.RC5 = 1; for (count = 1; count < 300000; count++); PORTCbits.RC5 = 0; saton=0; bcd=50; mcd=50; mflag=0; while(bcd>0) bflash=1; decrec=1; //Battery Check SetChanADC(ADC_CH0); ConvertADC(); //perform ADC conversion while(BusyADC()); //wait for result adc_result = ReadADC(); //get ADC result if (PORTDbits.RD7==0) curfew=1; while(adc_result<0x03DC || curfew==1) bcd=0; mcd=0; rcd=0; if (mflash==1) PORTDbits.RD3 = 1; for (count = 1; count < 300000; count++); PORTDbits.RD3 = 0;
71
mflash=0; if (rflash==1) PORTCbits.RC4 = 1; for (count = 1; count < 300000; count++); PORTCbits.RC4 = 0; rflash=0; if (bflash==1) PORTCbits.RC5 = 1; for (count = 1; count < 300000; count++); PORTCbits.RC5 = 0; bflash=0; if (decrec==1) PORTCbits.RC6 = 1; for (count = 1; count < 300000; count++); PORTCbits.RC6 = 0; decrec=0; reboot=1; SetChanADC(ADC_CH0); ConvertADC(); //perform ADC conversion while(BusyADC()); //wait for result adc_result = ReadADC(); //get ADC result if(adc_result<0x03F2) adc_result=0x00; if (PORTDbits.RD7==1) curfew=0; //Timeout Programming for(count = 1; count < 40000; count++); if (rcd>0) rflash=1; rcd--; if (mcd>0) mflash=1; mcd--; bcd--; if(PORTDbits.RD6==1) for (count = 1; count < 300000; count++); if(PORTDbits.RD6==1) bcd=50;
72
if(PORTDbits.RD4==1) for (count = 1; count < 300000; count++); if(PORTDbits.RD4==1) if (rto==1) PORTCbits.RC4 = 1; for (count = 1; count < 300000; count++); PORTCbits.RC4 = 0; rto=0; rcd=50; bcd=50; if(PORTDbits.RD5==1) for (count = 1; count < 300000; count++); if (PORTDbits.RD5==1) if (mto==1) PORTDbits.RD3 = 1; for (count = 1; count < 300000; count++); PORTDbits.RD3 = 0; mto=0; bcd=50; mcd=50; //Red light for timeout if(rcd==0) if (rflash==1) PORTCbits.RC4 = 1; for (count = 1; count < 300000; count++); PORTCbits.RC4 = 0; rflash=0; rto=1; if(PORTDbits.RD4==1) bcd=50; rcd=50; if(mcd==0)
The following code was added to the file reqc.c located in the tinyproxy root/src
directory. The function that was edited is handle_connection(). This code was placed at the
beginning of the function.
void handle_connection (int fd) int res; /* This is in the original Tinyproxy Source Code */ ssize_t i; struct conn_s *connptr; struct request_s *request = NULL; hashmap_t hashofheaders = NULL; char sock_ipaddr[IP_LENGTH]; char peer_ipaddr[IP_LENGTH]; char peer_string[HOSTNAME_LENGTH]; /*End of original source code */ /* code added for ECE project */ log_message (LOG_CONN, "Beginning IP test"); / res = system ("/home/ece480/test/test.py");
/*Call being made to python script */ if (res == 0)
log_message (LOG_CONN, "Connection Confirmed");
log_message (LOG_CONN, "Error Running Python Script"); else log_message (LOG_CONN, "Error Running Python Script"); /* End of modifications to Tiny proxy */
75
Python Script Source Code #! /usr/bin/python import sys import time import subprocess import serial saveout=sys.stdout fsock=open("/usr/local/var/log/python.log","a") def getIP(): # This function checks to see if the Internet is accessible via a # a ping. It pings Google, yahoo, and bib. Upon one of these being # successful the function returns True. If none of they are # reachable the function returns False domains = ["google.com", "yahoo.com", "bbc.com"] for domain in domains: ret = subprocess.call("ping -c 1 %s" % domain, shell=True) if ret==0: return True else: return False def exiting(): # This is a function that is used to clean up all loose ends when # ending this script. This includes, writing the exit to the log # redirecting stdout back to the terminal (or where ever it has to # go and closing the log file. print "%s CLOSING" % time.strftime("%Y-%m-%d %H:%M:%S") sys.stdout=saveout fsock.close sys.exit(0) def sendSig():
# This function is where a call will be made to send a turn on signal # to Baraka from the satellite school (At time of writing this Rift Valley # and Manyara Secondary) # All this does is open a serial connection for 1 second and then closes it.
# this allows a signal to be sent to the transmitter. print "%s STATUS Sending turn on single" \
# This is a where almost everything happens, like all good programs this is # rather short and should be easy to follow. All that is happening here # is there is a loop that is started which looks for the and active
Internet # connection. # If it is detected the loop breaks and the program exits. # If the is no Internet connection valid then a turn on signal is sent # and the loop continues until an active connection is detected.
sys.stdout=fsock print "%s STARTING Entering main loop." \ % (time.strftime("%Y-%m-%d %H:%M:%S")) count=0 while True: n=getIP() if n==True: print "%s STATUS Internet Connection Confirmed" \ % time.strftime("%Y-%m-%d %H:%M:%S") sendSig() exiting() break else: sendSig()
print "%s STATUS Connection invalid, sending Turn on signal" \ % (time.strftime("%Y-%m-%d %H:%M:%S")) count+=1 print "%s STATUS turn on signal has been sent %d times" \ % (time.strftime("%Y-%m-%d %H:%M:%S"), count) time.sleep(5) main()
77
Gantt Chart (Screenshots go in order from top-left to bottom-right)