func main() { mqttAdaptor := mqtt.NewAdaptor("tcp://test.mosquitto.org:1883", "blinker") firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0") led := gpio.NewLedDriver(firmataAdaptor, "13") work := func() { mqttAdaptor.On("lights/on", func(data []byte) { led.On() }) mqttAdaptor.On("lights/off", func(data []byte) { led.Off() }) data := []byte("") gobot.Every(1*time.Second, func() { mqttAdaptor.Publish("lights/on", data) }) gobot.Every(2*time.Second, func() { mqttAdaptor.Publish("lights/off", data) }) } robot := gobot.NewRobot("mqttBot", []gobot.Connection{mqttAdaptor, firmataAdaptor}, []gobot.Device{led}, work, ) robot.Start() }
func main() { keys := keyboard.NewDriver() mqttAdaptor := mqtt.NewAdaptor("tcp://iot.eclipse.org:1883", "conductor") work := func() { keys.On(keyboard.Key, func(data interface{}) { key := data.(keyboard.KeyEvent) switch key.Key { case keyboard.ArrowUp: mqttAdaptor.Publish("rover/frente", []byte{}) case keyboard.ArrowRight: mqttAdaptor.Publish("rover/derecha", []byte{}) case keyboard.ArrowDown: mqttAdaptor.Publish("rover/atras", []byte{}) case keyboard.ArrowLeft: mqttAdaptor.Publish("rover/izquierda", []byte{}) } }) } robot := gobot.NewRobot("keyboardbot", []gobot.Connection{mqttAdaptor}, []gobot.Device{keys}, work, ) robot.Start() }
func main() { mqttAdaptor := mqtt.NewAdaptor("tcp://test.mosquitto.org:1883", "pinger") work := func() { mqttAdaptor.On("hello", func(data []byte) { fmt.Println("hello") }) mqttAdaptor.On("hola", func(data []byte) { fmt.Println("hola") }) data := []byte("o") gobot.Every(1*time.Second, func() { mqttAdaptor.Publish("hello", data) }) gobot.Every(5*time.Second, func() { mqttAdaptor.Publish("hola", data) }) } robot := gobot.NewRobot("mqttBot", []gobot.Connection{mqttAdaptor}, work, ) robot.Start() }