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. automating or running a process back
QtWS25 Last Chance

automating or running a process back

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 2.6k Views
  • 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.
  • N Offline
    N Offline
    Network1618033
    wrote on last edited by
    #1

    Hi everyone
    I would like to automate sending SMS with an application i am writting but i don't how i to do it. My application must be connected to a server from where it get informations to send via SMS. I am wondering how to create for example a class that inherit QMainWindow and run a process that will check the status of the connection with the server, get information from the server and and send them via mail or SMS every 5 minutes.

    I resume the fonctioning :

    • Create a QMainWindow object
    • Connect to the server and a SMS modem
    • Check the status of the connection
    • Send commands and Receive informations
    • Send the information via SMS
    • And update information sent status
    jsulmJ 1 Reply Last reply
    0
    • N Network1618033

      Hi everyone
      I would like to automate sending SMS with an application i am writting but i don't how i to do it. My application must be connected to a server from where it get informations to send via SMS. I am wondering how to create for example a class that inherit QMainWindow and run a process that will check the status of the connection with the server, get information from the server and and send them via mail or SMS every 5 minutes.

      I resume the fonctioning :

      • Create a QMainWindow object
      • Connect to the server and a SMS modem
      • Check the status of the connection
      • Send commands and Receive informations
      • Send the information via SMS
      • And update information sent status
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Network1618033 For networking start here: http://doc.qt.io/qt-5/qtnetwork-index.html
      You can take a look at examples provided with Qt.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      N 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Network1618033 For networking start here: http://doc.qt.io/qt-5/qtnetwork-index.html
        You can take a look at examples provided with Qt.

        N Offline
        N Offline
        Network1618033
        wrote on last edited by
        #3

        @jsulm thank for your answer. i forgot something. I'm using QtTelnet (Github) class to establish connection between my application and the server. That works fine. Now i'm looking to check the status and send my commands, receive answer(informations) and send them every 5 minutes.

        jsulmJ 1 Reply Last reply
        0
        • N Network1618033

          @jsulm thank for your answer. i forgot something. I'm using QtTelnet (Github) class to establish connection between my application and the server. That works fine. Now i'm looking to check the status and send my commands, receive answer(informations) and send them every 5 minutes.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Network1618033 said in automating or running a process back:

          QtTelnet

          I never used it and I'm not sure why you use insecure Telnet to connect to the server. But QtTelnet has documentation.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          N 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Network1618033 said in automating or running a process back:

            QtTelnet

            I never used it and I'm not sure why you use insecure Telnet to connect to the server. But QtTelnet has documentation.

            N Offline
            N Offline
            Network1618033
            wrote on last edited by Network1618033
            #5

            @jsulm Telnet was the solution my teacher suggest me but i am at your disposal for any other solution that can be secured and easy :) . Otherwise I think you have not understand my problem. It is the automating my problem. Should i use a loop (if it is possible) for example or there is an design pattern that permit me run a code that will check my connection state, communicate with my server and send the SMS.

            jsulmJ 1 Reply Last reply
            0
            • S Offline
              S Offline
              Sunfluxgames
              wrote on last edited by Sunfluxgames
              #6

              @Network1618033

              Once the server is setup and listening on the sms port grab the datastream from a Qbytearray. Check the first two bytes in the data stream this will be your Opcode or Packetheader..

              qbytearray recvbuff;
              //get the first 2 bytes in the packet
              
              //now handling those two bytes or qstring or std:: message
              quint16 opcode;
              switch(opcode) 
              {
                  case ErrorConnection : cout << 'message'; // 
                           break;       // exits the switch
                  case LoginSuccessful : cout << 'messge';
                           break;
                  case BadLogin : cout << 'message';
                           break;
              }
              

              Check the status of the connection - Should be a event handler for this to check the State and return it.
              Send commands and Receive informations - Send function that sends it to the client or server. Recv side see code.
              Send the information via SMS - Send it from the server with a send method.
              And update information sent status - Create a signal and slot with a timer and a function that sends it base of time.

              Could try QtHttp and do it over http or Qtcp

              N 1 Reply Last reply
              0
              • N Offline
                N Offline
                Network1618033
                wrote on last edited by
                #7
                This post is deleted!
                1 Reply Last reply
                0
                • S Sunfluxgames

                  @Network1618033

                  Once the server is setup and listening on the sms port grab the datastream from a Qbytearray. Check the first two bytes in the data stream this will be your Opcode or Packetheader..

                  qbytearray recvbuff;
                  //get the first 2 bytes in the packet
                  
                  //now handling those two bytes or qstring or std:: message
                  quint16 opcode;
                  switch(opcode) 
                  {
                      case ErrorConnection : cout << 'message'; // 
                               break;       // exits the switch
                      case LoginSuccessful : cout << 'messge';
                               break;
                      case BadLogin : cout << 'message';
                               break;
                  }
                  

                  Check the status of the connection - Should be a event handler for this to check the State and return it.
                  Send commands and Receive informations - Send function that sends it to the client or server. Recv side see code.
                  Send the information via SMS - Send it from the server with a send method.
                  And update information sent status - Create a signal and slot with a timer and a function that sends it base of time.

                  Could try QtHttp and do it over http or Qtcp

                  N Offline
                  N Offline
                  Network1618033
                  wrote on last edited by Network1618033
                  #8

                  @Sunfluxgames Thanks i'm going try what you explaned. Someone talk me also about Qthread that can permit me run process back. Is it a good idea to ?

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Sunfluxgames
                    wrote on last edited by
                    #9

                    (windows or linux)????

                    Are you automating the client and server or just server. If this is so I would create a expect script batch file to run a client.

                    Server wise..

                    Main.cpp

                    #include <QCoreApplication>
                    #include "mytcpserver.h"
                    
                    int main(int argc, char *argv[])
                    {
                        QCoreApplication a(argc, argv);
                        
                        // create MyTcpServer
                        // MyTcpServer constructor will create QTcpServer
                    
                        MyTcpServer server;
                    
                        return a.exec();
                    }
                    

                    mytcpserver.h:

                    /#ifndef MYTCPSERVER_H
                    #define MYTCPSERVER_H
                    
                    #include <QObject>
                    #include <QTcpSocket>
                    #include <QTcpServer>
                    #include <QDebug>
                    
                    class MyTcpServer : public QObject
                    {
                        Q_OBJECT
                    public:
                        explicit MyTcpServer(QObject *parent = 0);
                        
                    signals:
                        
                    public slots:
                        void newConnection();
                    
                    private:
                        QTcpServer *server;
                    };
                    
                    #endif // MYTCPSERVER_H
                    

                    mytcpserver.cpp:

                    /#include "mytcpserver.h"
                    
                    MyTcpServer::MyTcpServer(QObject *parent) :
                        QObject(parent)
                    {
                        server = new QTcpServer(this);
                    
                        // whenever a user connects, it will emit signal
                        connect(server, SIGNAL(newConnection()),
                                this, SLOT(newConnection()));
                    
                       unsigned int port = 2222 //sms port
                    
                        if(!server->listen(QHostAddress::Any, port))
                        {
                            //"Server could not start";
                        }
                        else
                        {
                            //"Server started!";
                        }
                    }
                    
                    void MyTcpServer::newConnection()
                    {
                        // need to grab the socket
                        QTcpSocket *socket = server->nextPendingConnection();
                    
                        QByteArray recvbuff;
                    
                    while(!recvbuff.contains('\n')) 
                    {
                        socket->waitForReadyRead();
                        recvbuff += socket->readAll();
                    }
                     //A function to process client mesasge
                    processTeleNetMessage(message);
                    }
                    
                    void MyTcpServer::processTeleNetMessage(Qstring message)
                    {
                           //use a case system to do login process or Qstring Compare
                          // send automated message read from a text file or just hardcode the message here.
                          socket->write("eat a dick\r\n");
                          socket->flush();
                         socket->waitForBytesWritten(3000);
                    
                        /// when all done etc..  // disconnects client...
                       socket->close();
                    
                    }
                    

                    Now if your doing this all in one application then yea you could use a Qthread to create events that loop thru all this processing. Really up to you and how you want to build this application.

                    1 Reply Last reply
                    0
                    • N Network1618033

                      @jsulm Telnet was the solution my teacher suggest me but i am at your disposal for any other solution that can be secured and easy :) . Otherwise I think you have not understand my problem. It is the automating my problem. Should i use a loop (if it is possible) for example or there is an design pattern that permit me run a code that will check my connection state, communicate with my server and send the SMS.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Network1618033 said in automating or running a process back:

                      Otherwise I think you have not understand my problem

                      That's true as your description is unclear.
                      Please do not use QThread until you really know you really need them.
                      Qt networking classes are asynchronous, so there is usually no need for threads.
                      To me it is not really clear what your question/problem actually is.
                      "Connect to the server and a SMS modem" - what modem is it and how do you connect to it?
                      "Check the status of the connection" - again: what modem is it? How do you access it?
                      "Send commands and Receive informations" - what commands? What information? Send/receive to/from where (modem)?
                      "Send the information via SMS" - depends on the way you access the modem.
                      "And update information sent status" - update where?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      N 1 Reply Last reply
                      1
                      • N Offline
                        N Offline
                        Network1618033
                        wrote on last edited by
                        #11
                        This post is deleted!
                        1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @Network1618033 said in automating or running a process back:

                          Otherwise I think you have not understand my problem

                          That's true as your description is unclear.
                          Please do not use QThread until you really know you really need them.
                          Qt networking classes are asynchronous, so there is usually no need for threads.
                          To me it is not really clear what your question/problem actually is.
                          "Connect to the server and a SMS modem" - what modem is it and how do you connect to it?
                          "Check the status of the connection" - again: what modem is it? How do you access it?
                          "Send commands and Receive informations" - what commands? What information? Send/receive to/from where (modem)?
                          "Send the information via SMS" - depends on the way you access the modem.
                          "And update information sent status" - update where?

                          N Offline
                          N Offline
                          Network1618033
                          wrote on last edited by Network1618033
                          #12

                          @jsulm

                          OK i'm going explan clearly !.

                          I have a BSC(Base Station Controller) that permit to manage failure on GSM equipements(BTS - Base Tranceiver Station - , Links , TRX) connected to it. Informations about Failures can be get from the BSC by sending some commands (for example "ls" on ubuntu that return the list of directories and files existing in the current directory). As the supervision Office is far from the BSC we can use telnet protocol to connect to it in order to send commands we want. In order to warn technicians of some possible failures i decided to automate "sending command to the server in order to receive the list of failures and send these failures via SMS" . I judged that if i want to send SMS with my application, a GSM modem is required. For this I thought that my application should work in the following way :

                          • It must have a main window that show the current failures and their state (Sent or not)

                          Behind this main window a process must execute the following task :

                          • When starting , the application should attempt to connect to the different equipments (BSC, GSM modem).

                          • If the connections failed the application should wait for them succeed or until the someone close the application.

                          • If the connections succeeded the application should start sending commands every 5 minutes for examples in order to list failures and send them via SMS. Before every sending actions (sending commands or messages) the application must check the state of connection to the equipment in order to stuck in waiting and show the in main windows that there is a problem to connect to an equipment.

                          • After sending SMS the application must update the state of failure sent

                          I expect i have been more clear now !.
                          Please excuse me for my spelling mistakes or grammatical error; I do not speak fluent English.

                          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