0

I am working on a project on a Raspberry Pi. I am trying to autorun a Python script automatically when the Raspberry Pi is powered up. However, this Python script generates an HTTPS link to access a flask server. I am facing a problem as when the raspberry pi is turned on it does not run the python script. For the autorun code, I have tried the crontab, rc.local, and the autostart folder but in vain. After some debugging, I have figured out that the problem causing the python script not to autorun is the ssl_context present in the main of the code.

When I tried to run the code from thonny it ran fine. But when booting the pi it does not run. I have provided the code below. I would really appreciate any kind of help. Thank you in advance.

from flask import Flask, render_template, Response, request
from flask import Flask, jsonify, request
from camera_a import VideoCamera
import time
import threading
import os
#import ssl


pi_camera = VideoCamera(flip=True) # flip pi camera if upside down.

# App Globals (do not edit)
app = Flask(__name__)

@app.route("/")
def index():
           return render_template('index.html') #you can customze index.html here
           print("starting")

def gen(camera):
    #get camera frame
    while True:
        frame = camera.get_frame()
        yield (b'--frame\r\n'
               b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')

@app.route('/video_feed')
def video_feed():
     return Response(gen(pi_camera),
                    mimetype='multipart/x-mixed-replace; boundary=frame')

if __name__ == '__main__':
           app.run(host='0.0.0.0', debug=False, ssl_context=('cert.pem','key.pem'))

Where cert.pem and the key.pem are the server cerificate and the private key respectively.

3
  • what research have you done? ... your question has been asked many times
    – jsotola
    Jun 7 at 5:41
  • the question answered are for running a normal python script. But the one am asking is for running a python script that generates an HTTPS link. I have tried all the method I have come across to make it run at startup but it does not run. Jun 7 at 5:46
  • You probably need the full path for the cert.pem and key.pem files.
    – Craig
    Jun 7 at 20:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.