Example #1
0
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()
}
Example #2
0
var _ = Describe("Sensors", func() {

	var (
		service *sensors.SensorService
		broker  *mockBroker
		gbot    *gobot.Gobot
	)

	BeforeEach(func() {
		// Remove line below to get more debug info
		log.SetOutput(&testutils.NullReadWriteCloser{})

		gbot = gobot.NewGobot()
		adapter := newMockAdapter("mock adapter")
		broker = newMockBroker()
		service = sensors.Initialize(gbot, adapter, broker)
	})

	It("publishes sensor name to sensor list", func() {
		service.NewTouchSensor("4")
		go gbot.Start()
		broker.IsConnectedOutput.ret0 <- true
		Eventually(broker.PublishCalled).Should(Receive(BeTrue()))
		Eventually(broker.PublishInput.arg0).Should(Receive(Equal(sensors.SENSORS_LIST_KEY)))
		Eventually(broker.PublishInput.arg1).Should(Receive(MatchJSON(`{"sensors":["/wff/v1/sp1/touchsensor4"]}`)))
	})

	Context("Touch", func() {

		It("adds touch robot to gobot", func() {
			service.NewTouchSensor("2")