Benutzer-Werkzeuge

Webseiten-Werkzeuge


sqlite

SQLite

Introduction

Install

 sudo apt-get install sqlite3

Schema for Sensors

table Log (
  Id       integer primary key autoincrement,
  DateI    integer, # Insert timestamp unix time
  Msg      text,    # Log message text
  LogLevel text,    # level of importance critical, important, info
  value    real     # value if relevant for mlog message
          )
  
table Sensor (
  Id          integer primary key autoincrement,
  DateI       integer, # Insert timestamp unix time
  Sensor      text,    # Sensor ID
  Sonsortyp   text,    # Sensor type
  Room        text     # Room where sensor is installed, eg. Outside, Technik, Basteln, UGFlur
             )
  
 
table Measure (
  Id       integer primary key autoincrement,
  DateI    integer, # Insert timestamp unix time
  Sensor   text,    # Sensor ID
  Valuetyp text,    # Value type eg, temperature, humidity
  value    real     # measured value
              )
  
 ------------- Views ----------------

View LogV
    Select *,
           datetime(dateI, 'unixepoch') as STRDate, 
           strftime('%Y',datetime(dateI, 'unixepoch')) as Year,
           strftime('%d',datetime(dateI, 'unixepoch')) as day,
           strftime('%m',datetime(dateI, 'unixepoch'))as month,
           strftime('%H',datetime(dateI, 'unixepoch')) as hour,
           strftime('%M',datetime(dateI, 'unixepoch'))as minute, 
           strftime('%S',datetime(dateI, 'unixepoch')) as second,
    from Log
 
View SensorV
    Select *,
           datetime(dateI, 'unixepoch') as STRDate, 
           strftime('%Y',datetime(dateI, 'unixepoch')) as Year,
           strftime('%d',datetime(dateI, 'unixepoch')) as day,
           strftime('%m',datetime(dateI, 'unixepoch'))as month,
           strftime('%H',datetime(dateI, 'unixepoch')) as hour,
           strftime('%M',datetime(dateI, 'unixepoch'))as minute, 
           strftime('%S',datetime(dateI, 'unixepoch')) as second,
    from Sensor
 
View MeasureV 
    Select *, 
           datetime(dateI, 'unixepoch') as STRDate, 
           strftime('%Y',datetime(dateI, 'unixepoch')) as Year,
           strftime('%d',datetime(dateI, 'unixepoch')) as day,
           strftime('%m',datetime(dateI, 'unixepoch'))as month,
           strftime('%H',datetime(dateI, 'unixepoch')) as hour,
           strftime('%M',datetime(dateI, 'unixepoch'))as minute, 
           strftime('%S',datetime(dateI, 'unixepoch')) as second,
     from Measure
 

Auwertungs views

create view latestvaluelabor1 as 
     SELECT value 
     FROM Measure_V_A 
     WHERE sensor = 'Labor-1' 
     ORDER BY dateI DESC 
     LIMIT 1;
 

Example code

convert unix timestamp to date, year, month, etc

SELECT datetime(dateI, 'unixepoch') as STRDate, strftime('%Y',datetime(dateI, 'unixepoch')) as Year
, strftime('%d',datetime(dateI, 'unixepoch')) as day
, strftime('%m',datetime(dateI, 'unixepoch'))as month
, strftime('%H',datetime(dateI, 'unixepoch')) as hour
, strftime('%M',datetime(dateI, 'unixepoch'))as minute
, strftime('%S',datetime(dateI, 'unixepoch')) as second from Daten
sqlite.txt · Zuletzt geändert: von 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki