Kivy Python - Callback Function with partial
<p>I want to 'pull' some values from my Arduino in kivy on Raspberry, which is connected via a wireless NRF24 module. I am using <a href="https://tmrh20.github.io/RF24/" rel="nofollow">this</a> library with a <a href="https://tmrh20.github.io/RF24/Python.html" rel="nofollow">python wrapper</a> </p>

<p>In pure Python the code works well and now I want to integrate it in Kivy. </p>

<p>For that I made two functions inside <code>zimmerwetter.py</code>:</p>

<p>One for setting up the radio device and returns the radio object (should be running once the application starts):</p>

<pre><code>def radiosetup():
    radio = RF24(RPI_BPLUS_GPIO_J8_22, RPI_BPLUS_GPIO_J8_24, BCM2835_SPI_SPEED_8MHZ)

    # doing setup stuff...

    return radio
</code></pre>

<p>and another function which send an request to the Arduino which delivers some enviroment date (temperatur, humidity etc.). </p>

<pre><code>def getenviroment(self,radio):

    millis = lambda: int(round(time.time() * 1000))
    # send command
    send_payload = 'getdata'
    # First, stop listening so we can talk.

    radio.stopListening()

    # Take the time, and send it.  This will block until complete
    print 'Now sending length ', len(send_payload), ' ... ',
    radio.write(send_payload[:len(send_payload)])

    a = datetime.datetime.now()

    # Now, continue listening
    radio.startListening()

    # Wait here until we get a response, or timeout
    started_waiting_at = millis()
    timeout = False
    while (not radio.available()) and (not timeout):
        if (millis() - started_waiting_at) &gt; 1000:
            timeout = True

    # Describe the results
    if timeout:
        b = datetime.datetime.now()
        #      print(b - a)
        print 'failed, response timed out.'
    else:
        # Grab the response, compare, and send to debugging spew
        length = radio.getDynamicPayloadSize()
        receive_payload = []
        receive_payload = radio.read(length)

        print 'got response size=', length
        print struct.unpack("bbbbhbbbb", ''.join(chr(c) for c in receive_payload))
        b = datetime.datetime.now()
        print(b - a)
        return receive_payload
</code></pre>

<p>The getenviroment function should be called later every x seconds from the kivy app, the partial function is used as suggested in <a href="https://github.com/kivy/kivy/blob/master/kivy/clock.py" rel="nofollow">the kivy clock module</a></p>

<pre><code>from zimmerwetter import *

class PyowmApp(App):
    def build(self):
        radio = radiosetup()
        Clock.schedule_interval(partial(getenviroment,radio), 10)
</code></pre>

<p>The Error is :</p>

<pre><code>   File "/home/pi/pyscripts/pyowm/zimmerwetter.py", line 83, in getenviroment
     radio.stopListening()
 AttributeError: 'float' object has no attribute 'stopListening'
</code></pre>

<p>I am wondering why a float object is returned, when I print the radio object with help(radio), it returns <code>class RF24(Boost.Python.instance)</code> and the function stoplistening() exists.</p>