Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Unhandled exception in callback handler

    Scheduled Pinned Locked Moved Support & Troubleshooting
    3 Posts 2 Posters 55 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      AlganEren
      last edited by

      
      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!!

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jcaron @AlganEren
        last edited by

        @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.

        1 Reply Last reply Reply Quote 0
        • A Offline
          AlganEren
          last edited by

          @jcaron How can I do what you say

          1 Reply Last reply Reply Quote 0

          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
          • 1 / 1
          • First post
            Last post

          Pycom on Twitter

          Pycom