예제 #1
0
파일: main.go 프로젝트: wfernandes/IoT
func main() {
	flag.Parse()
	config, err := config.Configuration(*configFilePath)
	if err != nil {
		panic(err)
	}
	logging.SetLogLevel(config.LogLevel)
	gbot := gobot.NewGobot()

	broker := broker.NewMQTTBroker("edison processor", config.BrokerUrl)
	err = broker.Connect()
	if err != nil {
		panic(err)
	}
	logging.Log.Info("Successfully connected to broker")

	adapter := edison.NewEdisonAdaptor("edison")
	//	adapter := testutils.NewMockAdapter("mockAdapter")
	service := sensors.Initialize(gbot, adapter, broker)

	for pin, stype := range config.Sensors {
		switch stype {
		case "touch":
			service.NewTouchSensor(pin)
		case "sound":
			service.NewSoundSensor(pin)
		}
	}

	logging.Log.Info("Starting gobot bot...")
	gbot.Start()
}
예제 #2
0
파일: main.go 프로젝트: wfernandes/IoT
func main() {

	flag.Parse()
	config, err := config.Configuration(*configFilePath)
	if err != nil {
		panic(err)
	}
	logging.SetLogLevel(config.LogLevel)

	alertChan := make(chan *event.Event, 100)
	mqttBroker := broker.NewMQTTBroker("wff_notification", config.BrokerUrl)
	subscriber := subscribe.New(mqttBroker, alertChan)
	// Subscribe to all available sensor keys
	go subscriber.Start()

	// Set up the Twilio notifier
	notifier := notifiers.NewTwilio(config.TwilioAccountSid, config.TwilioAuthToken, config.TwilioFromPhone, config.To)

	service := notification.New(notifier, alertChan, time.Duration(config.NotificationIntervalMinutes)*time.Minute)
	service.Start()
}
예제 #3
0
package broker_test

import (
	"github.com/wfernandes/iot/broker"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("MQTT Broker", func() {

	var mc *broker.MQTTBroker

	BeforeEach(func() {
		mc = broker.NewMQTTBroker("some_client_id", "tcp://test.mosquitto.org:1883")
	})

	It("isConnected returns false if not connected yet", func() {
		Expect(mc.IsConnected()).To(BeFalse())
	})

	It("does not panic if it tries to publish without connecting first", func() {
		Expect(func() { mc.Publish("some_key", []byte("some value")) }).ToNot(Panic())
	})

	It("does not panic if it tries to subscribe without connecting first", func() {
		f := func([]byte) { /*do nothing*/ }
		Expect(func() { mc.Subscribe("some_key", f) }).ToNot(Panic())
	})

	Context("cannot connect", func() {