github github.com/gianarb
twitter twitter.com/gianarb
MQ Telemetry Transport
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Next generation robotics framework with support for 15 different platforms
package main
import (
"time"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/platforms/raspi"
)
func main() {
gbot := gobot.NewGobot()
r := raspi.NewRaspiAdaptor("raspi")
led := gpio.NewLedDriver(r, "led", "7")
work := func() {
gobot.Every(1*time.Second, func() {
led.Toggle()
})
}
robot := gobot.NewRobot("blinkBot",
[]gobot.Connection{r},
[]gobot.Device{led},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}
Start webserver
func main() {
http.HandleFunc("/", homeHandler)
http.HandleFunc("/api", apiHandler)
http.ListenAndServe(":8080", nil)
}
MQTT publisher
data, _ := ioutil.ReadAll(r.Body)
var b byte
var opts = MQTT.NewClientOptions()
opts.AddBroker("tcp://test.mosquitto.org:1883")
c := MQTT.NewClient(opts)
t := c.Connect()
t.Wait()
c.Publish("go-iot", b, false, data)
content := []string{"OK"}
js, _ := json.Marshal(content)
w.Write(js)
Templating
func homeHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=UTF-8")
t, _ := template.ParseFiles("tpl/home.html")
t.Execute(w, map[string]string{})
}
Select PIN- GoBot.io
gbot := gobot.NewGobot()
r := raspi.NewRaspiAdaptor("raspi")
dirA := gpio.NewLedDriver(r, "dirA", "3")
dirB := gpio.NewLedDriver(r, "dirB", "5")
pwmA := gpio.NewLedDriver(r, "pwmA", "7")
pwmB := gpio.NewLedDriver(r, "pwmB", "15")
Getting Started
work := func(){
dirA.On()
dirB.Off()
}
car := gobot.NewRobot("mqttBot",
[]gobot.Connection{r},
[]gobot.Device{dirA, dirB, pwmA, pwmB},
work,
)
MQTT support - GoBot
mqttAdaptor := mqtt.NewMqttAdaptor("go-iot", "tcp://test.mosquitto.org:1883", "raspy")
work := func() {
mqttAdaptor.On("go-iot", func(data []byte) {
if string(data) == "giu" {
}
}
Change direction - GoBot
if string(data) == "right" {
dirA.Off()
dirB.On()
pwmA.Off()
pwmB.On()
}
if string(data) == "left" {
dirA.On()
dirB.Off()
pwmA.On()
pwmB.Off()
}
Delorean current robot - GoBot
car := gobot.NewRobot("mqttBot",
[]gobot.Connection{r, mqttAdaptor},
[]gobot.Device{dirA, dirB, pwmA, pwmB},
work,
)
gbot.AddRobot(car)
gbot.Start()