hdurdle / MMM-BMWConnected

Magic Mirror Module to display data from BMW Connected drive for your car.
MIT License
7 stars 11 forks source link

again: not trying to connect #11

Closed shgtjgh closed 2 years ago

shgtjgh commented 2 years ago

Hi, On oct. 3rd i had the same issue. out of the blue again. message: failed to parse data, error SyntaxError , unexpected end of JSON input help!

SAR71 commented 2 years ago

For me this looks like they have changed something on API site :-S I'm not the professional in this but I'll have a look into it soon :-)

nuttersrest commented 2 years ago

Yep they have changed the API URL, the old one I was using would authenticate but would return nothing causing the unexpected end of JSON input.

I am in the UK and changed the base API Address to be b2vapi.bmwgroup.com which allowed it to work again. The list of API URIs I have found are below from looking through the API docs. No idea if the others work as before, but the Rest of the World one worked for me.

Rest of the World b2vapi.bmwgroup.com

North America b2vapi.bmwgroup.us

China b2vapi.bmwgroup.cn:8592

shgtjgh commented 2 years ago

I tried www.b2vapi.bmwgroup.com and http://b2vapi.bmwgroup.com but the module didn't even came up. It didn't show up that it was loading. What else can I do?

SAR71 commented 2 years ago

Hi @nuttersrest,

thank you so much! That definately did the trick!! Thank you so much!

@shgtjgh you can just put into your congif this:

{ //https://github.com/hdurdle/MMM-BMWConnected module: "MMM-BMWConnected", header: 'Mein BMW 5er', position: "top_left", config: { apiBase: "b2vapi.bmwgroup.com", email: "your email", password: "your PW", refresh: 15, vehicleAngle: 310 } },

shgtjgh commented 2 years ago

Hi @nuttersrest,

YES!! I'm back again. it works. thx a lot!

chris-wei-17 commented 2 years ago

Hi all - I am still running in to this problem even after going through the various related issues and making the changes. Could anyone help me or share their files if they have a working US version? I’ve updated the api address, locale, and added the “rejectUnauthorized: false” and still getting the error that the token file cannot be found when the mirror is started

jannekalliola commented 2 years ago

I had similar problem that was due to wrong password. It caused BMW not to allow logins at all. Try changing your password using forgot password in the web and try again.

I'm from EU, so unfortunately I cannot offer further help with the US version.

chris-wei-17 commented 2 years ago

@jannekalliola thank you for the input, that's a helpful data point to know that it is working for you. I checked my password before, but maybe changing it will help. Could you let me know which address you are using for apiBase and if you have put "rejectUnauthorized: false" in to the bmwrequest.js file?

jannekalliola commented 2 years ago

@chris-wei-17 I'm using b2vapi.bmwgroup.com and I've added that line to bmwrequest.js file. Can you access your data using mobile app or website with your credentials? That's the easiest way to check whether the password is still kosher.

nuttersrest commented 2 years ago

Hi @chris-wei-17

Not sure if the following will be of much help but worth checking. I gave up on gettting @hdurdle code to work. Following one of the other posts on the issues a user @philmavedzenge posted his fork of this code which he had updated to get working. There were issues but some of the things you had tried above were added and it started working again. Recently BMW changed the API URLs which I identified above and by changing that in my config it started working. Below is what i think you will need to do in ordert to get it working for you, no promises though.

That should get you up and running, if not then you could try changing the API base to b2vapi.bmwgroup.com and leave everything as else as is.

@philmavedzenge made some changes to his MMM-BMWConnected.js file to stop it showing the battery charge as he did not have a hybrid or electric. if you want to display the charge then just take out the text that makes the icon invalid (thus not showing), it is commented so easy to spot in a couple of areas.

I am not in the US, so the above is my best guess. Hope it works

jannekalliola commented 2 years ago

If you get it working and want to configure which items are displayed, check out my fork: https://github.com/jannekalliola/MMM-BMWConnected

The bmwrequest.js file has been changed as mentioned above, and then there are new config flags to turn on and off various items on the display.

chris-wei-17 commented 2 years ago

@nuttersrest @jannekalliola thank you for all of the suggestions. I've tried every trick I can find and still get the following error when loading MM: Failed to read file: Error: ENOENT: no such file or directory, open 'modules/MMM-BMWConnected/bmwtoken.json'

I tried using the powershell scripts too, played with the parameters, kept getting a null token back and none of the scripts relying on Get-Token would successfully run.

Oh well, hopefully someone with a working US config will show up eventually. Although I imagine if they've found this comment then they're in the same boat as me

jannekalliola commented 2 years ago

@chris-wei-17 I got the same error when my password was expired. The system tries to read a token and prints that error message if it does not exist. Then it tries to request a new token and that request function does not have any logging.

I added a couple of console.log() calls in lib/bmwrequest.js after line 27 to dig deeper in my mystery.

console.log(data); console.log(headers);

Checking out the responses, I saw an error message that directed me forward (to change my password and try again).

Maybe you could add those and then check the message? Post them here if they do not help you directly fix the problem.

Spieke96 commented 2 years ago

Hi guys, I receive the same issue like @chris-wei-17 but use different country. I implement the console log like @jannekalliola say and receive the following output.

[03.04.2022 13:07.30.938] [LOG] Failed to read file: Error: ENOENT: no such file or directory, open 'modules/MMM-BMWConnected/bmwtoken.json' [03.04.2022 13:07.31.276] [LOG] {"error":"invalid_client","error_description":"Client authentication failed (unknown client)"} [03.04.2022 13:07.31.280] [LOG] { date: 'Sun, 03 Apr 2022 11:07:31 GMT', 'content-type': 'application/json', 'transfer-encoding': 'chunked', connection: 'close', 'x-correlationid': 'Id-f37f4962b9d40f14af0b70d1 0', 'client-remote-ip': '192.168.44.78', host: 'api-emea.bmwgroup.net', 'x-cnection': 'close', 'x-forgerock-transactionid': 'rrt-8968941931210567040-a-geu3-17077-13736193-1', 'access-control-allow-origin': '', 'access-control-allow-headers': 'Authorization, Origin, X-c2b-Authorization, X-c2b-mTAN, X-Requested-With, X-c2b-Sender-Id, X-c2b-External-Id, Content-Type, Accept, Cache-Control, KeyId, x-dtc', 'access-control-max-age': '3628800', 'access-control-allow-credentials': 'true', 'access-control-allow-methods': 'POST, GET, OPTIONS, PUT, DELETE, HEAD', 'referrer-policy': 'strict-origin', 'x-c2b-request-id': 'rrt-8968941931210567040-a-geu3-17077-13736193-1' } [03.04.2022 13:07.31.298] [ERROR] Failed to read token:Couldn't find token in response

I use the following configuration. { module: "MMM-BMWConnected", header: 'BMW Connected', position: "bottom_left", config: { email: "MyEMail", password: "MyPassword", apiBase: "b2vapi.bmwgroup.com", distance: "km", country: "Germany", //Type exactly as it appears on https://www.bmw-connecteddrive.com/ region: "REST_OF_WORLD" //Choose one : NORTH_AMERICA,CHINA,REST_OF_WORLD } },

Yesterday, I change my password and get the same error again so my password should not be the problem.

Are you have any idea how to fix it ?

stutoni commented 2 years ago

I have the same problem as Spieke96.I use it in Norway

yfre commented 2 years ago

BMW has changed the authentication method and the API. this was investigated and fix in node-red bmw project https://github.com/krauskopf/node-red-contrib-car-bmw

i have applied similar fixes to my fork of MMM-BMW-Connected project https://github.com/yfre/MMM-BMWConnected it is working for me

but as i (still) have non-electric car i could not move attributes related to electric car to the new API. maybe someone can take my fork and add electric related stuff.

new API also provides much more information (configuration, issues, services, etc) and also supports multiple cars, so, additional information can be added as well

Spieke96 commented 2 years ago

Hi @yfre, Thank you, for generate this fork. The Bearer Token is now generated and saved in the bmwtoken.json

In my case it is not woking fine because the screen shows only loading and not my car data. I see that the bwmresponse.json is not filled (0 Byte File). I try to fix it with rejectUnauthorized: false resolution of this Issue https://github.com/hdurdle/MMM-BMWConnected/issues/8 but I receive the same result Loading... :'(

I would show you a log but in the log is no error received.

Could you please post your configuration that you use? Explain: config: { email: "", password: "", apiBase: "www.b2vapi.bmwgroup.com", // try b2vapi.bmwgroup.com, https://b2vapi.bmwgroup.com and other distance: "km", country: "Germany", //Type exactly as it appears on https://www.bmw-connecteddrive.com/ region: "REST_OF_WORLD" //Choose one : NORTH_AMERICA,CHINA,REST_OF_WORLD }

yfre commented 2 years ago

@Spieke96 you were pretty quick with testing.

bwmresponse.json must be empty. it was my local file i created manually to write down the attributes i get from new API.

the issue is "www." in the apiBase. see my configuration

module: "MMM-BMWConnected", header: 'BMW Connected', position: "bottom_left", config: { email: "..", password: "..", apiBase: "b2vapi.bmwgroup.com", distance: "km", vehicleAngle: 10, country: "Germany", region: "REST_OF_WORLD" }

one more note - layout maybe broken as it has now less information (no electro), im trying to fix it.

Spieke96 commented 2 years ago

@yfre, Thank you for your help, it works.

jannekalliola commented 2 years ago

@yfre Thank you for fixing the login. I merged my previous fork with yours and added support to electric vehicles + more configuration options.

The fork can be found here: https://github.com/jannekalliola/MMM-BMWConnected