dsyleixa123
Posts: 1482
Joined: Mon Jun 11, 2018 11:22 am

Re: C++ functions to retrieve and set IPs a/o SSIDs in the local home network?

Wed May 12, 2021 10:58 am

thank you, unfortunately I have no idea what this is for or what it means, it does not look like common C or C++ functions or variable definitions:
static sdRet
avBar
sdArg1
sdArg2
sdSiz dsn
sdArgs::ArgIdx
sdSizeOk
throw sde_App
sdConStr
csi.push_back
sudo iwlist "+ds[dsn]+" scan"
sdFileLoad
&cso,
sdStanza
stz.Next(&b,&e))
sdConStr cs;
sdVar v;
...
a.s.o.

But OTOH, I am actually not into low-level or bare-metal code, I just was looking for wrappers or High-level API functions like

Code: Select all

#include <Wifi.h>
string locip = WiFi.localIP();
string ssid = Wifi.SSID();
string gwip = WiFi.gatewayIP();
int  rssi = WiFi.RSSI();
int  numnets = WiFi.scanNetworks();
int  connxx = WiFi.begin(ssid, pass);
a.s.o....
(that's like it works in Arduino C++ WiFi or Wifi101 class ( https://www.arduino.cc/en/Reference/WiFi101 ), esp8266WiFi class similar

swampdog
Posts: 698
Joined: Fri Dec 04, 2015 11:22 am

Re: C++ functions to retrieve and set IPs a/o SSIDs in the local home network?

Fri May 14, 2021 6:41 am

You were supposed to read it as pseudo code to give you an idea how concise the job ought to be. I'll make one more attempt.

I've built QT a lot but never written a QT program. Nevertheless, even the junk(*) I came up with below demonstrates all the tools are there..

Code: Select all

#ifndef MAIN_HPP
#define MAIN_HPP

#include <qobject.h>

class Main : public QObject
{
 Q_OBJECT

public:
//Main(QObject * parent = nullptr)
 Main(QObject * =nullptr){}

private slots:
 void Run();

signals:
// void finished();
};

#endif // MAIN_HPP

Code: Select all

#include <QCoreApplication>
#include <QTextStream>
#include <QTimer>

#include <QFile>
#include <QRegularExpression>
#include "main.hpp"

#define DIE(x) do { QCoreApplication::exit(x); return; } while(0)

void Main::Run()
{
QTextStream os  (stdout);
os << "Qt version: " << QT_VERSION_STR << endl;
QFile f("/wrk/zz");
QStringList sl;
if(!f.exists())DIE(1);
if(!f.open(QIODevice::ReadOnly))DIE(2);
while(!f.atEnd())sl.append(f.readLine());
f.close();
int n(0);
QRegularExpression r("[[:space:]](Cell[[:space:]]{1,}.*|Channel:[[:digit:]]{1,}|ESSID:.*)");
for(QStringList::const_iterator i=sl.constBegin();i!=sl.constEnd();++i){
    QRegularExpressionMatchIterator ri(r.globalMatch(*i));
    while(ri.hasNext()){
        QRegularExpressionMatch rm(ri.next());
        os<<n++<<','<<rm.captured()<<'\n';
    }
}
DIE(0);
  //emit finished();
}

int main(int argc, char *argv[])
{
 QCoreApplication   a   (argc, argv);
 Main               m;

// QObject::connect(&m,SIGNAL(finished()),&a,SLOT(quit()));
 QTimer::singleShot(0,&m,SLOT(Run()));

 return a.exec();
}
It took a couple of hours to come up with that. Vast majority of time spend on google and hitting F1 on the class names to read what the methods do.

(*) you can tell when I write junk because I barely format it. :-)

dsyleixa123
Posts: 1482
Joined: Mon Jun 11, 2018 11:22 am

Re: C++ functions to retrieve and set IPs a/o SSIDs in the local home network?

Fri May 14, 2021 7:02 am

ok, thanks, I didn't understand that your code above was sort of pseudo code. But tbh, I didn't want to dig into that lowlevel-coding and start developing all of that from the scratch, I was looking more for high-level libs with wrappers ( C-functions, C++ classes), just to #include, and just need to call the method names similar like those from Aduino WiFi class, ready to use.

Code: Select all

#include <Wifi.h>
string locip = WiFi.localIP();
string ssid = Wifi.SSID();
string gwip = WiFi.gatewayIP();
int  rssi = WiFi.RSSI();
int  numnets = WiFi.scanNetworks();
int  connxx = WiFi.begin(ssid, pass);
Perhaps someone is inspired to rewrite the Arduino C++ WiFi cass for the Pi :ugeek: :mrgreen: (of course mainly the method names for the UI API, the actual code behind and beneath it of course must be a completely different Linux code instead freeRTOS or avr-gcc).
https://www.arduino.cc/en/Reference/WiFi101

swampdog
Posts: 698
Joined: Fri Dec 04, 2015 11:22 am

Re: C++ functions to retrieve and set IPs a/o SSIDs in the local home network?

Fri May 14, 2021 8:02 am

dsyleixa123 wrote:
Fri May 14, 2021 7:02 am
Perhaps someone is inspired to rewrite the Arduino C++ WiFi cass for the Pi :ugeek: :mrgreen: (of course mainly the method names for the UI API, the actual code behind and beneath it of course must be a completely different Linux code instead freeRTOS or avr-gcc).
https://www.arduino.cc/en/Reference/WiFi101
That's you probably!

dsyleixa123
Posts: 1482
Joined: Mon Jun 11, 2018 11:22 am

Re: C++ functions to retrieve and set IPs a/o SSIDs in the local home network?

Fri May 14, 2021 8:26 am

If I'll once get all the single functions to c+p then I might try to bind them all in a class ;)

Return to “C/C++”