Slide 1

Slide 1 text

TinyGo: Getting the upper hen GopherCon UK, London - 17 August 2022 Donia Chaiehloudj Powder @doniacld

Slide 2

Slide 2 text

My ideal hen house 01 What is TinyGo? What’s the plan? Demo time Things I learned 02 03 04 05 06 What’s next?

Slide 3

Slide 3 text

MY IDEAL HEN HOUSE 01. My ideal hen house ● Monitor my hen house ○ temperature ○ humidity ● Visualise the metrics

Slide 4

Slide 4 text

THE GOAL 01. My ideal hen house

Slide 5

Slide 5 text

— TinyGo website at tinygo.org TinyGo is a compiler for the Go programming language but for smaller kinds of systems.

Slide 6

Slide 6 text

SMALL SYSTEMS 02. What is TinyGo? ● Microcontrollers (86 boards) ● WebAssembly ● Tiny CLI

Slide 7

Slide 7 text

TINYGO COMPILER: HISTORY https://aykevl.nl/ 02. What is TinyGo? Ayke exploring existing projects 01/02/19 TinyGo 0.1 TinyGo used by the industry TinyGo adopted by users for side projects 03/02/19 FOSDEM @aurelievache

Slide 8

Slide 8 text

TINYGO COMPILER: ANOTHER GO COMPILER The LLVM Project is a collection of modular and reusable compilers. https://tinygo.org/docs/concepts/compiler-internals/pipeline/ 02. What is TinyGo?

Slide 9

Slide 9 text

GO VS TINYGO: HELLO WORLD SIZE ❯ go build -o bin/helloworld-go hello/hello_world.go ❯ tinygo build -o bin/helloworld-tinygo hello/hello_world.go ❯ ll bin/ total 5120 -rwxr-xr-x 1 doniacld staff 1.8M Aug 14 18:40 helloworld-go -rwxr-xr-x 1 doniacld staff 29K Aug 14 18:41 helloworld-tinygo go version go1.18.5 darwin/arm64 0.24.0 darwin/amd64 (using go version go1.18.5 and LLVM version 14.0.0) 02. What is TinyGo?

Slide 10

Slide 10 text

GO VS TINYGO: GO LANGUAGE FEATURES 02. What is TinyGo? Concurrency ✅ Concurrency != Parallelism Reflection 󰠼 Marshal structure with json fields doesn't work Garbage Collection ✅ -gc=none, -gc=leaking, -gc=conservative Standard libraries 󰠼 Packages supported by TinyGo e.g.: net/http 🎯 Compatibility with Go ecosystem

Slide 11

Slide 11 text

FLASH COMMAND tinygo flash -target= .go 1. Compiles the program on your computer 2. Writes it on chip memory (ROM) 3. Runs it on the chip NB: Built-in led is blinking while writing 02. What is TinyGo?

Slide 12

Slide 12 text

FLASH COMMAND tinygo flash -target= .go 1. Compiles the program on your computer 2. Writes it on chip memory (ROM) 3. Runs it on the chip NB: Built-in led is blinking while writing 02. What is TinyGo?

Slide 13

Slide 13 text

LET’S DEBUG 02. What is TinyGo?

Slide 14

Slide 14 text

DEBUGGING TOOLS ❯ ll /dev/tty.* 02. What is TinyGo? Serial port: connector by which a device sends data one bit at a time.

Slide 15

Slide 15 text

https://github.com/doniacld/tinygo-discovery/blob/main/hello/hello_gophers.go https://github.com/doniacld/tinygo-discovery/blob/main/utils/read_serial.go READ FROM THE SERIAL PORT 02. What is TinyGo? ❯ go run hello_gophers.go 2022/08/14 18:23:14 Hi London! What's up GopherCon UK 2022? 2022/08/14 18:23:15 Hi London! What's up GopherCon UK 2022? ❯ go run utils/read_serial.go -port /dev/cu.usbmodem1401 1970/01/01 00:00:03 Hi London! What's up GopherCon UK 2022? 1970/01/01 00:00:04 Hi London! What's up GopherCon UK 2022?

Slide 16

Slide 16 text

DEBUGGING TOOLS 02. What is TinyGo? TinyGo built-in debugging tool for binary on chip ● based on gdb ● debug probes not included on every board ● observe scheduler $ tinygo gdb -target=microbit examples/microbit-blink [...] target halted due to debug-request, current mode: Thread xPSR: 0xc1000000 pc: 0x0000071c msp: 0x20000800 (gdb) continue Continuing. ...

Slide 17

Slide 17 text

ELECTRICAL CIRCUIT 03. What’s the plan? Arduino Nano 33 IoT DHT22 DATA GROUND VCC

Slide 18

Slide 18 text

THE BIG PICTURE 03. What’s the plan?

Slide 19

Slide 19 text

PRODUCTION ENVIRONMENT 03. What’s the plan?

Slide 20

Slide 20 text

USEFUL TINYGO PACKAGES https://github.com/doniacld/tinygo-discovery/blob/main/tiny-hen/main.go 03. What’s the plan?

Slide 21

Slide 21 text

MEASUREMENT PSEUDO CODE https://github.com/doniacld/tinygo-discovery/blob/main/tiny-hen/main.go 03. What’s the plan?

Slide 22

Slide 22 text

THE GOOD OLD GO WEB SERVER https://xkcd.com/910/ 03. What’s the plan?

Slide 23

Slide 23 text

GO WEB SERVER: PROMETHEUS GAUGE DEFINITIONS https://github.com/doniacld/tiny-hen/blob/main/cmd/prommetric/metric.go 03. What’s the plan?

Slide 24

Slide 24 text

INFRASTRUCTURE 03. What’s the plan?

Slide 25

Slide 25 text

Demo time https://tinyurl.com/gopher-praying-sticker

Slide 26

Slide 26 text

TINYGO CHEAT SHEET 05. Things I learned ● TinyGo: Go compiler for small places ● Flash: tinygo flash -target= main.go ● TinyGo drivers examples are a treasure chest 💎 ● Hardware recommendations: samd21/samd51 board, or an rp2040 or TinyGo Playground ● You can enter the IoT world with your current skills and your IDE ○ VS code plugin ○ GoLand plugin

Slide 27

Slide 27 text

WHAT’S NEXT? ● Use async protocol (MQTT) ● Long range WiFi board (LoRaWAN) ● Deploy in the cloud ● Add a fox detection system https://tinyurl.com/gopher-far-west-sticker 06. What’s next?

Slide 28

Slide 28 text

https://github.com/doniacld/tinygo-discovery https://github.com/doniacld/tiny-hen @doniacld THANK YOU 🐣

Slide 29

Slide 29 text

RESOURCES @doniacld ● TinyGo doc ● Go doc ● TinyGo discovery examples repository ● TinyHen project repository ● Kube stack prometheus doc ● Grafana dashboards Kubernetes