Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Gateway serial port commands in one message. How can the recive and send it?

Gateway serial port commands in one message. How can the recive and send it?

Scheduled Pinned Locked Moved Development
10 Posts 3 Posters 2.8k Views 4 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.
  • Marat KhM Offline
    Marat KhM Offline
    Marat Kh
    wrote on last edited by
    #1

    Hi!
    I need to send 16 commands from gateway to nodes.
    When i send in com port Gateway command like:
    ->1;2;1;0;2;1\n1;11;1;0;2;1\n1;1;1;0;2;0\n1;2;1;0;2;0\n1;14;1;0;2;0\n1;16;1;0;2;1\n

    the gateway recive only first command in line 1;2;1;0;2;1\n
    i think becouse:
    examples/SerialGateway/SerialGateway.ino
    void serialEvent() {
    while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inputPos<MAX_RECEIVE_LENGTH-1 && !commandComplete) {
    if (inChar == '\n') {
    inputString[inputPos] = 0;
    commandComplete = true;
    } else {
    // add it to the inputString:
    inputString[inputPos] = inChar;
    inputPos++;
    }
    } else {
    // Incoming message too long. Throw away
    inputPos = 0;
    }
    }

    But after this, the gate send command to node by NRF24 module.

    How can i recive and send multiple commands in one message?

    THNX!

    1 Reply Last reply
    0
    • hekH Offline
      hekH Offline
      hek
      Admin
      wrote on last edited by
      #2

      It's a newline character you're sending between the commands right? Not the string"\n"

      Marat KhM 1 Reply Last reply
      0
      • Marat KhM Offline
        Marat KhM Offline
        Marat Kh
        wrote on last edited by
        #3

        This is \n
        _serialPort.WriteLine(GateCommand);

        string command = "" + nodename + ";" + neonnumber + ";1;0;2;" + powerstatus;
        // NODE_NAME, NUMBER_NEON, 1(set), 0 - без доставки, 2 - V_STATUS, VALUE (1- on, 2 - off);
        return command;

        1 Reply Last reply
        0
        • hekH hek

          It's a newline character you're sending between the commands right? Not the string"\n"

          Marat KhM Offline
          Marat KhM Offline
          Marat Kh
          wrote on last edited by
          #4

          @hek This is \n i think in the logger look like
          ->1;11;1;0;2;1#0A1;10;1;0;2;1#0A1;9;1;0;2;1#0A1;8;1;0;2;1#0A1;7;1;0;2;1#0A1;6;1;0;2;1#0A1;5;1;0;2;1#0A1;4;1;0;2;1#0A

          I don't khew why C# code sent multiple command in 1 line,
          i wrote once commande:
          _serialPort.WriteLine(GateCommand);

          GateCommand - It one command lke 1;16;1;0;2;1\n

          Bit in one tread in one time moment

          1 Reply Last reply
          0
          • hekH Offline
            hekH Offline
            hek
            Admin
            wrote on last edited by
            #5

            Hmm.. it should probably be a
            return;
            after
            commandComplete = true;

            Thanks for reporting. I see we have the same issue in the development branch.

            1 Reply Last reply
            0
            • hekH Offline
              hekH Offline
              hek
              Admin
              wrote on last edited by
              #6

              https://github.com/mysensors/Arduino/pull/400

              Marat KhM 1 Reply Last reply
              0
              • hekH hek

                https://github.com/mysensors/Arduino/pull/400

                Marat KhM Offline
                Marat KhM Offline
                Marat Kh
                wrote on last edited by
                #7

                @hek Thnx.

                But can you explane how can i use this now in my code (from example):

                void loop()  
                { 
                  gw.process();
                
                  checkButtonTriggeredInclusion();
                  checkInclusionFinished();
                  
                  if (commandComplete) {
                    // A command wass issued from serial interface
                    // We will now try to send it to the actuator
                    parseAndSend(gw, inputString);
                    commandComplete = false;  
                    inputPos = 0;
                  }
                }
                
                
                /*
                  SerialEvent occurs whenever a new data comes in the
                 hardware serial RX.  This routine is run between each
                 time loop() runs, so using delay inside loop can delay
                 response.  Multiple bytes of data may be available.
                 */
                void serialEvent() {
                  while (Serial.available()) {
                    // get the new byte:
                    char inChar = (char)Serial.read(); 
                    // if the incoming character is a newline, set a flag
                    // so the main loop can do something about it:
                    if (inputPos<MAX_RECEIVE_LENGTH-1 && !commandComplete) { 
                      if (inChar == '\n') {
                        inputString[inputPos] = 0;
                        commandComplete = true;
                      } else {
                        // add it to the inputString:
                        inputString[inputPos] = inChar;
                        inputPos++;
                      }
                    } else {
                       // Incoming message too long. Throw away 
                        inputPos = 0;
                    }
                  }
                

                I mean function serialEvent in one package can see only first command, from 0 possition to \n.

                Thnx so much

                1 Reply Last reply
                0
                • hekH Offline
                  hekH Offline
                  hek
                  Admin
                  wrote on last edited by
                  #8

                  I wrote exactly how you should change it above.

                  Marat KhM 1 Reply Last reply
                  0
                  • hekH hek

                    I wrote exactly how you should change it above.

                    Marat KhM Offline
                    Marat KhM Offline
                    Marat Kh
                    wrote on last edited by
                    #9

                    @hek
                    Ok! Thnx so much!!!

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      robosensor
                      wrote on last edited by
                      #10

                      @hek, I suspect that there is something wrong with this pull request. If you just returning true, then protocolParse() will not be called and gatewayTransportReceive() function in MyGatewayTransport.cpp will receive previously parsed message.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      17

                      Online

                      11.7k

                      Users

                      11.2k

                      Topics

                      113.1k

                      Posts


                      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • MySensors
                      • OpenHardware.io
                      • Categories
                      • Recent
                      • Tags
                      • Popular