Add possibility to specify interval mesure.
This commit is contained in:
parent
466b7060d8
commit
b8f1add31f
|
|
@ -2,6 +2,7 @@ package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
|
|
||||||
|
|
@ -14,15 +15,17 @@ type AddTempController struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *AddTempController) Get() {
|
func (c *AddTempController) Get() {
|
||||||
sens := c.Ctx.Input.Param(":sensor")
|
mac := c.Ctx.Input.Param(":sensor")
|
||||||
val, _ := strconv.Atoi(c.Ctx.Input.Param(":val"))
|
val, _ := strconv.Atoi(c.Ctx.Input.Param(":val"))
|
||||||
|
|
||||||
s := sensor.GetSensorByMac(sens)
|
fmt.Println("MAC: ", mac)
|
||||||
|
|
||||||
|
s := sensor.GetSensorByMac(mac)
|
||||||
if s == nil {
|
if s == nil {
|
||||||
sensor.AddSensor(sens)
|
sensor.AddSensor(mac)
|
||||||
s = sensor.GetSensorByMac(sens)
|
s = sensor.GetSensorByMac(mac)
|
||||||
}
|
}
|
||||||
|
|
||||||
temperature.AddData(s.Id, int64(val))
|
temperature.AddData(s.Id, int64(val))
|
||||||
c.Ctx.Output.Body([]byte("OK"))
|
c.Ctx.Output.Body([]byte(strconv.FormatInt(s.Interval, 10)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
|
|
||||||
"datahouse/models/sensor"
|
"datahouse/models/sensor"
|
||||||
|
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SensorsController struct {
|
type SensorsController struct {
|
||||||
|
|
@ -21,8 +23,13 @@ func (c *SensorsController) Get() {
|
||||||
func (c *SensorsController) Post() {
|
func (c *SensorsController) Post() {
|
||||||
description := c.Input().Get("description")
|
description := c.Input().Get("description")
|
||||||
mac := c.Input().Get("mac")
|
mac := c.Input().Get("mac")
|
||||||
|
intervalStr := c.Input().Get("interval")
|
||||||
|
interval, err := strconv.ParseInt(intervalStr, 10, 0)
|
||||||
|
|
||||||
sensor.UpdateSensor(mac, description)
|
if err == nil {
|
||||||
|
sensor.UpdateSensor(mac, description, interval)
|
||||||
c.Redirect("/sensors", 302)
|
c.Redirect("/sensors", 302)
|
||||||
|
} else {
|
||||||
|
c.Redirect("/404", 404)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,12 @@ import (
|
||||||
"datahouse/models/utils"
|
"datahouse/models/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type SensorTable struct {
|
type SensorTable struct {
|
||||||
Id int64
|
Id int64
|
||||||
SensorMAC string
|
SensorMAC string
|
||||||
Description string
|
Description string
|
||||||
|
Interval int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -31,6 +33,7 @@ func GetSensorByMac(sensorMac string) (*SensorTable) {
|
||||||
ret.Id = utils.GetInt(m, "Id")
|
ret.Id = utils.GetInt(m, "Id")
|
||||||
ret.SensorMAC = utils.GetString(m, "SensorMAC")
|
ret.SensorMAC = utils.GetString(m, "SensorMAC")
|
||||||
ret.Description = utils.GetString(m, "Description")
|
ret.Description = utils.GetString(m, "Description")
|
||||||
|
ret.Interval = utils.GetInt(m, "Interval")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -68,6 +71,7 @@ func GetAllSensor() ([]SensorTable) {
|
||||||
r.Id = utils.GetInt(m, "Id")
|
r.Id = utils.GetInt(m, "Id")
|
||||||
r.SensorMAC = utils.GetString(m, "SensorMAC")
|
r.SensorMAC = utils.GetString(m, "SensorMAC")
|
||||||
r.Description = utils.GetString(m, "Description")
|
r.Description = utils.GetString(m, "Description")
|
||||||
|
r.Interval = utils.GetInt(m, "Interval")
|
||||||
|
|
||||||
ret = append(ret, *r)
|
ret = append(ret, *r)
|
||||||
}
|
}
|
||||||
|
|
@ -88,19 +92,21 @@ func GetSensor(id int64) (*SensorTable) {
|
||||||
ret.Id = utils.GetInt(m, "Id")
|
ret.Id = utils.GetInt(m, "Id")
|
||||||
ret.SensorMAC = utils.GetString(m, "SensorMAC")
|
ret.SensorMAC = utils.GetString(m, "SensorMAC")
|
||||||
ret.Description = utils.GetString(m, "Description")
|
ret.Description = utils.GetString(m, "Description")
|
||||||
|
ret.Interval = utils.GetInt(m, "Interval")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func UpdateSensor(mac, description string) {
|
func UpdateSensor(mac, description string, interval int64) {
|
||||||
o := orm.NewOrm()
|
o := orm.NewOrm()
|
||||||
o.Using(database.Alias)
|
o.Using(database.Alias)
|
||||||
|
|
||||||
s := GetSensorByMac(mac)
|
s := GetSensorByMac(mac)
|
||||||
if o.Read(s) == nil {
|
if o.Read(s) == nil {
|
||||||
s.Description = description
|
s.Description = description
|
||||||
|
s.Interval = interval
|
||||||
o.Update(s)
|
o.Update(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
<br/>
|
||||||
<footer class="footer">
|
<footer class="footer">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<p class="text-muted">Place sticky footer content here.</p>
|
<p class="text-muted">Place sticky footer content here.</p>
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,22 @@
|
||||||
<div class="panel panel-info">
|
<div class="panel panel-info">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<h3 class="panel-title">{{$val.SensorMAC}}</h3>
|
<h3 class="panel-title">{{$val.SensorMAC}}</h3>
|
||||||
|
<input type="hidden" name="mac" value="{{$val.SensorMAC}}"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Nom du capteur : </label>
|
<label>Interval de prise de mesure : </label>
|
||||||
<input type="hidden" name="mac" value="{{$val.SensorMAC}}"/>
|
<input type="number" class="form-control" name="interval" value="{{$val.Interval}}"/>
|
||||||
<input type="text" class="form-control" name="description" value="{{$val.Description}}"/>
|
<label>secondes</label>
|
||||||
<input class="btn btn-default btn btn-info" type="submit" value="Enregistrer"/>
|
|
||||||
</div>
|
</div>
|
||||||
|
<br/><br/>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Nom du capteur : </label>
|
||||||
|
<input type="text" class="form-control" name="description" value="{{$val.Description}}"/>
|
||||||
|
</div>
|
||||||
|
<br/><br/>
|
||||||
|
<input class="btn btn-default btn btn-success" type="submit" value="Enregistrer"/>
|
||||||
|
<!-- <input class="btn btn-default btn btn-danger" type="submit" value="Supprimer"/> -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue