예제 #1
0
// ExportDriver Exports a driver using the 'driver' protocol, and announces it
func (c *Connection) ExportDriver(driver Driver) error {

	time.Sleep(config.Duration(time.Second*3, "drivers.startUpDelay"))

	topic := fmt.Sprintf("$node/%s/driver/%s", config.Serial(), driver.GetModuleInfo().ID)

	announcement := driver.GetModuleInfo()

	announcement.ServiceAnnouncement = model.ServiceAnnouncement{
		Schema: "http://schema.ninjablocks.com/service/driver",
	}

	_, err := c.exportService(driver, topic, announcement)

	if err != nil {
		return err
	}

	if config.Bool(false, "autostart") {
		err := c.GetServiceClient(topic).Call("start", struct{}{}, nil, time.Second*20)
		if err != nil {
			c.log.Fatalf("Failed to autostart driver: %s", err)
		}
	}

	return nil
}
예제 #2
0
	roomModel := NewRoomModel()
	siteModel := NewSiteModel()
	thingModel := NewThingModel()

	return []interface{}{
		moduleModel, &moduleModel.baseModel,
		channelModel, &channelModel.baseModel,
		deviceModel, &deviceModel.baseModel,
		roomModel, &roomModel.baseModel,
		siteModel, &siteModel.baseModel,
		thingModel, &thingModel.baseModel,
	}
}

var fsSyncLog = logger.GetLogger("FS Sync")
var fsSyncInterval = config.Duration(time.Second, "homecloud.fsSync.minInterval")
var fsSyncEnabled = config.Bool(false, "homecloud.fsSync.enabled")
var fsSyncTask *time.Timer

func syncFS() {
	if fsSyncEnabled {
		if fsSyncTask == nil {
			fsSyncTask = time.AfterFunc(fsSyncInterval, func() {
				fsSyncLog.Debugf("Syncing filesystem...")
				exec.Command("sync").Output()
			})
		}

		fsSyncTask.Reset(fsSyncInterval)
	}
}
package remote

import (
	"encoding/gob"
	"fmt"
	"image"
	"net"
	"time"

	"github.com/ninjasphere/gestic-tools/go-gestic-sdk"
	"github.com/ninjasphere/go-ninja/config"
	"github.com/ninjasphere/go-ninja/logger"
)

// This is the maximum time we will wait for a frame before disconnecting the remote pane
var remotePaneTimeout = config.Duration(time.Second, "led.remote.paneTimeout")

type Pane struct {
	Disconnected   chan bool
	log            *logger.Logger
	conn           net.Conn
	incoming       *gob.Decoder
	outgoing       *gob.Encoder
	enabled        bool
	incomingFrames chan *Incoming
	keepAwake      bool
	locked         bool
}

type Outgoing struct {
	FrameRequested bool
예제 #4
0
package simtime

import (
	"container/heap"
	"runtime/debug"
	"time"

	"github.com/ninjasphere/go-ninja/config"
	"github.com/ninjasphere/go-ninja/logger"
)

var log = logger.GetLogger("simtime")

var enabled = config.Bool(false, "simtime.enable")
var startOffset = config.Duration(time.Hour*24*30, "simtime.startOffset")
var offset = config.Duration(0, "simtime.offset")
var allowFuture = config.Bool(false, "simtime.allowFuture")

var currentTime = time.Now()

var addQueue = make(chan *event)
var queue = eventQueue{}

var added = make(chan bool)
var tick = make(chan bool)
var start = make(chan bool)

func addQueuedEvents() {
	for {
		select {
		case e := <-addQueue:
예제 #5
0
	"strings"
	"time"

	"github.com/hashicorp/mdns"
	"github.com/ninjasphere/go-ninja/api"
	"github.com/ninjasphere/go-ninja/bus"
	"github.com/ninjasphere/go-ninja/config"
	"github.com/ninjasphere/go-ninja/logger"
	"github.com/ninjasphere/go-ninja/model"

	ledmodel "github.com/ninjasphere/sphere-go-led-controller/model"
)

var log = logger.GetLogger("Client")

var orphanTimeout = config.Duration(time.Second*30, "client.orphanTimeout")
var defaultTimeout = time.Second * 5

const (
	clientHelperPath = "/opt/ninjablocks/bin/client-helper.sh"
)

type client struct {
	conn                 *ninja.Connection
	master               bool
	bridged              bool
	led                  *ninja.ServiceClient
	foundMaster          chan bool
	localBus             bus.Bus
	masterBus            bus.Bus
	masterReceiveTimeout *time.Timer
	"os"
	"time"

	"github.com/bugsnag/bugsnag-go"
	"github.com/ninjasphere/gestic-tools/go-gestic-sdk"
	"github.com/ninjasphere/go-ninja/api"
	"github.com/ninjasphere/go-ninja/config"
	"github.com/ninjasphere/go-ninja/model"
	owm "github.com/ninjasphere/openweathermap"
	"github.com/ninjasphere/sphere-go-led-controller/fonts/O4b03b"
	"github.com/ninjasphere/sphere-go-led-controller/util"
)

var enableWeatherPane = config.MustBool("led.weather.enabled")
var weatherUpdateInterval = config.MustDuration("led.weather.updateInterval")
var temperatureDisplayTime = config.Duration(time.Second*5, "led.weather.temperatureDisplayTime")

var globalSite *model.Site
var timezone *time.Location

type WeatherPane struct {
	siteModel   *ninja.ServiceClient
	site        *model.Site
	getWeather  *time.Timer
	tempTimeout *time.Timer
	temperature bool
	weather     *owm.ForecastWeatherData
	image       util.Image
}

func NewWeatherPane(conn *ninja.Connection) *WeatherPane {