howdy killers-
title kinda gives it away, but the goal here is to ditch my track power and go remote. ideally for zero money dollar bucks. i had a handful of ziao esp32c3 boards lying about. going to stick an drv8871 driver board on one and set her up as a softap and server. other guy gets a slider pot and acts as the client. leaves a bunch of room to expand. this is just to get something rolling.
i am not a programmer. i am an very nearly an idiot actually. what you are about to see took me two days to get working. the basic code is listed below. try not to get to offended.
i would like to know the best way to pass a pwm value using my current setup. for things like turning things on an off i am fine with filtering the incoming stream with endsWith. i can make that work and that is all i need. lol i don't know how to do that with a pwm value though as the string contains the ascii and not the decimal(?) number that i want.
anywho, i am really easily confused so please keep things basic or point to examples if you can.
Thanks!
softap and server:
#include <WiFi.h>
#include <WebServer.h>
const char* ssid = "redacted";
const char* password = "redacted";
IPAddress local_ip(192,168,4,1);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);
WiFiServer server(80);
void setup() {
Serial.begin(115200);
while (! Serial);
WiFi.softAP(ssid, password);
WiFi.softAPConfig(local_ip, gateway, subnet);
delay(1000);
Serial.println(WiFi.softAPIP());
server.begin();
}
void loop(){
WiFiClient client = server.available();
if (client) {
String currentLine = "";
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
if (c == '\n') {
if (currentLine.length() == 0) {
client.println("OK");
client.println();
break;
} else {
currentLine = "";
}
} else if (c != '\r') {
currentLine += c;
}
Serial.println("");
if (currentLine.endsWith("123")) {
//Serial.println("");
Serial.println("got 123");
//client.println("dips for days");
break;
}
if (currentLine.endsWith("456")) {
//Serial.println("");
Serial.println("got 456");
//client.println("dips for days");
break;
}
}
}
client.stop();
}
}
client:
#include <WiFi.h>
const char* ssid = "ballslap";
const char* password = "talcpowe";
const char* host = "192.168.4.1";
const int port = 80;
int toast = 200;
void setup() {
Serial.begin(115200);
while (! Serial);
Serial.println("got serial");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println(".");
}
Serial.println("got wifi");
}
void loop() {
WiFiClient hub;
if (!hub.connect(host, port)) {
Serial.println("no hub");
delay(3000);
return;
}
//hub.println("GET /11");
hub.println("123");
Serial.println("got through");
Serial.println("123");
delay(5000);
hub.stop();
}