Apollon77 / alexa-remote

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cookie refresh, mqtt and other....

shodge12 opened this issue · comments

Hi,

Found this archive while looking for a cookie refresh solution while sending commands to alexa. Will your code, once it has a working cookie, auto refresh it automatically - forever?

When I have the example program configured with useWsMqtt=true, I get the following log messages which look like something is wrong.... (no messages if false) [In ether case I can send commands to Alexa with a modified example.js program]

Alexa-Remote WS-MQTT: Initialization Msg 1 sent
Alexa-Remote WS-MQTT: Initialization Msg 2+3 sent
Alexa-Remote WS-MQTT: Initialization not done within 30s
Alexa-Remote WS-MQTT: Close: 1005:
Alexa-Remote WS-MQTT: Retry Connection in NaNs
Alexa-Remote WS-MQTT: Open https://dp-gw-na-js.amazon.com/?x-amz-device-type=ALGCNCL9K0HM&x-amz-device-serial=undefined-1556940942909
[repeat]

lastly, cookieRefreshInterval: 7 * 24 * 60 * 1000 is in the example code AND in the source code for the library. Should this not be 7 * 24 * 60 * 60 * 1000? (7 days in milliseconds)...

Thanks,
-Stan

Please provide full debug log. Yes it should refresh at given interval. Default 7 days. The library itself will convert into ms, the value in options is in seconds.

It seems that the mqtt connection can not be opened and that’s why it is trying to reconnect. That’s why full log please.

Thanks for the reply.

I see no .log file, so I assume you are wanting the full console output. There is a great deal of personal account information posted here including a working cookie for access - so I '####' what I could see as sensitive....

I also added the following after the deviceseerial for loop....
alexa.sendSequenceCommand("########","speak","test",function (err,payload) {

    if (err) {
        console.log (err);
        return;
    }

    console.log(payload);
    });

[If I remove the above - the result is the same....]
----------Log--------------------

stan@FPGA-1:/alexa-remote/node_modules/alexa-remote2/example$ sudo node example.js
Alexa-Remote: Use as User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
Alexa-Remote: Use as Login-Amazon-URL: amazon.com
Alexa-Remote: Use as Base-URL: pitangui.amazon.com
Alexa-Remote: cookie was provided
Alexa-Remote: Sending Request with {"host":"pitangui.amazon.com","path":"/api/bootstrap?version=0","method":"GET","timeout":10000,"headers":{}}
Alexa-Remote: Response: {"authentication":{"authenticated":true,"canAccessPrimeMusicContent":true,"customerEmail":"#########","customerId":"##############","customerName":"Stanley #########"}}
Alexa-Remote: Authentication checked: true
Alexa-Remote: No authentication check needed (time elapsed 1)
Alexa-Remote: Sending Request with {"host":"alexa-comms-mobile-service.amazon.com","path":"/accounts","method":"GET","timeout":10000,"headers":{}}
Alexa-Remote: Response: [{"commsId":"amzn1.comms.id.person.amzn1
amzn1.account.AEHBENBQXQR3M52CJAXP7U7KGI7Q","directedId":"amzn1.account.AEHBENBQXQR3M52CJAXP7U7KGI7Q","phoneCountryCode":"1","phoneNumber":"#########","firstName":"Stanley","lastName":"#####","phoneticFirstName":null,"phoneticLastName":null,"commsProvisionStatus":"PROVISIONED","isChild":false,"signedInUser":true,"commsProvisioned":true,"speakerProvisioned":false}]
Alexa-Remote: No authentication check needed (time elapsed 370)
Alexa-Remote: Sending Request with {"host":"pitangui.amazon.com","path":"/api/devices-v2/device?cached=true&=1556984099512","method":"GET","timeout":10000,"headers":{}}
Alexa-Remote: Response: {"devices":[{"accountName":"Stanley's Echo Show","appDeviceList":[],"capabilities":["SUPPORT_CALENDAR_ALERT","PAIR_BT_SINK","POPTART","CUSTOM_ALARM_TONE","I_HEART_RADIO","SUPPORTS_CONNECTED_HOME_CLOUD_ONLY","SOUND_SETTINGS","ASCENDING_ALARM_VOLUME","ALLOW_LOG_UPLOAD","AUDIBLE","TUNE_IN","DREAM_TRAINING","SALMON","TIMERS_AND_ALARMS","MUSIC_SKILL","TIMERS_ALARMS_NOTIFICATIONS_VOLUME","LEMUR_ALPHA","TUPLE_CATEGORY_B","REMINDERS","EARCONS","TUPLE","SHARKNADO","PERSISTENT_CONNECTION","KINDLE_BOOKS","PANDORA","FAR_FIELD_WAKE_WORD","GOLDFISH","VOLUME_SETTING","CHANGE_NAME","DS_VOLUME_SETTING","AUDIO_PLAYER","MICROPHONE","FLASH_BRIEFING","SLEEP","VOICE_TRAINING","SUPPORTS_SOFTWARE_VERSION","FACTORY_RESET_DEVICE","SET_LOCALE","AMAZON_MUSIC"],"charging":null,"clusterMembers":[],"deviceAccountId":"##############","deviceFamily":"KNIGHT","deviceOwnerCustomerId":"##############","deviceType":"A1NL4BVLQ4L3N3","deviceTypeFriendlyName":null,"essid":null,"language":null,"macAddress":null,"online":true,"parentClusters":[],"postalCode":null,"registrationId":null,"remainingBatteryLevel":null,"serialNumber":"##############","softwareVersion":"635559420"},{"accountName":"Stanley's Alexa Web Interface","appDeviceList":[],"capabilities":["SUPPORTS_CONNECTED_HOME_CLOUD_ONLY","I_HEART_RADIO","VOLUME_SETTING","GOLDFISH","DEREGISTER_DEVICE","AUDIBLE","TUNE_IN","DREAM_TRAINING","CHANGE_NAME","TIMERS_AND_ALARMS","MICROPHONE","AUDIO_PLAYER","MUSIC_SKILL","SLEEP","PEONY","AMAZON_MUSIC","PERSISTENT_CONNECTION","KINDLE_BOOKS"],"charging":null,"clusterMembers":[],"deviceAccountId":"A011899510N6U166B8NTP","deviceFamily":"UNKNOWN","deviceOwnerCustomerId":"##############","deviceType":"A1VZJGJYCRI78V","deviceTypeFriendlyName":"Alexa Web Interface","essid":null,"language":null,"macAddress":null,"online":false,"parentClusters":[],"postalCode":null,"registrationId":null,"remainingBatteryLevel":null,"serialNumber":"5a632d9723ac4fdc9f2702c41c239a00","softwareVersion":"0"},{"accountName":"This Device","appDeviceList":[{"deviceAccountId":"A0268553JHACTO3BGHU6","deviceType":"A2IVLV5VM2W81","serialNumber":"F7CD756FE7344C3A8DAE8D4363B9984F"},{"deviceAccountId":"A01685792XYDOQHT6AB6S","deviceType":"A2IVLV5VM2W81","serialNumber":"B360BCE5BB774AB4AE80F9B040A3B85E"},{"deviceAccountId":"A08369582RU6QHZ3BBDY9","deviceType":"A2IVLV5VM2W81","serialNumber":"62AB35D6F79C4DA291B51E9B5CA5DBB0"},{"deviceAccountId":"A038640232SH55U4NFPTU","deviceType":"A2IVLV5VM2W81","serialNumber":"24e5114b2f5fb563afd133556c6d0449"},{"deviceAccountId":"A06617873CDS5YLNXQ79W","deviceType":"A2IVLV5VM2W81","serialNumber":"3671472f181a14ea39afeb96c7ba0d33"},{"deviceAccountId":"A0343701KL37BCN1M6E2","deviceType":"A2IVLV5VM2W81","serialNumber":"b287af069584ba67cbbb32d494aff3bf"},{"deviceAccountId":"A01109451WS0L8LVIRLX","deviceType":"A2IVLV5VM2W81","serialNumber":"8c764161847ac73316c7b9f315acc53b"},{"deviceAccountId":"A0008832PYJ5ZYYZ203L","deviceType":"A2IVLV5VM2W81","serialNumber":"332a854c7a6febb423807c75862eb5f1"},{"deviceAccountId":"A06940932LIWREXQV0MFU","deviceType":"A2IVLV5VM2W81","serialNumber":"aeaf9fb5c21df7fe9bb4bd180b87ac9c"},{"deviceAccountId":"A06839975PFDF3ZKUVPO","deviceType":"A2IVLV5VM2W81","serialNumber":"144e1dc1a2b62b68316591b768788417"},{"deviceAccountId":"A0654912A3ZRSJY7U7RL","deviceType":"A2IVLV5VM2W81","serialNumber":"705c0492834a6d4505f545fc0c69636d"},{"deviceAccountId":"A06848023TNLG2OK7DIH9","deviceType":"A2IVLV5VM2W81","serialNumber":"2e66c959511d550f82310339f04de620"},{"deviceAccountId":"A09860092T2VG4TJQC9H7","deviceType":"A2IVLV5VM2W81","serialNumber":"7158856fa5373e7e7dc3cb4ee8b5a9c1"},{"deviceAccountId":"A040980626U9EBD32S2P3","deviceType":"A2IVLV5VM2W81","serialNumber":"36e46a1bd5bae4bc81d5efd047e708f3"},{"deviceAccountId":"A01960752YIPJTQJW46QX","deviceType":"A2IVLV5VM2W81","serialNumber":"3f1ea8d8e368abaedee65ca763e737b9"}],"capabilities":["REMINDERS","VOLUME_SETTING","MICROPHONE"],"charging":null,"clusterMembers":[],"deviceAccountId":"A0268553JHACTO3BGHU6","deviceFamily":"VOX","deviceOwnerCustomerId":"##############","deviceType":"A2IVLV5VM2W81","deviceTypeFriendlyName":null,"essid":null,"language":null,"macAddress":null,"online":true,"parentClusters":[],"postalCode":null,"registrationId":null,"remainingBatteryLevel":null,"serialNumber":"F7CD756FE7344C3A8DAE8D4363B9984F","softwareVersion":"1"},{"accountName":"Stanley's Alexa Apps","appDeviceList":[{"deviceAccountId":"A2KAUZ41BH8EC","deviceType":"A2825NDLA7WDZV","serialNumber":"F86FA88CEE2A4EF88222CD79F9EB0FEC"},{"deviceAccountId":"A3OBPW0ACOHSU0","deviceType":"A3NWHXTQ4EBCZS","serialNumber":"4A4CE9685DED42839259E2DBC753A495"},{"deviceAccountId":"AX2RXL5W29C41","deviceType":"A3NWHXTQ4EBCZS","serialNumber":"D1634922B7F34A4DBF7A145393F4A0B9"},{"deviceAccountId":"A1644R7LNLVGOC","deviceType":"A3NWHXTQ4EBCZS","serialNumber":"4E54435F9F764DADBDEF1CAA81888CEA"},{"deviceAccountId":"A30T2GIQ25BDQY","deviceType":"A3NWHXTQ4EBCZS","serialNumber":"BDE14BCFC64F4E75B9E29CE9FD910F9C"},{"deviceAccountId":"A1YF3FBZVTR86X","deviceType":"A3NWHXTQ4EBCZS","serialNumber":"4BC3FFC6F0F745FA9457E675A580AEE0"},{"deviceAccountId":"A082428416DL49JLH3RTY","deviceType":"A3NWHXTQ4EBCZS","serialNumber":"E2CC8E0A18F44F10A071CB5B2C170B50"},{"deviceAccountId":"A08628212PAGQLIR6V2N6","deviceType":"A3NWHXTQ4EBCZS","serialNumber":"956BE1082F704C55B953DD7E47B44815"}],"capabilities":["VOLUME_SETTING","PEONY","MICROPHONE"],"charging":null,"clusterMembers":[],"deviceAccountId":"A2KAUZ41BH8EC","deviceFamily":"AMAZONMOBILEMUSIC_IOS","deviceOwnerCustomerId":"##############","deviceType":"A2825NDLA7WDZV","deviceTypeFriendlyName":null,"essid":null,"language":null,"macAddress":null,"online":false,"parentClusters":[],"postalCode":null,"registrationId":null,"remainingBatteryLevel":null,"serialNumber":"F86FA88CEE2A4EF88222CD79F9EB0FEC","softwareVersion":"0"}]}
Alexa-Remote: No authentication check needed (time elapsed 1008)
Alexa-Remote: Sending Request with {"host":"pitangui.amazon.com","path":"/api/wake-word?
=1556984100150","method":"GET","timeout":10000,"headers":{}}
Alexa-Remote: Response: {"wakeWords":[{"active":true,"deviceSerialNumber":"##############","deviceType":"A1NL4BVLQ4L3N3","midFieldState":null,"wakeWord":"ALEXA"}]}
Alexa-Remote: No authentication check needed (time elapsed 1309)
Alexa-Remote: Sending Request with {"host":"pitangui.amazon.com","path":"/api/bluetooth?cached=true&_=1556984100451","method":"GET","timeout":10000,"headers":{}}
Alexa-Remote: Response: {"bluetoothStates":[{"deviceSerialNumber":"##############","deviceType":"A1NL4BVLQ4L3N3","friendlyName":"Echo Show-JEH","gadgetPaired":false,"online":true,"pairedDeviceList":null,"sconeBattery":null,"sconePaired":false,"softwareVersion":"635559420","streamingState":null},{"deviceSerialNumber":"5a632d9723ac4fdc9f2702c41c239a00","deviceType":"A1VZJGJYCRI78V","friendlyName":null,"gadgetPaired":false,"online":false,"pairedDeviceList":null,"sconeBattery":null,"sconePaired":false,"softwareVersion":"0","streamingState":null},{"deviceSerialNumber":"F7CD756FE7344C3A8DAE8D4363B9984F","deviceType":"A2IVLV5VM2W81","friendlyName":null,"gadgetPaired":false,"online":false,"pairedDeviceList":null,"sconeBattery":null,"sconePaired":false,"softwareVersion":"1","streamingState":null},{"deviceSerialNumber":"F86FA88CEE2A4EF88222CD79F9EB0FEC","deviceType":"A2825NDLA7WDZV","friendlyName":null,"gadgetPaired":false,"online":false,"pairedDeviceList":null,"sconeBattery":null,"sconePaired":false,"softwareVersion":"0","streamingState":null}]}
Alexa-Remote WS-MQTT: Cookie incomplete : null
"session-id=139-9800655-7004958; session-id-time=2187659155l; ubid-main=133-0419421-9370641; x-main=L4Ph3hSLKS6iTRNj@uSpXRgQQMtQ8Skw; at-main=Atza|IwEBICKC0fkcOS9D_NKmxWGmSio8IkDbwTrTRT3zJFyJvgtnyo8aAo1aIFStOMGtDeAa0tWuXDD7gs_RygYu4Gv1TalgtX-ecILlfsSD_CbVb-pBcJEnngaSSkNfVK8BgzUKd27qOzbOnt84vlS17iOQA5qBfnyn53Rl8r1c4RMx-hSHhFCDjW3U49JbpHqmTpte1BUaaPSHdrju7PkfA3ldcFO3waFHG21bOqXHsZbibXmOQZKcknoesZFptEBjSBzbdLDDUxSokaZtk2MkuSBhyTxAViAwiVLclIvyNeCpKaL4vbKXkFcYQgEwk3hfaeEJv2QSyJDlzzbAb0uPOfbbRpeVLPOX0ai-63XAn7UDPUbUv7tW2iiSEdafBU36kvZuY7LXxMdvofpYVokUvsow8RzZu0HT-fMdMa_klLMMJikq7scwGe23n4w2jvp8u-Wc9II; sess-at-main=42xb4lPS9CYoSyQ8O7cS19GPPDZgfJWj+Gb+XDoYfZ4=; csrf=##############"
"##############"
null
##############
5a632d9723ac4fdc9f2702c41c239a00
F7CD756FE7344C3A8DAE8D4363B9984F
F86FA88CEE2A4EF88222CD79F9EB0FEC
Alexa-Remote: No authentication check needed (time elapsed 2213)
Alexa-Remote: Sending Request with {"host":"pitangui.amazon.com","path":"/api/behaviors/preview","method":"POST","timeout":10000,"headers":{}}and data={"behaviorId":"PREVIEW","sequenceJson":"{"@type":"com.amazon.alexa.behaviors.model.Sequence","startNode":{"@type":"com.amazon.alexa.behaviors.model.OpaquePayloadOperationNode","operationPayload":{"deviceType":"A1NL4BVLQ4L3N3","deviceSerialNumber":"##############","locale":"de-DE","customerId":"##############","textToSpeak":"test"},"type":"Alexa.Speak"}}","status":"ENABLED"}
Alexa-Remote WS-MQTT: Open: https://dp-gw-na-js.amazon.com/?x-amz-device-type=ALEGCNGL9K0HM&x-amz-device-serial=undefined-1556984101349
Alexa-Remote WS-MQTT: Initialization Msg 1 sent
Alexa-Remote WS-MQTT: Initialization Msg 2+3 sent
Alexa-Remote: Response: No body
Error: no body
at IncomingMessage.res.on (/home/stan/alexa-remote/node_modules/alexa-remote2/alexa-remote.js:709:69)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
Alexa-Remote WS-MQTT: Initialization not done within 30s
Alexa-Remote WS-MQTT: Close: 1005:
Alexa-Remote WS-MQTT: Retry Connection in NaNs
Alexa-Remote WS-MQTT: Open: https://dp-gw-na-js.amazon.com/?x-amz-device-type=ALEGCNGL9K0HM&x-amz-device-serial=undefined-1556984131660
Alexa-Remote WS-MQTT: Initialization Msg 1 sent
Alexa-Remote WS-MQTT: Initialization Msg 2+3 sent
Alexa-Remote WS-MQTT: Initialization not done within 30s
Alexa-Remote WS-MQTT: Close: 1005:
Alexa-Remote WS-MQTT: Retry Connection in NaNs
Alexa-Remote WS-MQTT: Open: https://dp-gw-na-js.amazon.com/?x-amz-device-type=ALEGCNGL9K0HM&x-amz-device-serial=undefined-1556984161944
Alexa-Remote WS-MQTT: Initialization Msg 1 sent
Alexa-Remote WS-MQTT: Initialization Msg 2+3 sent
^C

I let it run for a long time.... Finally said this at the end...
Alexa-Remote WS-MQTT: Initialization Msg 1 sent
Alexa-Remote WS-MQTT: Close: 4001: before - Could not find any vali
Alexa-Remote WS-MQTT: Cookie invalid!

then no more messages.....

-Stan

...
I also suggest adding the following to the example.js code to set the proxy login language...

amazonPageProxyLanguage: 'en-US', // optional, override language used for proxy login page, defaule is "de_DE"

-Stan

OK,

Again, the math on the cookieRefreshInterval in the example code (and in you alexa-remote.js) is wrong. The value is in ms as it is being used in your code. I cannot find any conversions anywhere. The value should be:
7 (days) x 24 (hrs) x 60 (minutes per hr) x 60 (seconds per min) x 1000 (ms in 1 sec).
7 x 24 x 60 x 60 x 1000
not
7 x 24 x 60 x 1000

Its likely not a big issue as it will just cause the cookie to be refreshed every ~3hrs or so instead of once per week...

...or have I missed something hidden in your code?

-Stan

now I got it :-) will be fixed in 2.3.0 coming later today