Week 27 28 29

2 minute read

WEEK 27-28-29

  1. I have improved two example videos to load the program to physical tello in python and in scratch for the channel kibotics.
  2. I have continued investigating how to achieve the integration of the tello drone from kibotics with MacOs and Windows. Check if with PyInstaller you could only make the self-contained file without entering the python interpreter, which is what gives problems when not allowing a cross compilation, but I have not see the way to do it by this method. I have found a possible way to do it for windows, by using wine:
    • Wine (recursive backronym for Wine Is Not an Emulator) is a free and open-source compatibility layer that aims to allow computer programs (application software and computer games) developed for Microsoft Windows to run on Unix-like operating systems. Wine also provides a software library, known as Winelib, against which developers can compile Windows applications to help port them to Unix-like systems
    • The idea would be to use pyinstaller previously installed inside wine and to be able to run it from there.
      $ wine python.exe Scripts/pip.exe install pyinstaller
      
    • I have tried integrating it in kibotics-web server and it is able to get the .exe, but it fails when executing it because it is not integrating the necessary library. I will try to investigate further how to fix this bug.
    • Disadvantages of using wine:
      • It requires previously installing wine on the machine where the server is running.
    • References:
      • https://www.it-swarm.dev/es/python/como-creo-un-ejecutable-de-windows-con-pyinstaller-en-ubuntu/960967170/
      • http://www.python.org.ar/wiki/Recetario/CrearEjecutableWindowsDesdeLinux
      • https://www.it-swarm.dev/es/python/compilacion-cruzada-de-un-script-python-en-linux-en-un-ejecutable-de-windows/969633203/
  3. I have started to study how the flask library works to use it with the raspberry pi. I have made an example that consists of turning on two LEDs from a web page.
    • Video with the example
    • Sample code:
        import RPi.GPIO as GPIO
        from flask import Flask, render_template, request
        app = Flask(__name__)
      
        GPIO.setmode(GPIO.BCM)
      
        # Create a dictionary called pins to store the pin number, name, and pin state:
        pins = {
           23 : {'name' : 'GPIO 23', 'state' : GPIO.LOW},
           24 : {'name' : 'GPIO 24', 'state' : GPIO.LOW}
           }
      
        # Set each pin as an output and make it low:
        for pin in pins:
           GPIO.setup(pin, GPIO.OUT)
           GPIO.output(pin, GPIO.LOW)
      
        @app.route("/")
        def main():
           # For each pin, read the pin state and store it in the pins dictionary:
           for pin in pins:
              pins[pin]['state'] = GPIO.input(pin)
           # Put the pin dictionary into the template data dictionary:
           templateData = {
              'pins' : pins
              }
           # Pass the template data into the template main.html and return it to the user
           return render_template('main.html', **templateData)
      
        # The function below is executed when someone requests a URL with the pin number and action in it:
        @app.route("/<changePin>/<action>")
        def action(changePin, action):
           # Convert the pin from the URL into an integer:
           changePin = int(changePin)
           # Get the device name for the pin being changed:
           deviceName = pins[changePin]['name']
           # If the action part of the URL is "on," execute the code indented below:
           if action == "on":
              # Set the pin high:
              GPIO.output(changePin, GPIO.HIGH)
              # Save the status message to be passed into the template:
              message = "Turned " + deviceName + " on."
           if action == "off":
              GPIO.output(changePin, GPIO.LOW)
              message = "Turned " + deviceName + " off."
      
           # For each pin, read the pin state and store it in the pins dictionary:
           for pin in pins:
              pins[pin]['state'] = GPIO.input(pin)
      
           # Along with the pin dictionary, put the message into the template data dictionary:
           templateData = {
              'pins' : pins
           }
      
           return render_template('main.html', **templateData)   
      
        if __name__ == "__main__":   
           app.run(host='0.0.0.0', port=80, debug=True)   
      
    • References:
      • https://randomnerdtutorials.com/raspberry-pi-web-server-using-flask-to-control-gpios/
      • https://www.programoergosum.es/tutoriales/control-de-gpio-con-flask-en-raspberry-pi/

Updated: