Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Distributing 'print' over multiple printable objects

  1. #1
    Senior Member
    Join Date
    Jul 2014
    Posts
    139

    Distributing 'print' over multiple printable objects

    I'm a huge fan of Teensy (I have 7 of them!) and have recently started a project that needs to be a little more polished and reliable. To help this, I'm trying to create a robust 'debug console' for easy status checking, configuration update and debugging when things inevitably go wrong.

    My project uses a WIZ820io & Micro SD Card Adaptor so I have an ethernet port available. The core of my code only uses 1 of the WIZ820io's 4 available sockets, so it is my intention to have the other 3 sockets available on port 23 (i.e. telnet). Also assume that the Teensy is on a secure subnet (I'm aware Telnet is terrible for security). It is also possible to connect via USB serial for debugging.

    In summary; when my code generates a debug message (which there are different levels of so the user can change the verbosity of the debug output), I'd like the message to go to (in the 'worse' case) the USB serial, and 3 sockets.

    I really like the ease of use of 'print' and 'println' and the built in conversions from ints to strings and more. So I'd like to be able to call something like 'Debug.println("")' and under the hood it calls 'Serial.println("")', 'TelnetClient1.println("")', 'TelnetClient2.println("")', etc. (Where 'TelnetClientX' is of type EthernetClient)

    My investigation so far has told me that I will probably have to create a class that inherits from some built in arduino type ('printable' possibly?), and I haven't been able to find an example of where this kind of advanced debug console functionality exists which does surprise me. Can anyone please help me with suggestions?

    Thanks,
    Mark

  2. #2
    Senior Member
    Join Date
    Jul 2014
    Posts
    139
    Also just remembered an idea I had whilst thinking about this... is it possible to make the 'String' class support 'Print' style functionality? This would be acceptable as I would just create my debug strings using 'String.print' and then send the String to my debug function (i.e. Debug.send(String debugString))

  3. #3
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    If you use, say, Serial.sprintf() to format char arrays you don't need the high overhead of the string class.

    You can also run a standard SYSLOG protocol server on some computer, always-on, even an RPi. Lots of free syslog server software for all OSes. Some NASes like my Synology have a syslog server.

    Then have etherent things send SYSLOG formatted status messages to that server. It uses simple UDP. Syslog messages are all text with specific codes for severity levels. The syslog client side is just open socket UDP, compose a string syslog message, put string chars on the UDP socket.

    Syslog servers have ways to sort/filter and forward or email or text if severity is > x.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •