Esp 5 — ESP32 simulation

An interactive ESP32 circuit simulation you can run free in your browser on Velxio, by jnk.

Components

Sketch code

#include <WiFi.h>
#include <PubSubClient.h>

const char* WIFI_SSID = "Velxio-GUEST";
const char* WIFI_PASS = "";
const char* MQTT_SERVER = "broker.emqx.io";
const char* CMD_TOPIC = "janak_waterpump_2026/command";
const char* STATUS_TOPIC = "janak_waterpump_2026/status";

const int LOW_PIN = 25;
const int HIGH_PIN = 26;

const unsigned long INTERVAL = 2000;
const unsigned long RECONNECT = 3000;

WiFiClient wifiClient;
PubSubClient mqtt(wifiClient);

bool pumpRequest = false;
bool lastLow = false;
bool lastHigh = false;

unsigned long lastCommand = 0;
unsigned long lastPing = 0;
unsigned long lastWiFi = 0;
unsigned long lastMQTT = 0;

void callback(char* topic, byte* payload, unsigned int len) {
  String msg = "";

    for (unsigned int i = 0; i < len; i++) {
        msg += (char)payload[i];
          }

            Serial.println("PUMP STATUS: " + msg);
            }

            void connectWiFi() {
              if (WiFi.status() == WL_CONNECTED ||
                    millis() - lastWiFi < RECONNECT) {
                        return;
                          }

                            lastWiFi = millis();
                              WiFi.begin(WIFI_SSID, WIFI_PASS);
                                Serial.println("WiFi connecting...");
                                }

                                void connectMQTT() {
                                  if (WiFi.status() != WL_CONNECTED ||
                                        mqtt.connected() ||
                                              millis() - lastMQTT < RECONNECT) {
                                                  return;
                                                    }

                                                      lastMQTT = millis();

                                                        if (mqtt.connect("TANK_ESP32_JANAK_2026")) {
                                                            Serial.println("MQTT connected");
                                                                mqtt.subscribe(STATUS_TOPIC);
                                                                  }
                                                                    else {
                                                                        Serial.print("MQTT failed: ");
                                                                            Serial.println(mqtt.state());
                                                                              }
                                                                              }

                                                                              void sendCommand(bool on) {
                                                                                if (!mqtt.connected()) return;

                                                                                  const char* msg = on ? "PUMP_ON" : "PUMP_OFF";

                                                                                    mqtt.publish(C

More projects by jnk