Pass variable from to lib class?

  • I have the following... how do access or pass rtc to the lib class

    from machine import RTC
    class LOGGING:
        global bdebug
        global rtc #not woking
        def logger(msg,showtime=True,level=3,topic="",bdebug=True,debuglevel=3): #error0,warning1,debug2,info3,verbose4
            if bdebug and debuglevel>=level:
                if showtime:
                    print(str([0])+str([1])+str([2])+"T"+str([3])+str([4])+str([5])," | ",msg)
                    # send_msg("outbox",msg)
                    # send_msg("outbox",msg)

    ******** NameError: name 'rtc' is not defined ***********************

  • @misterlisty Have you got an rtc = RTC() statement in your code? You need to have that to make any calls to (Note the upper and lower cases in your code).

    utime.localtime() might also be useful to you...


Pycom on Twitter