Giter VIP home page Giter VIP logo

niu-info's Introduction

niu-info

Easy Bash-Script to get Live-Informations about you NIU E-scooter using the NIU API. I ride a NIU N1S 2019 Special Blue (gloss) version.

How it works

Simply by requesting the NIU API using curl its possible to gain a lot of information about your NIU Scooter. You only need cURL, jq, your API-Token (check "How to get your Token" for that) and the Serial-Number of you Scooter.

Here are some examples using the NIU-API in combination with jq:

Request motor_data:
curl -X GET -H "token: YOURTOKEN" https://app-api-fk.niu.com/v3/motor_data/index_info\?sn=YOURSERIALNUMBER | jq
Response:
{
  "data": {
    "isCharging": 0,
    "lockStatus": 0,
    "isAccOn": 0,
    "isFortificationOn": "",
    "isConnected": true,
    "postion": {
      "lat": 52.512615,
      "lng": 13.419838333333333
    },
    "hdop": 0,
    "time": 1567101176297,
    "batteries": {
      "compartmentA": {
        "bmsId": "BN1GPC2BXXXXXXXX",
        "isConnected": true,
        "batteryCharging": 68,
        "gradeBattery": "99.2"
      }
    },
    "leftTime": "17.0",
    "estimatedMileage": 39,
    "gpsTimestamp": 1567101176297,
    "infoTimestamp": 1567101176297,
    "nowSpeed": 0,
    "batteryDetail": true,
    "centreCtrlBattery": 100,
    "ss_protocol_ver": 3,
    "ss_online_sta": "1",
    "gps": 3,
    "gsm": 20,
    "lastTrack": {
      "ridingTime": 689,
      "distance": 4235,
      "time": 1567092471296
    }
  },
  "desc": "成功",
  "trace": "成功",
  "status": 0
}
Request battery_info:
curl -X GET -H "token: YOURTOKEN" https://app-api-fk.niu.com/v3/motor_data/battery_info\?sn\=YOURSERIALNUMBER
Response:
{
  "data": {
    "batteries": {
      "compartmentA": {
        "items": [
          {
            "x": 0,
            "y": 0,
            "z": 0
          },
          {
            "x": 1,
            "y": 0,
            "z": 0
          },
          ...->
          (cutted for better overview)
          <-...
          {
            "x": 485,
            "y": 0,
            "z": 0
          },
          {
            "x": 486,
            "y": 0,
            "z": 0
          }
        ],
        "totalPoint": 487,
        "bmsId": "BN1GPC2BXXXXXXXX",
        "isConnected": true,
        "batteryCharging": 68,
        "chargedTimes": "8",
        "temperature": 36,
        "temperatureDesc": "normal",
        "energyConsumedTody": 85,
        "gradeBattery": "99.2"
      }
    },
    "isCharging": 0,
    "centreCtrlBattery": "100",
    "batteryDetail": true,
    "estimatedMileage": 39
  },
  "desc": "成功",
  "trace": "成功",
  "status": 0
}
If you messed something up with the token, this is the response:
{
  "data": "",
  "desc": "登录信息错误",
  "trace": "Fail!TOKEN ERROR",
  "status": 1131
}

How to get your Token

In order to log in the NIU cloud to retrieve any data using the API you need the serial number of your niu-scooter and an authentication token. The easiest way to obtain the token (and serial number too) is by capturing the packets from the NIU App (using Wireshark, mitmproxy or any other packet capture software) and extracting the token field from the HTTP header.

I my case i use mitmproxy on Linux together with an Android Device so this tutorial is for that setup:

  1. start mitmproxy on your computer, note ip and port (10.0.0.245:8080 in my case)

  2. setup proxy on android device in wifi settings

  3. open niu app to force a api-get request

  4. check mitmproxy and search for the request.. ..and hit return

  5. there's your token and serial number (yay \o/)

  6. dont forget to undo your proxy wifi settings :)

Any questions? Need help?

Feel free to contact me on Telegram if you need any help or have any questions!

niu-info's People

Contributors

cascha42 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.