コード例 #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
ファイル: config_test.go プロジェクト: wfernandes/IoT
			var jsonStr []byte = []byte(`{
				"TwilioAccountSid": "some_sid",
				"TwilioAuthToken": "some_auth_token",
				"TwilioFromPhone": "some_phone_number",
				"BrokerUrl": "some_broker_url"
		  	}`)

			config, err := config.FromBytes(jsonStr)
			Expect(err).ToNot(HaveOccurred())
			Expect(config).ToNot(BeNil())
			Expect(config.NotificationIntervalMinutes).To(Equal(10))
			Expect(config.LogLevel).To(Equal(logging.INFO))
		})
	})

	Context("reading the file", func() {

		It("returns error for invalid config file path", func() {
			_, err := config.Configuration("idonotexist.json")
			Expect(err).To(HaveOccurred())
		})

		It("returns config for valid config file", func() {
			config, err := config.Configuration("fixtures/config.json")
			Expect(err).ToNot(HaveOccurred())
			Expect(config.TwilioAccountSid).ToNot(BeEmpty())
			Expect(config.TwilioAuthToken).ToNot(BeEmpty())
		})
	})
})