diff --git a/backend/lib/Definition/EntityDefinition.json b/backend/lib/Definition/EntityDefinition.json index 91894e1..a0cbf2c 100644 --- a/backend/lib/Definition/EntityDefinition.json +++ b/backend/lib/Definition/EntityDefinition.json @@ -31,14 +31,16 @@ "required" : ["title"], "optional" : ["description", "details:", "owner:", "tolerance"], "interpreter" : "AggregatorInterpreter", - "icon" : "" // TODO look for an icon + "icon" : "", // TODO look for an icon + "de_name" : "Gruppe" }, { "name" : "user", "required" : ["title"], "optional" : ["description", "details:", "owner:", "tolerance"], "interpreter" : "AggregatorInterpreter", - "icon" : "" // TODO look for an icon + "icon" : "", // TODO look for an icon + "de_name" : "Nutzer" }, { "name" : "power", @@ -46,7 +48,8 @@ "optional" : ["description", "details:", "owner:", "address:", "tolerance"], "interpreter" : "MeterInterpreter", "unit" : "kW/h", - "icon" : "" // TODO look for an icon + "icon" : "", // TODO look for an icon + "de_name" : "Strom" }, { "name" : "gas", @@ -54,7 +57,8 @@ "optional" : ["description", "details:", "owner:", "address:", "tolerance"], "interpreter" : "MeterInterpreter", "unit" : "m³/h", - "icon" : "" // TODO look for an icon + "icon" : "", // TODO look for an icon + "de_name" : "Gas" }, { "name" : "water", @@ -62,7 +66,8 @@ "optional" : ["description", "details:", "owner:", "address:", "tolerance"], "interpreter" : "MeterInterpreter", "unit" : "m³/h", - "icon" : "" // TODO look for an icon + "icon" : "", // TODO look for an icon + "de_name" : "Wasser" }, { "name" : "temperature", @@ -70,7 +75,8 @@ "optional" : ["description", "details:", "owner:", "address:", "tolerance"], "interpreter" : "SensorInterpreter", "unit" : "°C", - "icon" : "" // TODO look for an icon + "icon" : "", // TODO look for an icon + "de_name" : "Temperatur" }, { "name" : "pressure", @@ -78,7 +84,8 @@ "optional" : ["description", "details:", "owner:", "address:", "tolerance"], "interpreter" : "SensorInterpreter", "unit" : "hPa", - "icon" : "" // TODO look for an icon + "icon" : "", // TODO look for an icon + "de_name" : "Luftdruck" }, { "name" : "humidity", @@ -86,7 +93,8 @@ "optional" : ["description", "details:", "owner:", "address:", "tolerance"], "interpreter" : "SensorInterpreter", "unit" : "%", - "icon" : "" // TODO look for an icon + "icon" : "", // TODO look for an icon + "de_name" : "Luftfeuchtigkeit" }, { "name" : "windspeed", @@ -94,20 +102,23 @@ "optional" : ["description", "details:", "owner:", "address:", "tolerance"], "interpreter" : "SensorInterpreter", "unit" : "km/h", - "icon" : "" // TODO look for an icon + "icon" : "", // TODO look for an icon + "de_name" : "Windgeschwindigkeit" }, { "name" : "radition", "required" : ["title"], "optional" : ["description", "details:", "owner:", "address:", "tolerance"], "interpreter" : "SensorInterpreter", - "icon" : "" // TODO look for an icon + "icon" : "", // TODO look for an icon + "de_name" : "Strahlung" }, { "name" : "luminosity", "required" : ["title"], "optional" : ["description", "details:", "owner:", "address:", "tolerance"], "interpreter" : "SensorInterpreter", - "icon" : "" // TODO look for an icon + "icon" : "", // TODO look for an icon + "de_name" : "Lichtstärke" } ] diff --git a/backend/lib/Definition/PropertyDefinition.json b/backend/lib/Definition/PropertyDefinition.json index 51e9fb2..bd5fc4e 100644 --- a/backend/lib/Definition/PropertyDefinition.json +++ b/backend/lib/Definition/PropertyDefinition.json @@ -31,54 +31,64 @@ "type" : "string", "pattern" : "/[a-z0-9 ]/", "min": 3, - "max" : 255 + "max" : 255, + "de_name" : "Titel" }, { "name" : "description", - "type" : "string", + "type" : "text", "pattern" : "/[a-z0-9 ]/", // TODO add whitespaces as \t \n \r - "max" : 255 // TODO allowed column size in database? + "max" : 255, // TODO allowed column size in database? + "de_name" : "Beschreibung" }, { "name" : "cost", "type" : "float", - "min" : 0 + "min" : 0, + "de_name" : "Kosten" }, { "name" : "resolution", "type" : "integer", - "min" : 1 + "min" : 1, + "de_name" : "Auflösung" }, { "name" : "tolerance", "type" : "float", "min" : 0, - "max" : 1 + "max" : 1, + "de_name" : "Toleranz" }, { "name" : "address:lat", "type" : "float", "min" : -90, - "max" : 90 + "max" : 90, + "de_name" : "Latitude" }, { "name" : "address:lon", "type" : "float", "min" : -90, - "max" : 90 + "max" : 90, + "de_name" : "Longitude" }, { "name" : "address:city", "type" : "string", - "pattern" : "" // TODO add pattern + "pattern" : "", // TODO add pattern + "de_name" : "Stadt" }, { "name" : "address:houseno", - "type" : "string" + "type" : "string", + "de_name" : "Hausnummer" }, { "name" : "address:postal", - "type" : "string" + "type" : "string", + "de_name" : "Postleitzahl" }, { "name" : "address:state", @@ -273,29 +283,35 @@ "Wallis and Futuna Islands", "Yemen", "Zambia" - ] + ], + "de_name" : "Land" }, { "name" : "address:country", - "type" : "string" + "type" : "string", + "de_name" : "Staat" }, { "name" : "photo:url", "type" : "string", - "pattern" : "" // TODO add pattern + "pattern" : "", // TODO add pattern + "de_name" : "Foto (URL)" }, { "name" : "cuuid", "type" : "string", - "max" : 37 + "max" : 37, + "de_name" : "Cotroller UUID" }, { "name" : "port", "type" : "string", - "max" : 6 + "max" : 6, + "de_name" : "Controller Pin" }, { "name" : "active", - "type" : "boolean" + "type" : "boolean", + "de_name" : "Aktiv?" } ] diff --git a/backend/lib/Definition/PropertyDefinition.php b/backend/lib/Definition/PropertyDefinition.php index 427f5b4..a9ffd60 100644 --- a/backend/lib/Definition/PropertyDefinition.php +++ b/backend/lib/Definition/PropertyDefinition.php @@ -36,7 +36,7 @@ class PropertyDefinition extends Definition { const FILE = '/lib/Definition/PropertyDefinition.json'; /** - * One of: string, integer, float, boolean, multiple + * One of: string, integer, float, boolean, multiple, text * * @var string */ @@ -84,6 +84,7 @@ class PropertyDefinition extends Definition { public function validateValue($value) { switch ($this->type) { case 'string': + case 'text': $invalid = !is_string($value); $invalid |= isset($this->pattern) && !preg_match($this->pattern, $value); $invalid |= isset($this->min) && strlen($value) < $this->min; diff --git a/controller/README b/controller/README new file mode 100644 index 0000000..3e13b28 --- /dev/null +++ b/controller/README @@ -0,0 +1 @@ +Dieses Verzeichnis enthällt den Sourcecode für die Messcontroller und deren Webfrontend. \ No newline at end of file diff --git a/controller/index.html b/controller/index.html new file mode 100644 index 0000000..2cc8346 --- /dev/null +++ b/controller/index.html @@ -0,0 +1,42 @@ + + + + +volkszaehler.org - controller setup + + + + +

