def envia_foto(Bot, mensaje=''): global camara #------------------ejemplo envio de foto------------------------------------------------------- # camera.init(0, format=camera.JPEG) try: camera.init(0, format=camera.JPEG) except OSError as exc: camera.deinit() Bot.send_message(Bot.canal, exc.args[0]) print(exc.args) return Led = Pin(4, Pin.OUT) # define flash Led.on() #enciende flash # girar vertical camera.flip(0) # giro horizontal camera.mirror(0) camera.framesize(camara.tamanyo_imagen) #'FRAME_240X240'/4, 'FRAME_96X96'/0, 'FRAME_CIF'/6, 'FRAME_FHD'/14, 'FRAME_HD'/11, 'FRAME_HQVGA'/3, 'FRAME_HVGA'/7, 'FRAME_P_3MP'/16, 'FRAME_P_FHD'/20, 'FRAME_P_HD'/15, 'FRAME_QCIF'/2, 'FRAME_QHD'/18, 'FRAME_QQVGA'/1, 'FRAME_QSXGA'/21, 'FRAME_QVGA'/5, 'FRAME_QXGA'/17, 'FRAME_SVGA'/9, 'FRAME_SXGA'/12, 'FRAME_UXGA'/13, 'FRAME_VGA'/8, 'FRAME_WQXGA'/19, 'FRAME_XGA'/10 # efectos especiales camera.speffect(camara.efecto_especial) # EFFECT_NONE (default) EFFECT_NEG EFFECT_BW EFFECT_RED EFFECT_GREEN EFFECT_BLUE EFFECT_RETRO # white balance camera.whitebalance(camara.balance_blancos) # The options are the following: # WB_NONE (default) WB_SUNNY WB_CLOUDY WB_OFFICE WB_HOME # saturation camera.saturation(camara.saturacion) # -2,2 (default 0). -2 grayscale # brightness camera.brightness(camara.brillo) # -2,2 (default 0). 2 brightness # contrast camera.contrast(camara.contraste) #-2,2 (default 0). 2 highcontrast # quality camera.quality(camara.calidad) # 10-63 lower number means higher quality bufer = camera.capture() print('captura realizada') Led.off() #apaga flash with open('file.jpg', 'w') as k: k.write(bufer) bufer = None camera.deinit() Bot.envia_archivo_multipart(configuracion.Chat_Id, 'file.jpg', 'sendPhoto', 'photo', mensaje)
async def port3(cs, rq): rqp = rq[1].split('/') if rqp[1] == 'apikey': # Must have /apikey/<REQ> if rqp[2] == 'flash': # /apikey/flash/<what> if rqp[3] == 'on': flash_light.on() else: flash_light.off() cs.send(b'%s' % hdr['OK']) elif rqp[2] == 'pix': w = int(rqp[3]) if w > 0 and w < 13: camera.framesize(w) cs.send(b'%s' % hdr['OK']) elif rqp[2] == 'qua': w = int(rqp[3]) if w > 9 and w < 64: camera.quality(w) cs.send(b'%s' % hdr['OK']) elif rqp[2] == 'con': w = int(rqp[3]) if w > -3 and w < 3: camera.contrast(w) cs.send(b'%s' % hdr['OK']) elif rqp[2] == 'sat': w = int(rqp[3]) if w > -3 and w < 3: camera.saturation(w) cs.send(b'%s' % hdr['OK']) elif rqp[2] == 'bri': w = int(rqp[3]) if w > -3 and w < 3: camera.brightness(w) cs.send(b'%s' % hdr['OK']) elif rqp[2] == 'spe': w = int(rqp[3]) if w >= 0 and w < 7: camera.speffect(w) cs.send(b'%s' % hdr['OK']) elif rqp[2] == 'wbl': w = int(rqp[3]) if w >= 0 and w < 5: camera.whitebalance(w) cs.send(b'%s' % hdr['OK']) else: cs.send(b'%s' % hdr['OK']) else: loop.create_task(foo([7, 5])) cs.send(b'%s' % hdr['OK']) clean_up(cs)
wifiConnectCount = 0 while True: cr = camera.init() print("Camera ready?: ", cr) if cr: break time.sleep(2) wifiConnectCount += 1 if wifiConnectCount >= 5: break if not cr: print("Camera not ready. Can't continue!") else: # reconfigure camera camera.speffect(2) # black and white camera.quality(10) # increase quality from 12 (default) to 10 # setup networking wifi = WIFI.STA.Sta(config['WIFI_SSID'], config['WIFI_PASSWORD']) wifi.connect() wifi.wait() wifiConnectCount = 0 while not wifi.wlan.isconnected(): print("WIFI not ready. Wait...") time.sleep(2) wifiConnectCount += 1 if wifiConnectCount >= 5: break if wifiConnectCount >= 5: print("WIFI not ready. Can't continue!") else:
def port3(cs, rq): rqp = rq[1].split('/') if rqp[1] == 'apikey': # Must have /apikey/<REQ> if rqp[2] == 'flash': # /apikey/flash/<what> if rqp[3] == 'on': flash_light.on() else: flash_light.off() cs.send(b'%s' % hdr['OK']) elif rqp[2] == 'fmt': w = int(rqp[3]) if w >= 0 and w <= 2: camera.pixformat(w) cs.send(b'%s' % hdr['OK']) elif rqp[2] == 'pix': w = int(rqp[3]) if w > 0 and w < 13: camera.framesize(w) cs.send(b'%s' % hdr['OK']) elif rqp[2] == 'qua': w = int(rqp[3]) if w > 9 and w < 64: camera.quality(w) cs.send(b'%s' % hdr['OK']) elif rqp[2] == 'con': w = int(rqp[3]) if w > -3 and w < 3: camera.contrast(w) cs.send(b'%s' % hdr['OK']) elif rqp[2] == 'sat': w = int(rqp[3]) if w > -3 and w < 3: camera.saturation(w) cs.send(b'%s' % hdr['OK']) elif rqp[2] == 'bri': w = int(rqp[3]) if w > -3 and w < 3: camera.brightness(w) cs.send(b'%s' % hdr['OK']) elif rqp[2] == 'ael': w = int(rqp[3]) if w > -3 and w < 3: camera.aelevels(w) cs.send(b'%s' % hdr['OK']) elif rqp[2] == 'aev': w = int(rqp[3]) if w >= 0 and w <= 1200: camera.aecvalue(w) cs.send(b'%s' % hdr['OK']) elif rqp[2] == 'agc': w = int(rqp[3]) if w >= 0 and w <= 30: camera.agcgain(w) cs.send(b'%s' % hdr['OK']) elif rqp[2] == 'spe': w = int(rqp[3]) if w >= 0 and w < 7: camera.speffect(w) cs.send(b'%s' % hdr['OK']) elif rqp[2] == 'wbl': w = int(rqp[3]) if w >= 0 and w < 5: camera.whitebalance(w) cs.send(b'%s' % hdr['OK']) else: cs.send(b'%s' % hdr['none']) else: cs.send(b'%s' % hdr['err']) clean_up(cs)