32 lines
558 B
Go
32 lines
558 B
Go
package controllers
|
|
|
|
import (
|
|
"strconv"
|
|
"fmt"
|
|
|
|
"github.com/astaxie/beego"
|
|
|
|
"datahouse/models/temperature"
|
|
"datahouse/models/sensor"
|
|
)
|
|
|
|
type AddTempController struct {
|
|
beego.Controller
|
|
}
|
|
|
|
func (c *AddTempController) Get() {
|
|
mac := c.Ctx.Input.Param(":sensor")
|
|
val, _ := strconv.Atoi(c.Ctx.Input.Param(":val"))
|
|
|
|
fmt.Println("MAC: ", mac)
|
|
|
|
s := sensor.GetSensorByMac(mac)
|
|
if s == nil {
|
|
sensor.AddSensor(mac)
|
|
s = sensor.GetSensorByMac(mac)
|
|
}
|
|
|
|
temperature.AddData(s.Id, int64(val))
|
|
c.Ctx.Output.Body([]byte(strconv.FormatInt(s.Interval, 10)))
|
|
}
|