Serial is dropping characters



  • Using the Example SerialGateway like this...

    // Enable debug prints to serial monitor
    //#define MY_DEBUG 
    
    
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Set LOW transmit power level as default, if you have an amplified NRF-module and
    // power your radio separately with a good regulator you can turn up PA level. 
    //#define MY_RF24_PA_LEVEL RF24_PA_LOW
    
    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    
    // Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
    //#if F_CPU == 8000000L
    //#define MY_BAUD_RATE 38400
    //#endif
    
    // Flash leds on rx/tx/err
    //#define MY_LEDS_BLINKING_FEATURE
    // Set blinking period
    //#define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Inverses the behavior of leds
    //#define MY_WITH_LEDS_BLINKING_INVERSE
    
    // Enable inclusion mode
    //#define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    
    // Inverses behavior of inclusion button (if using external pullup)
    //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
    
    // Set inclusion mode duration (in seconds)
    //#define MY_INCLUSION_MODE_DURATION 60 
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3 
    
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  5  // the PCB, on board LED
    
    #include <SPI.h>
    #include <MySensors.h>  
    
    void setup() { 
      // Setup locally attached sensors
    }
    
    void presentation() {
     // Present locally attached sensors 
    }
    
    void loop() { 
      // Send locally attached sensor data here 
    }
    
    void serialEvent() 
    { while (Serial.available())
      { String tStr = Serial.readString();
        if (tStr.charAt(0) == '*')
        { Serial.print(" testing here = ");
          Serial.print(tStr);
          Serial.println(">");
        } else
        { Serial.print("junk ");
          Serial.print(tStr);
          Serial.println(">");
        }
      }
    }
    
    

    When I send stuff *nbvbnvbv via the Arduino Terminal or my own Serial software I get this...

     testing here = *nbvbnvbv>
    junk bvbnvbv>
     testing here = *nbvbnvbv>
     testing here = *nbvbnvbv>
     testing here = *nbvbnvbv>
    junk nbvbnvbv>
     testing here = *nbvbnvbv>
    junk nbvbnvbv>
     testing here = *nbvbnvbv>
     testing here = *nbvbnvbv>
    junk nbvbnvbv>
    junk bvbnvbv>
    
    

    As you can see characters are getting lost. If I use the Arduino basic sketch and add the serialEvent to it, I never get dropped characters. I assume MySensors is off checking other stuff and misses the incoming Serial stream.

    How can I work around this as I need that '*' as the first character to signify a control string.

    How can I give the Serial the first bite at the cherry, always?



  • @AndErn said:

    Using the Example SerialGateway like this...
    testing here = *nbvbnvbv>
    junk nbvbnvbv>
    junk bvbnvbv>

    As you can see characters are getting lost.

    How can I work around this

    So, no one knows or no one cares. Can't make up my mind as to which it is.

    I guess not enough people use the Serial interface for the Dev's to care even to comment. {sigh}

    I tested MySensors 1.5 and it seems all OK, so I guess it is a failure of progress.


  • Admin

    You use serial GW, and also handle serial input yourself? this will collide when both read from the serial port.

    The missing characters are probably "eaten" by mysensors before your serial event routine reads them?

    You should look at using soft serial, do you have a separate serial for your own communication protocol, and for the mysensors protocol. (I assume that you are using atmega 328 based hw, as you don't mention which hw you are using.

    Another option is to use a higher end MCU, either atmega 1280, or atsamd21, both have more serial ports available (the later also have usb)



  • @tbowmo said:

    You use serial GW, and also handle serial input yourself?

    Using several Arduino Nano by the way and nRF24LO1.

    In the absence of any instructions for using Serial at all in v2, I am left to guessing how to proceed. I researched here a few days back and questions on Serial gateway for v2 is pretty much ignored.

    I ONLY handled serial myself as I could not find any reference to using the Serial Gateway in Examples. It is an appalling "Example" when it has three empty functions. How an Earth can anyone say that code below is an example of anything?

    How does it send data via serial to the attached PC?
    How does it receive data via serial from the attached PC?

    #include <SPI.h>
    #include <MySensors.h>  
    
    void setup() { 
      // Setup locally attached sensors
    }
    
    void presentation() {
     // Present locally attached sensors 
    }
    
    void loop() { 
      // Send locally attached sensor data here 
    }
    
    

  • Contest Winner

    Hi. I can assume it is caused by one of the points:

    • If you use 8Mhz atmega chip you can't use a serial with a speed higher than 57k. Otherwise you face character dropping.
    • I do not know the architecture of mysensors library very well, so I hope gurus can develop my thought. If the library uses some of interrupts handlers (for example timer interrupts) and ISR contains handlers that take a lot of time, it can cause dropping of hardware serial ISR and result in characters dropping at maximum serial speed.

  • Admin

    @AndErn

    the chosen GW transport is handled internally by the mysensors library, so if you choose W5100 (wired ethernet) the library itself handles W5100 communication.

    And the same is actually true, when defining it with MY_GATEWAY_SERIAL, then the mysensors library itself handles the serial port, transmitting data, and receiving the data from the serial port, according to the the MySensors serial protocol

    An example is usually meant to be able to run without modifications at all as a starter, and then people can start tinkering with it, and adjust different parameters in order to figure out how the example is working. And so, it should have started chatting along the serialport, if you just started the bare example up without modifications.

    I admit that there may be some lacks in documentation.. But you are welcome to pitch in, and give a helping hand if you feel something is missing.

    Btw. please remember that we are all here on a voluntary basis, using our free / spare time to develop this library. So we can't keep a track on all posts on the forum 24/7, because there comes so many new posts all the time. So we do miss a post here and there, we are only humans..


  • Contest Winner

    @AndErn MySensors is developed by people that also have day time jobs. You can't expect to get enterprise level support for something that is

    1. Free to use
    2. Developed on a spare-time basis
    3. Without a paid support organization

    Especially, if you don't use the polite tone suggested in the forum guidelines.
    People here try their best to help out as much as possible.


  • Hero Member

    @AndErn said:

    How an Earth can anyone say that code below is an example of anything?

    The example code demonstrates the plain simplicity of coding a fully functional MySensors gateway. The purpose and use of the gateway is well documented on the website if you take time to read.



  • Thank you all so much for all that wonderful help.

    @tbowmo I have no idea why you mention the W5100 when I am asking about passing data between the PC and Arduino via Serial.
    @Anticimex I do not expect that kind of support, I do expect an "example" to actually example something.

    The example does NOT handle the Serial to and from the serial port of the PC as it stands. I obviously need to have more in that Serial Gateway than three empty functions. AND YES, I read up on the subject including a few posts here as I mentioned in the OP but nothing seems to get data passing in both directions.

    Instead of rhetoric back at me, what about offering up some example code that you can see working on your PC?. I just need a very basic example using puTTY that works in both directions.

    Thank you.


  • Admin

    You could perhaps try to explain what you're trying to archive here...

    Sending stuff to the serial console at the same time using the node as a serial gateway? I don't understand why? It will interfere with the communication with the controller.


  • Admin

    @AndErn

    I was merely using w5100 as an example, as I also did with serial.

    I am using exactly that example sketch in my own serial gateway, with 3 empty functions. And it works!

    Have you even given it a chance, that is putting an unmodified GatewaySerial example into your arduino, connected a terminal emulator and checked the responses you get there? Before starting to tell us that we are doing everything wrong?


  • Mod

    @AndErn as others have already mentioned, you need to start behaving like a good community member. MySensors is a friendly community and letting your frustration on people who try to help is simply not ok. The forum guidelines are plain and simple:

    1. Be nice
    2. Don't place ads

    I will be watching the next 10 or so posts you make. I'm sure you can be friendly just like everyone else here.


  • Hardware Contributor

    Hello.

    I won't blame you if you're noob in coding, every one is a noob once 😉 but i think you were a bit too much confident..
    @AndErn said:
    How an Earth can anyone say that code below is an example of anything?

    Because, as you said, there is not so much lines in the sketch so a bit difficult to not see #include <MySensors.h> 😕
    As guys said, it includes everything behind the scene to help noobs to discover mysensors and being confused at the beginning with all the lib stuff. Instead of having to call every functions..I already said it on the forum though..Connect it to a controller and you have something in minutes 🙂

    That said, please explain why you're trying this. sure if you're using a controller that can interfere. but perhaps you're using your own?? and try to add things? why? do you need something? because there is already mysensors api. so you see not easy without all infos. people are kind here, no pain 😉


  • Admin



  • We appear to be on a merry go round to beat the messenger at each pass. You people need to READ my posts and respond to what I write, not just chest-thump.

    I have PC controller software that I have written (professional programmer for 40-years, so I have a few ideas on how things work) and it accesses the Nano via the USB-Serial connection. It sends commands to the network of Smart-Nodes and receives information from the network of Nodes.

    It is very much like MySensors but a lot less complicated than MySensors as it is designed to do just one job for one network with a half dozen specific and very-smart Nodes. By Smart-Nodes I mean every Node will keep actively controlling the A/C, heating etc if the power goes out as it frequently does out here in the boonies.

    It is working almost perfectly with the RF24network libraries, but after six or so days the network becomes unreliable with occasional data packets not being sent. I have tracked it down to within the RF24network but I do not want to spend days or weeks hunting down the problems and thought I would use MySensors for the networking as I had previously used 1.5 very successfully

    I feel it is a waste of any more time as NO ONE has yet shown me how to make the example work WITH 2.) Bear in mind I WROTE ABOVE it worked OK with 1.5 AND the basic Arduino Serial.



  • @mfalkvidd said:

    1. Don't place ads

    Seriously? What is that supposed to mean? Are you suggesting I am posting ads about puTTY?

    Watching my posts? Seriously, that's great as maybe you can offer some actual help rather than lazy rhetoric.

    That's about as "nice" as I can be when I am getting no actual help, just vilification.

    IF I am dogin it wrong then PLEASE show me how it should be done.



  • @tbowmo said:

    I am using exactly that example sketch in my own serial gateway, with 3 empty functions. And it works!

    Really? In both directions? You can send from puTTY and the Serial Gateway displays it --AND-- the Serial Gateway sends stuff and puTTY displays it?

    That's why I wrote above "code that you can see working on your PC?"


  • Admin

    @AndErn

    the gateway doesn't echo characters back to you, so if you send something to the GW, then you won't see it in your terminal (unless you have local echo on).

    I am using the sketch, and it prints startup messages from the GW, and also messages received from nodes on the MySensors network. I can also send messages to nodes (using Mysensors serial API to the GW)

    You still haven't told us if you see any messages on the serial, when you program the basic sketch in your GW. That is, program GatewaySerial example sketch into your arduino, and then open the terminal program in arduino, perhaps enable #define MY_DEBUG, then it sends even more text over the serial port..


  • Contest Winner

    @AndErn said:

    I feel it is a waste of any more time as NO ONE has yet shown me how to make the example work WITH 2.) Bear in mind I WROTE ABOVE it worked OK with 1.5 AND the basic Arduino Serial.

    Then stick to 1.5 and stop wasting the rest of us incompetent programmers (who have more or less than 40 years of experience) time with your ranting.


Log in to reply
 

Suggested Topics

  • 1
  • 2
  • 3
  • 10
  • 1
  • 6

58
Online

11.4k
Users

11.1k
Topics

112.7k
Posts