Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. var mqtt;
  2. //var host = "labsmartcity.uni.edu.pe"
  3. var port = 1884;
  4.  
  5. // Create a client instance
  6. client = new Paho.MQTT.Client(hostmqtt, port, "clientIdGIOWEB"+Math.floor(Math.random() * 22));
  7.  
  8. // set callback handlers
  9. client.onConnectionLost = onConnectionLost;
  10. client.onMessageArrived = onMessageArrived;
  11.  
  12. // connect the client
  13. var connectOptions = {
  14. onSuccess: onConnect,
  15. userName: "GIO DE MOFICICAR",
  16. password: "ESTO TAMBIEN",
  17. reconnect : true
  18. };
  19. client.connect(connectOptions);
  20.  
  21. // called when the client connects
  22. function onConnect() {
  23. // Once a connection has been made, make a subscription and send a message.
  24. console.log("onConnect");
  25. suscribe("+/UNI");
  26. suscribe("+/Norte");
  27. suscribe("+/Sur");
  28. suscribe("+/Este");
  29. }
  30.  
  31. function suscribe(topic){
  32. client.subscribe(topic);
  33. }
  34.  
  35. function unsuscribe(topic){
  36. client.unsuscribe(topic);
  37. }
  38.  
  39. // called when the client loses its connection
  40. function onConnectionLost(responseObject) {
  41. if (responseObject.errorCode !== 0) {
  42. console.log("onConnectionLost:"+responseObject.errorMessage);
  43. }
  44. }
  45. // called when a message arrives
  46. function onMessageArrived(message) {
  47. console.log("onMessageArrived:"+message.topic+"_"+message.payloadString);
  48. let obj = JSON.parse(message.payloadString);
  49. let mposi = {lat: obj.latitude, lng: obj.longitude};
  50. let placa = message.topic.split("/");
  51. //closeInfoWindow(markermovilidad[placa[0]]);
  52. let mmarker = getMarkerMovilidad(placa[0]);
  53. if(mmarker.getMap()!=null){
  54. markermovilidad[placa[0]] = addInfoWindow(mmarker, windowInformation(placa[0] , obj.date, GetApellidoMarker(placa[0])));
  55. markermovilidad[placa[0]].setPosition (mposi);
  56. google.maps.event.trigger( markermovilidad[placa[0]],'rightclick');
  57. }else{
  58. console.log("Su mapa es null");
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement