# -*- coding: utf-8 -*- # Copyright (c) 2020 Zorglub42 {contact(at)zorglub42.fr}. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 """FFBC8 weatherstation sensors API.""" import logging from flask_restx import Resource, reqparse from api.datamodel import (LAST_SENSORS_VALUES, GET_SENSOR_VALUES, SENSOR_VALUES_TREND) from api.restx import API from services.sensors import SensorsService NS = API.namespace('sensors', description='sensors resources') @NS.route('/last') class Last(Resource): """Last value for all sensors API Class.""" logger = None # pylint: disable=keyword-arg-before-vararg def __init__(self, api=None, *args, **kwargs): Resource.__init__(self, api, kwargs) self.logger = logging.getLogger(__name__) @API.marshal_with(LAST_SENSORS_VALUES) def get(self):
# All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 """FFBC8 weatherstation receive phone/browser data.""" import logging import socket import subprocess from flask import request from flask_restx import Resource import requests from api.restx import API import settings NS = API.namespace('phone', description='interact with phone') @NS.route('/GPS') class GPS(Resource): """Receive GPS data API Class.""" logger = None # pylint: disable=keyword-arg-before-vararg def __init__(self, api=None, *args, **kwargs): Resource.__init__(self, api, kwargs) self.logger = logging.getLogger(__name__) def _send_influx(self, data): if data == "":
import logging import json import urllib import requests from flask_restx import Resource from flask import request import settings from api.datamodel import RUNNING_SCENARIO from api.datamodel import STEP_POST, RECORDER_POST from api.restx import API as api from service.datamodel import RunningScenarioClass from service.exception import RecordingException from service.recorder import RecorderService NS = api.namespace('recorders', description='Recording sessions management') PARSER = api.parser() PARSER.add_argument( 'time', type=int, help='POSIX Timestamp (in nanosec) recorder started immediatly \ before this time', default=None, location='args') @NS.route('/environment/<string:env>') @api.doc(params={'env': 'Environment identifier'}) class Recorder(Resource): """Recorder services management class."""
# All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 """FFBC8 weatherstation Admin API.""" import logging from flask import request from flask_restx import Resource from api.datamodel import SYSTEM_COMMAND_PAYLOAD, SYSTEM_TIME,\ WIFI_CONFIG_EXTENDED, WIFI_CONFIG from api.restx import API from services.admin import AdminService NS = API.namespace('admin', description='Weather station admin') @NS.route("/ping") class Pinger(Resource): """System pingers.""" logger = None # pylint: disable=keyword-arg-before-vararg def __init__(self, api=None, *args, **kwargs): Resource.__init__(self, api, kwargs) self.logger = logging.getLogger(__name__) def get(self): """Ping system."""
# 1.0.0 - 2017-02-20 : Release of the file # import logging import requests from flask import request from flask_restx import Resource import settings from api.datamodel import POWER_MEASUREMENT, POWER_POST from api.restx import API as api from service.datamodel import PowerMeasurementClass, RunningScenarioClass from service.exception import RecordingException from service.recorder import RecorderService NS = api.namespace('servers', description='Operations related to servers') @NS.route('/<string:server>/consumption') @NS.deprecated class ServerConsumption(Resource): """Server consumption management API.""" log = logging.getLogger(__name__) @api.expect(POWER_POST) @api.marshal_with(POWER_MEASUREMENT) def post(self, server): # pylint: disable=locally-disabled,no-self-use """ Power consumption receiver (see /equipments/{equipement}/measurements).
# # Description : # API monitoring # ------------------------------------------------------- # History : # 1.0.0 - 2017-05-11 : Release of the file # import logging from flask_restx import Resource from api.datamodel import API_STATUS from api.restx import API as api from service.monitoring import MonitoringService NS = api.namespace('monitoring', description='API monitoring') @NS.route('/ping') class Ping(Resource): """API monitoring Ping class.""" logger = logging.getLogger(__name__) @api.marshal_with(API_STATUS) def get(self): """Return API status.""" self.logger.debug("GET ping") return MonitoringService().connect_influx()
import requests from flask import request from flask_restx import Resource from service.mqtt import MQTTService import settings from api.datamodel import API_STATUS, MEASUREMENT_POST from api.restx import API as api from service.datamodel import APIStatusClass, RunningScenarioClass from service.exception import RecordingException from service.recorder import RecorderService from service.mqtt import MQTTService NS = api.namespace('equipments', description='Equipements monitoring operations') @NS.route('/<string:equipement>/measurements') class EquipementMeasurements(Resource): """Server consumption management API.""" log = logging.getLogger(__name__) def __init__(self, api=None, *args, **kwargs): super().__init__(api, *args, **kwargs) self._mqtt_svc = MQTTService() @api.expect(MEASUREMENT_POST) @api.marshal_with(API_STATUS) def post(self, equipement): # pylint: disable=locally-disabled,no-self-use
# # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 """FFBC8 weatherstation receive GPS data.""" import logging from flask import request from flask_restx import Resource import requests from api.restx import API import settings NS = API.namespace( 'GPS', description='receive GPS data' ) @NS.route('/') class GPS(Resource): """Receive GPS data API Class.""" logger = None # pylint: disable=keyword-arg-before-vararg def __init__(self, api=None, *args, **kwargs): Resource.__init__(self, api, kwargs) self.logger = logging.getLogger(__name__) def _send_influx(self, data):