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

pywifi crossplatform library for connecting to Cozmo WIFI server (example) #9

Open
CozmoCyke opened this issue Sep 21, 2019 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@CozmoCyke
Copy link

CozmoCyke commented Sep 21, 2019

PyCozmo can only send command to Cozmo when the computer is connected to Cozmo WIFI server ! But now there's no code to connect your application to Cozmo wifi in PyCozmo.

Then I have try to use pywifi library to connect programmatically to Cozmo wifi ! This library is crossplatform.

https://pypi.org/project/pywifi/
https://github.com/awkman/pywifi

Example working with Windows 7 and last dev PyCozmo branch :

import pywifi
from pywifi import const
import time
import pycozmo

def pycozmo_program(cli: pycozmo.client.Client):

    cli.set_head_angle(pycozmo.MAX_HEAD_ANGLE.radians)
    time.sleep(1)
    cli.set_head_angle(pycozmo.MIN_HEAD_ANGLE.radians)
    time.sleep(1)

    cli.set_lift_height(pycozmo.MAX_LIFT_HEIGHT.mm)
    time.sleep(1)
    cli.set_lift_height(pycozmo.MIN_LIFT_HEIGHT.mm)
    time.sleep(1)

wifi = pywifi.PyWiFi()

ssid_Cozmo = 'Cozmo_' # add the Cozmo number
pw_Cozmo = '' # put Cozmo WIFI password with the dashes "-" ! 


iface = wifi.interfaces()[0]

iface.disconnect()
time.sleep(1)
assert iface.status() in\
    [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]

profile = pywifi.Profile()
profile.ssid = ssid_Cozmo
profile.auth = const.AUTH_ALG_OPEN
profile.akm.append(const.AKM_TYPE_WPA2PSK)
profile.cipher = const.CIPHER_TYPE_CCMP # = AES
profile.key = pw_Cozmo

iface.remove_all_network_profiles()
tmp_profile = iface.add_network_profile(profile)

iface.connect(tmp_profile)
time.sleep(30)
assert iface.status() == const.IFACE_CONNECTED

pycozmo.run_program(pycozmo_program)

#iface.disconnect()
#time.sleep(1)
#assert iface.status() in\
#    [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
@zayfod zayfod added enhancement New feature or request help wanted Extra attention is needed labels Sep 21, 2019
@legop3
Copy link

legop3 commented Apr 3, 2023

I just experimented with this. many modern Linux distros use nmcli now to control networks, pywifi uses wpa_cli which is not set up to be run without root in these aforementioned modern Linux distros.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants