Giter Club home page Giter Club logo

ewelink-rest-api-server's Introduction

Ewelink REST API Server

A Node.js server application that processes HTTP requests and forwards commands to eWeLink servers for device operations like turn on/off or toggling. This server utilizes the eWeLink API.

Docker

docker run \
  -p <port>:3000 \
  -e "EWELINK_USERNAME=<your_username>" \
  -e "EWELINK_PASSWORD=<your_password>"  \
  -e "EWELINK_REGION=<your_region>" \
  -e "HASHING_ALGORITHM=<your_preferred_algorithm>" \
  -e "SERVER_MODE=dev" \
  -v "<your_local_pem_certs_folder>:/usr/src/app/volume/ssl/" \
  doganm95/ewelink-rest-api-server

Arguments

  • -e EWELINK_USERNAME - Your Ewelink Username, usually an email address
  • -e EWELINK_PASSWORD - Your Ewelink password
  • -e EWELINK_REGION - Your region, e.g. eu, us
  • -e PASSWORD_HASHING_ALGORITHM - supported:
    RSA-MD4, RSA-MD5, RSA-MDC2, RSA-RIPEMD160, RSA-SHA1, RSA-SHA1-2, RSA-SHA224, RSA-SHA256, RSA-SHA3-224, RSA-SHA3-256, RSA-SHA3-384, RSA-SHA3-512, RSA-SHA384, RSA-SHA512, RSA-SHA512/224, RSA-SHA512/256, RSA-SM3, blake2b512, blake2s256, id-rsassa-pkcs1-v1_5-with-sha3-224, id-rsassa-pkcs1-v1_5-with-sha3-256, id-rsassa-pkcs1-v1_5-with-sha3-384, id-rsassa-pkcs1-v1_5-with-sha3-512, md4, md4WithRSAEncryption, md5, md5-sha1, md5WithRSAEncryption, mdc2, mdc2WithRSA, ripemd, ripemd160, ripemd160WithRSA, rmd160, sha1, sha1WithRSAEncryption, sha224, sha224WithRSAEncryption, sha256, sha256WithRSAEncryption, sha3-224, sha3-256, sha3-384, sha3-512, sha384, sha384WithRSAEncryption, sha512, sha512-224, sha512-224WithRSAEncryption, sha512-256, sha512-256WithRSAEncryption, sha512WithRSAEncryption, shake128, shake256, sm3, sm3WithRSAEncryption, ssl3-md5, ssl3-sha1, whirlpool.
    Default, if omitted: sha3-512
  • -e SERVER_MODE can be prod or dev. For initial container setup & testing, try dev. If everything works, you can switch to -e "SERVER_MODE=prod", to turn off console logs
  • -p <port_to_use>:3000
  • -v <local_cert_folder>:/usr/src/app/volume/ssl/ - can contain the cert.pem and privkey.pem as files. If omitted, a non-ssl-encrypted http server will start

Example

docker run \  
  -p 8080:3000 \  
  -e "[email protected]" \  
  -e "EWELINK_PASSWORD=passW"  \  
  -e "EWELINK_REGION=eu" \  
  -e "PASSWORD_HASHING_ALGORITHM=sha512" \  
  -e "SERVER_MODE=prod" \  
  -v "C:\Users\Dogan\OneDrive\Desktop\certs_tmp\:/usr/src/app/volume/ssl/" \  
  doganm95/ewelink-rest-api-server  

Usage

Authorization

If SSL encryption is enabled (using privkey.pem and cert.pem files), each request must include an Authorization header with a Bearer Token. This token is your eWeLink password hashed using your chosen algorithm (default: sha3-512). In dev mode, the container logs the hashed password for copying.

API Endpoints

Fetch Devices List

  • Method: GET
  • Description: Retrieve a list of all registered devices along with their details.

Control a Device

  • Method: POST
  • Description: Control a device using its name or ID.
  • Body:
    {  
        "devicenameincludes": ["desk", "light"],  
        "deviceid": "100012f3f4",
        "params": {
            "switch": "on",
            "outlet": 2
        }
    }
    • devicenameincludes: An array of keywords contained in the device name. The most relevant device is controlled based on these keywords.
    • deviceid: Direct device ID reference (prioritized over devicenameincludes).
    • switch: Device action - valid values are on, off, or toggle.
    • outlet: Optional for multi-relay devices (starts from 1).

Migration & Resources

For updates to accommodate eWeLink's new OAuth mechanism:

ewelink-rest-api-server's People

Contributors

dependabot[bot] avatar doganm95 avatar nkrasko avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

ewelink-rest-api-server's Issues

Server not reading params.switch from POST

When posting to the Docker container using a body such as:

{  
    "params": {
        "switch": "on"
    },
    "deviceid": "xxxxxxx"
}

The server crashes and logs the following:

file:///usr/src/app/server/server.js:31
    const requestedActionOnDevice = req.body.params.switch != undefined && req.body.params.switch != "" ? String(req.body.params.switch) : undefined;
                                                    ^

TypeError: Cannot read property 'switch' of undefined
    at file:///usr/src/app/server/server.js:31:53
    at Layer.handle [as handle_request] (/usr/src/app/server/node_modules/express/lib/router/layer.js:95:5)
    at next (/usr/src/app/server/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/usr/src/app/server/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/usr/src/app/server/node_modules/express/lib/router/layer.js:95:5)
    at /usr/src/app/server/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/usr/src/app/server/node_modules/express/lib/router/index.js:335:12)
    at next (/usr/src/app/server/node_modules/express/lib/router/index.js:275:10)
    at jsonParser (/usr/src/app/server/node_modules/body-parser/lib/types/json.js:119:7)
    at Layer.handle [as handle_request] (/usr/src/app/server/node_modules/express/lib/router/layer.js:95:5)```

Authentication failed

Thank you very much for this work!

I am having a hard time to get the authentication right.
I am using the same username (my mailadres) and password as I am using to log in to the ewelink app.
I am in the Netherlands, and have set the region to "eu"

When starting, I see an error in the docker log:
Authentication failed. The application will continue and respond with the error message, to make sure you are informed.

I am in doubt of the right region, so i also tried "nl". In that case I get a docker log error:
FetchError: request to https://nl-api.coolkit.cc:8080/api/user/login failed, reason: getaddrinfo ENOTFOUND nl-api.coolkit.cc

Which makes me think my eu region is correct.

Should I use the same credentials as using in the ewelink app?

Kind regards

Secure and expose

Code should be secured against exploits/injections etc, so it can be exposed to the internet for external access by port forwarding.

every login try should be logged into a db, and successful logins should give a notification, possibly over tasker on android.

Container restart on file change

Container should detect file changes in any mounted volume and auto-restart on change detection.

comparison options:

  • by hash (resource hungry for big files)
  • by size (bad)
  • by date (probably best)

This would enable changing certs in the ssl directory and having the container restart automatically.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.