• This my code so far on the puck , and I am able to connect using the python code below and send commands, but I am unable to return a value back, actually I do receive something, such as

    <type 'str'>
    <- Serial1
    >
    

    but it should be temperature reading of the puck. any help please

    Puck Code:

    function beam(ircode)
    {
      Puck.IR(require("pronto").decode(ircode)­);
      digitalWrite(LED2,1);
      setTimeout(function() 
      {
        digitalWrite(LED2,0);
      }, delayInMilliseconds);
      return E.getTemperature();
    }
    

    Python:

    import sys
    from bluepy.btle import UUID, Peripheral
    import time
    import binascii
    from bluepy import btle
    
    command = "\x03\x10beam(" +sys.argv[2]+ ");\n"
    
    class MyDelegate(btle.DefaultDelegate):
        def __init__(self):
            btle.DefaultDelegate.__init__(self)
    
        def handleNotification(self, cHandle, data):
            print("A notification was received: %s" %data)
            
    p = Peripheral(sys.argv[1], 'random')
    p.setDelegate(MyDelegate())
    try:
            UartService=p.getServiceByUUID(UUID("6E4­00001-B5A3-F393-E0A9-E50E24DCCA9E"))
            ch = UartService.getCharacteristics(UUID("6E4­00002-B5A3-F393-E0A9-E50E24DCCA9E"))[0]
    
            while len(command)>0:
                    ch.write(command[0:20]);
                    command = command[20:];
    
            
            p.writeCharacteristic(ch.valHandle+1, "\x02\x00")
    
            while True:
                if p.waitForNotifications(1.0):
                    # handleNotification() was called
                    continue
    
                print("Waiting...")
                # Perhaps do something else here
            [#rx](http://forum.espruino.com/search/?­q=%23rx) = UartService.getCharacteristics(UUID("6E4­00003-B5A3-F393-E0A9-E50E24DCCA9E"))[0]
            [#val](http://forum.espruino.com/search/­?q=%23val) = rx.read()
            [#print](http://forum.espruino.com/searc­h/?q=%23print) val
        
    
            p.disconnect()
    finally:
            p.disconnect()
    
About

Avatar for Ossama @Ossama started