Announcement

Collapse
No announcement yet.

Logging data to a file from Portal

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    sbkaya

    When you say "build" are you talking about the "Test Script" button on Portal's Editor Window.

    Also can you post the script you are trying to "build".

    Thanks

    Comment


    • #17
      Originally posted by RPS View Post
      sbkaya

      When you say "build" are you talking about the "Test Script" button on Portal's Editor Window.

      Also can you post the script you are trying to "build".

      Thanks
      I pushed "Test Script" button on Portal's Editor Window. I chose portal instead of RF module on the screen appearing after pushing "Test Script" button and then script is succesfully built. I learnt that Script only works in portal is chosen by this way.

      Thanks

      sbkaya
      Last edited by sbkaya; 01-22-2014, 02:12 AM.

      Comment


      • #18
        sbkaya

        I believe that was the point @jasonharper was trying to make, that call only works when you are doing a Portal Script. So did you get it to work? Remember to click the portal node in the "Node View" and "Change Portal Base file" in the "Node Info" panels.

        Just for clarity, Portal's has multiple functions, its an Admin/Monitoring tool for the mesh network, its a configuration/load tool for for individual nodes (OTA and direct connect).

        Most of these function are facialited by the SNAP module connected to your PC via USB or COM port. So you have to be careful about accessing COM ports in script loaded onto your bridge node or you lose Portal's ability to connect to the mesh and do these functions.

        Once a day we get an email or fourm post about somebody "bricking" their RF Engine when they just accidently hijacked the UART Portal use to talk to the mesh.

        Finally Portal has a desktop program interface (portal node in the node viewer) which allows you interact with the mesh by mixing Portal API's and Desktop Python modules to do intersting things.

        If you don't want to use Portal GUI you can download SNAP Connect off the Support Forum and write your own AP which has all the connectivity of Portal without "Synapse" GUI.

        http://forums.synapse-wireless.com/showthread.php?t=9
        http://forums.synapse-wireless.com/u...e%20Manual.pdf
        http://forums.synapse-wireless.com/u...0-examples.zip

        Comment


        • #19
          RPS

          Yes, I got it to work. ALso, thank you for usefull information about Portal. I am beginner about Synapse and Portal and I try to follow forum to learn about them.

          Comment


          • #20
            root variable ?

            I am trying to implement the logSupport.py.

            I have a file called performLog.py and I loaded it into portal. See below.

            import logSupport

            def performLog( pref, d ):
            logSupport.logToFile( root, "prefix", d );

            I was able to create the prefix.log file in documents/Portal once but now it does not work. I think I shut down portal, ate lunch and returned to work. I also looked in 'program files' but it is not there.

            The odd thing is that my string, d, is coming out into the Portal "Event Log". This is not impacting me but it is odd.

            Do I have to edit my performLog.py to fix my root variable? Can you explain exactly what I should type for the root variable. Is it global? Is it an integer? Is it a string? I assume it needs to be static.

            Comment


            • #21
              Tim,

              See Kevin's previous reply in this thread for an explanation on that root argument -

              In other words, the parent/containing object. If you are using logSupport.py functions from within Portal, there is a pre-existing object NAMED root that can be used (once! as in for one log file only) for this.

              It's important to note that you can only use each "root" object once per run of Portal. (Once you has used "file1" with root, you cannot use "file2" - the association has already been made).
              For your purposes, using root as-is should be fine.

              What was your intention with the argument "pref"? I don't see it used in your example code.

              As far as what happened to your file, I'm not sure I have enough information to go on. Feel free to give me another call tomorrow and we can work through it. I will be available in the afternoon

              Comment


              • #22
                root variable ?

                I was supposed to send the variable pref (preferred prefix) onto the logToFile function. I hardcoded the "prefix" instead and did not use the pref variable.

                Are my strings supposed to be coming out into the Portal "Event Log".

                I am still not happy guessing what the root variable does. I would like to understand what this does. I think it would help me find where my prefix.log file is placed. I read Kevin's discussion but I don't know what 'type' root is.

                Comment


                • #23
                  Yes, you will see the output in the event log.

                  That parameter can be any global object instance of any class. 'root' is just the name of an existing object that the example used. If you look at the code in the logSupport.py, the first time you run it, it initializes the logger and adds a member variable logSetup to the object you passed in and sets it to true. The next time it is called the code first checks for that member variable, and if true it won't initialize another logger, and instead just logs the data.

                  You can actually create a 'dummy' class for this purpose like the code snippet below.

                  Code:
                  class dummyLoggingClass:
                      pass
                  
                  myDummyLoggyObject = dummyLoggingClass()
                  
                  def performLog( d ):
                      logSupport.logToFile( myDummyLoggyObject, "myLogFile", d );

                  Comment


                  • #24
                    Stripped down version

                    I ended up deleting most of the logToFile function because I was have so many python/portal errors. I have pasted my final function below which is a stripped down version of the original logToFile.py. I works consistently now.

                    I think the new version of python and portal were having many conflicts.



                    def logToFile(this, baseName, logInfo):
                    """
                    Writes an entry to the specified logfile. Caller provides the baseName,
                    the logging facility will append timestamps to this baseName as needed.
                    "this" must be the object considered to "own" the logfile (can be root)
                    "logInfo" is the text to be logged, and it will automatically be preceeded
                    by a timestamp.
                    """
                    try:
                    this.logSetup == True
                    except:
                    this.stream = open("C:\\Users\\tec\\Documents\\Portal\\" + baseName + ".log", 'w')

                    this.logSetup = True
                    print "SetupComplete-----------------------------------------------"
                    this.stream.write( logInfo + "\n")
                    this.stream.flush()

                    Comment

                    Working...
                    X