Advertisement
Guest User

Openhab commuting Time

a guest
Aug 16th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. <?php
  2. $string = file_get_contents("http://dev.virtualearth.net/REST/V1/Routes/Driving?o=json&wp.0=***waypoint1***&wp.1=***waypoint2***&avoid=minimizeTolls&optmz=timeWithTraffic&routeAttributes=routeSummariesOnly&key=***apikey***");
  3. $json = json_decode($string, true);
  4. $json = $json[resourceSets][0][resources][0];
  5.  
  6. $travelDuration = round($json["travelDuration"]/60);
  7. $travelDurationTraffic = round($json["travelDurationTraffic"]/60);
  8. $travelDistance = $json["travelDistance"];
  9.  
  10. if ($travelDurationTraffic != 0) {
  11. sendCommand("Work_TimeNormal",$travelDuration);
  12. sendCommand("Work_TimeTraffic",$travelDurationTraffic);
  13. sendCommand("Work_KM",$travelDistance);
  14. }
  15.  
  16. function sendCommand($item, $data) {
  17. $url = "http://127.0.0.1:8080/rest/items/" . $item;
  18. $options = array(
  19. 'http' => array(
  20. 'header' => "Content-type: text/plain\r\n",
  21. 'method' => 'POST',
  22. 'content' => (string)$data,
  23. ),
  24. );
  25.  
  26. $context = stream_context_create($options);
  27. $result = file_get_contents($url, false, $context);
  28.  
  29. return $result;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement