go fmt + script.
This commit is contained in:
parent
24be86ef5f
commit
716835d67b
|
|
@ -3,7 +3,7 @@ package controllers
|
||||||
import (
|
import (
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
|
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/soilMoisture"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/soilMoisture"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AddSoilMoistController struct {
|
type AddSoilMoistController struct {
|
||||||
|
|
@ -11,11 +11,11 @@ type AddSoilMoistController struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *AddSoilMoistController) Get() {
|
func (c *AddSoilMoistController) Get() {
|
||||||
macArduino := c.GetString(soilMoisture.MacModuleWifiArduino)
|
macArduino := c.GetString(soilMoisture.MacModuleWifiArduino)
|
||||||
pinArduino := c.GetString(soilMoisture.PinArduino)
|
pinArduino := c.GetString(soilMoisture.PinArduino)
|
||||||
valeurCapteur, _ := c.GetInt(soilMoisture.ValeurCapteur)
|
valeurCapteur, _ := c.GetInt(soilMoisture.ValeurCapteur)
|
||||||
|
|
||||||
soilMoisture.AddData(pinArduino, macArduino, int64(valeurCapteur))
|
soilMoisture.AddData(pinArduino, macArduino, int64(valeurCapteur))
|
||||||
|
|
||||||
cpt := soilMoisture.GetCapteurByAdresse(macArduino, pinArduino)
|
cpt := soilMoisture.GetCapteurByAdresse(macArduino, pinArduino)
|
||||||
if cpt == nil || cpt.Id == 0 {
|
if cpt == nil || cpt.Id == 0 {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
|
||||||
|
cd controllers
|
||||||
|
go fmt
|
||||||
|
cd ../models
|
||||||
|
go fmt
|
||||||
|
cd ../routers
|
||||||
|
go fmt
|
||||||
|
cd ../watchlog
|
||||||
|
go fmt
|
||||||
|
cd ../xmpp
|
||||||
|
go fmt
|
||||||
|
|
||||||
20
main.go
20
main.go
|
|
@ -1,14 +1,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models"
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/database"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/database"
|
||||||
_ "git.kingpenguin.tk/chteufleur/datahouse.git/models/temperature"
|
_ "git.kingpenguin.tk/chteufleur/datahouse.git/models/temperature"
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/user"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/user"
|
||||||
_ "git.kingpenguin.tk/chteufleur/datahouse.git/routers"
|
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/xmpp"
|
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/watchlog"
|
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models"
|
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||||
|
_ "git.kingpenguin.tk/chteufleur/datahouse.git/routers"
|
||||||
|
"git.kingpenguin.tk/chteufleur/datahouse.git/watchlog"
|
||||||
|
"git.kingpenguin.tk/chteufleur/datahouse.git/xmpp"
|
||||||
|
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"github.com/astaxie/beego/logs"
|
"github.com/astaxie/beego/logs"
|
||||||
|
|
@ -26,7 +26,7 @@ var (
|
||||||
func init() {
|
func init() {
|
||||||
log.SetLogger(variables.LogType, variables.LogParams)
|
log.SetLogger(variables.LogType, variables.LogParams)
|
||||||
url := ""
|
url := ""
|
||||||
db := ""
|
db := ""
|
||||||
if database.DatabaseInstance == database.MySQL {
|
if database.DatabaseInstance == database.MySQL {
|
||||||
// MySQL
|
// MySQL
|
||||||
orm.RegisterDriver(database.MySQL, orm.DRMySQL)
|
orm.RegisterDriver(database.MySQL, orm.DRMySQL)
|
||||||
|
|
@ -57,23 +57,19 @@ func main() {
|
||||||
if !user.IsUserExist("admin") {
|
if !user.IsUserExist("admin") {
|
||||||
user.AddUser("admin", "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918")
|
user.AddUser("admin", "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918")
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
go xmpp_manager.Run()
|
|
||||||
go watchlog.Run()
|
|
||||||
*/
|
|
||||||
go reborn()
|
go reborn()
|
||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
// models.ChanRuns <- xmpp_manager.EndRun
|
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
models.ChanRuns <- watchlog.EndRun
|
models.ChanRuns <- watchlog.EndRun
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
// models.ChanRuns <- xmpp_manager.EndRun
|
||||||
|
|
||||||
beego.Run()
|
beego.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func reborn() {
|
func reborn() {
|
||||||
for {
|
for {
|
||||||
action := <- models.ChanRuns
|
action := <-models.ChanRuns
|
||||||
|
|
||||||
switch action {
|
switch action {
|
||||||
case xmpp_manager.EndRun:
|
case xmpp_manager.EndRun:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ChanRuns = make(chan string)
|
ChanRuns = make(chan string)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,45 +1,43 @@
|
||||||
package watchlog
|
package watchlog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/hpcloud/tail"
|
"github.com/hpcloud/tail"
|
||||||
|
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models"
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||||
|
|
||||||
"container/list"
|
"container/list"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
EndRun = "EndRunWatchlog"
|
EndRun = "EndRunWatchlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ListWebSocket = list.New()
|
ListWebSocket = list.New()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func Run() {
|
func Run() {
|
||||||
t, _ := tail.TailFile(variables.LogFilePath, tail.Config{Follow: true})
|
t, _ := tail.TailFile(variables.LogFilePath, tail.Config{Follow: true})
|
||||||
for line := range t.Lines {
|
for line := range t.Lines {
|
||||||
broadcastWebSocket(line.Text)
|
broadcastWebSocket(line.Text)
|
||||||
}
|
}
|
||||||
time.Sleep(30 * time.Second)
|
time.Sleep(30 * time.Second)
|
||||||
models.ChanRuns <- EndRun
|
models.ChanRuns <- EndRun
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func broadcastWebSocket(message string) {
|
func broadcastWebSocket(message string) {
|
||||||
for sub := ListWebSocket.Front(); sub != nil; sub = sub.Next() {
|
for sub := ListWebSocket.Front(); sub != nil; sub = sub.Next() {
|
||||||
// Immediately send event to WebSocket users.
|
// Immediately send event to WebSocket users.
|
||||||
ws := sub.Value.(*websocket.Conn)
|
ws := sub.Value.(*websocket.Conn)
|
||||||
err := ws.WriteMessage(websocket.TextMessage, []byte(message))
|
err := ws.WriteMessage(websocket.TextMessage, []byte(message))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
toRemove := sub
|
toRemove := sub
|
||||||
sub = sub.Prev()
|
sub = sub.Prev()
|
||||||
ListWebSocket.Remove(toRemove)
|
ListWebSocket.Remove(toRemove)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
28
xmpp/xmpp.go
28
xmpp/xmpp.go
|
|
@ -1,17 +1,15 @@
|
||||||
package xmpp_manager
|
package xmpp_manager
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"github.com/astaxie/beego/logs"
|
"github.com/astaxie/beego/logs"
|
||||||
|
|
||||||
"git.kingpenguin.tk/chteufleur/go-xmpp.git/src/xmpp"
|
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models"
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/relay"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/relay"
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||||
|
"git.kingpenguin.tk/chteufleur/go-xmpp.git/src/xmpp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Status_online = ""
|
Status_online = ""
|
||||||
Status_offline = ""
|
Status_offline = ""
|
||||||
|
|
@ -37,11 +35,11 @@ var (
|
||||||
|
|
||||||
JidStr = beego.AppConfig.String("JID")
|
JidStr = beego.AppConfig.String("JID")
|
||||||
passwdStr = beego.AppConfig.String("PWD")
|
passwdStr = beego.AppConfig.String("PWD")
|
||||||
serverPort = beego.AppConfig.String("PORT")
|
serverPort = beego.AppConfig.String("PORT")
|
||||||
|
|
||||||
jid xmpp.JID
|
jid xmpp.JID
|
||||||
stream = new(xmpp.Stream)
|
stream = new(xmpp.Stream)
|
||||||
client = new(xmpp.XMPP)
|
client = new(xmpp.XMPP)
|
||||||
|
|
||||||
Debug = true
|
Debug = true
|
||||||
)
|
)
|
||||||
|
|
@ -50,7 +48,6 @@ func init() {
|
||||||
log.SetLogger(variables.LogType, variables.LogParams)
|
log.SetLogger(variables.LogType, variables.LogParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func must(v interface{}, err error) interface{} {
|
func must(v interface{}, err error) interface{} {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Must error : ", err)
|
log.Error("Must error : ", err)
|
||||||
|
|
@ -62,15 +59,14 @@ func Run() {
|
||||||
// Create stream and configure it as a component connection.
|
// Create stream and configure it as a component connection.
|
||||||
log.Info("XMPP Run()")
|
log.Info("XMPP Run()")
|
||||||
jid = must(xmpp.ParseJID(JidStr)).(xmpp.JID)
|
jid = must(xmpp.ParseJID(JidStr)).(xmpp.JID)
|
||||||
stream = must(xmpp.NewStream(jid.Domain+":"+serverPort, &xmpp.StreamConfig{LogStanzas: Debug})).(*xmpp.Stream)
|
stream = must(xmpp.NewStream(jid.Domain+":"+serverPort, &xmpp.StreamConfig{LogStanzas: Debug})).(*xmpp.Stream)
|
||||||
client = must(xmpp.NewClientXMPP(stream, jid, passwdStr, &xmpp.ClientConfig{InsecureSkipVerify: true})).(*xmpp.XMPP)
|
client = must(xmpp.NewClientXMPP(stream, jid, passwdStr, &xmpp.ClientConfig{InsecureSkipVerify: true})).(*xmpp.XMPP)
|
||||||
|
|
||||||
mainXMPP()
|
mainXMPP()
|
||||||
log.Debug("xmpp.Run Ended")
|
log.Debug("xmpp.Run Ended")
|
||||||
models.ChanRuns <- EndRun
|
models.ChanRuns <- EndRun
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func mainXMPP() {
|
func mainXMPP() {
|
||||||
SendPresence(Status_online, Type_available, "")
|
SendPresence(Status_online, Type_available, "")
|
||||||
|
|
||||||
|
|
@ -96,12 +92,10 @@ func mainXMPP() {
|
||||||
log.Debug("mainXMPP Ended")
|
log.Debug("mainXMPP Ended")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func SendPresence(status, tpye, message string) {
|
func SendPresence(status, tpye, message string) {
|
||||||
client.Out <- xmpp.Presence{From: jid.Domain, Show: status, Type: tpye, Status: message}
|
client.Out <- xmpp.Presence{From: jid.Domain, Show: status, Type: tpye, Status: message}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func execDiscoCommand(iq *xmpp.Iq) {
|
func execDiscoCommand(iq *xmpp.Iq) {
|
||||||
log.Info("Discovery item iq received")
|
log.Info("Discovery item iq received")
|
||||||
reply := iq.Response(xmpp.IQTypeResult)
|
reply := iq.Response(xmpp.IQTypeResult)
|
||||||
|
|
@ -110,7 +104,7 @@ func execDiscoCommand(iq *xmpp.Iq) {
|
||||||
relays := relay.GetAllRelay()
|
relays := relay.GetAllRelay()
|
||||||
for _, r := range relays {
|
for _, r := range relays {
|
||||||
discoI := &xmpp.DiscoItem{JID: client.JID.Full(), Node: r.Mac, Name: "Relay : "}
|
discoI := &xmpp.DiscoItem{JID: client.JID.Full(), Node: r.Mac, Name: "Relay : "}
|
||||||
if (r.Description == "") {
|
if r.Description == "" {
|
||||||
discoI.Name += r.Mac
|
discoI.Name += r.Mac
|
||||||
} else {
|
} else {
|
||||||
discoI.Name += r.Description
|
discoI.Name += r.Description
|
||||||
|
|
@ -137,9 +131,9 @@ func execCommandAdHoc(iq *xmpp.Iq) {
|
||||||
// First step in the command
|
// First step in the command
|
||||||
if relais.Id != 0 {
|
if relais.Id != 0 {
|
||||||
reply := iq.Response(xmpp.IQTypeResult)
|
reply := iq.Response(xmpp.IQTypeResult)
|
||||||
cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocExecute, SessionID: xmpp.SessionID()/*+";"+relais.Mac*/}
|
cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocExecute, SessionID: xmpp.SessionID() /*+";"+relais.Mac*/}
|
||||||
|
|
||||||
cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocForm, Title: "Commande relais "+descriptionRelais}
|
cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocForm, Title: "Commande relais " + descriptionRelais}
|
||||||
field := &xmpp.AdHocField{Var: "command", Label: "Commande a executer", Type: "list-single"}
|
field := &xmpp.AdHocField{Var: "command", Label: "Commande a executer", Type: "list-single"}
|
||||||
fieldOption := &xmpp.AdHocFieldOption{Value: "toggle"}
|
fieldOption := &xmpp.AdHocFieldOption{Value: "toggle"}
|
||||||
field.Options = append(field.Options, *fieldOption)
|
field.Options = append(field.Options, *fieldOption)
|
||||||
|
|
@ -159,7 +153,7 @@ func execCommandAdHoc(iq *xmpp.Iq) {
|
||||||
reply := iq.Response(xmpp.IQTypeResult)
|
reply := iq.Response(xmpp.IQTypeResult)
|
||||||
cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocCompleted, SessionID: adHoc.SessionID}
|
cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocCompleted, SessionID: adHoc.SessionID}
|
||||||
|
|
||||||
cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocResult, Title: "Commande relais "+descriptionRelais}
|
cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocResult, Title: "Commande relais " + descriptionRelais}
|
||||||
cmd.XForm = *cmdXForm
|
cmd.XForm = *cmdXForm
|
||||||
|
|
||||||
note := &xmpp.AdHocNote{Type: xmpp.TypeAdHocNoteInfo}
|
note := &xmpp.AdHocNote{Type: xmpp.TypeAdHocNoteInfo}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue