Skip to content
Snippets Groups Projects
Commit 13f6bbff authored by jkerdreu's avatar jkerdreu
Browse files

Init cbor migration



git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2274 b32b6428-25c9-4566-ad07-03861ab6144f
parent d80db463
No related branches found
No related tags found
No related merge requests found
Showing
with 305 additions and 83 deletions
......@@ -8,7 +8,7 @@ from gevent.pywsgi import WSGIServer
from geventwebsocket.handler import WebSocketHandler
from .pages import default_pages
from .pages import default_pages,warp10
from .core import xaal_core
from .core import sio
......@@ -32,6 +32,7 @@ def run():
TEMPLATE_PATH.append(root)
xaal_core.setup()
warp10.setup()
# debug disable template cache & enable error reporting
debug(True)
bottle_app = default_app()
......
......@@ -33,8 +33,8 @@ def event_handler(ev_type,dev):
def setup():
""" setup xAAL Engine & Device. And start it in a Greenlet"""
helpers.setup_console_logger()
global monitor
helpers.setup_console_logger()
engine = Engine()
cfg = tools.load_cfg(PACKAGE_NAME)
if not cfg:
......
......@@ -85,8 +85,6 @@ def save_metadata(addr):
@route('/grid')
@view('grid.mako')
def test_grid():
......@@ -102,3 +100,4 @@ def socketio_latency_test():
@view('links.mako')
def links():
return {'title':'Links'}
from xaal.lib import tools
from .default import view,route
from .default import xaal_core as xaal
from bottle import get,response
import logging
import ujson
import requests
TOKEN=None
URL=None
CLASS = None
DAILY_REQ = """ [ $TOKEN '%s' { 'devid' '%s' } NOW 49 h ] FETCH """
bindings = {'thermometer.basic' : 'temperature',
'barometer.basic' : 'pressure',
'hygrometer.basic' : 'humidity',
'powermeter.basic' : 'power',
'co2meter.basic' : 'co2',
}
logger = logging.getLogger(__name__)
def setup():
global TOKEN,URL,CLASS
cfg = tools.load_cfg(xaal.PACKAGE_NAME).get('config',None)
if cfg:
TOKEN = cfg.get('warp10_token',None)
URL = cfg.get('warp10_url',None)
CLASS = cfg.get('warp10_class',None)
logger.warning("%s %s" % (URL,CLASS))
def init_req():
return """'%s' 'TOKEN' STORE\n""" % (TOKEN)
def query(req):
r = requests.post(URL,req)
print(r)
return r.text
def to_chartjs(data):
r = []
for tuple_ in data:
date = round(tuple_[0] / 1000)
value = tuple_[1]
#r.append({"x": date, "y":value })
r.append((date,value))
return r
@get('/warp10/daily/<addr>')
def daily(addr):
global CLASS
response.headers['Content-Type'] = 'application/json'
res = {}
dev=xaal.monitor.devices.get_with_addr(addr)
if dev:
req = init_req()
devtype = dev.devtype
var = bindings.get(devtype,None)
if not var:
return '{}'
class_ = '%s.%s.%s' % (CLASS,devtype,var)
tmp = DAILY_REQ % (class_,addr)
req = init_req() + tmp
data=query(req)
res = ujson.loads(data)[0][0]['v']
return ujson.dumps(to_chartjs(res))
@route('/warp10/graph/<addr>')
@view('graph.mako')
def graph(addr):
r = {"title" : "Warp10 daily","addr":addr}
return r
.onoffswitch {
position: relative; width: 60px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 1px solid #999999; border-radius: 20px;
}
.onoffswitch-inner {
display: block; width: 200%; margin-left: -100%;
transition: margin 0.1s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
display: block; float: left; width: 50%; height: 20px; padding: 0; line-height: 20px;
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "";
padding-left: 10px;
background-color: #ED054E; color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "";
padding-right: 10px;
background-color: #00bbd7; color: #DEDEDE;
text-align: right;
}
.onoffswitch-switch {
display: block; width: 16px; margin: 2px;
background: #FFFFFF;
position: absolute; top: 0; bottom: 0;
right: 36px;
border: 1px solid #999999; border-radius: 20px;
transition: all 0.1s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}
......@@ -152,8 +152,8 @@ ul.menu li a:hover {
}
.grid-background {
/*background-image: url("https://wallpaperscraft.com/image/spruce_shadow_dark_background_branch_68089_1920x1200.jpg");*/
background-image: url("/static/imgs/bg1.jpg");
/* background-image: url("https://wallpaperscraft.com/image/spruce_shadow_dark_background_branch_68089_1920x1200.jpg"); */
background-image: url("/static/imgs/bg3.jpg");
min-height: 900px;
padding: 0.5em;
}
......@@ -164,7 +164,7 @@ ul.menu li a:hover {
border-radius: 3px;
padding: 8px;
font-size: 120%;
height: 200px;
height: 250px;
border: 1px solid var(--color2);
/* display: flex; */
......
apps/dashboard/xaal/dashboard/static/imgs/bg3.jpg

162 KiB

apps/dashboard/xaal/dashboard/static/imgs/bg5.jpg

162 KiB

......@@ -113,7 +113,8 @@ function run_sio() {
});
}
//================ refresh attributes =======================================
// the old refresh_attributes blocks the page rendering process.
function sio_refresh_attributes_old() {
console.log('refresh_attributes');
var addrs = [];
......
......@@ -3,10 +3,10 @@
"name": "xAAL SocketIO DashBoard",
"background_color": "#fff",
"display": "standalone",
"start_url": "/",
"start_url": "../",
"icons": [
{
"src": "/static/imgs/launcher-icon-4x.png",
"src": "./imgs/launcher-icon-4x.png",
"type": "image/png",
"sizes": "192x192"
}
......
<barometer>
<span class="barometer">
<span class="pressure">{ pressure }&nbsp;hPa</span><br/>
</span>
<script>
this.addr = opts.xaal_addr;
this.pressure = null;
receive(data) {
this.pressure = Math.round(data['attributes']['pressure']);
this.update();
}
</script>
<style>
.barometer {
font-weight: bold;
color : var(--color1);
align: center;
}
</style>
</barometer>
<co2meter>
<span class="co2meter">
<span if={value} class="co2">{ value }&nbsp;ppm</span>
</span>
<script>
this.addr = opts.xaal_addr;
this.value = '';
receive(data) {
this.value = data['attributes']['co2'];
this.update();
}
</script>
<style>
.co2 {
font-weight: bold;
color : var(--color1);
align: center;
}
</style>
</co2meter>
<door>
<span class="door">
<span class="{class}">⚛</span>
</span>
<script>
this.addr = opts.xaal_addr;
this.class = 'close';
receive(data) {
state = data['attributes']['position'];
if (state == true) {
this.class = 'open'
}
else {
this.class = 'close'
}
this.update();
}
</script>
<style>
.open {
font-weight: bold;
color : var(--color3);
align: center;
}
.close {
font-weight: bold;
color : var(--color2);
align: center;
}
</style>
</door>
<hygrometer>
<span class="hygrometer">
<span class="humidity">{ humidity }&nbsp;%</span>
<span if={value} class="humidity">{ value }&nbsp;%</span>
</span>
<script>
this.addr = opts.xaal_addr;
this.humidity = '__';
this.value = null;
receive(data) {
this.humidity = data['attributes']['humidity'];
this.value = data['attributes']['humidity'];
this.update();
}
</script>
......
<lamp>
<div class="lamp">
<div class="{stateClass}">{ light }</div>
<button class="button ripple" name="btn_on" onclick={ btn }>ON</button>
<button class="button ripple" name="btn_off" onclick={ btn }>OFF</button>
<div class="onoffswitch">
<input type="checkbox" class="onoffswitch-checkbox" id={ tag_id } onchange={ chk } checked={checked}>
<label class="onoffswitch-label" for={ tag_id }>
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
<script>
this.addr = opts.xaal_addr
this.light = '__';
this.stateClass = 'state-unknow';
this.tag_id = 'btn_'+Math.random();
receive(data) {
state = data['attributes']['light']
state = data['attributes']['light']
if (state == true) {
this.light = 'ON'
this.stateClass = 'state-on'
this.checked = true
}
else {
this.light = 'OFF'
this.stateClass = 'state-off'
this.checked = false
}
this.update()
}
}
btn(e) {
if (e.target.name =='btn_on')
chk(e) {
if (e.target.checked == true)
sio_send_request(this.addr,'on',{})
if (e.target.name =='btn_off')
else
sio_send_request(this.addr,'off',{})
}
</script>
<style>
.state-on {
color: var(--color3);
font-weight: bold;
padding: 8px;
}
.state-unknow, .state-off {
color: var(--color1);
font-weight: bold;
padding: 8px;
}
</style>
</lamp>
<motion>
<span class="motion">
<span class="{class}">⚛</span>
</span>
<script>
this.addr = opts.xaal_addr;
this.presence = false;
this.class = 'no_motion';
receive(data) {
state = data['attributes']['presence'];
if (state == true) {
this.presence = true
this.class = 'motion'
}
else {
this.presence = false
this.class = 'no_motion'
}
this.update();
}
</script>
<style>
.motion {
font-weight: bold;
color : var(--color3);
align: center;
}
.no_motion {
font-weight: bold;
color : var(--color2);
align: center;
}
</style>
</motion>
<powermeter>
<span class="powermeter">
<span if={power} class="power">{ power }&nbsp;W</span><br/>
<span class="power">{ power }&nbsp;W</span><br/>
<span if={energy} class="energy">{ energy }&nbsp;kW</span>
</span>
......
<powerrelay>
<div class="powerrelay">
<div class="{stateClass}">{ power }</div>
<button class="button ripple" name="btn_on" onclick={ btn }>ON</button>
<button class="button ripple" name="btn_off" onclick={ btn }>OFF</button>
<div class="onoffswitch">
<input type="checkbox" class="onoffswitch-checkbox" id={ tag_id } onchange={ chk } checked={checked}>
<label class="onoffswitch-label" for={ tag_id }>
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
<script>
this.addr = opts.xaal_addr
this.power = '__';
this.stateClass = 'state-unknow';
this.tag_id = 'btn_'+Math.random();
receive(data) {
state = data['attributes']['power']
if (state == true) {
this.power = 'ON'
this.stateClass = 'state-on'
this.checked = true
}
else {
this.power = 'OFF'
this.stateClass = 'state-off'
this.checked = false
}
this.update()
}
btn(e) {
if (e.target.name =='btn_on')
chk(e) {
if (e.target.checked == true)
sio_send_request(this.addr,'on',{})
if (e.target.name =='btn_off')
else
sio_send_request(this.addr,'off',{})
}
</script>
<style>
.powerrelay {
}
.state-on {
color: var(--color3);
font-weight: bold;
padding: 8px;
}
.state-unknow, .state-off {
color: var(--color1);
font-weight: bold;
padding: 8px;
}
</style>
</powerrelay>
<thermometer>
<span class="thermometer">
<span class="temperature">{ temperature }&nbsp;°</span>
<span if={value} class="temperature">{ value }&nbsp;°</span>
</span>
<script>
this.addr = opts.xaal_addr
this.temperature = '__._';
this.value = null
receive(data) {
this.temperature = data['attributes']['temperature']
this.value = data['attributes']['temperature']
this.update()
}
</script>
......
......@@ -11,6 +11,7 @@
<meta name="mobile-web-app-capable" content="yes">
<link rel="manifest" href="/static/manifest.json">
<link rel="icon" href="/static/imgs/favicon.ico">
<meta name="theme-color" content="#333" />
<!-- CSS & Fonts -->
<link href="/static/css/site.css" rel="stylesheet">
......@@ -21,16 +22,7 @@
<!-- Menu -->
<div>
<ul class="menu">
<li><a href="#" onclick="openNav()">&#9776;</a></li>
<li><a href="/devices">Devices</a></li>
<li class="active"><a href="/grid">Grid</a></li>
<!--
<li><a href="/bottle_info">HTTPD</a></li>
<li><a href="/links">Links</a></li>
<li><a href="/stats">Stats</a></li>
-->
</ul>
<%include file="./menu.mako" />
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment