Giter VIP home page Giter VIP logo

pifi's Introduction

pifi

A headless wifi provisioning system, primarily designed for robots with Raspberry Pi's.

Build Status Coverage Status

Pifi uses NetworkManager to do the heavy lifting under the hood.

The command line tool is pifi:

Usage:
  pifi status                   Shows if the device is in AP mode or connected to a network
  pifi add <ssid> <password>    Adds a connection to scan/connect to on bootup (needs sudo)
  pifi remove <ssid>            Remove this network (may interfere with ssh)
  pifi list seen                Lists the SSIDs that see seen during bootup
  pifi list pending             Lists the SSIDs that still need to configured in NetworkManager
  pifi set-hostname <hostname>  Set the hostname of the system, also deletes existing AP mode configurations
  pifi --version                Prints the version of pifi on your system

Options:
  -h --help    Show this help message and exit
  --version    Show pifi version and exit

Pifi runs a script at boot up that does the following by default:

  • Determine if there is wifi device capable of access point mode
  • Scan for visible access points, and save the SSIDs to /var/lib/pifi/seen_ssids
  • Go through any pending connections in /var/lib/pifi/pending, and see if any are visiable
  • If any of the pending connections are visible, connect to them, and remove them from pending
  • Otherwise look for an existing AP mode definiton and start it
  • If there is no existing AP mode definition create one with the configuration in /etc/pifi/default_ap.em (SSID:<HOSTNAME><4HEX> and password:'robotseverywhere'). (Where <HOSTNAME> is the hostname of the system and <4HEX> is the last 4 digits of the device mac address.)
  • If AP mode was not started, and a button is configured, wait for a button press to start AP mode

Connecting to a network while in AP mode

Connect to the ap mode wifi (default <HOSTNAME><4HEX>, password robotseverywhere) on your laptop. (Where <HOSTNAME> is the hostname of the system and <4HEX> is the last 4 digits of the device mac address.)

SSH into the device with ssh [email protected].

Once logged into the device, run sudo pifi add WIFI_SSID PASSWORD, and reboot sudo reboot.

Your device should now be connected to your network.

Using a Button to Start AP Mode

When pifi starts without AP mode (because it connected to an existing network), if there is an input device specified in pifi.conf it will wait for a KEY_CONFIG press and start AP mode.

On Magni, the input device is the gpio-keys driver, connected to a button on the sonar board. This allows the button to show up as a input device, with a name specified in the device tree file. The same name should be specified in pifi.conf, so that pifi can grab that device and listen for events. On a event that matches a KEY_CONFIG press,

Installation

The recommended way to install is from debs. The apt source at https://packages.ubiquityrobotics.com/ has the packages.

If that source is configured on your system, simply run sudo apt install pifi.

To install from source, run sudo pip3 install . in the pifi directory after cloning this repo.

Dependencies

Note: Don't worry about dependencies if you are installing from debs, they will be installed automatically.

This package depends on python3-networkmanager, python3-empy, and python3-yaml.

python3-networkmanager is not availible in the standard ubuntu/debian repos, so you will have install it from pip3 install python-networkmanager, or use the debian package from https://packages.ubiquityrobotics.com/. More info here

Configuration

If you want to change the behavior of pifi, a few options are availible to tweak.

The main configuration file is a YAML file at /etc/pifi/pifi.conf.

The default configuration file is:

# YAML configuration file for pifi

# Should pifi delete other ap mode configurations in NetworkManager?
# Default: True
# If true, during the next boot where there are no networks availble 
# pifi will delete existing connections, and create a new default one
delete_existing_ap_connections: True

# The network interface to use for AP mode
# Default: any
# If set to any pifi will pick one automatically
ap_device: any

# The network interface to use for connecting out
# Default: any
# If set to any pifi will pick one automatically
client_device: any

# Path to a Linux LED device to use
# ex: /sys/class/leds/led0
status_led: None

# Name of a user input device to use
# ex: "Keyboard 5"
button_device_name: None

The settings of the default AP that pifi creates are also configurable. /etc/pifi/default_ap.em contains and empy template of the json that represents the connection settings.

The varibles passed into the template are the hostname of the system (hostname), the MAC address of the device (mac), and a newly generated UUIDv4 (uuid_str).

This is the default configuration:

{
    "connection": {
        "id": "Pifi AP Mode",
        "type": "802-11-wireless",
        "autoconnect": "False",
        "uuid": "@(uuid_str)"
    },

    "802-11-wireless": {
        "mode": "ap",
        "security": "802-11-wireless-security",
        "ssid": "@(hostname)@(mac.replace(":", "")[-4:])"
    },

    "802-11-wireless-security": {
        "key-mgmt": "wpa-psk",
        "psk": "robotseverywhere"
    },

    "ipv4": {
        "method": "shared"
    },
    "ipv6": {
        "method": "ignore"
    }
}

Empy uses the template format @() with python expressions inside of the parenthesis.

The mac.replace(":", "")[-4:] gets the last 4 digits of the MAC address after removing colons.

Interfacing

Your code can interface with pifi via the files in /var.

/var/lib/pifi/pending is a JSON file that contains a list of wifi connections that should be activated. The connections should be JSON serializations of the NetworkManager connection configuration.

Example contents of /var/lib/pifi/pending:

[
  {
    "ipv4": {
      "method": "auto"
    },
    "802-11-wireless-security": {
      "key-mgmt": "wpa-psk",
      "psk": "supersecurepassword"
    },
    "connection": {
      "type": "802-11-wireless",
      "autoconnect": true,
      "id": "wifi",
      "uuid": "ce17378f-b187-48ab-af93-48613e88a5e5"
    },
    "802-11-wireless": {
      "mode": "infrastructure",
      "ssid": "wifi",
      "security": "802-11-wireless-security"
    },
    "ipv6": {
      "method": "auto"
    }
  }
]

/var/lib/pifi/seen_ssids is a plain text file with the list of SSIDs seen when pifi was starting up, as many cards can't scan once they start AP mode.

Example contents of file:

xfinitywifi
xfinitywifi
xfinitywifi
Aleopile
Jhuangdds
Requilme-CA2
Linksys New
xfinitywifi
Aleopile
Jhuangdds
Requilme-CA2
ATT9C8eh3A
HOME-616E-2.4
HOME-99EB
linksys
xfinitywifi

Notice that the SSIDs can be duplicated (there will be one entry per AP).

pifi's People

Contributors

moffkalast avatar rohbotics avatar ulyssevautier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

pifi's Issues

AP mode does not activate on the fly when all networks are removed

Not sure if this is viable to implement, but it would be great if AP mode started in the case when:

  • pifi had previously set networks and connected to one

  • all networks are manually removed

Since otherwise the Pi needs to be restarted by unplugging power to be able to make any kind of connection again.

spelling "tunning"

PiFi is great. Thank you. Was exactly what I wanted and a super way to learn mpd to boot.

image

Small spelling error in interface. TUNNING should be TUNING

Support LEDs and Buttons

For status and forcing AP mode.

Would made easier by using the gpio-leds and gpio-keys drivers.

error: gpg: keyserver receiv failed: No name

Hello, thank you so much for sharing this method of provisioning Pi WiFi. I am new to Pi and I am not sure what's wrong but for some reason, I could not configure it. I am following the installation procedure and for some reason, the second command is showing me an error. When I use this code in my Raspberry pi terminal:

sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key C3032ED8

it shows me this error:

gpg: keyserver receiv failed: No name

I would really appeciate it if you can tell me how I can solve this issue.

Support of 18.04 or 20.04?

I noticed that the manual install instructions relies on a xenial bistro in your repo. Will that also work on 18.04 or 20.04?

Use argparse instead of docopt

That way we can eliminate a dependency, and provide more detailed help messages without being hindered by docopt's syntax.

pifi_startup fails to load pifi.conf and default_ap.em

pifi_startup fails to load pifi.conf and default_ap.em. I suspect that the ubiquityrobot user doesn't have access to the /etc folder. Here is the log file. If I recall correctly I am using the 2018-01-13-ubiquity-xenial-lxde image.

