I am currently building an application on Raspberry Pi using Python, and I am trying to connect to the wifi. The package I am using is wifi 0.3.8 installed via pip3.
The code looks like this for connecting:
cell = wifi.Scheme.find('wlan0', ssid)
scheme = wifi.Scheme.for_cell('wlan0', cell.ssid, cell, password)
scheme.save()
scheme.activate()
There are several problems I've encountered:
Uses ifup and ifdown
The current problem with the package is it uses /sbin/ifup and /sbin/ifdown. These are deprecated and do not work. My hack fix was to reroute to use /sbin/ifconfig wlan0 up and /sbin/ifconfig wlan0 down. Yes very hacky but it worked.
Modifies /etc/network/interfaces
The biggest problem I've encountered is modified /etc/network/interfaces by placing a connection string in there with something like:
source-directory /etc/network/interfaces.d
uface wlan0-[network-ssid-name]
Which breaks the wifi completely. I've had to re-type the entire configuration file to get it working again. It SHOULD be modifying /etc/wpa_supplicant/wpa_supplicant.conf only.
Would anyone have any suggestions on how to correctly connect to the wifi using Python?
Related
I am attempting to send data from a Python script running on a Raspberry Pi to a Java Micronaut ServerWebSocket running on a Windows machine, but I am getting asyncio.exceptions.TimeoutError errors during the process.
I attempted to use the websockets library in Python on the Raspberry Pi to establish a websocket connection, but encountered a ConnectionRefusedError. Is this issue related to a network problem as mentioned here, and should I ask somewhere else like Superuser or Serverfault? Or is there another solution to this problem?
As #life888888 suggested, it had something to do with Windows firewall.
But instead of the public firewall being the problem, it was the one for the domain network instead.
How could I launch code.py that only exists on a raspberry, from a python command line on a computer connected by an Ethernet cable. Machine A and the raspberry are connected to each other by a simple ethernet cable, and none of those two endpoints are connected to the internet. They only have the latest version of python installed and can't have anything more installed on them.
It looks like subprocess.Popen() could be a way to tackle it. But with the little knowledge I have I can't understand and know for sure if using this method is suitable !
Thank you for your time :)
One of the Ubuntu machines I manage is having an issue where it completely disables the network port every time I run a Python script on it. It does not matter what the script is, after about 5 minutes of execution, the network show as unreachable. I have tried disabling and re-enabling the network via the terminal but this does not bring the port back online. Even doing a normal reboot does nothing, I have to physically unplug the machine to get it to come back up. Has anyone had this problem before?
Edit: Linux version 4.15.0-99-generic (gcc version 7.5.0). The network is a domain with this computer hooking up via a dynamic IP linked to a static IP router. This is only one of about 50 Linux machines we (college IT staff) manage and this is the only one that has ever done anything like this. Other computers in the same room with the exact same network setup run scripts perfectly.
See https://docs.python.org/3.8/library/socket.html#example and read the part where it talks about why you need to use SO_REUSEADDR.
I'm using PyZMQ for IPC (over TCP) on Windows 10, as part of an automated updater. I have noticed that on some computers, a firewall prompt appears to select if it can use public or private internet, despite the fact that it makes no connections to the internet - only to localhost.
This PyInstaller-packaged script is launched by a user-land script.
So:
Script launches my PyInstaller-packaged script->
Script uses pyzmq strictly to connect to localhost->
Windows prompts how it should be allowed through firewall
This prompt doesn't stop the program, but I don't want users to see that and wonder what virus they might have.
This is the code that supposedly triggers it:
sckt = self.zmq_context.socket(zmq.REQ)
sckt.connect('tcp://localhost:%s' % updater_shared_port)
Is there anything I can do to stop that pop-up from Windows Firewall?
Thanks!
Yes, there is something:
may implement the connection by some other than tcp:// transport class.
ZeroMQ can help you build your ideas via smart transports{ ipc:// | inproc:// | vmci:// } given you need not assemble/disassemble the full-height-L3-ISO-OSI stack to reach a counterparty, hosted on the same localhost.
The firewall could be configured to allow your programmes to run unhindered. That might be a nuissance to do by hand. There's probably a way to have an installer configure the firewall appropriately, but that'll be a ton of work to set up.
On the off-chance that it's the binding end that's the causing the pop up (not the connecting end as you suggest), apparently one can bind a zmq socket to a particular interface. This is done with a connection string such as zmq_bind(socket, "tcp://127.0.0.1:5555"); This will clamp the socket to the loopback, which may well not trouble the firewall at all. zmq_bind(socket, "tcp://*:5555) will open a socket on all interfaces, including any Internet facing interfaces, which should certainly grab the attention of the firewall. If you've not already tried that, might be worth a quick go.
I am using Python 2.7 and wifi library (https://wifi.readthedocs.org/en/latest/) on a Raspberry Pi. I have managed to install wifi library using:
sudo pip install wifi
on the terminal. The library seems to work but I can't figure out the way to connect to a wifi using a password. The documentation on the website is a bit difficult to understand, especially if you are a Python noob like me. I used this:
>>> from wifi import Cell, Scheme
>>> Cell.all('wlan0')
and I got all the wifi networks available and also the one I want to connect to called test1. So I am sure that the library works. I followed the steps on the website but got a permission denied error at:
>>> scheme.save()
Also, before that there was this command:
>>> scheme = Scheme.for_cell('wlan0', 'home', cell)
Does anyone know what that 'home' refer to? Is it the SSID name? Can anyone help me connect to a wifi called test1 whose password is passwordtest1? Is there any easier way to connect to wifi through terminal so as not to use Python?. Thanks in advance.
After some research, I didn't find a way to connect easily to a wifi using Python on a Raspberry Pi. So I solved my problem by using the wifi command on the Terminal:
sudo wifi connect --ad-hoc SSID_Name
Which automatically asks me for an input: passkey> .Where you can actually type the password, press enter and after that it automatically connects to the wifi. After that I can run my Python script which needs a connection to the internet in order to run. The wifi command is preferable to other terminal commands when it comes to my problem cause it needs less time to connect to a wifi manually. For example it is preferable to the process which uses this terminal command:
sudo nano /etc/network/interfaces
I hope this helps everyone who has the same problem.