sih — ESP32 simulation

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

Components

Sketch code

#include <Wire.h>
#include <WiFi.h>
#include <PubSubClient.h>
#include <Adafruit_BME280.h>
#include <Adafruit_SSD1306.h>



void setNormalMode();
void setStormMode();
void mqttCommandCallback(
    char* topic,
    byte* payload,
    unsigned int length
);




float waterTemp = 0.0;
float airTemp = 0.0;
float humidity = 0.0;
float pressure = 0.0;

float accelX = 0.0;
float accelY = 0.0;
float accelZ = 0.0;

float gyroX = 0.0;
float gyroY = 0.0;
float gyroZ = 0.0;



String currentMode = "NORMAL";

float windSpeed = 10.0;
float waveHeight = 2.0;
float salinity = 33.0;
float iceConcentration = 60.0;
float currentSpeed = 0.8;


// ============================================================
// BUOY POSITION
// ============================================================

float buoyLatitude = -60.000000;
float buoyLongitude = 20.000000;


// ============================================================
// BATTERY
// ============================================================

float batteryPercent = 95.0;


// ============================================================
// TARGET ENVIRONMENT VALUES
// ============================================================

float targetWind = 10.0;
float targetWave = 2.0;
float targetSalinity = 33.0;
float targetIce = 60.0;
float targetCurrent = 0.8;

float targetBatteryDrain = 0.02;


// ============================================================
// WI-FI + MQTT
// ============================================================

const char* WIFI_SSID = "Velxio-GUEST";

const char* MQTT_BROKER =
    "test.mosquitto.org";

const int MQTT_PORT = 1883;


// Telemetry topic
const char* MQTT_TOPIC =
    "polarsenseai/buoy/telemetry";


// Command topic
const char* MQTT_COMMAND_TOPIC =
    "polarsenseai/buoy/command";


const char* MQTT_CLIENT_ID =
    "POLARSENSE-POLAR-001";


WiFiClient wifiClient;

PubSubClient mqttClient(
    wifiClient
);


unsigned long lastMqttReconnectAttempt = 0;


// ============================================================
// OLED
// ============================================================

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define OLED_ADDRESS 0x3C

Adafruit_SSD1306 display(
    SCREEN_WIDTH,
    SCREEN_HEIGHT,
    &Wire,
    OLED_RESET
);


// ============================================================
// BME280
// ============================================================

Adafruit_BME280 bme;


// ============================================================
// NTC
// ============================================================

#define NTC_PIN 33


// ============================================================
// MPU6050
// ============================================================

#define MPU_ADDR 0x68


// ============================================================
// UTILITY
// ============================================================

float moveToward(
    float current,
    float target,
    float amount
) {

    if (current < tar

More projects by dronrajdas