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. Unable to send and receive images between 2 Raspberry connected to Zigbee via UART.
Forum Updated to NodeBB v4.3 + New Features

Unable to send and receive images between 2 Raspberry connected to Zigbee via UART.

Scheduled Pinned Locked Moved Unsolved General and Desktop
42 Posts 4 Posters 8.0k 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.
  • J.HilkJ J.Hilk

    @Rika said in Unable to send and receive images between 2 Raspberry connected to Zigbee via UART.:

    @jsulm I have made your way, the above is the result from qDebug (). It only received 241 bytes so file imagexxx.jpg was not created. (my imageSize= 31021).

    at this point, you're not getting away with a simple I've tried that, it does not work.

    @jsulm is absolutely correct. Show us your actual code

    R Offline
    R Offline
    Rika
    wrote on last edited by
    #27

    @J-Hilk

    Send:

    #include "ui_serial.h"
    #include <QDebug>
    #include <QBuffer>
    #include <QPixmap>
    #include <QFile>
    
    
    serial::serial(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::serial)
    {
        ui->setupUi(this);
    
        serialPort = new QSerialPort(this);
        serialPort->setPortName("ttyAMA0");
        serialPort->setBaudRate(QSerialPort::Baud115200);
        serialPort->setDataBits(QSerialPort::Data8);
        serialPort->setStopBits(QSerialPort::OneStop);
        serialPort->setFlowControl(QSerialPort::NoFlowControl);
        serialPort->open(QIODevice::ReadWrite);
    
        if (serialPort->isOpen() == true){
            qDebug() <<"Port Opened....";
            connect(serialPort, SIGNAL(readyRead()), this, SLOT(on_readdata()));
        }
    }
    void serial::on_pushButton_2_clicked()
    {
        QFile* imageFile = new QFile("/home/pi/Desktop/image.jpg");
            imageFile->open(QIODevice::ReadOnly);
            QByteArray ba = imageFile->readAll();
            imageFile->close();
            delete imageFile;
            if(serialPort->isOpen()==true){
                serialPort->write(ba);
                qDebug()<<ba.size()<<"size_send:";
            }
    }
    

    Rec:

    #include "serial.h"
    #include "ui_serial.h"
    #include <QtSerialPort/QSerialPort>
    #include <QDebug>
    #include <QBuffer>
    #include <QPixmap>
    #include <QFile>
    #include <QMessageBox>
    
    serial::serial(QWidget *parent) :
       QMainWindow(parent),
       ui(new Ui::serial)
    {
       ui->setupUi(this);
    
       serialPort = new QSerialPort(this);
       serialPort->setPortName("ttyAMA0");
       serialPort->setBaudRate(QSerialPort::Baud115200);
       serialPort->setDataBits(QSerialPort::Data8);
       serialPort->setStopBits(QSerialPort::OneStop);
       serialPort->setFlowControl(QSerialPort::NoFlowControl);
       serialPort->open(QIODevice::ReadWrite);
    
       if (serialPort->isOpen() == true){
           qDebug() <<"Port Opened....";
           connect(serialPort, SIGNAL(readyRead()), this, SLOT(on_readdata()));
       }
    
    }
    
    serial::~serial()
    {
       delete ui;
       serialPort->close();
    }
    
    
    void serial::on_readdata()
    {
       ba.append( serialPort->readAll());
       qDebug()<<ba.size()<<"sizeeeee:";
       if (ba.size() == 31021) {
           QFile newDoc("/home/pi/Desktop/imagexx.jpg");
               if(newDoc.open(QIODevice::WriteOnly)){
                   newDoc.write(ba);
               }
               newDoc.close();
       }
    //    ui->label->setText(ba);
    
    //      QPixmap b;
    //      if(b.loadFromData(ba,"JPG")){
    //          ui->label->setPixmap(b);
    //      }
    
    }
    
    
    1 Reply Last reply
    0
    • mrjjM mrjj

      @J-Hilk
      Do you know if write blocks ?
      QByteArray ba; // local
      ba.fill('A', 1000);
      if(serialPort->isOpen()==true){
      serialPort->write(ba); // blocks here ? as ba is by reference

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #28

      @mrjj IIRC, it's passed on to the OS during the write call and that copies the data. But I'm not entirely sure 😬


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      mrjjM 1 Reply Last reply
      0
      • J.HilkJ J.Hilk

        @mrjj IIRC, it's passed on to the OS during the write call and that copies the data. But I'm not entirely sure 😬

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #29

        @J-Hilk
        Yeah i was wondering since its a board if that still happens as it would
        make sense we get cut if not.

        @Rika
        Can you try this

        void serial::on_pushButton_2_clicked()
        {
                static QByteArray ba;
                ba.fill('A', 1000);
                if(serialPort->isOpen()==true){
                    serialPort->write(ba);
                    qDebug()<<ba.size()<<"size_send:";
                }
        }
        

        and tell me if we still only get up to 190 bytes with the sizeeeee message.

        R 1 Reply Last reply
        1
        • mrjjM mrjj

          @J-Hilk
          Yeah i was wondering since its a board if that still happens as it would
          make sense we get cut if not.

          @Rika
          Can you try this

          void serial::on_pushButton_2_clicked()
          {
                  static QByteArray ba;
                  ba.fill('A', 1000);
                  if(serialPort->isOpen()==true){
                      serialPort->write(ba);
                      qDebug()<<ba.size()<<"size_send:";
                  }
          }
          

          and tell me if we still only get up to 190 bytes with the sizeeeee message.

          R Offline
          R Offline
          Rika
          wrote on last edited by
          #30

          @mrjj I tried, still only get 190.
          16 sizeeeee:
          32 sizeeeee:
          64 sizeeeee:
          64 sizeeeee:
          14 sizeeeee:

          mrjjM 1 Reply Last reply
          0
          • R Rika

            @mrjj I tried, still only get 190.
            16 sizeeeee:
            32 sizeeeee:
            64 sizeeeee:
            64 sizeeeee:
            14 sizeeeee:

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #31

            @Rika
            Good testing.
            So even it says
            qDebug()<<ba.size()<<"size_send:";
            1000 size_send
            you only get
            5 lines of
            16 sizeeeee:
            32 sizeeeee:
            64 sizeeeee:
            64 sizeeeee:
            14 sizeeeee:
            ?

            R 1 Reply Last reply
            0
            • mrjjM mrjj

              @Rika
              Good testing.
              So even it says
              qDebug()<<ba.size()<<"size_send:";
              1000 size_send
              you only get
              5 lines of
              16 sizeeeee:
              32 sizeeeee:
              64 sizeeeee:
              64 sizeeeee:
              14 sizeeeee:
              ?

              R Offline
              R Offline
              Rika
              wrote on last edited by Rika
              #32

              @mrjj Sometimes 4 lines, sometimes 7 lines, but the total is 190 bytes. With 500-A, received only 230

              mrjjM 1 Reply Last reply
              0
              • R Rika

                @mrjj Sometimes 4 lines, sometimes 7 lines, but the total is 190 bytes. With 500-A, received only 230

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #33

                @Rika
                Ok
                if we do
                ba.fill('A', 10);
                do you then get all ?

                R 1 Reply Last reply
                0
                • mrjjM mrjj

                  @Rika
                  Ok
                  if we do
                  ba.fill('A', 10);
                  do you then get all ?

                  R Offline
                  R Offline
                  Rika
                  wrote on last edited by
                  #34

                  @mrjj yes.

                  mrjjM 1 Reply Last reply
                  0
                  • R Rika

                    @mrjj yes.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #35

                    @Rika
                    So it seems data get cut over some size.

                    What Os is running on the boards ?

                    Also maybe Zigbee has some sort of max transfer size ?

                    R 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @Rika
                      So it seems data get cut over some size.

                      What Os is running on the boards ?

                      Also maybe Zigbee has some sort of max transfer size ?

                      R Offline
                      R Offline
                      Rika
                      wrote on last edited by
                      #36

                      @mrjj I use raspbian. I tried using a PC connected to zigbee and sent photos to my Pi4 + Zigbee with Realterm, my Pi4 received the photos. I think the error is in the program sends the data.

                      1 Reply Last reply
                      0
                      • J.HilkJ Offline
                        J.HilkJ Offline
                        J.Hilk
                        Moderators
                        wrote on last edited by
                        #37

                        well, lets narrow it down,
                        write returns a quint64 with the actual number of bytes written to the serialport, what does that return ?

                        void serial::on_pushButton_2_clicked()
                        {
                                static QByteArray ba;
                                ba.fill('A', 1000);
                                if(serialPort->isOpen()==true){
                                    quint64 send = serialPort->write(ba);
                                    qDebug()<<send << " of" << ba.size()<<"size_send:";
                                }
                        }
                        

                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        R 1 Reply Last reply
                        1
                        • J.HilkJ J.Hilk

                          well, lets narrow it down,
                          write returns a quint64 with the actual number of bytes written to the serialport, what does that return ?

                          void serial::on_pushButton_2_clicked()
                          {
                                  static QByteArray ba;
                                  ba.fill('A', 1000);
                                  if(serialPort->isOpen()==true){
                                      quint64 send = serialPort->write(ba);
                                      qDebug()<<send << " of" << ba.size()<<"size_send:";
                                  }
                          }
                          
                          R Offline
                          R Offline
                          Rika
                          wrote on last edited by
                          #38

                          @J-Hilk 1000 of 1000 size.

                          J.HilkJ 1 Reply Last reply
                          0
                          • R Rika

                            @J-Hilk 1000 of 1000 size.

                            J.HilkJ Offline
                            J.HilkJ Offline
                            J.Hilk
                            Moderators
                            wrote on last edited by
                            #39

                            @Rika well,
                            to make sure your 2nd application is not simply very late in its creation/startup process, try clicking the button a 2nd time, see if something changes :D

                            After that, time for a serial port listing device, to check what is actually transferred


                            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                            Q: What's that?
                            A: It's blue light.
                            Q: What does it do?
                            A: It turns blue.

                            mrjjM 1 Reply Last reply
                            0
                            • J.HilkJ J.Hilk

                              @Rika well,
                              to make sure your 2nd application is not simply very late in its creation/startup process, try clicking the button a 2nd time, see if something changes :D

                              After that, time for a serial port listing device, to check what is actually transferred

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #40

                              @J-Hilk
                              When i goggle Zigbee , i do see max payload mentioned.
                              Do you think that could be the cause here ?
                              I never used Zigbee so not sure if its even an issue.

                              J.HilkJ 1 Reply Last reply
                              1
                              • mrjjM mrjj

                                @J-Hilk
                                When i goggle Zigbee , i do see max payload mentioned.
                                Do you think that could be the cause here ?
                                I never used Zigbee so not sure if its even an issue.

                                J.HilkJ Offline
                                J.HilkJ Offline
                                J.Hilk
                                Moderators
                                wrote on last edited by J.Hilk
                                #41

                                @mrjj uh, I should read the opening post more clearly,

                                You're right, that is most likely the issue, ZigBee is a low data transfer protocol and from what my quick google search told me, limited to about 100 - 200 bytes, which fits exactly here

                                for a quick and dirty test, we could split the test byte array and send it delayed, that should work

                                void serial::on_pushButton_2_clicked()
                                {
                                        static QByteArray ba;
                                           int index(0);
                                           ba.fill('A', 1000);
                                           if(serialPort->isOpen()==true){
                                               QTimer *t = new QTimer();
                                               auto sendSection = [=,&index]()->void{
                                                   serialPort->write(ba.data() + index * 100, 100);
                                                   index ++;
                                                   if(index == 10)
                                                       t->deleteLater();
                                               };
                                               QObject::connect(t, &QTimer::timeout, sendSection);
                                               t->start(1000);
                                        //       quint64 send = serialPort->write(ba);
                                               qDebug()<< ba.size()<<"size_send:";
                                           }
                                }
                                

                                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                Q: What's that?
                                A: It's blue light.
                                Q: What does it do?
                                A: It turns blue.

                                1 Reply Last reply
                                2
                                • R Offline
                                  R Offline
                                  Rika
                                  wrote on last edited by
                                  #42

                                  @mrjj @J-Hilk Sorry for my late reply. The problem is when I try to send from PC with Realterm (Pc is also connected to Zigbee), on Pi4 I still get pictures.

                                  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