Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSP-W118 support #6

Open
vladimiroltean opened this issue Nov 22, 2024 · 2 comments
Open

DSP-W118 support #6

vladimiroltean opened this issue Nov 22, 2024 · 2 comments

Comments

@vladimiroltean
Copy link

Hi,
Thanks for the work put into this library!
I was trying to run it and see what it does on a DSP-W118 smart plug that I have. These devices seem to be different from what I've seen about W115/W245. The device is not pingable, and an nmap scan only shows:

PORT     STATE SERVICE
8080/tcp open  http-proxy

I think the library is able to log in (thus there are similarities as well), but subsequent commands present in switch.js like get_setting or set_setting fail.

Here is the get_setting log:

Need to connect. Doing that now.
Socket open
Connected. Signing in.
{"command":"sign_in","scope":["user","device:status","device:control","viewing","photo","policy","client","event"],"sequence_id":1001,"timestamp":1732227049,"client_id":""} written.
Got message:  {
  command: 'sign_in',
  scope: [
    'user',
    'device:status',
    'device:control',
    'viewing',
    'photo',
    'policy',
    'client',
    'event'
  ],
  sequence_id: 1001,
  timestamp: 1732227049,
  client_id: '',
  salt: '997703371',
  init: 0,
  code: 0,
  message: 'no error',
  device_id: '60634C27ED17'
}
Connection successful.
Signed in!
Getting state
{"command":"get_setting","setting":[{"type":16,"idx":0}],"sequence_id":1002,"timestamp":1732
227049,"client_id":"","device_id":"60634C27ED17","device_token":"60634C27ED17-edd08ee26d2185
000c0183fab431572308853b7f"} written.
Socket error: RangeError: Invalid WebSocket frame: MASK must be clear
    at Receiver.getInfo (/usr/share/nodejs/ws/lib/receiver.js:299:14)
    at Receiver.startLoop (/usr/share/nodejs/ws/lib/receiver.js:136:22)
    at Receiver._write (/usr/share/nodejs/ws/lib/receiver.js:83:10)
    at writeOrBuffer (node:internal/streams/writable:392:12)
    at _write (node:internal/streams/writable:333:10)
    at Writable.write (node:internal/streams/writable:337:10)
    at TLSSocket.socketOnData (/usr/share/nodejs/ws/lib/websocket.js:1272:35)
    at TLSSocket.emit (node:events:517:28)
    at addChunk (node:internal/streams/readable:368:12)
    at readableAddChunk (node:internal/streams/readable:341:9) {
  code: 'WS_ERR_UNEXPECTED_MASK',
  [Symbol(status-code)]: 1002
}
Had error: Error: Socket closed: undefined (RangeError: Invalid WebSocket frame: MASK must be clear)
    at WebSocketClient.<anonymous> (/opt/dlinkWebSocketClient/index.js:241:28)
    at Object.onceWrapper (node:events:632:26)
    at WebSocketClient.emit (node:events:517:28)
    at WebSocket.<anonymous> (/opt/dlinkWebSocketClient/index.js:118:26)
    at WebSocket.emit (node:events:517:28)
    at Receiver.receiverOnError (/usr/share/nodejs/ws/lib/websocket.js:1158:13)
    at Receiver.emit (node:events:517:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

And here is the set_setting log:

Need to connect. Doing that now.
Socket open
Connected. Signing in.
{"command":"sign_in","scope":["user","device:status","device:control","viewing","photo","policy","client","event"],"sequence_id":1001,"timestamp":1732228516,"client_id":""} written.
Got message:  {
  command: 'sign_in',
  scope: [
    'user',
    'device:status',
    'device:control',
    'viewing',
    'photo',
    'policy',
    'client',
    'event'
  ],
  sequence_id: 1001,
  timestamp: 1732228516,
  client_id: '',
  salt: '937988399',
  init: 0,
  code: 0,
  message: 'no error',
  device_id: '60634C27ED17'
}
Connection successful.
Signed in!
{"command":"set_setting","setting":[{"uid":0,"metadata":{"value":1},"idx":0,"type":16}],"seq
uence_id":1002,"timestamp":1732228517,"client_id":"","device_id":"60634C27ED17","device_toke
n":"60634C27ED17-b73dcaa5e05cfbc3e419fe97f103db38cb03f29a"} written.
Socket error: RangeError: Invalid WebSocket frame: MASK must be clear
    at Receiver.getInfo (/usr/share/nodejs/ws/lib/receiver.js:299:14)
    at Receiver.startLoop (/usr/share/nodejs/ws/lib/receiver.js:136:22)
    at Receiver._write (/usr/share/nodejs/ws/lib/receiver.js:83:10)
    at writeOrBuffer (node:internal/streams/writable:392:12)
    at _write (node:internal/streams/writable:333:10)
    at Writable.write (node:internal/streams/writable:337:10)
    at TLSSocket.socketOnData (/usr/share/nodejs/ws/lib/websocket.js:1272:35)
    at TLSSocket.emit (node:events:517:28)
    at addChunk (node:internal/streams/readable:368:12)
    at readableAddChunk (node:internal/streams/readable:341:9) {
  code: 'WS_ERR_UNEXPECTED_MASK',
  [Symbol(status-code)]: 1002
}
Had error: Error: Socket closed: undefined (RangeError: Invalid WebSocket frame: MASK must be clear)
    at WebSocketClient.<anonymous> (/opt/dlinkWebSocketClient/index.js:241:28)
    at Object.onceWrapper (node:events:632:26)
    at WebSocketClient.emit (node:events:517:28)
    at WebSocket.<anonymous> (/opt/dlinkWebSocketClient/index.js:118:26)
    at WebSocket.emit (node:events:517:28)
    at Receiver.receiverOnError (/usr/share/nodejs/ws/lib/websocket.js:1158:13)
    at Receiver.emit (node:events:517:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

I don't know much about WebSockets. From the API documentation of the error, my understanding is that the device is using a mask in its communication, and somehow the ws library treats that as a protocol violation and doesn't handle it?!
I would appreciate some pointers, hints, suggestions.

@Garfonso
Copy link
Owner

Thanks for reporting.

I once got a W118 for testing, but I was not yet able to login successfully, since the app now seems to always automatically pair with the device... not sure, though. Did you just close the app, once the device rebooted or what?

I saw these UNEXPETED MASK errors, too, sometime... but somehow I could not reproduce them, when I tried again. Hm. :-/

@vladimiroltean
Copy link
Author

Yes, after I input the Wi-Fi authentication details of the network through the SmartLife Android application, the smart socket rebooted, and I used that time to close the Android application (go to Overview, swipe up) so it wouldn't link to the cloud account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants