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 12.2k 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.
    • JerryPJ Offline
      JerryP @MZ-BER
      last edited by

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

      MZ-BERM 1 Reply Last reply Reply Quote 0
      • MZ-BERM Offline
        MZ-BER @JerryP
        last edited by

        @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 Reply Quote 0
        • S Do not disturb
          sdetweil @MZ-BER
          last edited by

          @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

          MZ-BERM 1 Reply Last reply Reply Quote 0
          • MZ-BERM Offline
            MZ-BER @sdetweil
            last edited by

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

            MZ-BERM 1 Reply Last reply Reply Quote 0
            • MZ-BERM Offline
              MZ-BER @MZ-BER
              last edited by MZ-BER

              @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 Reply Quote 0
              • S Do not disturb
                sdetweil @MZ-BER
                last edited by sdetweil

                @mz-ber exec(“voc list”, (e, sdo, sde)=

                execs the command “voc list”
                and the exec function returns
                error (e)
                stdout (sdo)
                and stderr(sde)

                so if no error (e is null)

                it sends the command output to the listResults function

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                MZ-BERM 1 Reply Last reply Reply Quote 0
                • MZ-BERM Offline
                  MZ-BER @sdetweil
                  last edited by

                  @sdetweil Thank you for the explanation. Is the function executing voc list in the terminal? If I’m doing manually voc list I’m getting a result.

                  Is there a way to see what the script is getting back in detail?

                  Again, thank you very much!

                  S 1 Reply Last reply Reply Quote 0
                  • S Do not disturb
                    sdetweil @MZ-BER
                    last edited by

                    @mz-ber yes executing just like on console

                    nothing built in to show results.

                    but you could add a

                    console.log(sdo)

                    before the call to listResults()

                    and see it where u start mm
                    npm start

                    it should be the same outout

                    Sam

                    How to add modules

                    learning how to use browser developers window for css changes

                    MZ-BERM 1 Reply Last reply Reply Quote 0
                    • MZ-BERM Offline
                      MZ-BER @sdetweil
                      last edited by MZ-BER

                      @sdetweil Alright, I added the console.log before the call listResult() and it is getting the details from my car. I feel sooo close to get this running but I dont know where it is stuck. :anguished_face:

                      91d24ae5-cc19-4460-8dca-fae88fc947e2-image.png

                      Is maybe the regex search not getting the details viewed?

                      listResult: function(output) {
                          var re = /^([^ ]+)\s\(([^\)]+)\)\s([^ ]+)$/gm
                      
                      S 1 Reply Last reply Reply Quote 0
                      • S Do not disturb
                        sdetweil @MZ-BER
                        last edited by

                        @mz-ber so the regular expression isn’t finding your text

                        /^([^ ]+)\s\(([^\)]+)\)\s([^ ]+)$/gm
                        

                        I use this for building and testing rejects

                        https://regex101.com/

                        Sam

                        How to add modules

                        learning how to use browser developers window for css changes

                        MZ-BERM 1 Reply Last reply Reply Quote 0
                        • MZ-BERM Offline
                          MZ-BER @sdetweil
                          last edited by

                          @sdetweil Yes, I also checked that with regex101. Can I just parse in the details I have?

                          listResult: function(output) {
                              var re = B-PY 186 (V90) XVASS123345
                          
                          S 2 Replies Last reply Reply Quote 0
                          • S Do not disturb
                            sdetweil @MZ-BER
                            last edited by

                            @mz-ber the regex returns an array of matched things

                            Sam

                            How to add modules

                            learning how to use browser developers window for css changes

                            1 Reply Last reply Reply Quote 0
                            • S Do not disturb
                              sdetweil @MZ-BER
                              last edited by sdetweil

                              @mz-ber i think the regex is not expecting the 186

                              try ths one

                              /^([^ ]+)\s.*\(([^\/]+)\/([^\)]+)\)$/gm
                              

                              start of string ^
                              capture up to the 1st space ([^ ]+)
                              skip everything to (and including) the open paren \s.*(
                              get the two things in the parens, separated by /, not including the parens
                              capture up to the slash ([^/]+)
                              skip the slash /
                              capture up to the close pareen ([^)]+)
                              skip the close paren )
                              end of string $

                              Sam

                              How to add modules

                              learning how to use browser developers window for css changes

                              MZ-BERM 1 Reply Last reply Reply Quote 0
                              • MZ-BERM Offline
                                MZ-BER @sdetweil
                                last edited by

                                @sdetweil Your one is not working. Here are the details I try to get:

                                B-PY 186 (V90/2019) YV1PWAKUDK1XXXXXX

                                I also played a bit with the expression and removed the white space:

                                before:

                                listResult: function(output) {
                                    var re = /^([^ ]+)\s\(([^\)]+)\)\s([^ ]+)$/gm
                                

                                after:

                                listResult: function(output) {
                                    var re = /^([^]+)\s\(([^\)]+)\)\s([^]+)$/gm
                                

                                That is working based on regex101 and I dont get the error anymore. But nothing is loaded into the MM

                                S 1 Reply Last reply Reply Quote 0
                                • S Do not disturb
                                  sdetweil @MZ-BER
                                  last edited by

                                  @mz-ber the regex has to return 3 items

                                  Sam

                                  How to add modules

                                  learning how to use browser developers window for css changes

                                  MZ-BERM 1 Reply Last reply Reply Quote 0
                                  • MZ-BERM Offline
                                    MZ-BER @sdetweil
                                    last edited by

                                    @sdetweil Right! And I guess it is doing so? Or am I wrong? b5cae454-af0f-4887-abbb-bd6117d3fe82-image.png

                                    S 1 Reply Last reply Reply Quote 0
                                    • S Do not disturb
                                      sdetweil @MZ-BER
                                      last edited by

                                      @mz-ber i do not know what the module is expecting or its process

                                      it also does a voc dashboard…
                                      and parses that…

                                      Sam

                                      How to add modules

                                      learning how to use browser developers window for css changes

                                      MZ-BERM 1 Reply Last reply Reply Quote 0
                                      • MZ-BERM Offline
                                        MZ-BER @sdetweil
                                        last edited by

                                        @sdetweil Yes, I guess voc list should work. But really quick to voc dashboard

                                        That is the list I’m getting

                                        B-PY 186 Position             : (52.55352783203125, 13.4XXXXXXXXXX6, '2022-03-06 20:20:32+01:00', None, None)
                                        B-PY 186 Door lock            : Locked
                                        B-PY 186 Heater               : Off
                                        B-PY 186 Odometer             : 34484 km
                                        B-PY 186 Trip meter 1         : 131 km
                                        B-PY 186 Trip meter 2         : 1 km
                                        B-PY 186 Fuel amount          : 40 L
                                        B-PY 186 Fuel level           : 72 %
                                        B-PY 186 Fuel consumption     : 9.9 L/100 km
                                        B-PY 186 Range                : 440 km
                                        B-PY 186 Average speed        : 31 km/h
                                        B-PY 186 Last trip            : 2022-03-06 20:20:32+01:00
                                        B-PY 186 Engine               : On
                                        B-PY 186 Door lock            : On
                                        B-PY 186 Hood                 : Closed
                                        B-PY 186 Tailgate             : Closed
                                        B-PY 186 Front left door      : Closed
                                        B-PY 186 Front right door     : Closed
                                        B-PY 186 Rear left door       : Closed
                                        B-PY 186 Rear right door      : Closed
                                        B-PY 186 Front left window    : Closed
                                        B-PY 186 Front right window   : Closed
                                        B-PY 186 Rear left window     : Closed
                                        B-PY 186 Rear right window    : Closed
                                        B-PY 186 Front right tyre     : OK
                                        B-PY 186 Front left tyre      : OK
                                        B-PY 186 Rear right tyre      : OK
                                        B-PY 186 Rear left tyre       : OK
                                        B-PY 186 Washer fluid         : OK
                                        B-PY 186 Brake Fluid          : OK
                                        B-PY 186 Service              : OK
                                        B-PY 186 Bulbs                : OK
                                        B-PY 186 Doors                : Closed
                                        B-PY 186 Windows              : Closed
                                        

                                        With the regular expression /^([^\s]+)\s([\w\s]+)\:\s(.+)$/gm it is not perfectly matching the groups:

                                        32a5261a-5834-40ce-acec-4775b24fca0a-image.png

                                        B-PY 186 should be always in group 1. Do you have an idea to adjust the expression?

                                        MZ-BERM 1 Reply Last reply Reply Quote 0
                                        • MZ-BERM Offline
                                          MZ-BER @MZ-BER
                                          last edited by

                                          I got it to work! Finally.

                                          The whole problem was my licence plate. The regular expression wasn’t able to grab the right groups. Thank you @sdetweil for helping me to investigate.

                                          S 1 Reply Last reply Reply Quote 0
                                          • S Do not disturb
                                            sdetweil @MZ-BER
                                            last edited by

                                            @mz-ber how did u fix the regex?

                                            i would change the 1st capture to
                                            in the list

                                            ^([^\(]+)\s  =capture up to but not including (
                                            

                                            in the scan = capture 1st 8 chars
                                            how long is a license number? always 8?

                                            ^(.{8})\s
                                            

                                            Sam

                                            How to add modules

                                            learning how to use browser developers window for css changes

                                            MZ-BERM 1 Reply Last reply Reply Quote 0

                                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                            With your input, this post could be even better 💗

                                            Register Login
                                            • 1
                                            • 2
                                            • 2 / 2
                                            • First post
                                              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