volkszaehler.org - controller setup

+

Hier können Sie ihren Stromzähler einrichten.

+ +

Kanäle

+

Derzeit sind folgende Zähler/Sensoren konfiguriert:

+ + +
#UUIDTypPortValue
+ +

Kanal hinzufügen

+

Hier können sie einen neuen Kanal hinzufügen:

+ +
Allgemeine Eigenschaften + + + + + +
+
+ +
Spezifische Eigenschaften + +
+
+ + +
+
Debug
+
+ + \ No newline at end of file diff --git a/controller/php/channel.php b/controller/php/channel.php new file mode 100644 index 0000000..733740b --- /dev/null +++ b/controller/php/channel.php @@ -0,0 +1,51 @@ + 'add', + 'DELETE' => 'delete', + 'GET' => 'get' +); + +$operation = (isset($_GET['operation'])) ? $_GET['operation'] : $methodMapping[$_SERVER['REQUEST_METHOD']]; + +// read channels +$fd = fopen($filename, 'r') or die('cant open file'); +while (($data = fgetcsv($fd, 100, ';')) !== FALSE) { + $channels[] = array( + 'uuid' => $data[0], + 'type' => $data[1], + 'port' => $data[2], + 'last_value' => $data[3], + 'last_timestamp' => $data[4] + ); +} +fclose($fd); + +if ($operation == 'add') { + $channels[] = array( + 'uuid' => $_GET['uuid'], + 'type' => $_GET['type'], + 'port' => $_GET['port'] + ); +} +elseif ($operation == 'delete') { + $channels = array_filter($channels, function($channel) { + return $channel['uuid'] != $_GET['uuid']; + }); +} + +if (in_array($operation, array('delete', 'add'))) { + $fd = fopen($filename, 'w') or die('cant open file'); + foreach ($channels as $channel) { + fputcsv($fd, $channel, ';'); + } + fclose($fd); +} + +// return all channels as JSON +echo json_encode($channels); + +?> \ No newline at end of file diff --git a/controller/php/channels.csv b/controller/php/channels.csv new file mode 100644 index 0000000..bb2252e --- /dev/null +++ b/controller/php/channels.csv @@ -0,0 +1,2 @@ +1234;power;PD0;; +12345;power;PD0 diff --git a/controller/script.js b/controller/script.js new file mode 100644 index 0000000..c543252 --- /dev/null +++ b/controller/script.js @@ -0,0 +1,105 @@ +var backend = '../backend'; +var controller = 'php/channel.php'; + +var entities; +var properties; +var channels; + +$(document).ready(function() { + // get entities from backend + $.getJSON(backend + '/capabilities/definition/entity.json', function(data) { + entities = data.definition.entity; + for (var i in entities) { + $('select, [name=type]').append(''); + } + }); + + // get properties from backend + $.getJSON(backend + '/capabilities/definition/property.json', function(data) { + properties = data.definition.property; + }); + + // get channels from controller + $.getJSON(controller, showChannels); + + $('select').change(function(event) { showEntityForm(event.target.value); }); +}); + + +function showEntityForm(type) { + $('#properties').empty(); + var type = getDefinition(entities, type); + + for (var i in type.optional) { + var property = getDefinition(properties, type.optional[i]); + + if (property) { + var input = getPropertyForm(property); + $('#properties').append('' + input + '') + } + } +} + +function deleteChannel(uuid) { + $.get(controller, {operation: 'delete', uuid: uuid}, function(data) { + + }) +} + +function addChannel() { + +} + +function addChannelBackend(channel, backendUrl) { + +} + +function addChannelController(uuid) { + +} + +function getDefinition(definition, type) { + for (var i in definition) { + if (definition[i].name == type) { + return definition[i]; + } + } +} + +function getPropertyForm(property) { + var input; + + switch (property.type) { + case 'string': + case 'float': + case 'integer': + input = ''; + break; + + case 'text': + input = ''; + break; + + case 'boolean': + input = ''; + + case 'multiple': + for (var k in property.options) { + options.push('