Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mqtt;
- //var host = "labsmartcity.uni.edu.pe"
- var port = 1884;
- // Create a client instance
- client = new Paho.MQTT.Client(hostmqtt, port, "clientIdGIOWEB"+Math.floor(Math.random() * 22));
- // set callback handlers
- client.onConnectionLost = onConnectionLost;
- client.onMessageArrived = onMessageArrived;
- // connect the client
- var connectOptions = {
- onSuccess: onConnect,
- userName: "GIO DE MOFICICAR",
- password: "ESTO TAMBIEN",
- reconnect : true
- };
- client.connect(connectOptions);
- // called when the client connects
- function onConnect() {
- // Once a connection has been made, make a subscription and send a message.
- console.log("onConnect");
- suscribe("+/UNI");
- suscribe("+/Norte");
- suscribe("+/Sur");
- suscribe("+/Este");
- }
- function suscribe(topic){
- client.subscribe(topic);
- }
- function unsuscribe(topic){
- client.unsuscribe(topic);
- }
- // called when the client loses its connection
- function onConnectionLost(responseObject) {
- if (responseObject.errorCode !== 0) {
- console.log("onConnectionLost:"+responseObject.errorMessage);
- }
- }
- // called when a message arrives
- function onMessageArrived(message) {
- console.log("onMessageArrived:"+message.topic+"_"+message.payloadString);
- let obj = JSON.parse(message.payloadString);
- let mposi = {lat: obj.latitude, lng: obj.longitude};
- let placa = message.topic.split("/");
- //closeInfoWindow(markermovilidad[placa[0]]);
- let mmarker = getMarkerMovilidad(placa[0]);
- if(mmarker.getMap()!=null){
- markermovilidad[placa[0]] = addInfoWindow(mmarker, windowInformation(placa[0] , obj.date, GetApellidoMarker(placa[0])));
- markermovilidad[placa[0]].setPosition (mposi);
- google.maps.event.trigger( markermovilidad[placa[0]],'rightclick');
- }else{
- console.log("Su mapa es null");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement