Delorean made in home

Move your Raspberry Pi+ by the WEB

Gianluca Arbezzano

Developer @Corley SRL

github github.com/gianarb

twitter twitter.com/gianarb

Find the differences

Developer @Corley SRL

Ingredients

Implementation

MQTT

MQ Telemetry Transport

  • Thinked by IBM for Internet of Things
  • Application Protocol over TPC/IP
  • Real Time and Pub/Sub implementation
  • Simplicity, simplicity, simplicity!
    • 0 - without warranty
    • 1 - Message delivered but it can be duplicated
    • 2 - Message delivered without duplication
  • Networkin handling

Golang

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

  • Powerd by Google
  • Async and parallel design
  • Funny

Gobot.io

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()
}
            
            

Overview

Controller

Lines: 140

See project

Delorean

Lines: 68

See project

Controller

          







          
          

Controller

Start webserver

            
func main() {
	http.HandleFunc("/", homeHandler)
	http.HandleFunc("/api", apiHandler)
	http.ListenAndServe(":8080", nil)
}
            
            

Controller

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)
            
            

Controller

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{})
}
            
            

Delorean

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

Delorean

Getting Started

            
work := func(){
  dirA.On()
  dirB.Off()
}

car := gobot.NewRobot("mqttBot",
    []gobot.Connection{r},
    []gobot.Device{dirA, dirB, pwmA, pwmB},
    work,
)
            
            

Delorean

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

  }
}
        
        

Delorean

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

Delorean current robot - GoBot

        
	car := gobot.NewRobot("mqttBot",
		[]gobot.Connection{r, mqttAdaptor},
		[]gobot.Device{dirA, dirB, pwmA, pwmB},
		work,
	)

	gbot.AddRobot(car)

	gbot.Start()
        
        

Thanks!!