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