POST http://localhost:1234/v1/device
- Accept: application/json
- Content-Type: application/json
{ //
"hwaddr": [2,2,2,4,5,6],
"capabilities": {
"produces": [
"temperature",
"humidity"
],
"consumes": [
"date",
"time",
"value1",
"value2"
]
}
}
PUT http://localhost:1234/v1/device
- Accept: application/json
- Content-Type: application/json
{
"hwaddr": [2,2,2,4,5,6],
"resources": [
{
"what": "temperature",
"value": { "real": 22.0 }
},
{
"what": "humidity",
"value": { "real": 41.0 }
}
]
}
GET http://localhost:1234/v1/device
- Accept: application/json
- Content-Type: application/json
[2,2,2,4,5,6]
drop table if exists devices;
create table devices (
id varchar(32) not null primary key,
label varchar(32));
drop table if exists provisions;
create table provisions (
deviceID varchar(32) not null references devices(id),
what varchar(32) not null,
val numeric,
primary key (deviceID, what)
);
drop table if exists consumptions;
create table consumptions (
consumingDeviceID varchar(32) not null references devices(id),
what varchar(32) not null,
producingDeviceID varchar(32) references devices(id),
produces varchar(32),
primary key (consumingDeviceID, what),
foreign key (producingDeviceID, produces) references provisions(deviceID, what)
);
SELECT provisions.what as what, provisions.val as val
FROM consumptions
JOIN provisions
ON consumptions.producingDeviceID = provisions.deviceID
AND consumptions.produces = provisions.what
AND consumptions.consumingDeviceID = ?
AND provisions.val IS NOT NULL;
select * from devices join provisions where devices.id = provisions.deviceID;
select * from devices join consumptions where devices.id = consumingDeviceID;
select * from devices join provisions where devices.id = deviceID;
insert into devices (id, label) values ('c:0:f:f:e:e', 'fake');
insert into provisions (deviceID, what, val) values ('c:0:f:f:e:e', 'level', 100.0);
update consumptions set producingDeviceID = 'c:0:f:f:e:e', produces = 'level' where consumingDeviceID = '2:2:2:4:5:6' and what = 'value1'
SELECT consumptions.what, provisions.val
FROM consumptions
JOIN provisions
ON consumptions.producingDeviceID = provisions.deviceID
AND consumptions.produces = provisions.what
AND consumptions.consumingDeviceID = '2:2:2:4:5:6'
AND provisions.val IS NOT NULL;
insert into devices (id, label)
update consumptions set producingDeviceID = 'c:0:f:f:e:e', produces = 'level' where consumingDeviceID = '216:58:221:34:102:18' and what = 'top';
update consumptions set producingDeviceID = '2:2:2:4:5:6', produces = 'humidity' where consumingDeviceID = '216:58:221:34:102:18' and what = 'middle';
update consumptions set producingDeviceID = '2:2:2:4:5:6', produces = 'temperature' where consumingDeviceID = '216:58:221:34:102:18' and what = 'bottom';
<select>
<optgroup label="TestGroup">
<option value="test">Test</option>
<option value="test1">Test1</option>
<option value="test2">Test2</option>
</optgroup>
<optgroup label="bestGroup">
<option value="best">Best</option>
<option value="best1">Best1</option>
<option value="best2">Best2</option>
</optgroup>
<!-- optgroup for each device -->
<!-- option for each device's produced item -->
</select>