Exemplo n.º 1
0
// Demos the Gobot Every function, which provides a way
// to trigger recurring functionality.
func blinkLedOverAndOver(gbot *gobot.Gobot) {

	// Create an instance of our chosen adapter type
	// and pass it to the LED driver. The names given here
	// are used in the management functionality.
	beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
	led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_15")

	// Robots in the Gobot colletion run a "work" function
	// when they fire
	work := func() {
		gobot.Every(1*time.Second, func() {
			led.Toggle()
		})
	}

	// A Robot is a board or device, and is one of the things managed by a Gobot.
	// Here we make one with the adaptor and led objects we made above.
	// The constructor creates a new named robot, provided a connection and a device
	// which will map to something like a GPIO pin.

	// A Robot can be composed of as many Connections and Devices as you like,
	// meaning that you can create something out of a group of supported hardware pieces
	// and treat it in code as a single logical unit.
	robot := gobot.NewRobot("blinkBot",
		[]gobot.Connection{beagleboneAdaptor},
		[]gobot.Device{led},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemplo n.º 2
0
	"log"

	"encoding/json"

	"github.com/hybridgroup/gobot"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/wfernandes/iot/event"
	"github.com/wfernandes/iot/sensor_processor/testutils"
)

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")