Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/soypat/ether-swtch
Low level Ethernet stack marshaller/unmarshaller for use in tiny places.
https://github.com/soypat/ether-swtch
Last synced: about 2 months ago
JSON representation
Low level Ethernet stack marshaller/unmarshaller for use in tiny places.
- Host: GitHub
- URL: https://github.com/soypat/ether-swtch
- Owner: soypat
- License: bsd-2-clause
- Archived: true
- Created: 2021-06-26T22:45:33.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-27T23:11:50.000Z (about 1 year ago)
- Last Synced: 2024-05-01T16:22:11.771Z (9 months ago)
- Language: Go
- Size: 227 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-tinygo - ether-swtch - Low level Ethernet/IP/TCP/HTTP stack marshaller/unmarshaller for use in tiny places. (Embedded Systems / Protocol implementations)
README
# Archived
No longer maintained.See seqs for a proper TCP/IP stack implementation: https://github.com/soypat/seqs
# ether-swtch
Low level Ethernet/IP/TCP/HTTP stack marshaller/unmarshaller for use in tiny places.Below is an example of an HTTP server for the ENC28J60 integrated circuit using TinyGo. Works on the Arduino Mega 2560. Use build tag `-tags=noheap` to reduce heap allocations.
```go
package mainimport (
"net"swtch "github.com/soypat/ether-swtch"
"github.com/soypat/ether-swtch/hex"
)func main() {
var (
// SPI Chip select pin. Can be any Digital pin.
spiCS = machine.D53
MAC = net.HardwareAddr{0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xFF}
MyIP = net.IP{192, 168, 1, 5} //static setup is the only one available
)// Configure writer/reader integrated circuit.
dev := enc28j60.New(spiCS, machine.SPI0)err := dev.Init(MAC)
if err != nil {
println(err.Error())
}
const okHeader = "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"
timeout := time.Second * 1
// Spin up HTTP server which responds with "Hello world!"
swtch.HTTPListenAndServe(dev, MAC, MyIP, timeout, func(URL []byte) (response []byte) {
return []byte(okHeader + "Hello world!")
}, printNonNilErr)
}func printNonNilErr(err error) {
if err != nil {
println(err.Error())
}
}
```With `noheap` build tag enabled the above program consumes the following memory
```
code data bss | flash ram
22278 765 856 | 23043 1621
```
The program should be small enough to run on the Arduino UNO as well (2k sram, 32k flash).