• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Volvo on Call

Scheduled Pinned Locked Moved Solved Troubleshooting
34 Posts 4 Posters 8.5k Views 4 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    MZ-BER @JerryP
    last edited by Mar 1, 2022, 3:55 PM

    @jerryp Okay, do I need an api key from google maps?

    J 1 Reply Last reply Mar 1, 2022, 3:56 PM Reply Quote 0
    • J Offline
      JerryP @MZ-BER
      last edited by Mar 1, 2022, 3:56 PM

      @mz-ber
      yes i’f you use the map function. I have add the api and it’s working fine

      M 1 Reply Last reply Mar 1, 2022, 4:01 PM Reply Quote 0
      • M Offline
        MZ-BER @JerryP
        last edited by Mar 1, 2022, 4:01 PM

        @jerryp is it working for you without the map function? I’m actually not interested in it.

        J 1 Reply Last reply Mar 1, 2022, 4:16 PM Reply Quote 0
        • J Offline
          JerryP @MZ-BER
          last edited by Mar 1, 2022, 4:16 PM

          @mz-ber
          Yes but i have put the api key in the config. I dont have try it whitout the key

          M 1 Reply Last reply Mar 1, 2022, 4:24 PM Reply Quote 0
          • M Offline
            MZ-BER @JerryP
            last edited by Mar 1, 2022, 4:24 PM

            @jerryp Would you do me a favor and test it without the key or a wrong key? Just wondering if that is the issue

            J 1 Reply Last reply Mar 1, 2022, 5:25 PM Reply Quote 0
            • J Offline
              JerryP @MZ-BER
              last edited by Mar 1, 2022, 5:25 PM

              @mz-ber
              yes it’s working like above whit out api key

              M 1 Reply Last reply Mar 6, 2022, 7:02 PM Reply Quote 0
              • M Offline
                MZ-BER @JerryP
                last edited by Mar 6, 2022, 7:02 PM

                @jerryp Hi Jerry - thank you for checking! I still stuck and I dont know where I’m doing something wrong. I dont want to give up because I know it is still working for you.

                The weird thing is that the API works perfect. I can pull all informations from my car via voc dashborad.
                Only the module is telling me: No vehicle found

                67c14e9f-cf68-4f2a-a410-4ec4b5289826-image.png

                That is my current config:

                {
                	  module: "MMM-VolvoOnCall",
                	  disabled: false,
                	  debug: true,
                	  position: "top_left",
                	  config: {
                		scanInterval: 1000 * 60 * 30,
                		units: "metric", 
                		timestampFormat: "MMM D. HH:mm:ss",
                		durationFormat: "HH:mm",
                		display: { 
                					info: true,
                					position: true,
                					status: true,
                					notice: true,
                					trip: true,
                					}
                				}
                			},
                

                It is setup correctly I guess.

                I’m wondering where in this node_helper.js is the voc pulled from? I’m not good in JavaScript :-(

                const exec = require('child_process').exec
                const spawn = require('child_process').spawn
                const moment = require("moment")
                
                var NodeHelper = require("node_helper")
                
                module.exports = NodeHelper.create({
                  start: function() {
                    this.config = null
                    this.carInfo = []
                  },
                
                  socketNotificationReceived: function(noti, payload) {
                    if (noti == "SCAN") {
                      this.scan()
                      this.trip()
                    }
                    if (noti == "INIT") {
                      this.config = payload
                      this.list()
                    }
                  },
                
                  list: function() {
                    exec("voc list", (e, sdo, sde)=>{
                      if (e) {
                        console.log("[VOC] ERROR(>list):", e.toString())
                      } else {
                        this.listResult(sdo)
                      }
                    })
                  },
                
                  listResult: function(output) {
                    var re = /^([^ ]+)\s\(([^\)]+)\)\s([^ ]+)$/gm
                    var matches = null
                    var result = []
                    while (matches = re.exec(output)) {
                      this.carInfo.push({
                        id: matches[1],
                        type: matches[2],
                        vin: matches[3]
                      })
                    }
                    if (this.carInfo.length > 0) {
                      this.sendSocketNotification("INITIALIZED", this.carInfo)
                    } else {
                      console.log("[VOC] ERROR: No vehicle found. Check your account. Module stopped.")
                    }
                
                  },
                
                
                  scan: function() {
                    exec("voc dashboard", (e, sdo, sde)=> {
                      if (e) {
                        console.log("[VOC] ERROR:", e.toString())
                      } else {
                        this.scanResult(sdo)
                        //this.sendSocketNotification("RESULT", sdo)
                      }
                    })
                  },
                
                  scanResult: function(output) {
                    var carIndex = this.carInfo.map((value, index, array)=>{
                      return value.id
                    })
                    var result = []
                    var re = /^([^\s]+)\s([\w\s]+)\:\s(.+)$/gm
                    var matches = null
                    while (matches = re.exec(output)) {
                      var idx = carIndex.indexOf(matches[1])
                      var key = matches[2].trim()
                      var value = this.reformValue(key, matches[3].trim())
                      if (typeof result[idx] == 'undefined') {
                        result[idx] = []
                      }
                      result[idx].push({
                        id: matches[1],
                        key: key,
                        value: value
                      })
                    }
                
                    if (Object.keys(result).length == 0) {
                      console.log("[VOC] ERROR: No information could be retrieved.")
                      console.log(output)
                    } else {
                      this.sendSocketNotification("SCAN_RESULT", result)
                    }
                  },
                
                  reformValue: function(key, value) {
                    if (key == "Position") {
                      var re = /([0-9\.\-]+)\,\s([0-9\.\-]+),\s\'([^\']+)\'/
                      var matches = re.exec(value)
                      if (matches) {
                        return {
                          lat: matches[1],
                          long: matches[2],
                          time: moment(matches[3]).format("X")
                        }
                      } else {
                        return null
                      }
                    }
                    if (key == "Fuel level") {
                      return value.replace(/\s/, "")
                    }
                    if (key == "Fuel amount" || key == "Range" || key == "Odometer" || key == "Average speed") {
                      return value.replace(/[^0-9\.]+/g, '')
                    }
                    if (key == "Fuel consumption") {
                      var re = /^([0-9\.]+)/g
                      var matches = re.exec(value)
                      if (matches) {
                        return matches[1]
                      }
                    }
                
                    return value
                  },
                
                  trip: function() {
                    for(var i = 0; i < this.carInfo.length; i++) {
                      try {
                        carId = this.carInfo[i].id
                        var sdo = ""
                        var result = spawn('voc', [
                          '-i', carId,
                          '--json', 'trips'
                        ])
                        result.stdout.on('data', (data)=>{
                          sdo += data
                        })
                        result.on('close', (killcode)=>{
                          this.tripResult(carId, JSON.parse(sdo))
                        })
                      } catch (e) {
                        console.log("[VOC] ERROR:", e.toString())
                      }
                    }
                  },
                
                  tripResult: function(carId, obj) {
                    if (Array.isArray(obj) && obj.length > 0) {
                      var trip = obj[0]
                      var detail = trip.tripDetails[0]
                      var ret = {
                        title: trip.name,
                        category: trip.category,
                        note: trip.userNotes,
                        fuelConsumption : detail.fuelConsumption,
                        electricalConsumption : detail.electricalConsumption,
                        electricalRegeneration: detail.electricalRegeneration,
                        distance: detail.distance,
                        startTime: moment(detail.startTime).format("X"),
                        startPosition: detail.startPosition,
                        endTime: moment(detail.endTime).format("X"),
                        endPosition: detail.endPosition,
                      }
                      this.sendSocketNotification("TRIP_RESULT", {id:carId, data:ret})
                    } else {
                      return
                    }
                  }
                
                })
                
                S 1 Reply Last reply Mar 6, 2022, 7:08 PM Reply Quote 0
                • S Offline
                  sdetweil @MZ-BER
                  last edited by Mar 6, 2022, 7:08 PM

                  @mz-ber

                  list: function() {
                      exec("voc list", (e, sdo, sde)=>{
                        if (e) {
                          console.log("[VOC] ERROR(>list):", e.toString())
                        } else {
                          this.listResult(sdo)
                        }
                      })
                    },
                  

                  then the good results are parsed in listResult()

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  M 1 Reply Last reply Mar 6, 2022, 7:11 PM Reply Quote 0
                  • M Offline
                    MZ-BER @sdetweil
                    last edited by Mar 6, 2022, 7:11 PM

                    @sdetweil Thank you Sam! Can you please tell me what the letters in the bracket mean? (e, sdo, sde)

                    M 1 Reply Last reply Mar 6, 2022, 7:13 PM Reply Quote 0
                    • M Offline
                      MZ-BER @MZ-BER
                      last edited by MZ-BER Mar 6, 2022, 7:13 PM Mar 6, 2022, 7:13 PM

                      @mz-ber Oh I guess I understand. If the function is not getting the right details than -> e if everything is okay than -> sdo

                      S 1 Reply Last reply Mar 6, 2022, 7:17 PM Reply Quote 0
                      • 1
                      • 2
                      • 3
                      • 4
                      • 1 / 4
                      1 / 4
                      • First post
                        10/34
                        Last post
                      Enjoying MagicMirror? Please consider a donation!
                      MagicMirror created by Michael Teeuw.
                      Forum managed by Sam, technical setup by Karsten.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy