Passing one object to another
-
I have created a logging class that works fine except when I wish to pass an instance of BLE class so that I can redirect the logs to BLE.
oBLE = BLE(oConfig,devicename)
oLOGGING = LOGGING(oBLE)
oLOGGING.logger("config::oBLE[" + str(oBLE.enable) + "]",level=4)****ERROR *** logger::Exception'NoneType' object has no attribute 'Write_log'
class LOGGING: def __init__(self, oBLE): self.oBLE = oBLE def logger(self,msg,showtime=True,level=3,topic="",bdebug=True,debuglevel=3): #error0,warning1,debug2,info3,verbose4 try: self.oBLE.Write_log(msg) except Exception as e: print(" logger::Exception" + str(e)) if bdebug and debuglevel>=level: if showtime: print(" | ",msg) else: print(msg) # send_msg("outbox",msg)class BLE: global intRTCErrors def __init__(self,oConfig,devicename="devicename"): global bluetooth self.oConfig = oConfig self.bluetooth = Bluetooth() self.devicename=devicename self.char1_read_counter=-1 self.BLEchr=None self.bluetooth.init() self.__enable = True # DEFAULT VALUE IF NOT FOUND IN NVMEM self.__started = False print("---START --- BLUEON ------------------------------------------------") global chr1 try: # LOGGING.logger("CMD::BLEADVERTISE...") global chr_light global chr_temp global chr_humidity global chr_batt global chr3 self.bluetooth.set_advertisement(name=self.devicename, service_uuid=b'1134567890123456') self.bluetooth.callback(trigger=Bluetooth.CLIENT_CONNECTED | Bluetooth.CLIENT_DISCONNECTED, handler=self.BLE_connection_callback) self.bluetooth.advertise(True) # LOGGING.logger("CMD::BLEADVERTISE::Setup Service #DEEDAAFB-0000-0000-0000-000000000001") srv1 = self.bluetooth.service(uuid=uuid2bytes('DEEDAAFB-0000-0000-0000-000000000001'), isprimary=True,nbr_chars=5) chr1 = srv1.characteristic(uuid=uuid2bytes('DEEDAAFB-0000-0000-000C-000000000001'),properties=Bluetooth.PROP_WRITE | Bluetooth.PROP_INDICATE | Bluetooth.PROP_BROADCAST | Bluetooth.PROP_READ | Bluetooth.PROP_NOTIFY, value=self.devicename) chr_light = srv1.characteristic(uuid=uuid2bytes('DEEDAAFB-0000-0000-000C-000000000002'),properties=Bluetooth.PROP_BROADCAST | Bluetooth.PROP_READ | Bluetooth.PROP_NOTIFY, value=0) chr_temp = srv1.characteristic(uuid=uuid2bytes('DEEDAAFB-0000-0000-000C-000000000003'),properties=Bluetooth.PROP_BROADCAST | Bluetooth.PROP_READ | Bluetooth.PROP_NOTIFY, value=0) chr_humidity = srv1.characteristic(uuid=uuid2bytes('DEEDAAFB-0000-0000-000C-000000000004'),properties=Bluetooth.PROP_BROADCAST | Bluetooth.PROP_READ | Bluetooth.PROP_NOTIFY, value=0) chr_batt = srv1.characteristic(uuid=uuid2bytes('DEEDAAFB-0000-0000-000C-000000000005'),properties=Bluetooth.PROP_BROADCAST | Bluetooth.PROP_READ | Bluetooth.PROP_NOTIFY, value=0) #chr1 = srv1.characteristic(uuid=b'ab34567890123456', value=5) char1_cb = chr1.callback(trigger=Bluetooth.CHAR_WRITE_EVENT, handler=self.write_handler) char2_cb = chr1.callback(trigger=Bluetooth.CHAR_READ_EVENT, handler=self.read_handler) # LOGGING.logger("CMD::BLEADVERTISE::DRM Service #DEEDAAFB-0000-0000-0000-000000000002") # srv2 = bluetooth.service(uuid=uuid2bytes('DEEDAAFB-0000-0000-0000-000000000002'), isprimary=True) # chr2 = srv2.characteristic(uuid=uuid2bytes('DEEDAAFB-0000-0000-000C-000000000002'),properties=Bluetooth.PROP_INDICATE | Bluetooth.PROP_BROADCAST | Bluetooth.PROP_READ | Bluetooth.PROP_NOTIFY, value=str(wl.ifconfig())) # char2_read_counter = 0xF0 # char2_cb = chr2.callback(trigger=Bluetooth.CHAR_WRITE_EVENT | Bluetooth.CHAR_READ_EVENT, handler=char2_cb_handler) # LOGGING.logger("CMD::BLEADVERTISE::Command Service #DEEDAAFB-0000-0000-0000-000000000003") srv3 = self.bluetooth.service(uuid=uuid2bytes('DEEDAAFB-0000-0000-0000-000000000003'), isprimary=True) self.BLEchr = srv3.characteristic(uuid=uuid2bytes('DEEDAAFB-0000-0000-000C-000000000003'),properties=Bluetooth.PROP_INDICATE | Bluetooth.PROP_BROADCAST | Bluetooth.PROP_READ | Bluetooth.PROP_NOTIFY, value="logging..") char3_cb = self.BLEchr.callback(trigger=Bluetooth.CHAR_WRITE_EVENT, handler=self.BLE_CommandService_handler) self.BLEchr.value("ble logging.....") self.Write_log("bleuey more..") except Exception as e: intRTCErrors=0 print("ble::exceptiond " + str(e),level=1) print("---END --- BLUEON ------------------------------------------------") return "BLEADVERTISE..DONE" def Write_log(self,slog): print("Blueit..",slog) self.BLEchr.value(slog)
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login