コード例 #1
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()
}
コード例 #2
0
ファイル: subscribe_test.go プロジェクト: wfernandes/IoT
var _ = Describe("Subscriber", func() {

	var (
		outputChan chan *event.Event
		broker     *mockBroker
	)
	Context("without errors", func() {

		BeforeEach(func() {
			outputChan = make(chan *event.Event, 100)
			broker = newMockBroker()
		})

		It("reads initial list of sensor keys", func() {
			broker.ConnectOutput.ret0 <- nil
			s := subscribe.New(broker, outputChan)
			s.Start()
			Eventually(broker.ConnectCalled).Should(Receive(BeTrue()))
			Eventually(broker.SubscribeCalled).Should(Receive(BeTrue()))
			Eventually(broker.SubscribeInput.arg0).Should(Receive(Equal(subscribe.SENSORS_LIST_KEY)))
			data := []byte(`{"sensors":["/wff/v1/sp1/touchsensor", "/wff/v1/sp1/soundsensor"]}`)
			getSensorList := <-broker.SubscribeInput.arg1
			getSensorList(data)
			Eventually(broker.SubscribeCalled).Should(Receive(BeTrue()))
			Eventually(broker.SubscribeInput.arg0).Should(Receive(Equal("/wff/v1/sp1/touchsensor")))
			Eventually(broker.SubscribeInput.arg0).Should(Receive(Equal("/wff/v1/sp1/soundsensor")))
		})

		It("disconnects mqtt client when stop is called", func() {
			s := subscribe.New(broker, outputChan)
			s.Stop()