Skip to content

DSP-W118 support #6

@vladimiroltean

Description

@vladimiroltean

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions