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.
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.
curl -X GET -H "token: YOURTOKEN" https://app-api-fk.niu.com/v3/motor_data/index_info\?sn=YOURSERIALNUMBER | jq
{
"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
}
curl -X GET -H "token: YOURTOKEN" https://app-api-fk.niu.com/v3/motor_data/battery_info\?sn\=YOURSERIALNUMBER
{
"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
}
{
"data": "",
"desc": "登录信息错误",
"trace": "Fail!TOKEN ERROR",
"status": 1131
}
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:
-
start mitmproxy on your computer, note ip and port (10.0.0.245:8080 in my case)
-
check mitmproxy and search for the request.. ..and hit return
-
dont forget to undo your proxy wifi settings :)
Feel free to contact me on Telegram if you need any help or have any questions!