Unhandled exception in callback handler



  • 
    from machine import UART
    import time
    from network import Bluetooth
    import adafruit_gps
    import pycom
    import _thread
    def parse_and_broadcast():
        while True:    
            gps.update()
            
            if not gps.has_fix:
                print('Waiting for fix...')
                continue
            print('=' * 40)  # Print a separator line. 
            print('Latitude: {} degrees'.format(gps.latitude))
            print('Longitude: {} degrees'.format(gps.longitude))
            print('Fix quality: {}'.format(gps.fix_quality))  
            latitude = gps.latitude   
            longitude = gps.longitude 
            latlong = latitude + longitude
            print("latlong:",latlong)
            chr1.value(latlong)
            
                
                #if gps.satellites is not None:
                    #print('# satellites: {}'.format(gps.satellites))
                #if gps.altitude_m is not None:
                    #print('Altitude: {} meters'.format(gps.altitude_m))
                #if gps.track_angle_deg is not None:
                    #print('Speed: {} knots'.format(gps.speed_knots))
                #if gps.track_angle_deg is not None:
                    #print('Track angle: {} degrees'.format(gps.track_angle_deg))
                #if gps.horizontal_dilution is not None:
                    #print('Horizontal dilution: {}'.format(gps.horizontal_dilution))
                #if gps.height_geoid is not None:
                    #print('Height geo ID: {} meters'.format(gps.height_geoid))            
                
    
        
    def conn_cb (bt_o):
        events = bt_o.events()
        if  events & Bluetooth.CLIENT_CONNECTED:
            print("Client connected")
        elif events & Bluetooth.CLIENT_DISCONNECTED:
            print("Client disconnected")
    
    
    def char1_cb(chr,arg1=None):
        events = chr.events()
        if events &  Bluetooth.CHAR_READ_EVENT :
            parse_and_broadcast()
    uart = UART(1, baudrate=115200, pins=('P8','P4'))    #tx rx 
    gps = adafruit_gps.GPS(uart) 
    print('Advertising Bluetooth...')
    bluetooth = Bluetooth()
    bluetooth.advertise(True)
    bluetooth.set_advertisement(name='gps', service_uuid=b'1234567890abcdef') 
    srv1 = bluetooth.service(uuid='0000000000000000', isprimary=True)
    chr1 = srv1.characteristic(uuid='0000000000000002', properties=Bluetooth.PROP_INDICATE | Bluetooth.PROP_BROADCAST | Bluetooth.PROP_READ | Bluetooth.PROP_WRITE| Bluetooth.PROP_NOTIFY, value='InitialValue')
    bluetooth.callback(trigger=Bluetooth.CLIENT_CONNECTED | Bluetooth.CLIENT_DISCONNECTED, handler=conn_cb)
    chr1.callback(trigger=Bluetooth.CHAR_READ_EVENT | Bluetooth.CHAR_NOTIFY_EVENT, handler=char1_cb)
    

    I am using fipy over pysense. I connected external gps. I am reading on uart. I parse. I broadcast the data over ble to the terminal application. after a while I get an error from ble as below
    Screen Shot 2020-08-27 at 13.18.11.png
    How can ı fix this error?
    Do you have any ideas guys?
    Can you help me?
    Thank you!!



  • @jcaron How can I do what you say



  • @AlganEren You can't write to the characteristic unless there is a client connected. You'll have to store the current connection state and only update the characteristic when you are connected.


Log in to reply
 

Pycom on Twitter