finding connected Wifi network - qt

I'm using Ubuntu 18.04.
How do I retrieve the name of the WiFi that the system is connected to. So far I'm querying with the following but it is returning interface names instead of Wifi names:
QNetworkConfigurationManager nwkMgr;
QList<QNetworkConfiguration> nwkCnfList = nwkMgr.allConfigurations();
for(const QNetworkConfiguration &ncnf : nwkCnfList)
{
qDebug() << ncnf.name() << ncnf.bearerType();
if (ncnf.bearerType() == QNetworkConfiguration::BearerWLAN)
{
// would like to detect WiFi here
qDebug() << "WiFi:" << ncnf.name();
}
}
This lists the interfaces:
"Wired connection 1" 1
"ens33" 1
How can I get the NAME of the Wifi?

Can you use system variables ? If so do this:
export WNAME=$(iw dev | grep ssid | awk '{print $2}')
It will export it to a variable WNAME and you can use it inside scripts untill you logout or shutdown the system.

Related

Listing Directory Entries with Qt on Remote Windows Server

I am on a Windows Server which is in the same network as the Server with the computer name service.
I got this simple code which tries to list the content
QFileInfoList fiList = QDir("\\service\\Documents").entryInfoList(QDir::Files);
qDebug() << "sizeof filist: " << fiList.size();
for (const QFileInfo& fi : fiList)
{
qDebug() << fi.absoluteFilePath();
}
The output is the following:
sizeof filist: 0
I make sure that the folder is shared on the network by checking the properties and also using the windows explorer. I can access the folder via Windows Explorer.
Is the functionality I am trying to achieve not possible with QDir?
It turns out there are 2 backslashes more needed because \ needs to be escaped.
So the right code would be:
QFileInfoList fiList = QDir("\\\\service\\Documents").entryInfoList(QDir::Files);
qDebug() << "sizeof filist: " << fiList.size();
for (const QFileInfo& fi : fiList)
{
qDebug() << fi.absoluteFilePath();
}

Can I link two separate executables with MPI_open_port and share port information in a text file?

