developing mytrafficcam
DESCRIPTION
Sharing of how I build a web service for monitoring traffic condition in Malaysia-Singapore border. A community project by HackerspaceJB, in Johor Bahru.TRANSCRIPT
![Page 1: Developing MyTrafficCam](https://reader035.vdocuments.us/reader035/viewer/2022081804/53fd96ea8d7f72a81c8b49ab/html5/thumbnails/1.jpg)
Developing MyTrafficCamLeong Hean Hong
#HackerspaceJB #HSJB
![Page 2: Developing MyTrafficCam](https://reader035.vdocuments.us/reader035/viewer/2022081804/53fd96ea8d7f72a81c8b49ab/html5/thumbnails/2.jpg)
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
![Page 3: Developing MyTrafficCam](https://reader035.vdocuments.us/reader035/viewer/2022081804/53fd96ea8d7f72a81c8b49ab/html5/thumbnails/3.jpg)
System Design
Sponsor: JLP Technologies
![Page 4: Developing MyTrafficCam](https://reader035.vdocuments.us/reader035/viewer/2022081804/53fd96ea8d7f72a81c8b49ab/html5/thumbnails/4.jpg)
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
![Page 5: Developing MyTrafficCam](https://reader035.vdocuments.us/reader035/viewer/2022081804/53fd96ea8d7f72a81c8b49ab/html5/thumbnails/5.jpg)
Components In Web Service
Sponsor: Hongineer
![Page 6: Developing MyTrafficCam](https://reader035.vdocuments.us/reader035/viewer/2022081804/53fd96ea8d7f72a81c8b49ab/html5/thumbnails/6.jpg)
Software Stack
● CentOS● Apache● PHP 5.2
○ GluePHP (micro-framework)○ Twig Templating library
Sponsor: Property.cc
![Page 7: Developing MyTrafficCam](https://reader035.vdocuments.us/reader035/viewer/2022081804/53fd96ea8d7f72a81c8b49ab/html5/thumbnails/7.jpg)
Development Tools
● Sublime Text○ Programming editor
● Filezilla○ For deployment on production server
● Git○ Source control
● Bitbucket○ Free private repo○ Code backup
![Page 8: Developing MyTrafficCam](https://reader035.vdocuments.us/reader035/viewer/2022081804/53fd96ea8d7f72a81c8b49ab/html5/thumbnails/8.jpg)
Defining API
● Client makes request via HTTP● Response in JSON● API specifications documented in Google
Doc○ Establish standardization across team
![Page 9: Developing MyTrafficCam](https://reader035.vdocuments.us/reader035/viewer/2022081804/53fd96ea8d7f72a81c8b49ab/html5/thumbnails/9.jpg)
Defining API
![Page 10: Developing MyTrafficCam](https://reader035.vdocuments.us/reader035/viewer/2022081804/53fd96ea8d7f72a81c8b49ab/html5/thumbnails/10.jpg)
CodeFu Techniques
![Page 11: Developing MyTrafficCam](https://reader035.vdocuments.us/reader035/viewer/2022081804/53fd96ea8d7f72a81c8b49ab/html5/thumbnails/11.jpg)
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
![Page 12: Developing MyTrafficCam](https://reader035.vdocuments.us/reader035/viewer/2022081804/53fd96ea8d7f72a81c8b49ab/html5/thumbnails/12.jpg)
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
![Page 13: Developing MyTrafficCam](https://reader035.vdocuments.us/reader035/viewer/2022081804/53fd96ea8d7f72a81c8b49ab/html5/thumbnails/13.jpg)
Rate-limiting Control
● Log IP address● Allow not more than 10 requests per second
per IP○ Currently we have only 6 cameras
![Page 14: Developing MyTrafficCam](https://reader035.vdocuments.us/reader035/viewer/2022081804/53fd96ea8d7f72a81c8b49ab/html5/thumbnails/14.jpg)
AnalyticsGrowing from 6K to 8K visitors
Busy night...
![Page 15: Developing MyTrafficCam](https://reader035.vdocuments.us/reader035/viewer/2022081804/53fd96ea8d7f72a81c8b49ab/html5/thumbnails/15.jpg)
Analytics
More traffic in Sat/Sun
![Page 16: Developing MyTrafficCam](https://reader035.vdocuments.us/reader035/viewer/2022081804/53fd96ea8d7f72a81c8b49ab/html5/thumbnails/16.jpg)
Challenges
![Page 17: Developing MyTrafficCam](https://reader035.vdocuments.us/reader035/viewer/2022081804/53fd96ea8d7f72a81c8b49ab/html5/thumbnails/17.jpg)
● LLM Camera down frequently● Need more cameras● Cost of running MTC
Challenges
![Page 18: Developing MyTrafficCam](https://reader035.vdocuments.us/reader035/viewer/2022081804/53fd96ea8d7f72a81c8b49ab/html5/thumbnails/18.jpg)
Running Out Of Bandwidth
18.50 GB in July 2014
1.73 GB from single host