var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot NetworkManager[645]: [1455208134.7764] keyfile: add connection in-memory (3079b2bd-bfa7-4cbe-80df-f4473b73899e,"Pifi AP Mode")
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot NetworkManager[645]: [1455208134.7849] device (wlan0): Activation: starting connection 'Pifi AP Mode' (3079b2bd-bfa7-4cbe-80df-f4473b73899e)
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot NetworkManager[645]: [1455208134.7889] keyfile: update /etc/NetworkManager/system-connections/Pifi AP Mode (3079b2bd-bfa7-4cbe-80df-f4473b73899e,"Pifi AP Mode") and persist connection
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot NetworkManager[645]: [1455208134.7896] audit: op="connection-add-activate" uuid="3079b2bd-bfa7-4cbe-80df-f4473b73899e" name="Pifi AP Mode" pid=751 uid=0 result="success"
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot NetworkManager[645]: [1455208134.8013] device (wlan0): state change: disconnected -> prepare (reason 'none') [30 40 0]
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot NetworkManager[645]: [1455208134.8022] manager: NetworkManager state is now CONNECTING
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot NetworkManager[645]: [1455208134.8310] device (wlan0): state change: prepare -> config (reason 'none') [40 50 0]
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot NetworkManager[645]: [1455208134.8320] device (wlan0): Activation: (wifi) access point 'Pifi AP Mode' has security, but secrets are required.
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot NetworkManager[645]: [1455208134.8320] device (wlan0): state change: config -> need-auth (reason 'none') [50 60 0]
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: WARN /etc/pifi/pifi.conf doesn't exist, using default configuration
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: Using wlan0 for AP mode support
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: Using wlan0 for wifi client mode
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: Device is not connected to any network, Looking for pending connections
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: No SSIDs from pending connections found, Starting AP mode
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: No existing AP mode connections found
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: Creating new default AP mode connection with config:
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: WARN /etc/pifi/default_ap.em doesn't exist, using fallback configuration
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: {
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: "connection": {
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: "type": "802-11-wireless",
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: "autoconnect": false,
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: "id": "Pifi AP Mode",
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: "uuid": "3079b2bd-bfa7-4cbe-80df-f4473b73899e"
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: },
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: "ipv4": {
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: "method": "shared"
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: },
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: "ipv6": {
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: "method": "ignore"
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: },
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: "802-11-wireless": {
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: "mode": "ap",
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: "ssid": "ubiquityrobot844C",
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: "security": "802-11-wireless-security"
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: },
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: "802-11-wireless-security": {
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: "psk": "robotseverywhere",
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: "key-mgmt": "wpa-psk"
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: }
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: }
var/log/syslog.1:Feb 11 16:28:54 ubiquityrobot pifi_startup[751]: Initializing AP Mode

pifi status crashes the program as does add or remove. Only changing hostname seems to work

I've tried installing, uninstalling. Nada. I'm on ros melodic on a raspi 4

My output from terminal

pi@llt0001:~/pifi $ pifi status
Traceback (most recent call last):
File "/usr/local/bin/pifi", line 10, in <module>
sys.exit(main())
File "/usr/local/lib/python3.7/dist-packages/pifi/pifi.py", line 347, in main
commands[args.command](argv[1:])
File "/usr/local/lib/python3.7/dist-packages/pifi/pifi.py", line 69, in status
for ApModeDevice in nm.managedAPCapableDevices():
File "/usr/local/lib/python3.7/dist-packages/pifi/nm_helper.py", line 96, in managedAPCapableDevices
for device in managedWifiDevices(NetworkManager=NetworkManager):
File "/usr/local/lib/python3.7/dist-packages/pifi/nm_helper.py", line 85, in managedWifiDevices
for device in NetworkManager.NetworkManager.GetDevices():
File "<string>", line 3, in GetDevices
 File "/home/pi/.local/lib/python3.7/site-packages/NetworkManager.py", line 261, in proxy
self._proxy = dbus.SystemBus().get_object(self.dbus_service, self.object_path, follow_name_owner_changes=True)File "/home/pi/.local/lib/python3.7/site-packages/dbus/bus.py", line 225, in get_object
self._require_main_loop()   # we don't get the signals otherwise
RuntimeError: To make asynchronous calls, receive signals or export objects, D-Bus connections must be attached to a main loop by passing mainloop=... to the constructor or calling dbus.set_default_main_loop(...)     

Wifi Slow connection

I am using my mobile hotspot with raspi 3b+ and ubuntu 18.04 to ssh into pi

Ssh works perfectly and the ping is around 3 to 4ms while on simple nodes like telop

but when switched to camera node, the camera feed from raspi is very laggy

at that point of time the ping is around 400 - 200ms

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.