예제 #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
			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())
		})
	})
})