server/api.py
def api_sensor(sensor_id):
  """ Returns all datapoints for given sensor
  """

  # Parse callback name. If not found take default
  callbackFunc = request.args.get("callback")
  if not callbackFunc:
    callbackFunc = DEFAULT_CALLBACK_FUNC

  # Retrieve sensor data
  cur = app.sqlite.cursor()
  query = """
      SELECT 
        device_name,
        value,
        value_timestamp
        FROM {0}
        WHERE device_uid = '{1}';
    """.format(DB_TABLE, sensor_id)

  # Execute query
  cur.execute(query)
  rows = cur.fetchall()

  # Parse and return
  device_name = ""
  sensor_values = []
  for row in rows:
    device_name = row[0]

    # Parse value and special cases
    value = row[1]
    if "temperature" in row[0].lower() or "temperature" in row[2].lower():
      try:
        value = float(value)/100
      except:
        pass
    if "True" in str(value):
      value = 1
    if "False" in str(value):
      value = 0
    if "none" in str(value).lower():
      value = 0
    if "light" in row[0].lower() or "light" in row[2].lower():
      try:
        value = float(value)/1000
      except:
        pass

    # Sensors emit None when turned off. Ignore
    if not "none" in str(row[2]).lower() and value != "":
      sensor_values.append("\"{0}\":{1}".format(row[2], value))

  return """{0}({{
    "sensor_id":"{1}",
    "sensor_name":"{2}",
    "values":{{{3}}}
  }});""".format(callbackFunc, sensor_id, device_name, ','.join(sensor_values))
 Returns all datapoints for given sensor
  
Returns all datapoints for given sensor
Returns all datapoints for given sensor
def api_sensor(sensor_id):
  callbackFunc = request.args.get("callback")
  if not callbackFunc:
    callbackFunc = DEFAULT_CALLBACK_FUNC
  cur = app.sqlite.cursor()
  query = """
      SELECT 
        device_name,
        value,
        value_timestamp
        FROM {0}
        WHERE device_uid = '{1}';
    """.format(DB_TABLE, sensor_id)
  cur.execute(query)
  rows = cur.fetchall()
  device_name = ""
  sensor_values = []
  for row in rows:
    device_name = row[0]
    value = row[1]
    if "temperature" in row[0].lower() or "temperature" in row[2].lower():
      try:
        value = float(value)/100
      except:
        pass
    if "True" in str(value):
      value = 1
    if "False" in str(value):
      value = 0
    if "none" in str(value).lower():
      value = 0
    if "light" in row[0].lower() or "light" in row[2].lower():
      try:
        value = float(value)/1000
      except:
        pass
    if not "none" in str(row[2]).lower() and value != "":
      sensor_values.append("\"{0}\":{1}".format(row[2], value))
  return """{0}({{
    "sensor_id":"{1}",
    "sensor_name":"{2}",
    "values":{{{3}}}
  }});""".format(callbackFunc, sensor_id, device_name, ','.join(sensor_values))
def api_sensor ( sensor_id ) : callbackFunc = request . args . get ( "callback" ) if not callbackFunc : callbackFunc = DEFAULT_CALLBACK_FUNC cur = app . sqlite . cursor ( ) query = """
      SELECT 
        device_name,
        value,
        value_timestamp
        FROM {0}
        WHERE device_uid = '{1}';
    """ . format ( DB_TABLE , sensor_id ) cur . execute ( query ) rows = cur . fetchall ( ) device_name = "" sensor_values = [ ] for row in rows : device_name = row [ 0 ] value = row [ 1 ] if "temperature" in row [ 0 ] . lower ( ) or "temperature" in row [ 2 ] . lower ( ) : try : value = float ( value ) / 100 except : pass if "True" in str ( value ) : value = 1 if "False" in str ( value ) : value = 0 if "none" in str ( value ) . lower ( ) : value = 0 if "light" in row [ 0 ] . lower ( ) or "light" in row [ 2 ] . lower ( ) : try : value = float ( value ) / 1000 except : pass if not "none" in str ( row [ 2 ] ) . lower ( ) and value != "" : sensor_values . append ( "\"{0}\":{1}" . format ( row [ 2 ] , value ) ) return """{0}({{
    "sensor_id":"{1}",
    "sensor_name":"{2}",
    "values":{{{3}}}
  }});""" . format ( callbackFunc , sensor_id , device_name , ',' . join ( sensor_values ) )
Returns all datapoints for given sensor
Returns all datapoints for given sensor
""" Returns all datapoints for given sensor
  """ # Parse callback name. If not found take default # Retrieve sensor data # Execute query # Parse and return # Parse value and special cases # Sensors emit None when turned off. Ignore
sensor_id