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



  • 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!


  • Admin

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



  • 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;



  • @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


  • Admin

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

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


  • Admin



  • @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


  • Admin

    I wrote exactly how you should change it above.



  • @hek
    Ok! Thnx so much!!!



  • @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.


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.