Semi-Live Image (IR)

...auto-refresh ... Upgrade in progress....for more info check out posts...

Sunday, 27 December 2015

Pi-Birdies! Part III - Pi-Python Knowledge (camera, sensors and ftp)

I feel like sharing some acquired, though by no means the finest of, pi-phython-knowledge for those that like myself need such a thing...
 
There are various parts to this code, which I again wish to precise, is by no means a finished product:
Part (1) - ftp connection
Part (2) - camera activation
Part (3) - sensory information retrieval
Part (4) - overlaying sensory information on camera stream
Part (5) - capture image
Part (6) - upload image to ftp server

----------------------------------------------------------
# -*- coding: utf-8 -*-
import io
import time
import picamera

# Part (1)
# import ftp library
import ftplib #sufficient actually to import only the class FTP
meinftp = ftplib.FTP("ftp.XXX.XXX.de","username","pwd") #important to only specify the ftp main address and not a subdirectory
directory = '/webspace/httpdocs/bought-the-pasta/videos/livestream/' #intended ftp-directory
meinftp.cwd(directory)

#local upload-directory
directory_local='/home/pi/Desktop/' #/home/pi/1-NistkastenProjekt/timelapse/
print "ftp: So sieht der Inhalt von ",directory, " vor dem Upload aus:"
print

meinftp.retrlines('LIST')

#my_stream = io.BytesIO()

# Part (2)
with picamera.PiCamera() as camera:

        #(this here should all be indented)
        # camera settings
        camera.resolution = (1024,768)
        camera.sharpness = 0
        camera.contrast = 0
        camera.brightness = 50
        camera.saturation = 0
        camera.ISO = 0
        camera.video_stabilization = False
        camera.exposure_compensation = 0
        camera.exposure_mode = 'auto'
        camera.meter_mode = 'average'
        camera.awb_mode = 'auto'
        camera.image_effect = 'none'
        camera.color_effects = None
        camera.rotation = 0
        camera.hflip = False
        camera.vflip = False
        camera.crop = (0.0, 0.0, 1.0, 1.0)

        camera.start_preview()

        # Part (3)
        from sense_hat import SenseHat
        sense = SenseHat()
        #print("check")

        while True:
         #(again indent)
                t = sense.get_temperature()
                p = sense.get_pressure()
                h = sense.get_humidity()
                t = round(t, 1)
                p = round(p, 1)
                h = round(h, 1)

                #print("Temp [C] = %s, Press =%s, Humidity =%s" % (t,p,h))

                #sense.show_message(" ", scroll_speed=0.1)
                ttext = str(t)
                ptext = str(p)
                htext = str(h)
       
                fulltext = "Temp: " + ttext + " [C]; Press: " + ptext + "; Hum: " + htext
                fulltext = "Pi-Birdies! " + fulltext
                #print(fulltext)

                # Part (4)

                camera.annotate_text = fulltext #("Pi-Birdies!""temp:",(ttext,ptext,htext))

                 # Part (5)       

                time.sleep(2)
                camera.capture(my_stream,'jpeg')
                camera.capture('/home/pi/Desktop/SnapshotStream000.jpg')
                #camera.stop_preview()

                filename = 'SnapshotStream000.jpg'


                print
                print 'Location and name of the local file: ' + directory_local + filename
                print

                 # Part (6) 

                file = open(directory_local+filename, 'rb') #reading mode

                print 'Upload: ftp-Server: ' + directory + filename

                #'STOR ' the required ftp command


                meinftp.storbinary('Stor '+filename, file)

                print "ftp: content of directory ",directory, " after upload:"
                print

                meinftp.retrlines('LIST')

                print
                print 'Die lokale Datei ' + directory_local+filename +' wird geschlossen.'
                file.close()

                #print meinftp.quit() #terminate FTP-connection
                #print
                #print 'Die FTP-connection terminated.'

No comments:

Post a Comment