question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot toggleDevice (or getPowerState)

See original GitHub issue

I can login, get device list for more info, however I cannot toggleDevice - the ewelink API returns HTTP 500, however payload/URL seems correct according to theirs docs in https://github.com/CoolKit-Technologies/apiDocs/blob/master/en/APICenter.md#http-update-device-status Sample code:

const ewelink = require('ewelink-api');

(async () => {
  const connection = new ewelink({
    email: 'validemail@in.valid.domain',
    password: 'validpassword',
    region: 'eu',
  });

  /* get all devices */
  const devices = await connection.getDevices();
  console.log(devices);

  for (device in devices) {
       console.log("Name: " + devices[device]["name"]);
       console.log("DeviceID: " + devices[device]["deviceid"]);
       console.log("ProductModel: " + devices[device]["productModel"]);
       const device_info = await connection.getDevice(devices[device]["deviceid"]);
       console.log(device_info["productModel"]);
       if (device_info["productModel"] === "BASICR2") {
           console.log("Toggling this one")
           const status = await connection.toggleDevice(devices[device]["deviceid"]);
           console.log(status);
       }
  }
})();

I’ve added some console.log to see what is happening and when calling toggleDevice I can see it’s successfully asking for device state (via const device = await this.getDevice(deviceId);) and correctly resolving the switch state (on/off), but when actually trying to turn it off/on the ewelink API ends with HTTP 500.

URL: https://eu-api.coolkit.cc:8080/api/user/device/status
PAYLOAD:
{ method: 'post',
  headers:
   { Authorization: 'Bearer <validauthorizationthatwasusedfewtimesalready>',
     'Content-Type': 'application/json' },
  body:
   '{"deviceid":"<validdeviceidfromloop>","params":{"switch":"off"},"appid":"YzfeftUVcZ6twZw1OoVKPRFYTrGEg01Q","nonce":"itj22djr","ts":1590686206,"version":8}' }
SERVER_RESP: <h2>Internal Server Error, real status: 500</h2>
(node:23243) UnhandledPromiseRejectionWarning: FetchError: invalid json response body at https://eu-api.coolkit.cc:8080/api/user/device/status reason: Unexpected token < in JSON at position 0
    at node_modules/node-fetch/lib/index.js:273:32
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:23243) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:23243) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

It could be (somehow?) worth noticing that this device is shared to this ewelink account. I also see a lot of strange things with ewelink API - β€œfd is null” or β€œdevice not found” when asking for getDevice (however they were just successfully listed via getDevices). However after few fails if I open original ewelink app it starts to report correct data for getDevice (I guess normal apps calls something more and populate (?) theirs cache)

EDIT Just tested on β€œmain” (not shared to) ewelink account - same behavior - HTTP 500. So I would assume β€œshared” device is not an issue here.

$ npm list
└─┬ ewelink-api@3.0.0
  β”œβ”€β”¬ arpping@0.3.1 (github:skydiver/arpping#ae65410343bdcbddb64b37ac9f674c65af1fe92c)
  β”‚ β”œβ”€β”€ child_process@1.0.2
  β”‚ └── os@0.1.1
  β”œβ”€β”€ crypto-js@4.0.0
  β”œβ”€β”€ delay@4.3.0
  β”œβ”€β”€ node-fetch@2.6.0
  β”œβ”€β”¬ random@2.2.0
  β”‚ β”œβ”€β”¬ babel-runtime@6.26.0
  β”‚ β”‚ β”œβ”€β”€ core-js@2.6.11
  β”‚ β”‚ └── regenerator-runtime@0.11.1
  β”‚ β”œβ”€β”€ ow@0.4.0
  β”‚ β”œβ”€β”€ ow-lite@0.0.2
  β”‚ └── seedrandom@3.0.5
  β”œβ”€β”¬ websocket@1.0.31
  β”‚ β”œβ”€β”¬ debug@2.6.9
  β”‚ β”‚ └── ms@2.0.0
  β”‚ β”œβ”€β”¬ es5-ext@0.10.53
  β”‚ β”‚ β”œβ”€β”¬ es6-iterator@2.0.3
  β”‚ β”‚ β”‚ β”œβ”€β”¬ d@1.0.1
  β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ es5-ext@0.10.53 deduped
  β”‚ β”‚ β”‚ β”‚ └── type@1.2.0
  β”‚ β”‚ β”‚ β”œβ”€β”€ es5-ext@0.10.53 deduped
  β”‚ β”‚ β”‚ └── es6-symbol@3.1.3 deduped
  β”‚ β”‚ β”œβ”€β”¬ es6-symbol@3.1.3
  β”‚ β”‚ β”‚ β”œβ”€β”€ d@1.0.1 deduped
  β”‚ β”‚ β”‚ └─┬ ext@1.4.0
  β”‚ β”‚ β”‚   └── type@2.0.0
  β”‚ β”‚ └── next-tick@1.0.0
  β”‚ β”œβ”€β”€ nan@2.14.1
  β”‚ β”œβ”€β”¬ typedarray-to-buffer@3.1.5
  β”‚ β”‚ └── is-typedarray@1.0.0
  β”‚ └── yaeti@0.0.6
  └─┬ websocket-as-promised@1.0.1
    β”œβ”€β”€ chnl@1.2.0
    β”œβ”€β”€ promise-controller@1.0.0
    └─┬ promise.prototype.finally@3.1.2
      β”œβ”€β”¬ define-properties@1.1.3
      β”‚ └── object-keys@1.1.1
      β”œβ”€β”¬ es-abstract@1.17.5
      β”‚ β”œβ”€β”¬ es-to-primitive@1.2.1
      β”‚ β”‚ β”œβ”€β”€ is-callable@1.1.5 deduped
      β”‚ β”‚ β”œβ”€β”€ is-date-object@1.0.2
      β”‚ β”‚ └─┬ is-symbol@1.0.3
      β”‚ β”‚   └── has-symbols@1.0.1 deduped
      β”‚ β”œβ”€β”€ function-bind@1.1.1 deduped
      β”‚ β”œβ”€β”¬ has@1.0.3
      β”‚ β”‚ └── function-bind@1.1.1 deduped
      β”‚ β”œβ”€β”€ has-symbols@1.0.1
      β”‚ β”œβ”€β”€ is-callable@1.1.5
      β”‚ β”œβ”€β”¬ is-regex@1.0.5
      β”‚ β”‚ └── has@1.0.3 deduped
      β”‚ β”œβ”€β”€ object-inspect@1.7.0
      β”‚ β”œβ”€β”€ object-keys@1.1.1 deduped
      β”‚ β”œβ”€β”¬ object.assign@4.1.0
      β”‚ β”‚ β”œβ”€β”€ define-properties@1.1.3 deduped
      β”‚ β”‚ β”œβ”€β”€ function-bind@1.1.1 deduped
      β”‚ β”‚ β”œβ”€β”€ has-symbols@1.0.1 deduped
      β”‚ β”‚ └── object-keys@1.1.1 deduped
      β”‚ β”œβ”€β”¬ string.prototype.trimleft@2.1.2
      β”‚ β”‚ β”œβ”€β”€ define-properties@1.1.3 deduped
      β”‚ β”‚ β”œβ”€β”€ es-abstract@1.17.5 deduped
      β”‚ β”‚ └─┬ string.prototype.trimstart@1.0.1
      β”‚ β”‚   β”œβ”€β”€ define-properties@1.1.3 deduped
      β”‚ β”‚   └── es-abstract@1.17.5 deduped
      β”‚ └─┬ string.prototype.trimright@2.1.2
      β”‚   β”œβ”€β”€ define-properties@1.1.3 deduped
      β”‚   β”œβ”€β”€ es-abstract@1.17.5 deduped
      β”‚   └─┬ string.prototype.trimend@1.0.1
      β”‚     β”œβ”€β”€ define-properties@1.1.3 deduped
      β”‚     └── es-abstract@1.17.5 deduped
      └── function-bind@1.1.1

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:21 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
ttz642commented, Jun 17, 2020

@skydiver getDevicePowerState fails with:

{"error":401,"errmsg":"no authorization"}

Will you be implementing a websocket version, ie: getWSDevicePowerState() ?

1reaction
ahmed-essawycommented, Jun 13, 2020

Thanks @skydiver , I tried the fix but, unfortunately, the same error still happen

Read more comments on GitHub >

github_iconTop Results From Across the Web

toggleDevice - eWeLink API
toggleDevice. Switch specified device current power state. Usage. const status = await connection.toggleDevice('<your device id>'); console.log(status);
Read more >
Cannot toggleDevice (or getPowerState) - githubmemory
I can login, get device list for more info, however I cannot toggleDevice - the ewelink API returns HTTP 500, however payload/URL seems...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found