|
1
|
|
|
import os |
|
2
|
|
|
import base64 |
|
3
|
|
|
import backend.fcmservice |
|
4
|
|
|
#from backend.fcmservice import BaseService |
|
5
|
|
|
from helpers.camerahelper import take_picture |
|
6
|
|
|
from messaging.sensormessages import SensorValueSchema |
|
7
|
|
|
from domain.sensors import SensorValue |
|
8
|
|
|
from backend.fcmcache import CacheKeys |
|
9
|
|
|
|
|
10
|
|
|
class CameraService(backend.fcmservice.BaseService): |
|
11
|
|
|
#def __init__(self, config, cache): |
|
12
|
|
|
# super(CameraService, config, cache) |
|
13
|
|
|
|
|
14
|
|
|
def take_picture(self, file_name='fullcycle_camera.png'): |
|
15
|
|
|
pic = take_picture(file_name, |
|
16
|
|
|
self.configuration.get('camera.size'), |
|
17
|
|
|
self.configuration.get('camera.quality'), |
|
18
|
|
|
self.configuration.get('camera.brightness'), |
|
19
|
|
|
self.configuration.get('camera.contrast')) |
|
20
|
|
|
return pic |
|
21
|
|
|
|
|
22
|
|
|
def store_picture_cache(self, file_name): |
|
23
|
|
|
if os.path.isfile(file_name): |
|
24
|
|
|
with open(file_name, 'rb') as photofile: |
|
25
|
|
|
picdata = photofile.read() |
|
26
|
|
|
#picture will be handled like a sensor |
|
27
|
|
|
reading = SensorValue('fullcyclecamera', base64.b64encode(picdata), 'camera') |
|
28
|
|
|
message = super().createmessageenvelope() |
|
29
|
|
|
sensorjson = message.jsonserialize(SensorValueSchema(), reading) |
|
30
|
|
|
self.cache.tryputcache(CacheKeys.camera, sensorjson) |
|
31
|
|
|
|