Minimized and with real time in the plots
This commit is contained in:
9
.gitignore
vendored
9
.gitignore
vendored
@@ -1,4 +1,9 @@
|
||||
# Artifacts
|
||||
build/
|
||||
.cache/
|
||||
sdkconfig*
|
||||
data/
|
||||
|
||||
# Dont leak wifi password to git database
|
||||
sdkconfig
|
||||
sdkconfig.old
|
||||
|
||||
.cache/
|
||||
|
||||
19
main.go
19
main.go
@@ -12,6 +12,7 @@ import (
|
||||
)
|
||||
|
||||
var dataFile *os.File
|
||||
var startTime time.Time
|
||||
|
||||
type VoltageData struct {
|
||||
Voltage float64 `json:"voltage"`
|
||||
@@ -24,7 +25,7 @@ func initDataFile() {
|
||||
}
|
||||
|
||||
// Generate a filename with timestamp
|
||||
filename := filepath.Join("data", fmt.Sprintf("voltages_%s.txt", time.Now().Format("20060102_150405")))
|
||||
filename := filepath.Join("data", fmt.Sprintf("voltages_%s.csv", time.Now().Format("20060102_150405")))
|
||||
file, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to open data file: %v", err)
|
||||
@@ -32,6 +33,11 @@ func initDataFile() {
|
||||
|
||||
dataFile = file
|
||||
log.Printf("Logging voltage data to %s\n", filename)
|
||||
|
||||
// Write CSV header
|
||||
_, _ = dataFile.WriteString("time_s,voltage\n")
|
||||
|
||||
startTime = time.Now()
|
||||
}
|
||||
|
||||
func handler(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -54,12 +60,15 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Print voltage to console
|
||||
fmt.Println("Received voltage:", v.Voltage)
|
||||
// Compute relative time
|
||||
relTime := time.Since(startTime).Seconds()
|
||||
|
||||
// Append voltage number to file
|
||||
// Print voltage to console
|
||||
fmt.Printf("Received voltage: %f at time %.3f s\n", v.Voltage, relTime)
|
||||
|
||||
// Append CSV line to file
|
||||
if dataFile != nil {
|
||||
if _, err := dataFile.WriteString(fmt.Sprintf("%f\n", v.Voltage)); err != nil {
|
||||
if _, err := dataFile.WriteString(fmt.Sprintf("%.3f,%.6f\n", relTime, v.Voltage)); err != nil {
|
||||
log.Printf("Failed to write to file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
menu "Example Configuration"
|
||||
|
||||
menu "Setup wifi"
|
||||
config ESP_WIFI_SSID
|
||||
string "WiFi SSID"
|
||||
default "myssid"
|
||||
@@ -11,59 +10,4 @@ menu "Example Configuration"
|
||||
default "mypassword"
|
||||
help
|
||||
WiFi password (WPA or WPA2) for the example to use.
|
||||
|
||||
choice ESP_WIFI_SAE_MODE
|
||||
prompt "WPA3 SAE mode selection"
|
||||
default ESP_STATION_EXAMPLE_WPA3_SAE_PWE_BOTH
|
||||
help
|
||||
Select mode for SAE as Hunt and Peck, H2E or both.
|
||||
config ESP_STATION_EXAMPLE_WPA3_SAE_PWE_HUNT_AND_PECK
|
||||
bool "HUNT AND PECK"
|
||||
config ESP_STATION_EXAMPLE_WPA3_SAE_PWE_HASH_TO_ELEMENT
|
||||
bool "H2E"
|
||||
depends on ESP_WIFI_ENABLE_SAE_H2E
|
||||
config ESP_STATION_EXAMPLE_WPA3_SAE_PWE_BOTH
|
||||
bool "BOTH"
|
||||
depends on ESP_WIFI_ENABLE_SAE_H2E
|
||||
endchoice
|
||||
|
||||
config ESP_WIFI_PW_ID
|
||||
string "PASSWORD IDENTIFIER"
|
||||
depends on ESP_STATION_EXAMPLE_WPA3_SAE_PWE_HASH_TO_ELEMENT|| ESP_STATION_EXAMPLE_WPA3_SAE_PWE_BOTH
|
||||
default ""
|
||||
help
|
||||
password identifier for SAE H2E
|
||||
|
||||
config ESP_MAXIMUM_RETRY
|
||||
int "Maximum retry"
|
||||
default 5
|
||||
help
|
||||
Set the Maximum retry to avoid station reconnecting to the AP unlimited when the AP is really inexistent.
|
||||
|
||||
choice ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD
|
||||
prompt "WiFi Scan auth mode threshold"
|
||||
default ESP_WIFI_AUTH_WPA2_PSK
|
||||
help
|
||||
The weakest authmode to accept in the scan mode.
|
||||
This value defaults to ESP_WIFI_AUTH_WPA2_PSK in case password is present and ESP_WIFI_AUTH_OPEN is used.
|
||||
Please select ESP_WIFI_AUTH_WEP/ESP_WIFI_AUTH_WPA_PSK in case AP is operating in WEP/WPA mode.
|
||||
|
||||
config ESP_WIFI_AUTH_OPEN
|
||||
bool "OPEN"
|
||||
config ESP_WIFI_AUTH_WEP
|
||||
bool "WEP"
|
||||
config ESP_WIFI_AUTH_WPA_PSK
|
||||
bool "WPA PSK"
|
||||
config ESP_WIFI_AUTH_WPA2_PSK
|
||||
bool "WPA2 PSK"
|
||||
config ESP_WIFI_AUTH_WPA_WPA2_PSK
|
||||
bool "WPA/WPA2 PSK"
|
||||
config ESP_WIFI_AUTH_WPA3_PSK
|
||||
bool "WPA3 PSK"
|
||||
config ESP_WIFI_AUTH_WPA2_WPA3_PSK
|
||||
bool "WPA2/WPA3 PSK"
|
||||
config ESP_WIFI_AUTH_WAPI_PSK
|
||||
bool "WAPI PSK"
|
||||
endchoice
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
/* ===================== CONSTS ===================== */
|
||||
|
||||
#define SERVER_URL "http://192.168.178.157:8080/data"
|
||||
#define RMS_WINDOW_MS 300
|
||||
#define RMS_WINDOW_MS 200
|
||||
#define CHANNEL ADC_CHANNEL_6
|
||||
|
||||
// TODO: Determine this
|
||||
@@ -38,7 +38,6 @@
|
||||
#define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
|
||||
|
||||
#define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_BOTH
|
||||
#define EXAMPLE_H2E_IDENTIFIER CONFIG_ESP_WIFI_PW_ID
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK
|
||||
|
||||
// Tag for logging
|
||||
@@ -117,7 +116,6 @@ void wifi_init_sta(void)
|
||||
*/
|
||||
.threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD,
|
||||
.sae_pwe_h2e = ESP_WIFI_SAE_MODE,
|
||||
.sae_h2e_identifier = EXAMPLE_H2E_IDENTIFIER,
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) );
|
||||
|
||||
13
plot.py
13
plot.py
@@ -3,10 +3,9 @@ import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
DATA_DIR = "data"
|
||||
SAMPLE_INTERVAL_MS = 300 # time between measurements in milliseconds
|
||||
|
||||
# Find the latest data file
|
||||
files = [f for f in os.listdir(DATA_DIR) if f.startswith("voltages_") and f.endswith(".txt")]
|
||||
files = [f for f in os.listdir(DATA_DIR) if f.startswith("voltages_") and f.endswith(".csv")]
|
||||
if not files:
|
||||
raise FileNotFoundError("No voltage data files found in 'data/'")
|
||||
|
||||
@@ -14,11 +13,10 @@ latest_file = max(files, key=lambda f: os.path.getmtime(os.path.join(DATA_DIR, f
|
||||
filepath = os.path.join(DATA_DIR, latest_file)
|
||||
print(f"Plotting data from {filepath}")
|
||||
|
||||
# Load voltage values
|
||||
voltages = np.loadtxt(filepath)
|
||||
|
||||
# Create time axis (in seconds)
|
||||
times = np.arange(len(voltages)) * (SAMPLE_INTERVAL_MS / 1000.0)
|
||||
# Load CSV data (skip header)
|
||||
data = np.loadtxt(filepath, delimiter=",", skiprows=1)
|
||||
times = data[:, 0]
|
||||
voltages = data[:, 1]
|
||||
|
||||
# Plot
|
||||
plt.figure(figsize=(10, 5))
|
||||
@@ -29,3 +27,4 @@ plt.title(f"Voltage Measurements ({latest_file})")
|
||||
plt.grid(True)
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user