$ sudo apt-get update
$ sudo apt-get install build-essential libssl-dev
$ sudo curl https://raw.githubusercontent.com/creationix/nvm/v0.25.0/install.sh | bash
$ source ~/.profile
$ nvm install 10
$ nvm alias default 10
Raspbian OS:https://www.raspberrypi.org/downloads/raspbian/
macOS
$ sudo diskutil list
$ sudo diskutil unmountDisk /dev/diskN
$ sudo dd bs=1m if=path_of_your_image.img of=/dev/rdiskN conv=sync
$ sudo diskutil eject /dev/rdiskN
As of the November 2016 release, Raspbian has the SSH server disabled by default. It can be enabled manually from the desktop
Method 1:
- Launch Raspberry Pi Configuration from the Preferences menu
- Navigate to the Interfaces tab
- Select Enabled next to SSH
- Click OK
or
Method 2:
$ sudo systemctl enable ssh
$ sudo systemctl start ssh
$ git clone https://github.com/creationix/nvm.git ~/.nvm
# $ cd ~/.nvm && git checkout v5.9.0
$ source ~/.nvm/nvm.sh
$ sudo vim ~/.bashrc
# 新增
source ~/.nvm/nvm.sh
$ nvm install 10
$ nvm alias default 10
$ npm install -g pm2
$ git clone https://github.com/TitanLi/Brunei-Hackation.git
$ cd Brunei-Hackation/API/raspberry-pi
$ npm install
$ pm2 start app.js --name "API-Service"
$ cd Brunei-Hackation/frontend/iot
$ npm install
$ pm2 start node_modules/react-scripts/scripts/start.js --name "web-service"
Method | URL |
---|---|
POST | http://127.0.0.1:30001/devices |
You can call API to create a device to cloud, then you can through a browser search http://127.0.0.1:30002 watch device on Web Dashboard.
Params:
Params | Type | Description | example |
---|---|---|---|
ip | String | Device IP address | "192.168.0.29" |
mac | String | Device media access control address (MAC address) |
"fa163e970e44" |
example:
{
"ip": "192.168.0.29",
"mac": "fa163e970e44"
}
Params:
Params | Type | example |
---|---|---|
status | String | "successfully" |
example:
{
"status": "successfully"
}
You can get a list of registered devices through the API.
Method | URL |
---|---|
GET | http://127.0.0.1:30001/devices |
None
Params:
Params | Type | Description | example |
---|---|---|---|
ip | String | Device IP address | "192.168.0.29" |
mac | String | Device media access control address (MAC address) |
"fa163e970e44" |
example:
[
{
"ip": "192.168.0.29",
"mac": "fa163e970e44"
},
{
"ip": "192.168.0.30",
"mac": "fa163e970e45"
}
]
You can update the sensor data through the registered mac address. Then search http://127.0.0.1:30002 through your browser, select the mac address of the device to view the data.
Method | URL |
---|---|
POST | http://127.0.0.1:30001/insert |
Params:
Params | Type | Description | example |
---|---|---|---|
mac | String | Device media access control address (MAC address) |
"fa163e970e44" |
sensorData | JSON Object | Arduino sensor data JSON key is the sensor name JSON value is the sensor value |
{ "humidity": "41", "temperature": "27" } |
JSON Object:
{
"Key1" : "Value1",
"Key2" : "Value2"
}
Annotation:
The sensorData parameter is a JSON Object whose "Key" is the name of the sensor and "Value" is the value of the sensor.
example:
{
"mac": "fa163e970e44",
"sensorData": {
"humidity": "41",
"temperature": "27"
}
}
example:
{
"status": "successfully"
}
Description: You can get the sensor data from the registered mac address.
Method | URL |
---|---|
GET | http://127.0.0.1:30001/query/:mac |
You can get the sensor data from the registered mac address.
Params:
Params | Type | Description | example |
---|---|---|---|
mac | String | The MAC above the Raspberry pi4 is the same as the WiFi SSID |
"fa163e970e44" |
Params:
Params | Type | Description | example |
---|---|---|---|
name | String | Sensor name | "humidity" |
value | String | Sensor data | "41" |
example:
[
{
"name": "humidity",
"value": "41"
},
{
"name": "temperature",
"value": "27"
}
]
You can get the host IP and MAC information by this API
Method | URL |
---|---|
GET | http://127.0.0.1:30001/localInfo |
None
Params:
Params | Type | Description | example |
---|---|---|---|
ip | String | Device IP address | "192.168.0.29" |
mac | String | Device media access control address (MAC address) |
"fa163e970e44" |
example:
{
"ip": "192.168.0.29",
"mac": "fa163e970e44"
}
Error message
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
handle method
$ rm -rf node_modules
$ rm package-lock.json
$ vim package.js ("react-scripts": "3.x.x" to "react-scripts": "^3.4.0")
$ npm install