balena-labs-research / python-wifi-connect

An API for controlling Wi-Fi connections on balena devices.
MIT License
15 stars 7 forks source link

Can't access API #6

Closed luandro closed 1 year ago

luandro commented 1 year ago

I'm trying to get this working with the starter-interface, but it seems nothing is running on port 9090. You can check the docker-compose file here.

Logs from the python-wifi-connect container:

[2023-03-05 17:53:59] - [INFO] - Checking for previously configured Wi-Fi connections...
command failed: Resource busy (-16)
[2023-03-05 17:54:12] - [WARNING] - IW resource busy. Retrying...
[2023-03-05 17:54:12] - [WARNING] - IW is unable to complete the request. This can happen on some devices and is usually nothing to worry about.
[2023-03-05 17:54:13] - [INFO] - Adding connection of type HOTSPOT
[2023-03-05 17:54:15] - [INFO] - Connection active.
[2023-03-05 17:54:15] - [INFO] - Listening on 172.17.0.1 port 9090

Payload from starter-interface:


{
    "message": "\u001b[31mconnect ECONNREFUSED 127.0.0.1:9090\u001b[39m",
    "name": "Error",
    "stack": "Error: \u001b[31mconnect ECONNREFUSED 127.0.0.1:9090\u001b[39m\n    at AxiosError.from (/app/node_modules/axios/dist/node/axios.cjs:789:14)\n    at RedirectableRequest.handleRequestError (/app/node_modules/axios/dist/node/axios.cjs:2744:25)\n    at RedirectableRequest.emit (node:events:525:35)\n    at eventHandlers.<computed> (/app/node_modules/follow-redirects/index.js:14:24)\n    at ClientRequest.emit (node:events:513:28)\n    at Socket.socketErrorListener (node:_http_client:494:9)\n    at Socket.emit (node:events:513:28)\n    at emitErrorNT (node:internal/streams/destroy:151:8)\n    at emitErrorCloseNT (node:internal/streams/destroy:116:3)\n    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)",
    "config": {
      "transitional": {
        "silentJSONParsing": true,
        "forcedJSONParsing": true,
        "clarifyTimeoutError": false
      },
      "adapter": [
        "xhr",
        "http"
      ],
      "transformRequest": [
        null
      ],
      "transformResponse": [
        null
      ],
      "timeout": 30000,
      "xsrfCookieName": "XSRF-TOKEN",
      "xsrfHeaderName": "X-XSRF-TOKEN",
      "maxContentLength": -1,
      "maxBodyLength": -1,
      "env": {},
      "headers": {
        "Accept": "application/json, text/plain, */*",
        "User-Agent": "axios/1.2.3",
        "Accept-Encoding": "gzip, compress, deflate, br"
      },
      "baseURL": "http://127.0.0.1:9090/",
      "method": "get",
      "url": "v1/connection_status"
    },
    "code": "ECONNREFUSED",
    "status": null
  }```
maggie44 commented 1 year ago

Try telling the starter interface in your compose file that it is on the bridge network like in the example starter interface compose:

    environment:
      NETWORK_MODE: bridge # Tell the app if running in `bridge` or `host` network mode

https://github.com/balena-labs-research/starter-interface/blob/5cc4965c6caecdad07875942ab209c8092ab6910/expressjs/src/routes/v1/Wifi.ts#L29

luandro commented 1 year ago

That did the trick, thanks @maggie0002 :tada:

keenanjohnson commented 1 year ago

Related to https://github.com/balena-labs-research/starter-interface/discussions/138