Developing MyTrafficCam

351 views

Published on

Sharing of how I build a web service for monitoring traffic condition in Malaysia-Singapore border. A community project by HackerspaceJB, in Johor Bahru.

Published in: Software
2 Comments
3 Likes
Statistics
Notes
No Downloads
Views
Total views
351
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
4
Comments
2
Likes
3
Embeds 0
No embeds

No notes for slide

Developing MyTrafficCam

  1. 1. Developing MyTrafficCam Leong Hean Hong #HackerspaceJB #HSJB
  2. 2. 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
  3. 3. System Design Sponsor: JLP Technologies
  4. 4. 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
  5. 5. Components In Web Service Sponsor: Hongineer
  6. 6. Software Stack ● CentOS ● Apache ● PHP 5.2 ○ GluePHP (micro-framework) ○ Twig Templating library Sponsor: Property.cc
  7. 7. Development Tools ● Sublime Text ○ Programming editor ● Filezilla ○ For deployment on production server ● Git ○ Source control ● Bitbucket ○ Free private repo ○ Code backup
  8. 8. Defining API ● Client makes request via HTTP ● Response in JSON ● API specifications documented in Google Doc ○ Establish standardization across team
  9. 9. Defining API
  10. 10. CodeFu Techniques
  11. 11. Time-sensitive Photo public static function photoURL($camId) { $time = time(); return "/photo/{$camId}/{$time}/".self::genHash($camId, $time); } Add timestamp to photo URL, expires in 5 seconds
  12. 12. Tie Photo To Client’s IP public 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
  13. 13. Rate-limiting Control ● Log IP address ● Allow not more than 10 requests per second per IP ○ Currently we have only 6 cameras
  14. 14. Analytics Growing from 6K to 8K visitors Busy night...
  15. 15. Analytics More traffic in Sat/Sun
  16. 16. Challenges
  17. 17. ● LLM Camera down frequently ● Need more cameras ● Cost of running MTC Challenges
  18. 18. Running Out Of Bandwidth 18.50 GB in July 2014 1.73 GB from single host
  19. 19. Feedback support@mytrafficcam.com

×