Garden railway wifi remote

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. :slight_smile:

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();
}

Tried. Failed. Please read the forum guide in the sticky post at the top of the forum section to find out how to post code correctly on the forum. You might learn some other important do's and dont's before it's too late.

2 Likes

You spelled "powder" incorrectly.

softap and server

#include <WiFi.h>
#include <WebServer.h>

const char* ssid = "ballslap";
const char* password = "talcpowe";
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();
}

i posted the code wrong?

guess it is already too late. lol

good luck people.

pimp out.

Where was I inaccurate?

Back in the day there were poles along the tracks with red and green lights for stop and go. The same red and green bulb leds also work as red and green light detectors! The train engine could see green with no red as go else stop. For speed control, flash green and or red like PWM.

If the poles sense adjacent train that light should be red both ways along that track.

1 Like
 String currentLine = "1234";
  int myInt = currentLine.toInt();

good luck.. ~q

1 Like

i like that idea a whole bunch.
i have a big ol' box of ho scale slot cars. i had a similar thought for controlling them a while back. flashing leds can do a lot. :slight_smile:

thanks!

ps-

before you ask i should say that i had designed some servo-switched roadway plates. the street lights were just to communicate with the cars as there would likely be one in close reach at all times. not to control the cars directly.

i can work with that.

thanks!

1 Like

Not much room in a slot car. How about smart track that senses the car and PWM's power to the track using FETs? Hall sensors under the track might work but the car won't sense the same with the motor is off where IR-reflect or block are pretty sure things, if the pin can be sensed under the track then it's easier to hide.

Ever used Sculpey to make figures for a layout? It's a modeling clay that sets at around 350F.

Consider IR-remote control with Arduino as a cheap alternative to radio.

integers -- bytes, chars, words, ints, longs and long longs are all binary.

ASCII is just char values (signed 8 bit, -128 to 127) that translate to symbols like letters and numerals. In code, '9' compiles as ASCII 9 the value 57. If I subtract ASCII 0 (48) from ASCII 9 I get the value 9.

char x = '7'; // x == 55
int y = x - '0'; // ASCII digit minus '0' gives the integer value.

char txt = 'T';
if ( txt >= 'A' && txt <= 'Z' ) // check if txt is a capital letter

You can read serial chars or chars from strings (avoid Strings on Arduino!) and build values from text the same way you learned numbers in school.

In code you start with a variable to accumulate a total, set to 0.
And then for every digit 0 to 9 you do the same;

total = total x 10 // moves the digits up one decimal place
total = total + digit (text - '0') // fills the new decimal place

and when a non-digit is read, total holds the value.

1 Like

holy carp.

you clowns redacted ballslap.
it isn't even a word.

honest, who is that weak?

sweet moses you boys are soft around here.
soft. like warm butter.
soft.
soft.
soft.

It wasn't redacted for being rude, it was redacted because it's your WiFi credentials, which you should keep secret.

baloney

Have fun with ASCII. Your topic isn't posted so well which has a LOT to do with the responses bvut.... you've been blind so far, ballsmack!

nothing i do i well posted

still gets the answers

ignorance is eternal

for all of us

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.