Compare commits
7 Commits
aab97ed40e
...
8ed7eafbe6
| Author | SHA1 | Date |
|---|---|---|
|
|
8ed7eafbe6 | |
|
|
da863e9f4f | |
|
|
4bd4c0417c | |
|
|
f0427c6508 | |
|
|
49c524c6ea | |
|
|
3ff845ed90 | |
|
|
295d564951 |
|
|
@ -13,7 +13,8 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
_, timezoneOffset = time.Now().Zone()
|
||||
timezoneName, timezoneOffset = time.Now().Zone()
|
||||
timezoneLocation = time.FixedZone(timezoneName, timezoneOffset)
|
||||
log = logs.NewLogger(10000)
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type LoginController struct {
|
||||
|
|
@ -18,7 +17,6 @@ const (
|
|||
UrlXmppAuth = "http://auth.xmpp.kingpenguin.tk/auth"
|
||||
)
|
||||
|
||||
|
||||
func (c *LoginController) Prepare() {
|
||||
}
|
||||
|
||||
|
|
@ -68,15 +66,17 @@ func (c *LoginController) Post() {
|
|||
|
||||
func isLoginOK(lgn, pwd string) bool {
|
||||
ret := false
|
||||
if len(strings.Split(lgn, "@")) != 1 {
|
||||
// JID inside
|
||||
log.Info("Auth by JID")
|
||||
usr := user.GetUserByLogin(strings.Split(lgn, "/")[0])
|
||||
usr := user.GetUserByLogin(lgn)
|
||||
if usr.Id == 0 {
|
||||
// User is not in database
|
||||
ret = false
|
||||
} else {
|
||||
resp, _ := http.Get(UrlXmppAuth+"?domain=datahouse.kingpenguin.tk&method=POST&jid="+lgn+"&transaction_id="+pwd)
|
||||
return ret
|
||||
}
|
||||
|
||||
log.Info("Standard auth")
|
||||
ret = pwd != "" && pwd == usr.Password
|
||||
|
||||
if !ret && usr.JID != "" {
|
||||
log.Info("Auth by JID")
|
||||
resp, _ := http.Get(UrlXmppAuth + "?domain=datahouse.kingpenguin.tk&method=POST&jid=" + usr.JID + "&transaction_id=datahouse")
|
||||
httpStatusCode := resp.StatusCode
|
||||
if resp != nil && httpStatusCode == 200 {
|
||||
ret = true
|
||||
|
|
@ -84,10 +84,5 @@ func isLoginOK(lgn, pwd string) bool {
|
|||
ret = false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.Info("Standard auth")
|
||||
usr := user.GetUserByLogin(lgn)
|
||||
ret = pwd != "" && pwd == usr.Password
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import (
|
|||
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/relay"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/sensor"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/temperature"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/teleinfo"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/temperature"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||
|
||||
"strconv"
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ package controllers
|
|||
import (
|
||||
"github.com/astaxie/beego"
|
||||
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/teleinfo"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||
|
||||
"html/template"
|
||||
"strconv"
|
||||
|
|
@ -24,11 +24,13 @@ func (c *AddTeleinfoController) Prepare() {
|
|||
func (c *AddTeleinfoController) Get() {
|
||||
adresse := c.GetString(teleinfo.AdresseCompteur)
|
||||
tarif := c.GetString(teleinfo.OptionTarifaire)
|
||||
option := c.GetString(teleinfo.OptionBase)
|
||||
hp, _ := c.GetInt(teleinfo.HeurePleinne)
|
||||
hc, _ := c.GetInt(teleinfo.HeureCreuse)
|
||||
option, _ := c.GetInt(teleinfo.OptionBase)
|
||||
isousc, _ := c.GetInt(teleinfo.IntensiteSouscrite)
|
||||
iinst, _ := c.GetInt(teleinfo.IntensiteInstantanne)
|
||||
imax, _ := c.GetInt(teleinfo.IntensiteMax)
|
||||
papp, _ := c.GetInt(teleinfo.PuissanceApparente)
|
||||
|
||||
teleinfo.AddData(adresse, tarif, option, int64(hp), int64(hc))
|
||||
teleinfo.AddData(adresse, tarif, int64(option), int64(isousc), int64(iinst), int64(imax), int64(papp))
|
||||
|
||||
cpt := teleinfo.GetCompteurByAdresse(adresse)
|
||||
if cpt == nil || cpt.Id == 0 {
|
||||
|
|
@ -37,8 +39,6 @@ func (c *AddTeleinfoController) Get() {
|
|||
c.Ctx.Output.Body([]byte(""))
|
||||
}
|
||||
|
||||
|
||||
|
||||
//——————————————————————————————————————————————————————————————————————————————
|
||||
// ViewTeleinfoController
|
||||
//——————————————————————————————————————————————————————————————————————————————
|
||||
|
|
@ -72,36 +72,18 @@ func (c *ViewTeleinfoController) Get() {
|
|||
c.TplName = "teleinfo.tpl"
|
||||
}
|
||||
|
||||
|
||||
func formatDataSensorTeleInfo(values []teleinfo.TeleinfoTable) string {
|
||||
ret := ""
|
||||
for a := 0; a < 2; a++ {
|
||||
ret += "{name : \""
|
||||
if a == 0 {
|
||||
ret += "Heure Pleines"
|
||||
} else {
|
||||
ret += "Heure Creuses"
|
||||
}
|
||||
ret += "\",marker : {enabled : true, radius : 3}, data : ["
|
||||
ret += "{name : \"Puissance apparente (VA)\",marker : {enabled : true, radius : 3}, data : ["
|
||||
for i := 0; i < len(values); i++ {
|
||||
if i > 0 {
|
||||
ret += ","
|
||||
}
|
||||
// TODO faire la dérivé de la puissance pour avoir les variations plutot que l'évolution de la puissance
|
||||
horodate := strconv.FormatInt((values[i].HorodateGMT.Unix()+int64(timezoneOffset))*1000, 10)
|
||||
value := ""
|
||||
if a == 0 {
|
||||
value = strconv.FormatInt(values[i].HeurePleinne, 10)
|
||||
} else {
|
||||
value = strconv.FormatInt(values[i].HeureCreuse, 10)
|
||||
}
|
||||
value := strconv.FormatInt(values[i].PuissanceApparente, 10)
|
||||
ret += "[" + horodate + "," + value + "]"
|
||||
}
|
||||
ret += "]}"
|
||||
|
||||
if a == 0 {
|
||||
ret += ","
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ import (
|
|||
"net/http"
|
||||
)
|
||||
|
||||
|
||||
|
||||
type WebSocketController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
|
@ -28,16 +26,12 @@ func (c *WebSocketController) Prepare() {
|
|||
c.Data["version"] = variables.Version
|
||||
}
|
||||
|
||||
|
||||
// Get method handles GET requests for WebSocketController.
|
||||
func (c *WebSocketController) Get() {
|
||||
c.Data["hostWS"] = "ws://" + c.Ctx.Request.Host + variables.WebSocketLogRoute
|
||||
c.TplName = "watchlog.tpl"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Join method handles WebSocket requests for WebSocketController.
|
||||
func (this *WebSocketController) Join() {
|
||||
// Upgrade from http request to WebSocket.
|
||||
|
|
@ -52,7 +46,6 @@ func (this *WebSocketController) Join() {
|
|||
|
||||
watchlog.ListWebSocket.PushFront(ws)
|
||||
|
||||
|
||||
// Message receive loop.
|
||||
for {
|
||||
_, _, err := ws.ReadMessage()
|
||||
|
|
|
|||
|
|
@ -15,8 +15,10 @@ const (
|
|||
AdresseCompteur = "ADCO"
|
||||
OptionTarifaire = "OPTARIF"
|
||||
OptionBase = "BASE" // Wh
|
||||
HeurePleinne = "HCHP" // Wh
|
||||
HeureCreuse = "HCHC" // Wh
|
||||
IntensiteSouscrite = "ISOUSC" // A
|
||||
IntensiteInstantanne = "IINST" // A
|
||||
IntensiteMax = "IMAX" // A
|
||||
PuissanceApparente = "PAPP" // VA
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -36,8 +38,6 @@ func init() {
|
|||
optionTarifaireTranslate["EJP."] = "EJP"
|
||||
}
|
||||
|
||||
|
||||
|
||||
//——————————————————————————————————————————————————————————————————————————————
|
||||
// TeleinfoTable
|
||||
//——————————————————————————————————————————————————————————————————————————————
|
||||
|
|
@ -46,23 +46,26 @@ type TeleinfoTable struct {
|
|||
HorodateGMT time.Time `orm:"auto_now;type(datetime)"`
|
||||
AdresseCompteur string
|
||||
OptionTarifaire string
|
||||
OptionBase string
|
||||
HeurePleinne int64
|
||||
HeureCreuse int64
|
||||
OptionBase int64
|
||||
IntensiteSouscrite int64
|
||||
IntensiteInstantanne int64
|
||||
IntensiteMax int64
|
||||
PuissanceApparente int64
|
||||
}
|
||||
|
||||
|
||||
func AddData(adresse, tarif, option string, hp, hc int64) {
|
||||
log.Info("Add teleinfo {adresse: %s, tarif: %s, option: %s, hp: %d, hc: %d}", adresse, tarif, option, hp, hc)
|
||||
func AddData(adresse, tarif string, base, isousc, iinst, imax, papp int64) {
|
||||
log.Info("Add teleinfo {adresse: %s, tarif: %s, base: %s Wh, isousc: %d A, iinst: %d A, imax: %d A, ppap: %d VA}", adresse, tarif, base, isousc, iinst, imax, papp)
|
||||
o := orm.NewOrm()
|
||||
o.Using(database.Alias)
|
||||
|
||||
ti := new(TeleinfoTable)
|
||||
ti.AdresseCompteur = adresse
|
||||
ti.OptionTarifaire = tarif
|
||||
ti.OptionBase = option
|
||||
ti.HeurePleinne = hp
|
||||
ti.HeureCreuse = hc
|
||||
ti.OptionBase = base
|
||||
ti.IntensiteSouscrite = isousc
|
||||
ti.IntensiteInstantanne = iinst
|
||||
ti.IntensiteMax = imax
|
||||
ti.PuissanceApparente = papp
|
||||
o.Insert(ti)
|
||||
}
|
||||
|
||||
|
|
@ -81,10 +84,13 @@ func GetAllDataForCompteur(adresseCompteur string) []TeleinfoTable {
|
|||
|
||||
d.AdresseCompteur = utils.GetString(m, "AdresseCompteur")
|
||||
d.OptionTarifaire = optionTarifaireTranslate[utils.GetString(m, "OptionTarifaire")]
|
||||
d.OptionBase = utils.GetString(m, "OptionBase")
|
||||
d.OptionBase = utils.GetInt(m, "OptionBase")
|
||||
|
||||
d.HeurePleinne = utils.GetInt(m, "HeurePleinne")
|
||||
d.HeureCreuse = utils.GetInt(m, "HeureCreuse")
|
||||
d.IntensiteSouscrite = utils.GetInt(m, "IntensiteSouscrite")
|
||||
d.IntensiteInstantanne = utils.GetInt(m, "IntensiteInstantanne")
|
||||
d.IntensiteMax = utils.GetInt(m, "IntensiteMax")
|
||||
|
||||
d.PuissanceApparente = utils.GetInt(m, "PuissanceApparente")
|
||||
|
||||
dataArray = append(dataArray, *d)
|
||||
}
|
||||
|
|
@ -106,10 +112,13 @@ func GetLastDataForCompteur(adresseCompteur string) *TeleinfoTable {
|
|||
|
||||
data.AdresseCompteur = utils.GetString(m, "AdresseCompteur")
|
||||
data.OptionTarifaire = optionTarifaireTranslate[utils.GetString(m, "OptionTarifaire")]
|
||||
data.OptionBase = utils.GetString(m, "OptionBase")
|
||||
data.OptionBase = utils.GetInt(m, "OptionBase")
|
||||
|
||||
data.HeurePleinne = utils.GetInt(m, "HeurePleinne")
|
||||
data.HeureCreuse = utils.GetInt(m, "HeureCreuse")
|
||||
data.IntensiteSouscrite = utils.GetInt(m, "IntensiteSouscrite")
|
||||
data.IntensiteInstantanne = utils.GetInt(m, "IntensiteInstantanne")
|
||||
data.IntensiteMax = utils.GetInt(m, "IntensiteMax")
|
||||
|
||||
data.PuissanceApparente = utils.GetInt(m, "PuissanceApparente")
|
||||
}
|
||||
}
|
||||
return data
|
||||
|
|
@ -121,8 +130,6 @@ func DeleteDataCompteur(adresseCompteur string) {
|
|||
o.Delete(&TeleinfoTable{AdresseCompteur: adresseCompteur})
|
||||
}
|
||||
|
||||
|
||||
|
||||
//——————————————————————————————————————————————————————————————————————————————
|
||||
// CompteurTeleinfoTable
|
||||
//——————————————————————————————————————————————————————————————————————————————
|
||||
|
|
@ -190,7 +197,6 @@ func GetSensor(id int64) *CompteurTeleinfoTable {
|
|||
o := orm.NewOrm()
|
||||
o.Using(database.Alias)
|
||||
|
||||
|
||||
var ret = new(CompteurTeleinfoTable)
|
||||
var maps []orm.Params
|
||||
_, err := o.QueryTable(new(CompteurTeleinfoTable)).Filter("Id", id).Values(&maps)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,9 @@ type TempTable struct {
|
|||
}
|
||||
|
||||
var (
|
||||
_, timezoneOffset = time.Now().Zone()
|
||||
timezoneName, timezoneOffset = time.Now().Zone()
|
||||
timezoneLocation = time.FixedZone(timezoneName, timezoneOffset)
|
||||
deltaTimeCompressData = 1440 * time.Hour
|
||||
log = logs.NewLogger(10000)
|
||||
)
|
||||
|
||||
|
|
@ -43,6 +45,22 @@ func AddData(sensor, value int64) {
|
|||
o.Insert(tmpTable)
|
||||
}
|
||||
|
||||
func AddDataWithHorodate(id, sensor, value int64, horodateGMT time.Time) {
|
||||
log.Info("Add Temperature {sensor: %s, value: %d, horodateGNT: %v}", sensor, value, horodateGMT)
|
||||
o := orm.NewOrm()
|
||||
o.Using(database.Alias)
|
||||
|
||||
tmpTable := new(TempTable)
|
||||
tmpTable.Id = id
|
||||
tmpTable.Value = value
|
||||
tmpTable.SensorID = sensor
|
||||
tmpTable.HorodateGMT = horodateGMT
|
||||
_, err := o.Insert(tmpTable)
|
||||
if err != nil {
|
||||
log.Info("Error on insert temperature ", err)
|
||||
}
|
||||
}
|
||||
|
||||
func GetAllTempForSensor(sensorId int64) []TempTable {
|
||||
o := orm.NewOrm()
|
||||
o.Using(database.Alias)
|
||||
|
|
@ -89,6 +107,13 @@ func DeleteTemperatureBySenor(sensorId int64) {
|
|||
|
||||
temps := GetAllTempForSensor(sensorId)
|
||||
for _, temp := range temps {
|
||||
o.Delete(&TempTable{Id: temp.Id})
|
||||
DeleteTemperatureById(temp.Id)
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteTemperatureById(tempId int64) {
|
||||
log.Info("Delete temperatures id : %d", tempId)
|
||||
o := orm.NewOrm()
|
||||
o.Using(database.Alias)
|
||||
o.Delete(&TempTable{Id: tempId})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ type User struct {
|
|||
Id int64
|
||||
Login string
|
||||
Password string
|
||||
JID string
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
@ -47,6 +48,7 @@ func GetUserByLogin(login string) *User {
|
|||
ret.Id = utils.GetInt(m, "Id")
|
||||
ret.Login = utils.GetString(m, "Login")
|
||||
ret.Password = utils.GetString(m, "Password")
|
||||
ret.JID = utils.GetString(m, "JID")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -65,6 +67,7 @@ func GetUser(id int64) *User {
|
|||
ret.Id = utils.GetInt(m, "Id")
|
||||
ret.Login = utils.GetString(m, "Login")
|
||||
ret.Password = utils.GetString(m, "Password")
|
||||
ret.JID = utils.GetString(m, "JID")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package variables
|
||||
|
||||
const (
|
||||
Version = "0.1.2"
|
||||
Version = "0.1.4"
|
||||
|
||||
SessionName = "Session_Data_House"
|
||||
|
||||
|
|
|
|||
|
|
@ -13,12 +13,12 @@
|
|||
|
||||
//----------------------------------------------------
|
||||
|
||||
const char* ssid = "SFR_4D28";
|
||||
const char* password = "catruntiterthsti9ale";
|
||||
/*
|
||||
const char* ssid = "TNCAP3F2E03";
|
||||
const char* password = "73ABCCAA87";
|
||||
*/
|
||||
const char* ssid = "L0AD";
|
||||
const char* password = "";
|
||||
*/
|
||||
|
||||
|
||||
const char* host = "datahouse.kingpenguin.tk";
|
||||
|
|
@ -29,8 +29,10 @@ const int DEFAULT_INTERVAL = 60000; // 60 sec
|
|||
String ADCO = "";
|
||||
String OPTARIF = "";
|
||||
String BASE = "";
|
||||
String HCHP = "";
|
||||
String HCHC = "";
|
||||
String ISOUSC = "";
|
||||
String IINST = "";
|
||||
String IMAX = "";
|
||||
String PAPP = "";
|
||||
bool sendData = false;
|
||||
//----------------------------------------------------
|
||||
|
||||
|
|
@ -57,7 +59,7 @@ void sendDataToServer() {
|
|||
}
|
||||
|
||||
// We now create a URI for the request
|
||||
String url = "/teleinfo/add?ADCO="+ADCO+"&OPTARIF="+OPTARIF+"&BASE="+BASE+"&HCHC="+HCHC+"&HCHP="+HCHP;
|
||||
String url = "/teleinfo/add?ADCO="+ADCO+"&OPTARIF="+OPTARIF+"&BASE="+BASE+"&ISOUSC="+ISOUSC+"&IINST="+IINST+"&IMAX="+IMAX+"&PAPP="+PAPP;
|
||||
|
||||
Serial.print("Requesting URL: ");
|
||||
Serial.println(url);
|
||||
|
|
@ -181,20 +183,25 @@ void loop() {
|
|||
|
||||
if (label == "ADCO" && isNumberSelf(value)) {
|
||||
ADCO = value;
|
||||
sendData = true;
|
||||
}
|
||||
if (label == "OPTARIF") {
|
||||
OPTARIF = value;
|
||||
}
|
||||
if (label == "BASE") {
|
||||
if (label == "BASE" && isNumberSelf(value)) {
|
||||
BASE = value;
|
||||
}
|
||||
if (label == "HCHC" && isNumberSelf(value)) {
|
||||
HCHC = value;
|
||||
sendData = true;
|
||||
if (label == "ISOUSC" && isNumberSelf(value)) {
|
||||
ISOUSC = value;
|
||||
}
|
||||
if (label == "HCHP" && isNumberSelf(value)) {
|
||||
HCHP = value;
|
||||
sendData = true;
|
||||
if (label == "IINST" && isNumberSelf(value)) {
|
||||
IINST = value;
|
||||
}
|
||||
if (label == "IMAX" && isNumberSelf(value)) {
|
||||
IMAX = value;
|
||||
}
|
||||
if (label == "PAPP" && isNumberSelf(value)) {
|
||||
PAPP = value;
|
||||
}
|
||||
|
||||
// if (millis() >= nextInterval) {
|
||||
|
|
|
|||
|
|
@ -138,11 +138,10 @@
|
|||
<center><h3><strong>{{.compteurDescription}}</strong></h3></center>
|
||||
<hr/>
|
||||
|
||||
<h4>N° Compteur: <small>{{.dataCompteur.AdresseCompteur}}</small></h4>
|
||||
<h4>Option tarifaire: <small>{{.dataCompteur.OptionTarifaire}}</small></p>
|
||||
<h4>Option base: <small>{{.dataCompteur.OptionBase}}</small></h4>
|
||||
<h4>Heure pleine: <small>{{.dataCompteur.HeurePleinne}} Wh</small></h4>
|
||||
<h4>Heure creuse: <small>{{.dataCompteur.HeureCreuse}} Wh</small></h4>
|
||||
<h4>N° Compteur : <small>{{.dataCompteur.AdresseCompteur}}</small></h4>
|
||||
<h4>Option tarifaire : <small>{{.dataCompteur.OptionTarifaire}}</small></p>
|
||||
<h4>Option base : <small>{{.dataCompteur.OptionBase}} Wh</small></h4>
|
||||
<h4>Intensité souscrite : <small>{{.dataCompteur.IntensiteSouscrite}} A</small></h4>
|
||||
|
||||
<div style="margin-top: 30px;" id="graphe"></div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue