+ All Categories
Home > Software > Developing MyTrafficCam

Developing MyTrafficCam

Date post: 27-Aug-2014
Category:
Upload: hean-hong-leong
View: 138 times
Download: 6 times
Share this document with a friend
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.
Popular Tags:
19
Developing MyTrafficCam Leong Hean Hong #HackerspaceJB #HSJB
Transcript
Page 1: Developing MyTrafficCam

Developing MyTrafficCamLeong Hean Hong

#HackerspaceJB #HSJB

Page 2: Developing MyTrafficCam

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

System Design

Sponsor: JLP Technologies

Page 4: Developing MyTrafficCam

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

Components In Web Service

Sponsor: Hongineer

Page 6: Developing MyTrafficCam

Software Stack

● CentOS● Apache● PHP 5.2

○ GluePHP (micro-framework)○ Twig Templating library

Sponsor: Property.cc

Page 7: Developing MyTrafficCam

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

Defining API

● Client makes request via HTTP● Response in JSON● API specifications documented in Google

Doc○ Establish standardization across team

Page 9: Developing MyTrafficCam

Defining API

Page 10: Developing MyTrafficCam

CodeFu Techniques

Page 11: Developing MyTrafficCam

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

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

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

AnalyticsGrowing from 6K to 8K visitors

Busy night...

Page 15: Developing MyTrafficCam

Analytics

More traffic in Sat/Sun

Page 16: Developing MyTrafficCam

Challenges

Page 17: Developing MyTrafficCam

● LLM Camera down frequently● Need more cameras● Cost of running MTC

Challenges

Page 18: Developing MyTrafficCam

Running Out Of Bandwidth

18.50 GB in July 2014

1.73 GB from single host


Recommended