![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
api-m77-raspberry-wifi-node-nmcli
Advanced tools
API to interact with the functionality of the m77-raspberry-wifi-node-nmcli module
Si quieres ver el documento en español, por favor consulta el archivo README_es.md
My natural language is Spanish. All texts have been translated with Google Translator.
This is the new integration of the new module to configure WiFi networks from nodejs
In current versions of Raspberry OS wpa_cli is no longer used, instead all network configuration is done through nmcli. For this reason the package m77-raspberry-wifi-node is no longer used, therefore the package api-m77-raspberry-wifi-node is not used either*
node.js server with express that creates an API with the functionalities of the module m77-raspberry-wifi-node-nmcli, with which you can configure the Wi-Fi network of Raspberry Pi that uses nmcli.
For developers who need to create a frontend with the functionalities of the m77-raspberry-wifi-node-nmcli module, it will be much easier to implement it as a backend.
As with my previous contributions. Because I have benefited a lot from the work of other people and organizations that offer development modules and I want to give something back to the community.
I hope you find it very useful and recommend it so that it reaches more developers :-)
From git
git clone https://github.com/mangos77/api-m77-raspberry-wifi-node.git
cd api-m77-raspberry-wifi-node
npm install
From npm
mkdir api-m77-raspberry-wifi-node-nmcli && cd api-m77-raspberry-wifi-node-nmcli && npm install api-m77-raspberry-wifi-node-nmcli --no-save && mv node_modules/api-m77-raspberry-wifi-node/* ./ && rm -rf node_modules && npm install
It is very simple to configure the package, it will be done in two files:
It is optional and only to modify the execution scripts to pass environment variables, such as the port for each type of execution:
"scripts": {
"dev": "PORT=8081 NODE_ENV=development node src/index",
"start": "PORT=8080 NODE_ENV=production node src/index"
},
In this file you will find the configuration of all the operation for the execution of the API
There are two blocks to configure depending on whether the execution is development or production:
const config = () => {
const config_dev = {}
const config_prod = {}
}
If running in production mode, the environment variable NODE_ENV=production is taken config_prod will overwrite the values of config_dev
The values to adjust are:
Example:
const config_dev = {
name: pkjson.name,
version: pkjson.version,
production: false,
port: process.env.PORT || 8081,
allowHosts: ['localhost', '127.0.0.1', 'iface=eth0'],
wifi_config: { debugLevel: 2 }
}
const config_prod = {
production: true,
port: process.env.PORT || 8080,
allowHosts: ['localhost', '127.0.0.1'],
wifi_config: { debugLevel: 0 }
}
In the docs folder you will find postman_collection.json: Postman collection to be imported and used
The available endpoints are:
In order to understand all the responses of each endpoint, it can be of great help to see the documentation of the module on which this api is based [m77-raspberry-wifi-node-nmcli](https://github.com /mangos77/m77-raspberry-wifi-node-nmcli)
List the available Wifi interfaces
IMPORTANT NOTE All of the following endpoints optionally can be submitted with the following parameters in the URL (device and debugLevel).
These values have a higher priority than those specified in config.js -> wifi_config and are used to give greater control of the actions if required.
Wifi interface status
URL parameters:
List of saved WiFi networks
List of all Wi-Fi networks available within range of the device, ordered by their power, but always the network to which it is connected first.
Delete all saved networks
Delete the specified network
URL parameters:
Establish connection with a Wi-Fi network
{
"ssid": "mangos77",
"psk": "ABCDE12345",
"bssid": "",
"ipaddress": "192.168.1.50",
"netmask": "255.255.255.0",
"gateway": "192.168.1.1",
"dns": ["8.8.8.8", "192.168.1.1"],
"hidden": false,
"timeout": 30
}
If you want to statically set ipaddress, netmask, gateway or dns; all of these parameters are required
Try to reconnect to one of the saved Wi-Fi networks
{
"ssid": "mangos77",
"timeout": 30
}
Disconnect the Wifi that is connected to the device
Enlista las interfaces ethernet disponibles
Status de la interfaz Ethernet
Set the Ethernet connection parameters
{
"ipaddress": "192.168.1.50",
"netmask": "255.255.255.0",
"gateway": "192.168.1.1",
"dns": ["8.8.8.8", "192.168.1.1"],
"timeout": 30
}
If you want to set ipaddress, netmask, gateway or dns statically; all these parameters are required
You can install pm2 to manage startup, number of instances, etc.
By default, it is not possible for you to set port 80 for execution since ports lower than 1024 are only accessible by the user root or *sudo.
But you can fix it with:
sudo iptables -A PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-port 8081
This is the list of all the response codes and what function they are associated with, if it is an error code (either in the responses the value of success indicates whether it was successful or an error).
This can be used to adapt the response texts as required in developments and/or translate them in the implementation.
Code | Err | Function | Description |
---|---|---|---|
1001 | list_interfaces | Wi-Fi interfaces found on the system | |
2001 | X | list_interfaces | There are no Wi-Fi interfaces in the system |
1011 | status | Got interface status | |
2011 | X | status | Failed to get the status of interface |
1021 | saved_networks | List of saved Wi-Fi networks | |
2021 | X | saved_networks | It was not possible to obtain the list of saved Wi-Fi networks in inteface |
1031 | scan | List of scanned Wi-Fi networks was obtained | |
2031 | X | scan | It was not possible to obtain the list of the scanned Wi-Fi networks in inteface |
1041 | remove_all_networks | All Wi-Fi networks removed | |
1051 | remove_network | Wi-Fi network has been removed on the system | |
2051 | X | remove_network | Wi-Fi network is not in saved networks |
1061 | connect | The Wi-Fi network has been successfully configured on interface | |
2061 | X | connect | Could not connect to SSID on interface |
2062 | X | connect | The static ipaddress is not valid |
2063 | X | connect | The static netmask is not valid |
2064 | X | connect | The static gateway is not valid |
2065 | X | connect | One or more static dns are not valid |
2066 | X | connect | To set a custom address parameters; ipaddress, netmask, gateway and dns are required |
1071 | reconnect | The Wi-Fi network has been successfully reconnected on interface | |
2071 | X | reconnect | Could not reconnect to SSID on interface, because the Wi-Fi network is not in those previously saved in the system |
1091 | disconnect | You have been disconnected from the Wi-Fi network | |
2091 | X | disconnect | There is no connection established to disconnect |
2092 | X | disconnect | It was not possible to disconnect from the network |
2093 | X | disconnect | An error occurred when obtaining the data of the connected Wi-Fi network to be able to disconnect |
1101 | init | Interface has been found on the system | |
2101 | X | init | The interface does not exist. Please execute the listInterfaces() method to get the list of available Wifi interfaces and set in init() method |
Code | Err | Function | Description |
---|---|---|---|
1002 | list_interfaces | Ethernet interfaces found on the system | |
2002 | X | list_interfaces | There are no ethernet interfaces in the system |
1012 | status | Got ethernet interface status | |
2013 | X | status | Failed to get the status of ethernet interface |
1062 | setConnection | The ethernet interface has been successfully configured | |
2067 | X | setConnection | Ethernet interface cable is not plugged in |
2068 | X | setConnection | Could not connect to ethernet interface |
2062 | X | setConnection | The static ipaddress is not valid |
2063 | X | setConnection | The static netmask is not valid |
2064 | X | setConnection | The static gateway is not valid |
2065 | X | setConnection | One or more static dns are not valid |
2066 | X | setConnection | To set a custom address parameters; ipaddress, netmask, gateway and dns are required |
1102 | init | Ethernet interface has been found on the system | |
2102 | X | init | The ethernet interface does not exist. Please execute the listInterfaces() method to get the list of available ethernet interfaces and set in init() method |
I hope it helps you and please tell me about any errors or comments :-)
FAQs
API to interact with the functionality of the m77-raspberry-wifi-node-nmcli module
The npm package api-m77-raspberry-wifi-node-nmcli receives a total of 273 weekly downloads. As such, api-m77-raspberry-wifi-node-nmcli popularity was classified as not popular.
We found that api-m77-raspberry-wifi-node-nmcli demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.