Add color on toggle button to represente relay stats
This commit is contained in:
parent
e4437dc6e3
commit
a3ce8abd39
|
|
@ -27,7 +27,10 @@ func (c *AddTempController) Prepare() {
|
||||||
|
|
||||||
func (c *AddTempController) Get() {
|
func (c *AddTempController) Get() {
|
||||||
mac := c.Ctx.Input.Param(":sensor")
|
mac := c.Ctx.Input.Param(":sensor")
|
||||||
val, _ := strconv.Atoi(c.Ctx.Input.Param(":val"))
|
valStr := c.Ctx.Input.Param(":val")
|
||||||
|
val, _ := strconv.Atoi(valStr)
|
||||||
|
|
||||||
|
// log.Info("Add Temperature (%s) : %s", mac, valStr)
|
||||||
|
|
||||||
s := sensor.GetSensorByMac(mac)
|
s := sensor.GetSensorByMac(mac)
|
||||||
if s == nil || s.Id == 0 {
|
if s == nil || s.Id == 0 {
|
||||||
|
|
@ -60,7 +63,10 @@ func addToTempBdd(snsor *sensor.SensorTable, val int) {
|
||||||
func saveInBDD(snsor *sensor.SensorTable, val int) {
|
func saveInBDD(snsor *sensor.SensorTable, val int) {
|
||||||
nowUTC := time.Now()
|
nowUTC := time.Now()
|
||||||
lastTempRecord := temperature.GetLastTempForSensor(snsor.Id)
|
lastTempRecord := temperature.GetLastTempForSensor(snsor.Id)
|
||||||
|
// intervalTmp := nowUTC.Unix() - lastTempRecord.HorodateGMT.Unix()
|
||||||
intervalTmp := nowUTC.Unix() - lastTempRecord.HorodateGMT.Unix() - int64(timezoneOffset)
|
intervalTmp := nowUTC.Unix() - lastTempRecord.HorodateGMT.Unix() - int64(timezoneOffset)
|
||||||
|
log.Debug("Senor Interval: %d", snsor.Interval)
|
||||||
|
log.Debug("Current interval: %d", intervalTmp)
|
||||||
if intervalTmp >= snsor.Interval {
|
if intervalTmp >= snsor.Interval {
|
||||||
temperature.AddData(snsor.Id, int64(val))
|
temperature.AddData(snsor.Id, int64(val))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
|
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/sensor"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/sensor"
|
||||||
temperatureTmp "git.kingpenguin.tk/chteufleur/datahouse.git/models/temperature/temp"
|
temperatureTmp "git.kingpenguin.tk/chteufleur/datahouse.git/models/temperature/temp"
|
||||||
|
|
@ -13,8 +14,13 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_, timezoneOffset = time.Now().Zone()
|
_, timezoneOffset = time.Now().Zone()
|
||||||
|
log = logs.NewLogger(10000)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
log.SetLogger("console", "")
|
||||||
|
}
|
||||||
|
|
||||||
type SensorPrint struct {
|
type SensorPrint struct {
|
||||||
Name string
|
Name string
|
||||||
Mac string
|
Mac string
|
||||||
|
|
|
||||||
|
|
@ -54,11 +54,13 @@ func (c *ViewRelayController) Post() {
|
||||||
ret := ""
|
ret := ""
|
||||||
if r.Id != 0 {
|
if r.Id != 0 {
|
||||||
ret += r.Mac + "/"
|
ret += r.Mac + "/"
|
||||||
|
// ligth stats (on/off)
|
||||||
if r.IpAddress != "" {
|
if r.IpAddress != "" {
|
||||||
getRep, err := httplib.Get("http://"+r.IpAddress+"/status").SetTimeout(3*time.Second, 3*time.Second).String()
|
getRep, err := httplib.Get("http://"+r.IpAddress+"/status").SetTimeout(3*time.Second, 3*time.Second).String()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ret += getRep
|
ret += getRep
|
||||||
} else {
|
} else {
|
||||||
|
ret += "/"
|
||||||
relay.UpdateSensorIpAddress(r.Mac, "")
|
relay.UpdateSensorIpAddress(r.Mac, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/temperature"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/temperature"
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||||
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -55,9 +54,7 @@ func (c *SensorsController) PostTempSensors() {
|
||||||
interval, err := strconv.ParseInt(intervalStr, 10, 0)
|
interval, err := strconv.ParseInt(intervalStr, 10, 0)
|
||||||
|
|
||||||
isDelete := c.Input().Get("delete")
|
isDelete := c.Input().Get("delete")
|
||||||
fmt.Println("Del: ", isDelete)
|
|
||||||
isSave := c.Input().Get("save")
|
isSave := c.Input().Get("save")
|
||||||
fmt.Println("Save: ", isSave)
|
|
||||||
if isSave != "" && err == nil {
|
if isSave != "" && err == nil {
|
||||||
sensor.UpdateSensor(mac, description, interval)
|
sensor.UpdateSensor(mac, description, interval)
|
||||||
c.Redirect("/sensors", 302)
|
c.Redirect("/sensors", 302)
|
||||||
|
|
@ -76,9 +73,7 @@ func (c *SensorsController) PostRelay() {
|
||||||
mac := c.Input().Get("mac")
|
mac := c.Input().Get("mac")
|
||||||
|
|
||||||
isDelete := c.Input().Get("delete")
|
isDelete := c.Input().Get("delete")
|
||||||
fmt.Println("Del: ", isDelete)
|
|
||||||
isSave := c.Input().Get("save")
|
isSave := c.Input().Get("save")
|
||||||
fmt.Println("Save: ", isSave)
|
|
||||||
if isSave != "" {
|
if isSave != "" {
|
||||||
relay.UpdateSensorDescription(mac, description)
|
relay.UpdateSensorDescription(mac, description)
|
||||||
c.Redirect("/sensors", 302)
|
c.Redirect("/sensors", 302)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package temp
|
package temp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
|
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/database"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/database"
|
||||||
|
|
@ -19,7 +20,12 @@ type TempTableTmp struct {
|
||||||
Value int64
|
Value int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
log = logs.NewLogger(10000)
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
log.SetLogger("console", "")
|
||||||
orm.RegisterModel(new(TempTableTmp))
|
orm.RegisterModel(new(TempTableTmp))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,6 +33,7 @@ func init() {
|
||||||
* Add the value into the database.
|
* Add the value into the database.
|
||||||
*/
|
*/
|
||||||
func AddData(sensor, value int64) {
|
func AddData(sensor, value int64) {
|
||||||
|
log.Info("Add tmp temperature {sensor: %s, value: %d}", sensor, value)
|
||||||
o := orm.NewOrm()
|
o := orm.NewOrm()
|
||||||
o.Using(database.Alias)
|
o.Using(database.Alias)
|
||||||
|
|
||||||
|
|
@ -55,6 +62,7 @@ func GetTemp(sensorId int64) *TempTableTmp {
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateTemp(sensorId, val int64, date time.Time) {
|
func UpdateTemp(sensorId, val int64, date time.Time) {
|
||||||
|
log.Info("Update tmp temperature {sensorId: %d, value: %d}", sensorId, val)
|
||||||
o := orm.NewOrm()
|
o := orm.NewOrm()
|
||||||
o.Using(database.Alias)
|
o.Using(database.Alias)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package temperature
|
package temperature
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
|
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/database"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/database"
|
||||||
|
|
@ -16,7 +17,13 @@ type TempTable struct {
|
||||||
Value int64
|
Value int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
_, timezoneOffset = time.Now().Zone()
|
||||||
|
log = logs.NewLogger(10000)
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
log.SetLogger("console", "")
|
||||||
orm.RegisterModel(new(TempTable))
|
orm.RegisterModel(new(TempTable))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -24,6 +31,7 @@ func init() {
|
||||||
* Add the value into the database.
|
* Add the value into the database.
|
||||||
*/
|
*/
|
||||||
func AddData(sensor, value int64) {
|
func AddData(sensor, value int64) {
|
||||||
|
log.Info("Add Temperature {sensor: %s, value: %d}", sensor, value)
|
||||||
o := orm.NewOrm()
|
o := orm.NewOrm()
|
||||||
o.Using(database.Alias)
|
o.Using(database.Alias)
|
||||||
|
|
||||||
|
|
@ -73,6 +81,7 @@ func GetLastTempForSensor(sensorId int64) *TempTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteTemperatureBySenor(sensorId int64) {
|
func DeleteTemperatureBySenor(sensorId int64) {
|
||||||
|
log.Info("Delete temperatures for sensor id : %d", sensorId)
|
||||||
o := orm.NewOrm()
|
o := orm.NewOrm()
|
||||||
o.Using(database.Alias)
|
o.Using(database.Alias)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package variables
|
package variables
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "0.0.4.1"
|
Version = "0.0.4.3"
|
||||||
|
|
||||||
SessionName = "Session_Data_House"
|
SessionName = "Session_Data_House"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,11 +65,12 @@ var forEachRelay = function() {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
success: function(result){
|
success: function(result){
|
||||||
var res = result.split("/");
|
var res = result.split("/");
|
||||||
if (res.length < 2) {
|
if (res.length < 3) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var mac = res[0];
|
var mac = res[0];
|
||||||
var status = res[1];
|
var status = res[1];
|
||||||
|
var relayStats = res[2];
|
||||||
|
|
||||||
// Update img of the left list
|
// Update img of the left list
|
||||||
var links = $(".relayLink")
|
var links = $(".relayLink")
|
||||||
|
|
@ -95,6 +96,18 @@ var forEachRelay = function() {
|
||||||
$(".jumbotron img").attr("src", "/static/img/bulbNone.png")
|
$(".jumbotron img").attr("src", "/static/img/bulbNone.png")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update button color of the selected relay
|
||||||
|
if ($(".jumbotron img").attr("id") == mac) {
|
||||||
|
$("#toggleButton").removeClass("btn-primary");
|
||||||
|
$("#toggleButton").removeClass("btn-danger");
|
||||||
|
|
||||||
|
if (relayStats == "down") {
|
||||||
|
$("#toggleButton").addClass("btn-primary");
|
||||||
|
} else {
|
||||||
|
$("#toggleButton").addClass("btn-danger");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue