Simple webserver in go
- Better Makefile - Added basic dependencies in the Makefile
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1,3 @@
|
||||
build/
|
||||
.cache/
|
||||
sdkconfig*
|
||||
|
||||
6
Makefile
Normal file
6
Makefile
Normal file
@@ -0,0 +1,6 @@
|
||||
monitor:
|
||||
idf.py -p /dev/ttyUSB0 flash monitor
|
||||
env:
|
||||
nix --experimental-features 'nix-command flakes' develop github:mirrexagon/nixpkgs-esp-dev#esp32-idf
|
||||
server:
|
||||
go run main.go
|
||||
8
dependencies.lock
Normal file
8
dependencies.lock
Normal file
@@ -0,0 +1,8 @@
|
||||
dependencies:
|
||||
idf:
|
||||
source:
|
||||
type: idf
|
||||
version: 5.5.1
|
||||
manifest_hash: 0938fe5fc43e8ea0c6dda60b9f593e186303cb1b17412f4d696784db8099a7e9
|
||||
target: esp32
|
||||
version: 2.0.0
|
||||
36
main.go
Normal file
36
main.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func handler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "POST only", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
http.Error(w, "read error", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
defer r.Body.Close()
|
||||
|
||||
fmt.Println("Received:", string(body))
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("ok"))
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/data", handler)
|
||||
|
||||
addr := ":8080"
|
||||
log.Println("Listening on", addr)
|
||||
log.Fatal(http.ListenAndServe(addr, nil))
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
idf_component_register(SRCS "station_example_main.c"
|
||||
PRIV_REQUIRES esp_wifi nvs_flash
|
||||
PRIV_REQUIRES esp_wifi nvs_flash esp_adc
|
||||
INCLUDE_DIRS ".")
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <math.h>
|
||||
|
||||
#include "esp_adc/adc_continuous.h"
|
||||
#include "esp_adc/adc_cali.h"
|
||||
|
||||
|
||||
/* The examples use WiFi configuration that you can set via project configuration menu
|
||||
|
||||
|
||||
Reference in New Issue
Block a user