{"id":13494211,"url":"https://github.com/tinygo-org/drivers","last_synced_at":"2025-05-15T00:06:50.072Z","repository":{"id":39666382,"uuid":"157855967","full_name":"tinygo-org/drivers","owner":"tinygo-org","description":"TinyGo drivers for sensors, displays, wireless adaptors, and other devices that use I2C, SPI, GPIO, ADC, and UART interfaces.","archived":false,"fork":false,"pushed_at":"2025-04-30T18:18:26.000Z","size":6845,"stargazers_count":656,"open_issues_count":143,"forks_count":209,"subscribers_count":21,"default_branch":"release","last_synced_at":"2025-05-09T07:51:31.600Z","etag":null,"topics":["adxl345","apa102","blinkm","bmp180","dotstar","ds3231","embedded","esp8266","gpio","hacktoberfest","i2c","lorawan","mag3110","mma8653","mpu6050","neopixels","sensors","spi","tinygo","ws2812"],"latest_commit_sha":null,"homepage":"https://tinygo.org","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tinygo-org.png","metadata":{"files":{"readme":"README-net.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"open_collective":"tinygo"}},"created_at":"2018-11-16T11:06:12.000Z","updated_at":"2025-05-07T16:53:24.000Z","dependencies_parsed_at":"2023-02-17T00:01:22.488Z","dependency_job_id":"a30fdbaa-95f0-46ad-acd7-8d934a585b0a","html_url":"https://github.com/tinygo-org/drivers","commit_stats":{"total_commits":661,"total_committers":83,"mean_commits":7.963855421686747,"dds":0.6127080181543116,"last_synced_commit":"1bf1a11067968352afa5d7a489a13561effb2146"},"previous_names":["tinygo-org/tinygo-drivers","aykevl/tinygo-drivers"],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinygo-org%2Fdrivers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinygo-org%2Fdrivers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinygo-org%2Fdrivers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinygo-org%2Fdrivers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinygo-org","download_url":"https://codeload.github.com/tinygo-org/drivers/tar.gz/refs/heads/release","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254249198,"owners_count":22039029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adxl345","apa102","blinkm","bmp180","dotstar","ds3231","embedded","esp8266","gpio","hacktoberfest","i2c","lorawan","mag3110","mma8653","mpu6050","neopixels","sensors","spi","tinygo","ws2812"],"created_at":"2024-07-31T19:01:22.901Z","updated_at":"2025-05-15T00:06:50.027Z","avatar_url":"https://github.com/tinygo-org.png","language":"Go","readme":"### Table of Contents\n\n- [\"net\" Package](#net-package)\n- [Using \"net\" Package](#using-net-package)\n- [Using \"net/http\" Package](#using-nethttp-package)\n- [Using \"crypto/tls\" Package](#using-cryptotls-package)\n- [Using Sockets](#using-sockets)\n\n## \"net\" Package\n\nTinyGo's \"net\" package is ported from Go.  The port offers a subset of Go's\n\"net\" package.  The subset maintains Go 1 compatiblity guarantee.  A Go\napplication that uses \"net\" will most-likey just work on TinyGo if the usage is\nwithin the subset offered.  (There may be external constraints such as limited\nSRAM on some targets that may limit full \"net\" functionality).\n\nContinue below for details on using \"net\" and \"net/http\" packages.\n\nSee src/net/READMD.md in the TinyGo repo for more details on maintaining\nTinyGo's \"net\" package.\n\n## Using \"net\" Package\n\nIdeally, TinyGo's \"net\" package would be Go's \"net\" package and applications\nusing \"net\" would just work, as-is.  TinyGo's net package is a partial port of\nGo's net package, so some things may not work because they have not been\nported.\n\nThere are a few features excluded during the porting process, in particular:\n\n- No IPv6 support\n- No DualStack support\n\nRun ```go doc -all ./src/net``` in TinyGo repo to see full listing of what has\nbeen ported.  Here is a list of things known to work.  You can find examples\nof these at [examples/net](examples/net/).\n\n### What is Known to Work\n\n(These are all IPv4 only).\n\n- TCP client and server\n- UDP client\n- TLS client\n- HTTP client and server\n- HTTPS client\n- NTP client (UDP)\n- MQTT client (paho \u0026 natiu)\n- WebSocket client and server\n\nMultiple sockets can be opened in a single app.  For example, the app could run\nas an http server listen on port :80 and also use NTP to get the current time\nor send something over MQTT.  There is a practical limit to the number of\nactive sockets per app, around 8 or 10, so don't go crazy.\n\nApplications using Go's net package will need a few setup steps to work with\nTinyGo's net package.  The steps are required before using \"net\".\n\n### Step 1: Probe to Load Network Driver\n\nCall Probe() to load the correct network driver for your target.  Probe()\nallows the app to work on multiple targets.\n\n```go\npackage main\n\nimport (\n\t\"tinygo.org/x/drivers/netlink/probe\"\n)\n\nfunc main() {\n\n\t// load network driver for target\n\tlink, dev := probe.Probe()\n\n\t...\t\n}\n```\n\nProbe() will load the driver with default configuration for the target.  For\ncustom configuration, the app can open code Probe() for the target\nrequirements.\n\nProbe() returns a [Netlinker](netlink/README.md) and a\n[Netdever](netdev/README.md), interfaces implemented by the network driver.\nNext, we'll use the Netlinker interface to connect the target to an IP network.\n\n### Step 2: Connect to an IP Network\n\nBefore the net package is fully functional, we need to connect the target to an\nIP network.\n\n```go\npackage main\n\nimport (\n\t\"tinygo.org/x/drivers/netlink\"\n\t\"tinygo.org/x/drivers/netlink/probe\"\n)\n\nfunc main() {\n\n\t// load network driver for target\n\tlink, _ := probe.Probe()\n\n\t// Connect target to IP network\n\tlink.NetConnect(\u0026netlink.ConnectParams{\n\t\tSsid:       \"my SSID\",\n\t\tPassphrase: \"my passphrase\",\n\t})\n\n\t// OK to use \"net\" from here on\n\t...\t\n}\n```\n\nOptionally, get notified of IP network connects and disconnects:\n\n```go\n\tlink.Notify(func(e netlink.Event) {\n\t\tswitch e {\n\t\tcase netlink.EventNetUp:   println(\"Network UP\")\n\t\tcase netlink.EventNetDown: println(\"Network DOWN\")\n\t})\n```\n\nHere is an example of an http server listening on port :8080:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\n\t\"tinygo.org/x/drivers/netlink\"\n\t\"tinygo.org/x/drivers/netlink/probe\"\n)\n\nfunc HelloServer(w http.ResponseWriter, r *http.Request) {\n\tfmt.Fprintf(w, \"Hello, %s!\", r.URL.Path[1:])\n}\n\nfunc main() {\n\n\t// load network driver for target\n\tlink, _ := probe.Probe()\n\n\t// Connect target to IP network\n\tlink.NetConnect(\u0026netlink.ConnectParams{\n\t\tSsid:       \"my SSID\",\n\t\tPassphrase: \"my passphrase\",\n\t})\n\n\t// Serve it up\n\thttp.HandleFunc(\"/\", HelloServer)\n\thttp.ListenAndServe(\":8080\", nil)\n}\n```\n\n## Using \"net/http\" Package\n\nTinyGo's net/http package is a partial port of Go's net/http package, providing\na subset of the full net/http package.  There are a few features excluded\nduring the porting process, in particular:\n\n- No HTTP/2 support\n- No TLS support for HTTP servers (no https servers)\n- HTTP client request can't be reused\n\nHTTP client methods (http.Get, http.Head, http.Post, and http.PostForm) are\nfunctional.  Dial clients support both HTTP and HTTPS URLs.\n\nHTTP server methods and objects are mostly ported, but for HTTP only; HTTPS\nservers are not supported.\n\nHTTP request and response handling code is mostly ported, so most the intricacy\nof parsing and writing headers is handled as in the full net/http package.\n\nRun ```go doc -all ./src/net/http``` in TinyGo repo to see full listing.\n\n## Using \"crypto/tls\" Package\n\nTinyGo's TLS support (crypto/tls) relies on hardware offload of the TLS\nprotocol.  This is different from Go's crypto/tls package which handles the TLS\nprotocol in software.\n\nTinyGo's TLS support is only available for client applications.  You can\nhttp.Get() to an https:// address, but you cannot http.ListenAndServeTLS() an\nhttps server.\n\nThe offloading hardware has pre-defined TLS certificates built-in.\n\n## Using Sockets\n\nThe Netdever interface is a BSD socket-like interface so an application can make direct\nsocket calls, bypassing the \"net\" package for the lowest overhead.\n\nHere is a simple TCP client application using direct sockets:\n\n```go\npackage main\n\nimport (\n\t\"net\"  // only need to parse IP address\n\n\t\"tinygo.org/x/drivers/netdev\"\n\t\"tinygo.org/x/drivers/netlink\"\n\t\"tinygo.org/x/drivers/netlink/probe\"\n)\n\nfunc main() {\n\n\t// load network driver for target\n\tlink, dev := probe.Probe()\n\n\t// Connect target to IP network\n\tlink.NetConnect(\u0026netlink.ConnectParams{\n\t\tSsid:       \"my SSID\",\n\t\tPassphrase: \"my passphrase\",\n\t})\n\n\t// omit error handling\n\n\tsock, _ := dev.Socket(netdev.AF_INET, netdev.SOCK_STREAM, netdev.IPPROTO_TCP)\n\n        dev.Connect(sock, \"\", net.ParseIP(\"10.0.0.100\"), 8080)\n\tdev.Send(sock, []bytes(\"hello\"), 0, 0)\n\n\tdev.Close(sock)\n\tlink.NetDisconnect()\n}\n```\n","funding_links":["https://opencollective.com/tinygo"],"categories":["Go","Embedded Systems"],"sub_categories":["General use"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinygo-org%2Fdrivers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinygo-org%2Fdrivers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinygo-org%2Fdrivers/lists"}