gamebeast2k / docker_traccar2mqtt

a small bridge between Traccar and a MQTT Broker maybe for your Smarthome like IO.Broker or Fhem.
5 stars 1 forks source link

Geofence / EVENT #1

Closed dossidr closed 4 years ago

dossidr commented 4 years ago

Hello GameBeast,

Thank you for the container. I'm dating it on a Synology DS918 . The container is running and I also get data in my Mqtt broker. I have adjusted your "server.js" a bit. Now I get more Paramter from Traccar. Unfortunately, I have two problems:

  1. I would like to receive the Geofences ID from Traccar. But this is probably not possible, as this is not in the "positions" as "attributes". Do you know a way to get to this "goefenceid" and send it to the Mqtt broker? Or how to send the EXIT / ENTRED to MQTT?

  2. here an error in the log comes up from time to time. "post incoming"

TypeError: Cannot read property 'latitude' of undefined

at send2mqtt (/app/server.js:52:29)

at /app/server.js:34:3

at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)

at next (/app/node_modules/express/lib/router/route.js:137:13)

at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)

at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)

at /app/node_modules/express/lib/router/index.js:281:22

at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)

at next (/app/node_modules/express/lib/router/index.js:275:10)

at urlencodedParser (/app/node_modules/body-parser/lib/types/urlencoded.js:82:7)>

Gruss Denny

gamebeast2k commented 4 years ago

Hi Denny,

first, sorry for the long replay.

i look in to it.

gamebeast2k commented 4 years ago

Hey Denny,

do you want share your changes to help others? it would be nice.

Yes i found a way to get the current GeofenceIDs. I have added it and its work fine. You get a comma separated string of current Geofences IDs in mqtt under ...username/geofanceIds.

The EXIT / ENTRED Events is possible via EventAPI from Traccar.

Your Error looks like a urlencode issue. Do you use some special chars like ä,ü,ö,ß ?

Mit freundlichen Grüßen / Best regards Gamebeast

dossidr commented 4 years ago

Hey Gamebeast, no Problem. It is nice to hear that there is a possibility to trigger the GEOFENCE ID. This allows me to link the presence in the individual GEOFENCE ID to the home automation. What do I have to do now? Do I need to Update the Coontainer? Do you have an example of what the Setup should look like? Here an excerpt from my extended Setup: // setup and send to mqtt broker function send2mqtt(json){ mqtt_client.on("error",function(error){ console.log("mqtt: Can't connect"+error) }); mqtt_client.on("connect",function(){ console.log("mqtt: connected "+ mqtt_client.connected); }) if (mqtt_client.connected == true){ let cache = {}; if(typeof json.device.name != "undefined"){ cache["name"] = json.device.name.replace(" ","_"); } if(typeof json.device.status != "undefined"){ cache["status"] = json.device.status; } if(typeof json.device.lastUpdate != "undefined"){ cache["lastUpdate"] = json.device.lastUpdate; } if(typeof json.device.model != "undefined"){ cache["model"] = json.device.model; } if(typeof json.device.uniqueid != "undefined"){ cache["uniqueid"] = json.device.uniqueid; } if(typeof json.device.positionid != "undefined"){ cache["positionid"] = json.device.positionid; } if(typeof json.position.latitude != "undefined"){ cache["lat"] = json.position.latitude; } if(typeof json.position.longitude != "undefined"){ cache["lon"] = json.position.longitude; } if(typeof json.position.altitude != "undefined"){ cache["altitude"] = json.position.altitude; } if(typeof json.position.course != "undefined"){ cache["course"] = json.position.course; } if(typeof json.position.speed != "undefined"){ cache["speed"] = json.position.speed; } if(typeof json.position.accuracy != "undefined"){ cache["accuracy"] = json.position.accuracy; } if(typeof json.position.network != "undefined"){ cache["network"] = json.position.network; } if(typeof json.position.deviceTime != "undefined"){ cache["deviceTime"] = json.position.deviceTime; } if(typeof json.position.address != "undefined"){ cache["address"] = json.position.address; } if(typeof json.position.attributes.batteryLevel != "undefined"){ cache["batteryLevel"] = json.position.attributes.batteryLevel; } if(typeof json.position.attributes.BATTERY != "undefined"){ cache["BATTERY"] = json.position.attributes.BATTERY; } if(typeof json.position.attributes.distance != "undefined"){ cache["distance"] = json.position.attributes.distance; } if(typeof json.position.attributes.totalDistance != "undefined"){ cache["totalDistance"] = json.position.attributes.totalDistance; } if(typeof json.position.attributes.motion != "undefined"){ cache["motion"] = json.position.attributes.motion; } for (var key in cache) { var value = ''+cache[key] mqtt_client.publish('traccar/'+cache["name"]+"/"+key, value,{retain:true,qos:1}); }; } }; ![Screenshot von 2020-03-17 21 58 10](https://user-images.githubusercontent.com/45298863/76900906-81ca6a00-689a-11ea-8b0c-bb68442ac173.png) Its very easy to be set your container full running inside Synology Docker Application. When you want i can made any information how integrate these toolchain to be using on a synology nas station and connect between traccar server. The target system is an fhem installation homeautomation. best regards denny many thanks....................

gamebeast2k commented 4 years ago

Hey,

so i have now added yours Variables. Code updated and tag it as Version 0.3 thanks for sharing :)

I dont know how you start the container. 2 Options a possible

  1. you get the sourcecode via "zip" or "git clone" from github you need to update your local copy "zip download -> overwrite" or "git pull". Dont forget to build the new dockerpackage with "docker-compose build" or "docker build" then just restart.
  2. If you use the dockerhub prebuild image from gamebeast/traccar2mqtt you need only say docker to download the new version via "docker pull gamebeast/traccar2mqtt:latest" then start docker container again.

The issue is now fixed (closed)

For any questinons or suggestion just write me a @Mail to info@gamebeast.de [EN|DE]

gamebeast2k commented 2 years ago

fixed in 1297cfe3c5b1d62a3b7a68f7e05b348506d7b635