allow min/max alerting for weight
This commit is contained in:
parent
f8a59825e6
commit
9e494e077f
|
|
@ -19,6 +19,7 @@ type OneMetric struct {
|
|||
Readonly bool
|
||||
Alarmactive string
|
||||
Smsnumber string
|
||||
Minmax string
|
||||
Timestamp string
|
||||
Temperature string
|
||||
Humidity string
|
||||
|
|
@ -370,6 +371,7 @@ func getLastMetrics(deveui string) OneMetric {
|
|||
res.Readonly = false
|
||||
res.Alarmactive = getDevAlarmactive(deveui)
|
||||
res.Smsnumber = getDevSmsnumber(deveui)
|
||||
res.Minmax = getDevMinmax(deveui)
|
||||
res.ActiveUntil = getActiveUntil(deveui)
|
||||
res.DaysUntilDeactivated = CalcDaysUntil(res.ActiveUntil)
|
||||
return res
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ type Dev struct {
|
|||
Alias string
|
||||
Alarmactive string
|
||||
Smsnumber string
|
||||
Minmax string
|
||||
ActiveUntil string // Abo bezahlt bis TT.MM.YYYY
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +106,7 @@ func updateScaleSettings(scaleSettings Dev) error {
|
|||
defer conn.Close()
|
||||
|
||||
// SET object
|
||||
_, err := conn.Do("HMSET", devPrefix+scaleSettings.Deveui, "alias", scaleSettings.Alias, "alarmactive", scaleSettings.Alarmactive, "smsnumber", scaleSettings.Smsnumber)
|
||||
_, err := conn.Do("HMSET", devPrefix+scaleSettings.Deveui, "alias", scaleSettings.Alias, "alarmactive", scaleSettings.Alarmactive, "smsnumber", scaleSettings.Smsnumber, "minmax", scaleSettings.Minmax)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -217,6 +218,28 @@ func getDevSmsnumber(deveui string) string {
|
|||
return res
|
||||
}
|
||||
|
||||
func getDevMinmax(deveui string) string {
|
||||
res := "0,0"
|
||||
|
||||
if deveui == "" {
|
||||
return res
|
||||
}
|
||||
|
||||
conn := globalPool.Get()
|
||||
defer conn.Close()
|
||||
|
||||
logit("getDevMinMax: Deveui: " + deveui)
|
||||
minmax, err := redis.String(conn.Do("HGET", devPrefix+deveui, "minmax"))
|
||||
if err == nil {
|
||||
logit("getDevAlarmactive: minmax: " + minmax)
|
||||
res = minmax
|
||||
} else {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func getActiveUntil(deveui string) string {
|
||||
res := ""
|
||||
|
||||
|
|
|
|||
21
scales.go
21
scales.go
|
|
@ -86,24 +86,41 @@ func save_scale_settingsHandler(response http.ResponseWriter, request *http.Requ
|
|||
return
|
||||
}
|
||||
|
||||
minmax, ok5 := request.URL.Query()["minmax"]
|
||||
|
||||
if !ok5 || len(minmax[0]) < 1 {
|
||||
log.Println("Url Param 'minmax' is missing")
|
||||
fmt.Fprintf(response, "{ \"rc\": 6, \"msg\": \"minmax must be specified in URL\" }")
|
||||
return
|
||||
}
|
||||
myminmax := minmax[0]
|
||||
|
||||
match2, _ := regexp.MatchString(`^[0-9]{1,6},[0-9]{1,6}$`, myminmax)
|
||||
if !(match2) {
|
||||
log.Println("Url Param 'minmax' is not valid")
|
||||
fmt.Fprintf(response, "{ \"rc\": 12, \"msg\": \"minmax is not valid, must be in in format 50000,80000\" }")
|
||||
return
|
||||
}
|
||||
|
||||
var mydev Dev
|
||||
mydev.Deveui = mydeveui
|
||||
mydev.Alias = myalias
|
||||
mydev.Alarmactive = myalarmactive
|
||||
mydev.Smsnumber = mysmsnumber
|
||||
mydev.Minmax = myminmax
|
||||
|
||||
// now we try to save the settings
|
||||
err := updateScaleSettings(mydev)
|
||||
|
||||
if err != nil {
|
||||
log.Println("Error to Update Device Settings")
|
||||
fmt.Fprintf(response, "{ \"rc\": 6, \"msg\": \"error with saving device settings\" }")
|
||||
fmt.Fprintf(response, "{ \"rc\": 7, \"msg\": \"error with saving device settings\" }")
|
||||
return
|
||||
} else {
|
||||
fmt.Fprintf(response, "{ \"rc\": 0, \"msg\": \"SUCCESS\" }")
|
||||
}
|
||||
|
||||
} else {
|
||||
fmt.Fprintf(response, "{ \"rc\": 7, \"msg\": \"Only available for logged in users\" }")
|
||||
fmt.Fprintf(response, "{ \"rc\": 8, \"msg\": \"Only available for logged in users\" }")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,16 @@
|
|||
<p id="smsnumber_errormsg" class="help is-danger"></p>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label">Minimum, Maximum (in Gramm)</label>
|
||||
<div class="control has-icons-right">
|
||||
<input id="minmax" class="input" type="text" maxlength="16"> <span id="minmax_exclamation" class="icon is-small is-right">
|
||||
<i class="fas fa-exclamation-triangle"></i>
|
||||
</span>
|
||||
</div>
|
||||
<p id="minmax_errormsg" class="help is-danger"></p>
|
||||
</div>
|
||||
|
||||
<div class="is-size-7">
|
||||
Device ID: <span id="deveui"></span>
|
||||
</div>
|
||||
|
|
@ -103,12 +113,13 @@ Sie erhalten eine E-Mail, sobald die Zahlung erfolgreich abgeschlossen ist.
|
|||
<p class="is-size-2 is-size-5-mobile has-text-centered has-text-weight-bold" ><span class="alias" id="alias_{{.Deveui}}">{{.Alias}}</span>{{ if not .Readonly }}<a class="show-modal" class="block-link"><span style="float:right;" class="icon is-size-4 is-size-5-mobile"><i class="fa fa-cog"></i></span></a>{{ end }}</p>
|
||||
<p id="alarmactive_{{.Deveui}}" hidden>{{.Alarmactive}}</p>
|
||||
<p id="smsnumber_{{.Deveui}}" hidden>{{.Smsnumber}}</p>
|
||||
<p id="minmax_{{.Deveui}}" hidden>{{.Minmax}}</p>
|
||||
<p id="lastmeasurement_{{.Deveui}}" class="has-text-centered">letzte übermittelte Messung: {{.Timestamp}}</p>
|
||||
<div id="{{.Deveui}}">
|
||||
<div class="column is-full notification is-warning">
|
||||
<nav class="level">
|
||||
<div class="level-item has-text-centered">
|
||||
<a class="block-link" href="/graph.html?deveui={{.Deveui}}&alias={{.Alias}}&property=t">
|
||||
<a class="block-link" href="/graph.html?deveui={{.Deveui}}&alias={{.Alias}}&property=t&minmax={{.Minmax}}">
|
||||
<div>
|
||||
<p class="icon"><i class="fa fa-thermometer-half"></i></p>
|
||||
<p id="temp_{{.Deveui}}" class="title">{{.Temperature}} °C</p>
|
||||
|
|
@ -116,7 +127,7 @@ Sie erhalten eine E-Mail, sobald die Zahlung erfolgreich abgeschlossen ist.
|
|||
</a>
|
||||
</div>
|
||||
<div class="level-item has-text-centered">
|
||||
<a class="block-link" href="/graph.html?deveui={{.Deveui}}&alias={{.Alias}}&property=h">
|
||||
<a class="block-link" href="/graph.html?deveui={{.Deveui}}&alias={{.Alias}}&property=h&minmax={{.Minmax}}">
|
||||
<div>
|
||||
<p class="icon"><i class="fa fa-tint"></i></p>
|
||||
<p id="humidity_{{.Deveui}}" class="title">{{.Humidity}} %</p>
|
||||
|
|
@ -132,7 +143,7 @@ Sie erhalten eine E-Mail, sobald die Zahlung erfolgreich abgeschlossen ist.
|
|||
</div>
|
||||
{{ else }}
|
||||
<div class="level-item has-text-centered">
|
||||
<a class="block-link" href="/graph.html?deveui={{.Deveui}}&alias={{.Alias}}&property=w">
|
||||
<a class="block-link" href="/graph.html?deveui={{.Deveui}}&alias={{.Alias}}&property=w&minmax={{.Minmax}}">
|
||||
<div>
|
||||
<p class="icon"><i class="fa fa-balance-scale"></i></p>
|
||||
<p id="weight_{{.Deveui}}" class="title is-size-2 has-text-weight-bold">{{.Weight_kg}} kg</p>
|
||||
|
|
@ -141,7 +152,7 @@ Sie erhalten eine E-Mail, sobald die Zahlung erfolgreich abgeschlossen ist.
|
|||
</div>
|
||||
{{ end }}
|
||||
<div class="level-item has-text-centered">
|
||||
<a class="block-link" href="/graph.html?deveui={{.Deveui}}&alias={{.Alias}}&property=p">
|
||||
<a class="block-link" href="/graph.html?deveui={{.Deveui}}&alias={{.Alias}}&property=p&minmax={{.Minmax}}">
|
||||
<div>
|
||||
<p class="icon"><i class="fa fa-cloud"></i></p>
|
||||
<p id="pressure_{{.Deveui}}" class="title">{{.Pressure}} hP</p>
|
||||
|
|
@ -149,7 +160,7 @@ Sie erhalten eine E-Mail, sobald die Zahlung erfolgreich abgeschlossen ist.
|
|||
</a>
|
||||
</div>
|
||||
<div class="level-item has-text-centered">
|
||||
<a class="block-link" href="/graph.html?deveui={{.Deveui}}&alias={{.Alias}}&property=vp">
|
||||
<a class="block-link" href="/graph.html?deveui={{.Deveui}}&alias={{.Alias}}&property=vp&minmax={{.Minmax}}">
|
||||
<div>
|
||||
<p class="icon"><i class="fa fa-battery-three-quarters"></i></p>
|
||||
<p id="acculevel_{{.Deveui}}" class="title">{{.BatteryPercent}} %</p>
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
var chart;
|
||||
|
||||
function drawGraph(deveui, alias, property, start, stop, create_graph) {
|
||||
function drawGraph(deveui, alias, property, start, stop, minmax, create_graph) {
|
||||
range = ""
|
||||
range = range + "&start=" + start;
|
||||
range = range + "&stop=" + stop;
|
||||
|
||||
var label;
|
||||
var labels = {};
|
||||
var annotations = {};
|
||||
var forceNiceScale = true;
|
||||
$(".button").removeClass("is-success");
|
||||
if (property=="t") {
|
||||
|
|
@ -15,12 +16,22 @@ function drawGraph(deveui, alias, property, start, stop, create_graph) {
|
|||
mysubtitle = 'Temperatur in °C';
|
||||
minfunc = function(min) { if (min > 0) { return 0 } else { return min } }
|
||||
maxfunc = function(max) { return max + 5 }
|
||||
labels = {
|
||||
offsetX: 40,
|
||||
offsetY: -5,
|
||||
align: 'right'
|
||||
};
|
||||
} else if (property=="vp") {
|
||||
$("#btn_vp").addClass("is-success");
|
||||
label = 'Akkuladung';
|
||||
mysubtitle = 'Akkuladung in Prozent';
|
||||
minfunc = function(min) { return 0 }
|
||||
maxfunc = function(max) { return 100 }
|
||||
labels = {
|
||||
offsetX: 40,
|
||||
offsetY: -5,
|
||||
align: 'right'
|
||||
};
|
||||
forceNiceScale = false;
|
||||
} else if (property=="w") {
|
||||
$("#btn_w").addClass("is-success");
|
||||
|
|
@ -28,9 +39,19 @@ function drawGraph(deveui, alias, property, start, stop, create_graph) {
|
|||
mysubtitle = 'Gewicht in Kilogramm';
|
||||
minfunc = function(min) { if (min > 5000) { return min - 2000 } else { return 0 } }
|
||||
maxfunc = function(max) { return max + 2000 }
|
||||
annotations = { yaxis: [
|
||||
{
|
||||
y: minmax.split(",")[0],
|
||||
y2: minmax.split(",")[1],
|
||||
borderColor: '#000',
|
||||
fillColor: '#00FF00'
|
||||
}
|
||||
]
|
||||
};
|
||||
labels = {
|
||||
offsetX: 50,
|
||||
offsetY: -4,
|
||||
offsetX: 45,
|
||||
offsetY: -5,
|
||||
align: 'right',
|
||||
formatter: function(val, index) {
|
||||
return (val / 1000.0).toFixed(3);
|
||||
}
|
||||
|
|
@ -41,6 +62,11 @@ function drawGraph(deveui, alias, property, start, stop, create_graph) {
|
|||
mysubtitle = 'Luftfeuchtigkeit in Prozent';
|
||||
minfunc = function(min) { return 0 }
|
||||
maxfunc = function(max) { return 100 }
|
||||
labels = {
|
||||
offsetX: 40,
|
||||
offsetY: -5,
|
||||
align: 'right'
|
||||
};
|
||||
forceNiceScale = false;
|
||||
} else if (property=="p") {
|
||||
$("#btn_p").addClass("is-success");
|
||||
|
|
@ -48,6 +74,11 @@ function drawGraph(deveui, alias, property, start, stop, create_graph) {
|
|||
mysubtitle = 'Luftdruck in Hektopascal';
|
||||
minfunc = function(min) { return 900 }
|
||||
maxfunc = function(max) { return 1060 }
|
||||
labels = {
|
||||
offsetX: 40,
|
||||
offsetY: -5,
|
||||
align: 'right'
|
||||
};
|
||||
} else {
|
||||
label = 'Unknown';
|
||||
mysubtitle = 'Unknown';
|
||||
|
|
@ -113,6 +144,7 @@ function drawGraph(deveui, alias, property, start, stop, create_graph) {
|
|||
max: maxfunc,
|
||||
forceNiceScale: forceNiceScale,
|
||||
labels: labels,
|
||||
opposite: true,
|
||||
floating: true
|
||||
},
|
||||
tooltip: {
|
||||
|
|
@ -120,6 +152,7 @@ function drawGraph(deveui, alias, property, start, stop, create_graph) {
|
|||
format: 'dd.MM.yyyy HH:mm'
|
||||
}
|
||||
},
|
||||
annotations: annotations,
|
||||
series: [{
|
||||
name: label,
|
||||
data: mydata
|
||||
|
|
@ -145,6 +178,7 @@ var alias = urlParams.get('alias');
|
|||
var property = urlParams.get('property');
|
||||
var start = urlParams.get('start');
|
||||
var stop = urlParams.get('stop');
|
||||
var minmax = urlParams.get('minmax') || "0,0";
|
||||
|
||||
range="";
|
||||
if (start == null) {
|
||||
|
|
@ -161,4 +195,4 @@ if (stop == null) {
|
|||
|
||||
$('#reportrange span').html(moment(start).locale('de').format('D. MMM YYYY') + ' - ' + moment(stop).locale('de').format('D. MMM YYYY'));
|
||||
|
||||
drawGraph(deveui, alias, property, start, stop, true);
|
||||
drawGraph(deveui, alias, property, start, stop, minmax, true);
|
||||
|
|
|
|||
|
|
@ -24,32 +24,32 @@ $(function() {
|
|||
s_start = start.utc().format('YYYY-MM-DDTHH:mm:ss[Z]');
|
||||
s_end = end.utc().format('YYYY-MM-DDTHH:mm:ss[Z]');
|
||||
//console.log("Start: " + s_start + ' End: ' + s_end + ' Property: '+ property);
|
||||
drawGraph(deveui, alias, property, s_start,s_end, false);
|
||||
drawGraph(deveui, alias, property, s_start,s_end, minmax, false);
|
||||
}
|
||||
|
||||
$('#btn_w').on("click", function() {
|
||||
change_property('w');
|
||||
drawGraph(deveui, alias, property, s_start, s_end, false);
|
||||
drawGraph(deveui, alias, property, s_start, s_end, minmax, false);
|
||||
});
|
||||
|
||||
$('#btn_t').on("click", function() {
|
||||
change_property('t');
|
||||
drawGraph(deveui, alias, property, s_start, s_end, false);
|
||||
drawGraph(deveui, alias, property, s_start, s_end, minmax, false);
|
||||
});
|
||||
|
||||
$('#btn_h').on("click", function() {
|
||||
change_property('h');
|
||||
drawGraph(deveui, alias, property, s_start, s_end, false);
|
||||
drawGraph(deveui, alias, property, s_start, s_end, minmax, false);
|
||||
});
|
||||
|
||||
$('#btn_p').on("click", function() {
|
||||
change_property('p');
|
||||
drawGraph(deveui, alias, property, s_start, s_end, false);
|
||||
drawGraph(deveui, alias, property, s_start, s_end, minmax, false);
|
||||
});
|
||||
|
||||
$('#btn_vp').on("click", function() {
|
||||
change_property('vp');
|
||||
drawGraph(deveui, alias, property, s_start, s_end, false);
|
||||
drawGraph(deveui, alias, property, s_start, s_end, minmax, false);
|
||||
});
|
||||
|
||||
$('#reportrange').daterangepicker({
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ function validate(what, text) {
|
|||
var re = /^[a-zA-Z0-9 ]{1,25}$/;
|
||||
} else if (what == 'smsnumber') {
|
||||
var re = /^\+[0-9]{11,11}$/;
|
||||
} else if (what == 'minmax') {
|
||||
var re = /^[0-9]{1,6},[0-9]{1,6}$/;
|
||||
}
|
||||
return re.test(text);
|
||||
}
|
||||
|
|
@ -50,11 +52,13 @@ $( document ).ready(function() {
|
|||
$(".show-modal").click(function() {
|
||||
$("#alias_exclamation").hide();
|
||||
$("#smsnumber_exclamation").hide();
|
||||
$("#minmax_exclamation").hide();
|
||||
var alias = $(this).prev().html();
|
||||
var deveui = $(this).prev().attr('id').replace("alias_","");
|
||||
$('#deveui').html(deveui);
|
||||
var alarmactive = $('#alarmactive_'+deveui).html();
|
||||
var smsnumber = $('#smsnumber_'+deveui).html();
|
||||
var minmax = $('#minmax_'+deveui).html();
|
||||
|
||||
$("#alias").val(alias);
|
||||
console.log(alarmactive);
|
||||
|
|
@ -64,6 +68,7 @@ $( document ).ready(function() {
|
|||
$('#checkbox').prop('checked', false);
|
||||
}
|
||||
$("#smsnumber").val(smsnumber);
|
||||
$("#minmax").val(minmax);
|
||||
$("#modal").addClass("is-active");
|
||||
});
|
||||
|
||||
|
|
@ -183,6 +188,25 @@ $( document ).ready(function() {
|
|||
$("#smsnumber_exclamation").hide();
|
||||
}
|
||||
|
||||
if (!validate('minmax',$('#minmax').val())) {
|
||||
$('#minmax_errormsg').html('Minium,Maximum, Beispiel: 20000,10000');
|
||||
$("#minmax").addClass("is-danger");
|
||||
$("#minmax_exclamation").show();
|
||||
is_valid = false;
|
||||
} else {
|
||||
const minmaxArr = $('#minmax').val().split(",");
|
||||
if ((Number(minmaxArr[1]) > Number(minmaxArr[0])) || (minmaxArr[1] == '0')) {
|
||||
$('#minmax_errormsg').html('');
|
||||
$("#minmax").removeClass("is-danger");
|
||||
$("#minmax_exclamation").hide();
|
||||
} else {
|
||||
$('#minmax_errormsg').html('Maximum muss grösser als Minimum sein (oder 0)');
|
||||
$("#minmax").addClass("is-danger");
|
||||
$("#minmax_exclamation").show();
|
||||
is_valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(is_valid)) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -195,6 +219,7 @@ $( document ).ready(function() {
|
|||
deveui: $('#deveui').html(),
|
||||
alias: $('#alias').val(),
|
||||
smsnumber: $("#smsnumber").val(),
|
||||
minmax: $("#minmax").val(),
|
||||
alarmactive: alarmactive
|
||||
},
|
||||
success: function(response) {
|
||||
|
|
@ -207,6 +232,7 @@ $( document ).ready(function() {
|
|||
}
|
||||
$('#alarmactive_'+$('#deveui').html()).html(alarmactive);
|
||||
$('#smsnumber_'+$('#deveui').html()).html($('#smsnumber').val());
|
||||
$('#minmax_'+$('#deveui').html()).html($('#minmax').val());
|
||||
}
|
||||
},
|
||||
error: function(xhr) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue