ysimonx / node-red-contrib-melcloud

node-red node for mitsubishi with melcloud API
MIT License
14 stars 5 forks source link

SyntaxError: Unexpected token T in JSON at position 0 using melcloud-connect #20

Open MPowerData opened 5 months ago

MPowerData commented 5 months ago

Since last night connecting to melcloud fails with below error:

SyntaxError: Unexpected token T in JSON at position 0.

Logging in to Melcloud with an internet browser and my credentials works fine.

How to debug this further?

ysimonx commented 5 months ago

Hello @MPowerData

I just tried on my own configuration : i have no issue

In order to answer to request, I also tried with "postman" the following request

Capture d’écran 2024-02-06 à 08 43 09

what do you get with the following command (if you are able to do it)

curl --location 'https://app.melcloud.com/Mitsubishi.Wifi.Client/Login/ClientLogin' \ --data-raw ' { "Email":"youremail@yourdomain.com", "Password":"yourpassword", "AppVersion":"1.22.7.0", "Persist":false, "CaptchaResponse":null }'

MPowerData commented 5 months ago

Hmm, interesting. When executing the curl command with my own credentials, I get:

404 - File or directory not found.

Am I doing something wrong?

ysimonx commented 5 months ago

Maybe you can try without the \ just before --data-raw, on 1 line command

curl --location 'https://app.melcloud.com/Mitsubishi.Wifi.Client/Login/ClientLogin' --data-raw ' { "Email":"youremail@yourdomain.com", "Password":"yourpassword", "AppVersion":"1.22.7.0", "Persist":false, "CaptchaResponse":null }'

I got

ysimonx@MacBook-Air-M1 ~ % curl --location 'https://app.melcloud.com/Mitsubishi.Wifi.Client/Login/ClientLogin' --data-raw ' { "Email":"youremail@yourdomain.com", "Password":"yourpassword", "AppVersion":"1.22.7.0", "Persist":false, "CaptchaResponse":null }' {"ErrorId":1,"ErrorMessage":null,"LoginStatus":0,"UserId":0,"RandomKey":null,"AppVersionAnnouncement":null,"LoginData":null,"ListPendingInvite":null,"ListOwnershipChangeRequest":null,"ListPendingAnnouncement":null,"LoginMinutes":0,"LoginAttempts":0,"EnableRegistration":true,"EnableEditStructure":true,"EnableFrostProtection":true,"EnableHolidayMode":true,"EnableTimer":true,"EnableScenes":true,"EnableInviteNewGuests":true,"EnableManageGuestAccess":true,"EnableControlOfGuestDevices":true}%

MPowerData commented 5 months ago

Yeah, that's better. :-)

{"ErrorId":1,"ErrorMessage":null,"LoginStatus":0,"UserId":0,"RandomKey":null,"AppVersionAnnouncement":null,"LoginData":null,"ListPendingInvite":null,"ListOwnershipChangeRequest":null,"ListPendingAn nouncement":null,"LoginMinutes":0,"LoginAttempts":0,"EnableRegistration":true,"EnableEditStructure":true,"EnableFrostProtection":true,"EnableHolidayMode":true,"EnableTimer":true,"EnableScenes":true ,"EnableInviteNewGuests":true,"EnableManageGuestAccess":true,"EnableControlOfGuestDevices":true}

ysimonx commented 5 months ago

ok

So, I do not understand the reason why the node-red module is not able to scrap data with this json error

did you upgrade something on your server (like npm, node or something else ?)

iontichy123 commented 5 months ago

Same here, I've not changed something on the raspi

romainlataye commented 5 months ago

Hello,

Same problem in my config.

MPowerData commented 5 months ago

ok

So, I do not understand the reason why the node-red module is not able to scrap data with this json error

did you upgrade something on your server (like npm, node or something else ?)

No, nothing changed in my setup.

ysimonx commented 5 months ago

@MPowerData @romainlataye @iontichy123

Can you give me some informations about your setup please ? linux ? docker ? node version ?

ysimonx commented 5 months ago

@MPowerData @romainlataye @iontichy123 I managed to have the same result It seem that melcloud is denying access after some requests

give me some times to find a solution

ysimonx commented 5 months ago

@MPowerData @romainlataye @iontichy123

Capture d’écran 2024-02-06 à 10 57 17

Melcloud just changed that

MPowerData commented 5 months ago

Hmmm, that could very well be the issue. I check the status every 5 minutes, but will need to adjust then,

Curious what the new limits are.

tinoetzold commented 5 months ago

Unfortunatelly, I have the same issue here: grafik

Update: the guys from HomeAssitent seem to deal with the same issue: https://github.com/home-assistant/core/issues/109728

OverWorldD commented 5 months ago

Yup, same here. I'll try to set a longer timeout, was fetching temps each minute

ysimonx commented 5 months ago

I just tried to update the node-red module extension to version 1.5.0 in order to avoid login each time and retains ContextKey http header between each request ... not sure it will be better

ysimonx commented 5 months ago

Yup, same here. I'll try to set a longer timeout, was fetching temps each minute

I tried 2 minutes, it seems to be good

OverWorldD commented 5 months ago

I just tried to update the node-red module extension to version 1.5.0 in order to avoid login each time and retains ContextKey http header between each request ... not sure it will be better

I was just going to say this, I was already logged in to melcloud in another browser and that worked fine, so the fetch request does not seem to be blocked, just the login. I'll see if i can figure out how to get the update, that was a good solution that should help one would think :)

EDIT:oh it was there in the pallette already. 1.5.0 let's give it a go :P Excellent work @ysimonx

EDIT2: I just need to wait now to get unblocked - i changed the polling interval to 24 hours for now, hope I get let in tomorrow

OverWorldD commented 5 months ago

What happens if context key times out server side? Will this force a new login from the node?

ysimonx commented 5 months ago

Hi @OverWorldD @tinoetzold @iontichy123 @MPowerData @romainlataye

I just published a 1.6.0 version of the extension palette for node-red-contrib-melcloud

As you can see, I now return in msg.context the famous ContextKey needed each time you want to scrap data from Melcloud

Capture d’écran 2024-02-07 à 08 17 01

I managed to find a way to keep this data between each call

It should be reset when it expires (@OverWorldD )

Hope it will be better

regards to everyone

ysimonx commented 5 months ago

Hi @OverWorldD @tinoetzold @iontichy123 @MPowerData @romainlataye it seems to be good with the last update 1.6.0 of this palette module extension. can you test please ?

tinoetzold commented 5 months ago

Thanks to @ysimonx for your effort, it is highly appreciated! Will do a test when I return home in the afternoon!

OverWorldD commented 5 months ago

Hi @OverWorldD @tinoetzold @iontichy123 @MPowerData @romainlataye it seems to be good with the last update 1.6.0 of this palette module extension. can you test please ?

I'll test! 1.5.0 got me locked out again after running requests every 2 minutes

miguelpruivo commented 5 months ago

They are blocking everyone that uses polling too often. At first (before 5th) I were using 30 seconds polling without issues (for more than a year I guess). Then I was unbanned and tried with 1 minute polling, still banned after a while. Now I'm using 15 minutes and since yesterday it seems to ben working fine. I'm still on version 1.4.x.

Is there anything relevant on this new version?

ysimonx commented 5 months ago

Is there anything relevant on this new version?

Yes @miguelpruivo : with the 1.6.0 version, i can pull each minute and more

miguelpruivo commented 5 months ago

@ysimonx but the polling was being done in my side (with a repeat inject node) isn't that the right way? I don't see any polling config in the melcloud node.

Captura de ecrã 2024-02-07, às 10 22 18
ysimonx commented 5 months ago

@ysimonx but the polling was being done in my side (with a repeat inject node) isn't that the right way?

yes, you will be able to change your inject node with the frequency you want

miguelpruivo commented 5 months ago

@ysimonx but the polling was being done in my side (with a repeat inject node) isn't that the right way?

yes, you will be able to change your inject node with the frequency you want

Yes, but that was what I've been using ever since. My question is: what does 1.5.0 and 1.6.0 change.

MPowerData commented 5 months ago

Thank you @ysimonx , I am gonna try every 5 minutes again...

ysimonx commented 5 months ago

@miguelpruivo

My question is: what does 1.5.0 and 1.6.0 change.

I had to fix another time the process in charge of keeping the ContextKey given by the login process

OverWorldD commented 5 months ago

Capture Still locked out after a couple of hours ((since about 11:30, it's 16:25 here now) even though I shut down the timestamp trigger nodes. Anyone know how long the lockout is?

Edit, was back in at around 18 so looks like 6 hours or so

tinoetzold commented 5 months ago

Hi @OverWorldD @tinoetzold @iontichy123 @MPowerData @romainlataye it seems to be good with the last update 1.6.0 of this palette module extension. can you test please ?

grafik Did some tests with the 1.6.0 version. On my end the "melcloud-connect" issue seems to be fixed, but I got temporary blocked with one of the five "melcloud-device" nodes I am using. Does your fix also apply for the "melcloud-device" node? I did some random switching stuff to see if it may fail again. Thx, Tino

ysimonx commented 5 months ago

thank you @tinoetzold I will do some additional tests with your comment

OverWorldD commented 5 months ago

I'm getting the same [object,object] response from the device node in my flow when trying to write to melcloud. I only have one device node and the connect nodes work. Just to confirm the same symptoms here.

OverWorldD commented 5 months ago

I just noticed that Melcloud for me does not update the inside temperature correctly. It seems stuck for me. Anyone else noticed this in the melcloud app? It's the same problem in the app, web, and the node-red node. Also the app seems to do strange refreshes every other second or three. It did not do this before. It feels like the melcloud team is updating something.

ysimonx commented 5 months ago

Hi @OverWorldD Yes, you're right Mitsubishi changed again the limit of scrapping values ...

I decided to create a new node "melcloud-context" : a specific node that will return a msg.ContextKey ... however, I have lots of job to do nowadays... not sure I will be able to fix all of this

tinoetzold commented 5 months ago

Hi @OverWorldD Yes, you're right Mitsubishi changed again the limit of scrapping values ...

I decided to create a new node "melcloud-context" : a specific node that will return a msg.ContextKey ... however, I have lots of job to do nowadays... not sure I will be able to fix all of this

Thanks for your work! Would be great if you could fix this, but I understand that this is challenging. Found a (quite awful) workaround to deal with the device node: I created a guest accout for each of my 5 devices, so the commands are quite distributed and do not seem to trigger the MelCloud limits, since I set at least 7 Minutes between each command to be send. I also reduced the temperature scrapting to each 30 Minutes, since I have additional sensors where they are crucial.

My complain at the MelCloud technical service was not sucessful, they rely on safety issues and pointed to the possibility of using Google Home for automation (which I do not think is as powerful as Node-Red). But they said that there will be an a change to the API which will be announced by their marketing in the next time (I ask why they do not make their API safe in order to alllow third party apps the access).

Have a great day! Tino

poggow commented 2 months ago

Hello, sorry for hijacking the thread but just tried the postman pasted above and getting the following answer :

{ "ErrorId": 1, "ErrorMessage": null, "LoginStatus": 0, "UserId": 0, "RandomKey": null, "AppVersionAnnouncement": null, "LoginData": null, "ListPendingInvite": null, "ListOwnershipChangeRequest": null, "ListPendingAnnouncement": null, "LoginMinutes": 0, "LoginAttempts": 0, "EnableRegistration": true, "EnableEditStructure": true, "EnableFrostProtection": true, "EnableHolidayMode": true, "EnableTimer": true, "EnableScenes": true, "EnableInviteNewGuests": true, "EnableManageGuestAccess": true, "EnableControlOfGuestDevices": true }

Shouldn't LoginStatus be one and be getting a ContextKey?

Thanks in advance for helping

EDIT : Working now, I just had to remove a ' before around my Body :

{ "Email": "{{email}}", "Password": "{{password}}", "AppVersion": "1.22.7.0", // "Language":{{language}}, "Persist": false, "CaptchaResponse": null }