I'm trying to create a shared MPI COMM between two executables which are both started independently, e.g.
mpiexec -n 1 ./exe1
mpiexec -n 1 ./exe2
I use MPI_Open_port to generate port details and write these to a file in exe1 and then read with exe2. This is followed by MPI_Comm_connect/MPI_Comm_accept and then send/recv communication (minimal example below).
My question is: can we write port information to file in this way, or is the MPI_Publish_name/MPI_Lookup_name required for MPI to work as in this, this and this? As supercomputers usually share a file system, this file based approach seems simpler and maybe avoids establishing a server.
It seems this should work according to the MPI_Open_Port documentation in the MPI 3.1 standard,
port_name is essentially a network address. It is unique within the communication universe to which it belongs (determined by the implementation), and may be used by any client within that communication universe. For instance, if it is an internet (host:port) address, it will be unique on the internet. If it is a low level switch address on an IBM SP, it will be unique to that SP
In addition, according to documentation on the MPI forum:
The following should be compatible with MPI: The server prints out an address to the terminal, the user gives this address to the client program.
MPI does not require a nameserver
A port_name is a system-supplied string that encodes a low-level network address at which a server can be contacted.
By itself, the port_name mechanism is completely portable ...
Writing the port information to file does work as expected, i.e creates a shared communicator and exchanges information using MPICH (3.2) but hangs at the MPI_Comm_connect/MPI_Comm_accept line when using OpenMPI versions 2.0.1 and 4.0.1 (on my local workstation running Ubuntu 12.04 but eventually needs to work on a tier 1 supercomputer). I have raised as an issue here but welcome a solution or workaround in the meantime.
Further Information
If I use the MPMD mode with OpenMPI,
mpiexec -n 1 ./exe1 : -n 1 ./exe2
this works correctly, so must be an issue with allowing the jobs to share ompi_global_scope as in this question. I've also tried adding,
MPI_Info info;
MPI_Info_create(&info);
MPI_Info_set(info, "ompi_global_scope", "true");
with info passed to all commands, with no success. I'm not running a server/client model as both codes run simultaneously so sharing a URL/PID from one is not ideal, although I cannot get this to work even using the suggested approach, which for OpenMPI 2.0.1,
mpirun -n 1 --report-pid + ./OpenMPI_2.0.1 0
1234
mpirun -n 1 --ompi-server pid:1234 ./OpenMPI_2.0.1 1
gives,
ORTE_ERROR_LOG: Bad parameter in file base/rml_base_contact.c at line 161
This failure appears to be an internal failure;
here's some additional information (which may only be relevant to an
Open MPI developer):
pmix server init failed
--> Returned value Bad parameter (-5) instead of ORTE_SUCCESS
and with OpenMPI 4.0.1,
mpirun -n 1 --report-pid + ./OpenMPI_4.0.1 0
1234
mpirun -n 1 --ompi-server pid:1234 ./OpenMPI_4.0.1 1
gives,
ORTE_ERROR_LOG: Bad parameter in file base/rml_base_contact.c at line 50
...
A publish/lookup server was provided, but we were unable to connect
to it - please check the connection info and ensure the server
is alive:
Using 4.0.1 means the error should not be related to this bug in OpenMPI.
Minimal code
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <iostream>
#include <fstream>
using namespace std;
int main( int argc, char *argv[] )
{
int num_errors = 0;
int rank, size;
char port1[MPI_MAX_PORT_NAME];
char port2[MPI_MAX_PORT_NAME];
MPI_Status status;
MPI_Comm comm1, comm2;
int data = 0;
char *ptr;
int runno = strtol(argv[1], &ptr, 10);
for (int i = 0; i < argc; ++i)
printf("inputs %d %d %s \n", i,runno, argv[i]);
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (runno == 0)
{
printf("0: opening ports.\n");fflush(stdout);
MPI_Open_port(MPI_INFO_NULL, port1);
printf("opened port1: <%s>\n", port1);
//Write port file
ofstream myfile;
myfile.open("port");
if( !myfile )
cout << "Opening file failed" << endl;
myfile << port1 << endl;
if( !myfile )
cout << "Write failed" << endl;
myfile.close();
printf("Port %s written to file \n", port1); fflush(stdout);
printf("Attempt to accept port1.\n");fflush(stdout);
//Establish connection and send data
MPI_Comm_accept(port1, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &comm1);
printf("sending 5 \n");fflush(stdout);
data = 5;
MPI_Send(&data, 1, MPI_INT, 0, 0, comm1);
MPI_Close_port(port1);
}
else if (runno == 1)
{
//Read port file
size_t chars_read = 0;
ifstream myfile;
//Wait until file exists and is avaialble
myfile.open("port");
while(!myfile){
myfile.open("port");
cout << "Opening file failed" << myfile << endl;
usleep(30000);
}
while( myfile && chars_read < 255 ) {
myfile >> port1[ chars_read ];
if( myfile )
++chars_read;
if( port1[ chars_read - 1 ] == '\n' )
break;
}
printf("Reading port %s from file \n", port1); fflush(stdout);
remove( "port" );
//Establish connection and recieve data
MPI_Comm_connect(port1, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &comm1);
MPI_Recv(&data, 1, MPI_INT, 0, 0, comm1, &status);
printf("Received %d 1\n", data); fflush(stdout);
}
//Barrier on intercomm before disconnecting
MPI_Barrier(comm1);
MPI_Comm_disconnect(&comm1);
MPI_Finalize();
return 0;
}
The 0 and 1 simply specify if this code writes a port file or reads it in the example above. This is then run with,
mpiexec -n 1 ./a.out 0
mpiexec -n 1 ./a.out 1

QGamepadManager does not detect controller disconnection on ubuntu

I am working on a Qt project with a drone. Me and my friends are controlling a drone with a Xbox 360 Controller.
So to detect buttons and axes we have used the QGamepadManager class which is in the gamepadmanager module. It works well ! But we have a problem with this simplified code :
while (true)
{
if (this->gamepad->isConnected()) {
cout << "gamepad connected" << endl;
} else {
cout << "gamepad disocnnected" << endl;
}
}
bool GamepadMonitor::isConnected()
{
return QGamepadManager::instance()->connectedGamepads().size() == 1;
}
On windows, the method isConnected() works well but not on Ubuntu. When we launch the application with the gamepad connected the buttons are recognized and axis too. But the disconnection is not detected. When we launch the application without the gamepad, the connection is not recognized.
I have installed the joystick package. I am on Ubuntu 16.04. I am developping with Qt 5.8.
Do you have an idea ?
EDIT : I add the dmesg output
When I connect the gamepad :
[ 330.430405] usb 3-1: new full-speed USB device number 4 using xhci_hcd
[ 330.575708] usb 3-1: New USB device found, idVendor=045e, idProduct=028e
[ 330.575714] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 330.575718] usb 3-1: Product: Controller
[ 330.575721] usb 3-1: Manufacturer: ©Microsoft Corporation
[ 330.575723] usb 3-1: SerialNumber: 1E69441
[ 331.614141] input: Microsoft X-Box 360 pad as /devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/input/input23
[ 331.622581] usbcore: registered new interface driver xpad
When I disconnect it :
[ 392.733786] usb 3-1: USB disconnect, device number 4
[ 392.733995] xpad 3-1:1.0: xpad_try_sending_next_out_packet - usb_submit_urb failed with result -19
I would recommand checking if Ubuntu itself detects the disconnection, by looking at the game state, or directly at dmesg output.
As it probably is detecting it, I encourage you to then fill a bug report on Qt tracker :)

ioctl (TUNSETIFF) : device or resource busy

I am unable to set TUN interface. Everywhere i searched and it says the device should be rooted.
I am setting up proxyserver on my ubuntu 14.04 system
static int get_interface(char *name) {
int interface = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (ioctl(interface, TUNSETIFF, (void *)&ifr) < 0) {
perror("Cannot get TUN interface");
exit(1);
}
return interface;
}
Check your device name (i.e. ifr.ifr_name). Another process maybe using the same device. For example, you may be trying to use tun0 and another process has it open already.

Qt5.4 QAudioOutput on Raspberry Pi With PulseAudio on the 3.5mm Audio Jack Doesn't work but Qt 5.3 Does

Qt5.3 sees the default Raspberry Pi also_output.0.analog-mono device ( 3.5 mm headphone jack ) and QAudioOutput from 5.3 successfully writes audio to that device and I can hear the audio with my headphones. This all works with default Raspbian, with PulseAudio 2.0 from apt-get, and no extra configuration. PulseAudio is run as session process and not in the System Daemon mode. Qt 5.4 does not see the device with the exact same source code and Raspbian ( except cross-compiled with Qt 5.4.0 and not Qt 5.3.2 ) and also cannot write data to it.
It gives me this error ( Please note that I've manually assigned both sys default:CARD=ALSA and 'default' but they both return the same 'snd_pcm_hw_params' error ):
Output Device name: "sysdefault:CARD=ALSA"
Output Device name: "default"
Default device is "default"
Output device is: "default"
"QAudioOutput: snd_pcm_hw_params: err = -12"
Pactl sees it:
pactl list sinks
Sink #0
State: SUSPENDED
Name: alsa_output.0.analog-mono
Description: bcm2835 ALSA Analog Mono
Driver: module-alsa-card.c
Sample Specification: u8 1ch 8000Hz
I've tried to modify /etc/pulse/default.pa with this at the bottom to force the output device:
load-module module-alsa-sink sink_name=alsa_output.0.analog-mono device=hw:0
set-default-sink alsa_output.0.analog-mono
Here is my setup code that gives the error:
// Coordinator receives Audio data
m_Format.setSampleRate(8000);
m_Format.setChannelCount(1);
m_Format.setSampleSize(8);
m_Format.setCodec("audio/pcm");
m_Format.setByteOrder(QAudioFormat::BigEndian);
m_Format.setSampleType(QAudioFormat::UnSignedInt);
QAudioDeviceInfo infoOut(QAudioDeviceInfo::defaultOutputDevice());
foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) {
qDebug() << "Output Device name: " << deviceInfo.deviceName();
}
qDebug() << "Default device is" << infoOut.deviceName();
if (!infoOut.isFormatSupported(m_Format))
{
qDebug()<< "Default format not supported - trying to use nearest";
m_Format = infoOut.nearestFormat(m_Format);
}
qDebug() << "Output device is: " << infoOut.deviceName();
m_AudioOutput = new QAudioOutput(infoOut, m_Format, this);
// This data accumulates and dumps data to output
m_DataForOutput.clear();
// Now Start playing
// m_Output gets written to to send data to speakers
m_Output = m_AudioOutput->start();
What in the world is going on? How come the same configuration works with 5.3.2 and not 5.4.1. Assigning the default audio device doesn't work... What can I do here and how can I make it work? Thanks!
The answer was to run in session mode ( not a system-wide PulseAudio daemon ) and edit default.pa to look like this:
## Create the default output device
#load-module module-udev-detect tsched=0
load-module module-alsa-card device_id=0
#load-module module-alsa-card device_id=0 tsched=0 fragments=10 fragment_size=640 tsched_buffer_size=4194384 tsched_buffer_watermark=262144
#load-module module-alsa-card device_id=0 tsched=0 fragments=6 fragment_size=16 tsched_buffer_size=4194384 tsched_buffer_watermark=262144
load-module module-suspend-on-idle timeout=86400
### Load several protocols
load-module module-native-protocol-unix
### Make sure we always have a sink around, even if it is a null sink.
#load-module module-always-sink

Resources