Date post: | 27-Aug-2014 |
Category: |
Software |
Upload: | hean-hong-leong |
View: | 138 times |
Download: | 6 times |
Developing MyTrafficCamLeong Hean Hong
#HackerspaceJB #HSJB
About
● MTC shows traffic condition for JB-SG travellers
● MTC aggregates cameras from different sources
● I talk about how it works● Share collected data● Describe some of the challenges
System Design
Sponsor: JLP Technologies
System Design
● Camera sources○ LTA (Singapore)○ LLM (Malaysia)○ Own camera @ Menara Cyberport
● Providing feed to○ Mobile clients (iOS + Android)○ Partner’s website
Sponsor: Common Extract
Components In Web Service
Sponsor: Hongineer
Software Stack
● CentOS● Apache● PHP 5.2
○ GluePHP (micro-framework)○ Twig Templating library
Sponsor: Property.cc
Development Tools
● Sublime Text○ Programming editor
● Filezilla○ For deployment on production server
● Git○ Source control
● Bitbucket○ Free private repo○ Code backup
Defining API
● Client makes request via HTTP● Response in JSON● API specifications documented in Google
Doc○ Establish standardization across team
Defining API
CodeFu Techniques
Time-sensitive Photopublic static function photoURL($camId) {
$time = time();
return "/photo/{$camId}/{$time}/".self::genHash($camId, $time);
}
Add timestamp to photo URL, expires in 5 seconds
Tie Photo To Client’s IPpublic static function photoURL($camId) {
return strtr('http://:host/v1api/photo/:camId/:hash', array(
':host' => $_SERVER['HTTP_HOST'],
':camId' => $camId,
':hash' => self::photoHash($camId)
));
}
protected static function photoHash($camId) {
return sha1(self::HASH_KEY.$camId.$_SERVER['REMOTE_ADDR']);
}
Prevent reuse of photo across devices
Rate-limiting Control
● Log IP address● Allow not more than 10 requests per second
per IP○ Currently we have only 6 cameras
AnalyticsGrowing from 6K to 8K visitors
Busy night...
Analytics
More traffic in Sat/Sun
Challenges
● LLM Camera down frequently● Need more cameras● Cost of running MTC
Challenges
Running Out Of Bandwidth
18.50 GB in July 2014
1.73 GB from single host