Skip to content

Simple Shell-Script to get Infos from you NIU E-Scooter using NIU API.

License

Notifications You must be signed in to change notification settings

cascha42/niu-info

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!

About

Simple Shell-Script to get Infos from you NIU E-Scooter using NIU API.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages