Ryan Malloy 4c91fd4811 ESP32 ST-4 autoguider library with thread-safe pulse guiding
Port of arduino-st4 (Kevin Ferrare) to ESP32/PlatformIO with:
- FreeRTOS mutex protection at every layer (Pin, Axis, Pulse, Controller)
- Hardware timer pulse guiding with ISR-safe deferred stop pattern
- Backward-compatible serial protocol (57600 baud, #-terminated)
- Extended commands: PULSE, POS?, SYNC, STATUS?, VERSION?
- Optional WiFi/WebSocket control (gated by ST4_WIFI_ENABLED)
- Dead-reckoning position tracker using esp_timer microsecond precision

All 4 examples build clean against esp32dev target.
2026-02-17 19:46:03 -07:00

60 lines
1.4 KiB
C++

// ST4-ESP32 WiFi Control Example
// Creates a WiFi AP with WebSocket server for wireless autoguiding
//
// Connect to WiFi AP, then open WebSocket at ws://<IP>/ws
// JSON commands:
// {"cmd":"move","axis":"ra","dir":"+"}
// {"cmd":"pulse","axis":"dec","dir":"-","ms":500}
// {"cmd":"stop"}
// {"cmd":"sync","ra":12.345,"dec":45.678}
// {"cmd":"status"}
//
// State broadcasts are sent automatically on direction changes
// and periodically during active slew
#ifndef ST4_WIFI_ENABLED
#define ST4_WIFI_ENABLED
#endif
#include <ST4.h>
ST4Controller controller;
ST4Serial st4Serial;
ST4WiFi st4WiFi;
const char* WIFI_SSID = "ST4-Guider";
const char* WIFI_PASS = "st4guide!";
void setup() {
Serial.begin(115200);
Serial.println("ST4 WiFi Control");
controller.begin(
ST4_PIN_RA_PLUS, ST4_PIN_RA_MINUS,
ST4_PIN_DEC_PLUS, ST4_PIN_DEC_MINUS,
ST4_PIN_LED
);
st4Serial.begin(controller, Serial);
ST4WiFiConfig wifiConfig = {
.ssid = WIFI_SSID,
.password = WIFI_PASS,
.apMode = true,
.httpPort = 80,
.broadcastIntervalMs = 250
};
st4WiFi.begin(controller, wifiConfig);
controller.connect();
Serial.println("WiFi AP: " + String(WIFI_SSID));
Serial.print("WebSocket: ws://");
Serial.print(WiFi.softAPIP());
Serial.println("/ws");
}
void loop() {
st4Serial.update();
st4WiFi.update();
}