Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not getWifiDevice (org.freedesktop.NetworkManager was not provided by any .service files) #8

Closed
diegoribero opened this issue Apr 29, 2019 · 2 comments

Comments

@diegoribero
Copy link

Hey guys

I'm testing this library on a Rpi3, for the sake of testing the module fast I flashed a 2019-04-08-raspbian-stretch-lite.img into the Pi

I wasn't able to install the module following your instructions as stated in issue #7, However, once installed I used the sample server code but it failed with a:
Error: Could not getWifiDevice at new NetworkManagerError (/home/pi/network-api/node_modules/nm-api/dist/nm/index.js:80:23)

image

Code:

const nm = require(’nm-api’);

const port = Number(process.env.NM_SERVICE_API_PORT);

nm.createHttpServer()
.then((app) => {
  app.listen(port);
  console.log(`NetworkManager HTTP APIs running on port ${port}`);
})
.catch((err) => {
  console.error('Something went wrong when starting nm-api server', err);
});

Rpi3 on 2019-04-08-raspbian-stretch-lite.img
Node: 10.15.3
npm: 6.9.0

@maciekrb
Copy link

You would rather want to run this inside of a balenalib node image. You can build a Dockerfile and install from the repo, for instance:

# netmanager/Dockerfile.template
FROM balenalib/%%RESIN_MACHINE_NAME%%-node:8

ENV DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket

RUN apt-get update && apt-get install --yes --no-install-recommends \
    build-essential \
    git \
    python \
  && apt-get clean 
COPY . /app
RUN cd /app && npm install
CMD ["node", "/app/index.js"]

A sample package.json looks like this:

# netmanager/package.json
{
  "name": "netmanager",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "nm-api": "git+https://github.com/balena-io-modules/nm-api.git#master"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

The index.js is pretty much the example code referenced in the nm-api repo:

const nm = require("nm-api");

const port = Number(8081);

nm.createHttpServer()
.then((app) => {
  app.listen(port);
  console.log(`NetworkManager HTTP APIs running on port ${port}`);
})
.catch((err) => {
  console.error('Something went wrong when starting nm-api server', err);
});

You also probably want a docker-compose.yml that enables the dbus communications.

version: '2'

services:
  netmanager:
    labels:
      io.balena.features.dbus: '1'
    build: 
      context: ./netmanager
    restart: always
    ports:
      - "8081:8081" # assumes you are running the HTTP service on this port

@diegoribero
Copy link
Author

This worked, thank you very much @maciekrb!
I may have had some configuration issues, it looks like at the time, the wifi device of my Rpi wasn't really due to additional hardware

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants