thgeorgiou / CuteESP

A Qt frontend to esptool, the ESP8622/ESP32 flashing tool
GNU General Public License v3.0
1 stars 3 forks source link

Support flashing over the air using Zeroconf #8

Open probonopd opened 5 years ago

probonopd commented 5 years ago

Support flashing over the air using Zeroconf, e.g., using https://github.com/jbagg/QtZeroConf.

probonopd commented 5 years ago

Something vaguely along the lines of

sudo apt-get -y install g++ libgl-dev libavahi-client-dev 
#include <QApplication>
#include <QGuiApplication>
#include <QDebug>
#include <QMainWindow>
#include "qzeroconf.h"

class mainWindow : public QMainWindow
{
    Q_OBJECT

public:
    mainWindow();

private:
    QZeroConf zeroConf;

private slots:
    void appStateChanged(Qt::ApplicationState state);
    void addService(QZeroConfService item);
    void removeService(QZeroConfService item);
    void updateService(QZeroConfService zcs);
};

mainWindow::mainWindow()
{
    show();
    connect(&zeroConf, &QZeroConf::serviceAdded, this, &mainWindow::addService);
    connect(&zeroConf, &QZeroConf::serviceRemoved, this, &mainWindow::removeService);
    connect(&zeroConf, &QZeroConf::serviceUpdated, this, &mainWindow::updateService);
    connect(qGuiApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(appStateChanged(Qt::ApplicationState)));
}

void mainWindow::appStateChanged(Qt::ApplicationState state)
{
    if (state == Qt::ApplicationSuspended) {
        zeroConf.stopBrowser();
    }
    else if (state == Qt::ApplicationActive) {
        if (!zeroConf.browserExists())
            zeroConf.startBrowser("_arduino._tcp");
    }
}

// ---------- Discovery Callbacks ----------

void mainWindow::addService(QZeroConfService zcs)
{
    qDebug() << "Added service: " << zcs;
    qDebug() << zcs->ip();
    qDebug() << zcs->port();
    qDebug() << zcs->txt();
    qDebug() << zcs->txt()["tcp_check"];
    qDebug() << zcs->txt()["ssh_upload"];
    qDebug() << zcs->txt()["board"];
    qDebug() << zcs->txt()["auth_upload"];
}

void mainWindow::removeService(QZeroConfService zcs)
{
    qDebug() << "Removed service: " << zcs;
}

void mainWindow::updateService(QZeroConfService zcs)
{
    qDebug() << "Service updated: " << zcs;
}

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    mainWindow window;
    return app.exec();
}