Sharing of how I build a web service for monitoring traffic condition in Malaysia-Singapore border. A community project by HackerspaceJB, in Johor Bahru.
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
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
7. Development Tools
● Sublime Text
○ Programming editor
● Filezilla
○ For deployment on production server
● Git
○ Source control
● Bitbucket
○ Free private repo
○ Code backup
8. Defining API
● Client makes request via HTTP
● Response in JSON
● API specifications documented in Google
Doc
○ Establish standardization across team
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. 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. Rate-limiting Control
● Log IP address
● Allow not more than 10 requests per second
per IP
○ Currently we have only 6 cameras