Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QNmeaPositionInfoSource with QBuffer IODevice, no updates received
Forum Updated to NodeBB v4.3 + New Features

QNmeaPositionInfoSource with QBuffer IODevice, no updates received

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 119 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tilmanns
    wrote on last edited by
    #1

    Hey everyone,

    so, I have a embedded device sending NMEA sentences over an mqtt broker. I am trying to write an application that uses those NMEA sentences to visualize position measurements with corresponding accuracy estimates.

    I got the broker working in Qt and am receiving multiple NMEA messages per second, but I am not receiving any signal of positionUpdated. I am using a QBuffer as a QIODevice for my QNmeaPositionInfoSource.
    NMEA messages are of types: $GNGGA $GNRMC $GNGLL $GNVTG and $GNGBS $GNGST
    The whole setup looks like this:

    // mqttpositionclient.h
    #ifndef MQTTPOSITIONCLIENT_H
    #define MQTTPOSITIONCLIENT_H
    
    #include <QNmeaPositionInfoSource  >
    #include <QQmlEngine>
    #include <QMqttClient>
    #include <QBuffer>
    class MqttPositionClient : public QNmeaPositionInfoSource
    {
        Q_OBJECT
        QML_ELEMENT
    public:
        MqttPositionClient();
    
        void subscribe();
    signals:
        void msgReceived(QByteArray msg, const QGeoPositionInfo& info);
    private:
        void read_mqtt_msg(const QByteArray &message, const QMqttTopicName &topic );
    
        QBuffer m_buffer;
        QMqttClient m_client;
    };
    
    #endif // MQTTPOSITIONCLIENT_H
    

    and

    
    #include <QMessageBox>
    #include <QTimer>
    MqttPositionClient::MqttPositionClient() : QNmeaPositionInfoSource (RealTimeMode), m_stream(&m_buffer), m_source(QNmeaPositionInfoSource::RealTimeMode) {
    
        m_client.setProtocolVersion(QMqttClient::MQTT_5_0);
        QString user_name = "censored";
        QString passwd = "censored";
        QString host_name = "censored.com";
        quint16 port = 8883;
        m_client.setUsername(user_name);
        m_client.setPassword(passwd);
        m_client.setPort(port);
        m_client.setHostname(host_name);
        m_client.setClientId("position_debugger");
    
        QSslConfiguration ssl_cfg;
        ssl_cfg.setProtocol(QSsl::TlsV1_3);
    
        m_client.connectToHostEncrypted(ssl_cfg);
    
        QTimer::singleShot(std::chrono::seconds(2), [this](){
            qInfo() << "subscribing";
            this->subscribe();
        });
    
        m_buffer.open(QIODeviceBase::ReadWrite);
        setDevice(&m_buffer);
    
        QObject::connect(&m_client, &QMqttClient::messageReceived,
                         this, &MqttPositionClient::read_mqtt_msg);
    
        QObject::connect(&m_source, &QNmeaPositionInfoSource::positionUpdated, [](const QGeoPositionInfo& info){
            qInfo() << "update received internally";
        });
    
        setUpdateInterval(1000);
        startUpdates();
    }
    
    
    void MqttPositionClient::read_mqtt_msg(const QByteArray &message, const QMqttTopicName &topic ){
        auto msgtype = message.first(6);
        qInfo() << msgtype;
    
        // to my understanding QIODevice::readyRead() should be emitted here? 
        // this signal is required according to the documentation [here](https://doc.qt.io/qt-6/qnmeapositioninfosource.html#setDevice)
        m_buffer.write(message);
    }
    
    
    void MqttPositionClient::subscribe(){
    
        QMqttTopicFilter topic("censored");
        auto subscription = m_client.subscribe(topic, 0);
        if (!subscription) {
            QMessageBox::information(nullptr, "mqtt subscription", "failed");
        }
    }
    
    

    I confirmed that read_mqtt_msg() is called repeatedly.

    When I use QNmeaPositionInfoSource::parsePosInfoFromNmeaData() I can decode some of the messages, however looking at the sourcecode at the QPositioning Repository, it seems like QNmeaPositionInfoSource takes multiple messages into account to generate its position and I'd rather use that implementation.

    Does anyone know what I am missing? I am also open for suggestions of different approaches to achieve what i'm going for.

    Thanks!

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved